From 6a66f46d4b416ce3408f8d938032d8b95265b1bb Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 6 Apr 2017 18:15:50 +0200 Subject: Map string keys to MySQL VARCHAR(128) instead of 255 to support 4-byte UTF-8 This is a backwards-incompatible change in that it may change your schema. To obtain the old behavior you will have to explicitly re-map std::string with the id_type pragma or explicitly specify the database type for each affected id member with the type pragma. --- doc/manual.xhtml | 42 ++++++++++++++++++++-------------------- odb/relational/mysql/context.cxx | 2 +- odb/relational/mysql/schema.cxx | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/doc/manual.xhtml b/doc/manual.xhtml index 074dbdc..4a9e2a0 100644 --- a/doc/manual.xhtml +++ b/doc/manual.xhtml @@ -6724,11 +6724,11 @@ class employee
 CREATE TABLE employer (
-  name VARCHAR (255) NOT NULL PRIMARY KEY);
+  name VARCHAR (128) NOT NULL PRIMARY KEY);
 
 CREATE TABLE employee (
   id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
-  employer VARCHAR (255) NOT NULL REFERENCES employer (name));
+  employer VARCHAR (128) NOT NULL REFERENCES employer (name));
   

6.1.2 To-Many Relationships

@@ -6765,14 +6765,14 @@ class employee
 CREATE TABLE project (
-  name VARCHAR (255) NOT NULL PRIMARY KEY);
+  name VARCHAR (128) NOT NULL PRIMARY KEY);
 
 CREATE TABLE employee (
   id BIGINT UNSIGNED NOT NULL PRIMARY KEY);
 
 CREATE TABLE employee_projects (
   object_id BIGINT UNSIGNED NOT NULL,
-  value VARCHAR (255) NOT NULL REFERENCES project (name));
+  value VARCHAR (128) NOT NULL REFERENCES project (name));
   

To obtain a more canonical database schema, the names of tables @@ -6797,7 +6797,7 @@ class employee

 CREATE TABLE employee_projects (
   employee_id BIGINT UNSIGNED NOT NULL,
-  project_name VARCHAR (255) NOT NULL REFERENCES project (name));
+  project_name VARCHAR (128) NOT NULL REFERENCES project (name));
   
@@ -7101,11 +7101,11 @@ class employee
 CREATE TABLE employer (
-  name VARCHAR (255) NOT NULL PRIMARY KEY);
+  name VARCHAR (128) NOT NULL PRIMARY KEY);
 
 CREATE TABLE employee (
   id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
-  employer VARCHAR (255) NOT NULL REFERENCES employer (name));
+  employer VARCHAR (128) NOT NULL REFERENCES employer (name));
   

If instead the many side (employee) of this @@ -7114,10 +7114,10 @@ CREATE TABLE employee (

 CREATE TABLE employer (
-  name VARCHAR (255) NOT NULL PRIMARY KEY);
+  name VARCHAR (128) NOT NULL PRIMARY KEY);
 
 CREATE TABLE employer_employees (
-  object_id VARCHAR (255) NOT NULL REFERENCES employer (name),
+  object_id VARCHAR (128) NOT NULL REFERENCES employer (name),
   value BIGINT UNSIGNED NOT NULL REFERENCES employee (id));
 
 CREATE TABLE employee (
@@ -7163,14 +7163,14 @@ class employee
 
   
 CREATE TABLE project (
-  name VARCHAR (255) NOT NULL PRIMARY KEY);
+  name VARCHAR (128) NOT NULL PRIMARY KEY);
 
 CREATE TABLE employee (
   id BIGINT UNSIGNED NOT NULL PRIMARY KEY);
 
 CREATE TABLE employee_projects (
   object_id BIGINT UNSIGNED NOT NULL REFERENCES employee (id),
-  value VARCHAR (255) NOT NULL REFERENCES project (name));
+  value VARCHAR (128) NOT NULL REFERENCES project (name));
   

If instead the other side of this relationship is made inverse, @@ -7178,10 +7178,10 @@ CREATE TABLE employee_projects (

 CREATE TABLE project (
-  name VARCHAR (255) NOT NULL PRIMARY KEY);
+  name VARCHAR (128) NOT NULL PRIMARY KEY);
 
 CREATE TABLE project_employees (
-  object_id VARCHAR (255) NOT NULL REFERENCES project (name),
+  object_id VARCHAR (128) NOT NULL REFERENCES project (name),
   value BIGINT UNSIGNED NOT NULL REFERENCES employee (id));
 
 CREATE TABLE employee (
@@ -8594,7 +8594,7 @@ CREATE TABLE temporary_employee (
 CREATE TABLE contractor (
   first TEXT NOT NULL,
   last TEXT NOT NULL,
-  email VARCHAR (255) NOT NULL PRIMARY KEY);
+  email VARCHAR (128) NOT NULL PRIMARY KEY);
   

The complete version of the code presented in this section is @@ -8878,7 +8878,7 @@ t.commit ();

 CREATE TABLE person (
   id BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
-  typeid VARCHAR(255) NOT NULL,
+  typeid VARCHAR(128) NOT NULL,
   first TEXT NOT NULL,
   last TEXT NOT NULL);
 
@@ -15348,7 +15348,7 @@ class person
      example:

-#pragma db value(std::string) type("TEXT") id_type("VARCHAR(128)")
+#pragma db value(std::string) type("TEXT") id_type("VARCHAR(64)")
 
 #pragma db object
 class person
@@ -15356,7 +15356,7 @@ class person
   ...
 
   #pragma db id
-  std::string email_; // Mapped to VARCHAR(128) NOT NULL.
+  std::string email_; // Mapped to VARCHAR(64) NOT NULL.
 
   std::string name_;  // Mapped to TEXT NOT NULL.
 };
@@ -19962,7 +19962,7 @@ person.hxx
 
     
       std::string
-      TEXT/VARCHAR(255)
+      TEXT/VARCHAR(128)
       NOT NULL
     
 
@@ -19982,7 +19982,7 @@ person.hxx
      differently depending on whether a member of this type
      is an object id or not. If the member is an object id,
      then for this member std::string is mapped
-     to the VARCHAR(255) MySQL type. Otherwise,
+     to the VARCHAR(128) MySQL type. Otherwise,
      it is mapped to TEXT.

Additionally, by default, C++ enums and C++11 enum classes are @@ -26105,7 +26105,7 @@ class object QString - TEXT/VARCHAR(255) + TEXT/VARCHAR(128) NULL @@ -26130,7 +26130,7 @@ class object differently depending on whether a member of this type is an object id or not. If the member is an object id, then for this member QString is mapped - to the VARCHAR(255) MySQL type. Otherwise, + to the VARCHAR(128) MySQL type. Otherwise, it is mapped to TEXT.

The basic sub-profile also provides support diff --git a/odb/relational/mysql/context.cxx b/odb/relational/mysql/context.cxx index cf75b12..3893c16 100644 --- a/odb/relational/mysql/context.cxx +++ b/odb/relational/mysql/context.cxx @@ -50,7 +50,7 @@ namespace relational {"float", "FLOAT", 0, false}, {"double", "DOUBLE", 0, false}, - {"::std::string", "TEXT", "VARCHAR(255)", false}, + {"::std::string", "TEXT", "VARCHAR(128)", false}, {"::size_t", "BIGINT UNSIGNED", 0, false}, {"::std::size_t", "BIGINT UNSIGNED", 0, false} diff --git a/odb/relational/mysql/schema.cxx b/odb/relational/mysql/schema.cxx index 5b1ad26..fe29d03 100644 --- a/odb/relational/mysql/schema.cxx +++ b/odb/relational/mysql/schema.cxx @@ -461,7 +461,7 @@ namespace relational pre_statement (); os << "CREATE TABLE IF NOT EXISTS " << qt_ << " (" << endl - << " " << qn_ << " VARCHAR(255) NOT NULL PRIMARY KEY," << endl + << " " << qn_ << " VARCHAR(128) NOT NULL PRIMARY KEY," << endl << " " << qv_ << " BIGINT UNSIGNED NOT NULL," << endl << " " << qm_ << " TINYINT(1) NOT NULL)" << endl; -- cgit v1.1