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 --- odb/relational/mssql/context.cxx | 12 ++++++++++++ odb/relational/mysql/context.cxx | 14 +++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'odb') 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