From 465a4467adec94bb8fe996732ea378664fcf5e86 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 23 Jan 2015 11:40:58 +0200 Subject: Handle SQL name limits in MySQL and SQL Server --- NEWS | 21 +++++++++++++-------- odb/relational/mssql/context.cxx | 12 ++++++++++++ odb/relational/mysql/context.cxx | 14 +++++++++++++- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 49e4aa4..ccbedde 100644 --- a/NEWS +++ b/NEWS @@ -36,16 +36,21 @@ Version 2.4.0 * Support for calling MySQL stored procedures. For details and limitations refer to Section 17.7, "MySQL Stored Procedures" in the ODB manual. - * New option, --statement-regex, can be used to process prepared statement - names that are used by PostgreSQL. This can be useful, for example, to - shorten names that exceed the PostgreSQL name limit. To this effect, ODB - now also warns when an SQL name exceeds the default PostgreSQL limit of - 63 characters. - * New option, --oracle-warn-truncation, makes ODB warn about SQL names that are longer than 30 characters and are therefore truncated. ODB - now also detects when such truncations lead to name conflicts and - issues diagnostics even without this option specified. + now also detects when such truncations lead to Oracle name conflicts + and issues diagnostics even without this option specified. + + * For MySQL, PostgreSQL, and SQL Server, ODB now warns when an SQL name + exceeds the database limit (64, 63, and 128 characters, respectively). + SQLite has no limitation on name lengths. For Oracle, which has a limit + that is much more likely to be reached in normal circumstances (30 + characters), a more comprehensive detection is implemented (see item + above). + + * New option, --statement-regex, can be used to process prepared statement + names that are used by PostgreSQL. This can be useful, for example, to + shorten names that exceed the PostgreSQL name limit. Version 2.3.0 diff --git a/odb/relational/mssql/context.cxx b/odb/relational/mssql/context.cxx index e99cdaf..eac4a95 100644 --- a/odb/relational/mssql/context.cxx +++ b/odb/relational/mssql/context.cxx @@ -133,6 +133,18 @@ namespace relational if (i->empty ()) continue; + // Warn if the name is greater than the 128 limit. + // + if (i->size () > 128) + { + cerr << "warning: SQL name '" << *i << "' is longer than the " + << "SQL Server name limit of 128 characters and will be " + << "truncated" << endl; + + cerr << "info: consider shortening it using #pragma db " + << "table/column/index or --*-regex options" << endl; + } + if (f) f = false; else diff --git a/odb/relational/mysql/context.cxx b/odb/relational/mysql/context.cxx index 4ccb206..945a3a9 100644 --- a/odb/relational/mysql/context.cxx +++ b/odb/relational/mysql/context.cxx @@ -129,13 +129,25 @@ namespace relational if (i->empty ()) continue; + // Warn if the name is greater than the 64 limit. + // + if (i->size () > 64) + { + cerr << "warning: SQL name '" << *i << "' is longer than " + << "the MySQL name limit of 64 characters and will " + << "be truncated" << endl; + + cerr << "info: consider shortening it using #pragma db " + << "table/column/index or --*-regex options" << endl; + } + if (f) f = false; else r += '.'; r += '`'; - r += *i; + r.append (*i, 0, 64); // Max identifier length is 64. r += '`'; } -- cgit v1.1