From b038ab0cd6335f3e4ec075d1e21f5d7bb89e3ffb Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 19 Jul 2011 13:42:18 +0200 Subject: New design for NULL semantics Now, instead of being specified as part of the SQL type with the type pragma, there are separate null and not_null pragmas. The not_null pragma was used to control NULL-ness of object pointers. Now the two pragmas are used consistently for object pointers and simple values (and in the future will work for composite values and containers). --- boost/common/smart-ptr/test.hxx | 2 +- boost/mysql/date-time/test.hxx | 8 ++--- common/lazy-ptr/test.hxx | 4 +-- common/query/test.hxx | 2 +- common/relationship/driver.cxx | 5 +-- mysql/types/test.hxx | 74 ++++++++++++++++++++--------------------- pgsql/types/test.hxx | 40 +++++++++++----------- qt/common/smart-ptr/test.hxx | 2 +- qt/mysql/date-time/test.hxx | 8 ++--- sqlite/types/test.hxx | 12 +++---- 10 files changed, 79 insertions(+), 78 deletions(-) diff --git a/boost/common/smart-ptr/test.hxx b/boost/common/smart-ptr/test.hxx index ea158e7..575c2e2 100644 --- a/boost/common/smart-ptr/test.hxx +++ b/boost/common/smart-ptr/test.hxx @@ -33,7 +33,7 @@ struct cont typedef std::vector > obj_list; - #pragma db inverse(c) not_null + #pragma db inverse(c) value_not_null obj_list o; }; diff --git a/boost/mysql/date-time/test.hxx b/boost/mysql/date-time/test.hxx index 235607f..b84bf0f 100644 --- a/boost/mysql/date-time/test.hxx +++ b/boost/mysql/date-time/test.hxx @@ -37,11 +37,11 @@ struct object std::vector dates; std::vector times; - // Specify NULL explicitly to suppress auto-initialization and - // auto-update characteristics of TIMESTAMP datatype, and to allow - // NULL values. + // Make timestamp NULL-able to suppress the auto-initialization and + // auto-update characteristics of the TIMESTAMP datatype, and to + // allow NULL values. // - #pragma db value_type ("TIMESTAMP NULL") + #pragma db value_type ("TIMESTAMP") value_null std::vector timestamps; std::vector durations; diff --git a/common/lazy-ptr/test.hxx b/common/lazy-ptr/test.hxx index b530316..32f6a43 100644 --- a/common/lazy-ptr/test.hxx +++ b/common/lazy-ptr/test.hxx @@ -38,7 +38,7 @@ public: typedef std::vector > obj_list; - #pragma db not_null + #pragma db value_not_null obj_list o; }; @@ -122,7 +122,7 @@ namespace tr1 typedef std::vector > obj_list; - #pragma db inverse(c) not_null + #pragma db inverse(c) value_not_null obj_list o; }; diff --git a/common/query/test.hxx b/common/query/test.hxx index 124ee72..21acb84 100644 --- a/common/query/test.hxx +++ b/common/query/test.hxx @@ -38,7 +38,7 @@ struct person #pragma db column ("first") std::string first_name_; - #pragma db column ("middle") type ("TEXT") + #pragma db column ("middle") type ("TEXT") null std::auto_ptr middle_name_; #pragma db column ("last") diff --git a/common/relationship/driver.cxx b/common/relationship/driver.cxx index abbae29..3ce7e8c 100644 --- a/common/relationship/driver.cxx +++ b/common/relationship/driver.cxx @@ -46,8 +46,9 @@ main (int argc, char* argv[]) a.v1.push_back (0); a.v1.push_back (new obj1 ("v1 2", "v1 2")); + // Set cannot contain NULL pointers. + // a.s1.insert (new obj1 ("s1 0", "s1 0")); - a.s1.insert (static_cast (0)); // VC 10 a.s1.insert (new obj1 ("s1 2", "s1 2")); a.m1[0] = new obj1 ("m1 0", "m1 0"); @@ -112,7 +113,7 @@ main (int argc, char* argv[]) t.commit (); } - // test NULL pointer + // Test NULL pointer. // delete a.o1; a.o1 = 0; diff --git a/mysql/types/test.hxx b/mysql/types/test.hxx index a4421b3..fa1d7b3 100644 --- a/mysql/types/test.hxx +++ b/mysql/types/test.hxx @@ -77,7 +77,7 @@ operator== (bitfield x, bitfield y) x.d == y.d; } -#pragma db value(bitfield) type ("BIT(4) NOT NULL") +#pragma db value(bitfield) type ("BIT(4)") typedef std::set set; typedef std::auto_ptr string_ptr; @@ -101,126 +101,126 @@ struct object // Integral types. // - #pragma db type ("BOOL NOT NULL") + #pragma db type ("BOOL") bool bool_; - #pragma db type ("TINYINT NOT NULL") + #pragma db type ("TINYINT") signed char schar_; - #pragma db type ("TINYINT UNSIGNED NOT NULL") + #pragma db type ("TINYINT UNSIGNED") unsigned char uchar_; - #pragma db type ("SMALLINT NOT NULL") + #pragma db type ("SMALLINT") short short_; - #pragma db type ("SMALLINT UNSIGNED NOT NULL") + #pragma db type ("SMALLINT UNSIGNED") unsigned short ushort_; - #pragma db type ("MEDIUMINT NOT NULL") + #pragma db type ("MEDIUMINT") int mint_; - #pragma db type ("MEDIUMINT UNSIGNED NOT NULL") + #pragma db type ("MEDIUMINT UNSIGNED") unsigned int umint_; - #pragma db type ("INT NOT NULL") + #pragma db type ("INT") int int_; - #pragma db type ("INT UNSIGNED NOT NULL") + #pragma db type ("INT UNSIGNED") unsigned int uint_; - #pragma db type ("BIGINT NOT NULL") + #pragma db type ("BIGINT") long long long_long_; - #pragma db type ("BIGINT UNSIGNED NOT NULL") + #pragma db type ("BIGINT UNSIGNED") unsigned long long ulong_long_; // Float types. // - #pragma db type ("FLOAT NOT NULL") + #pragma db type ("FLOAT") float float_; - #pragma db type ("FLOAT(32) NOT NULL") + #pragma db type ("FLOAT(32)") double float8_; - #pragma db type ("DOUBLE NOT NULL") + #pragma db type ("DOUBLE") double double_; - #pragma db type ("DECIMAL(6,3) NOT NULL") + #pragma db type ("DECIMAL(6,3)") std::string decimal_; // Data-time types. // - #pragma db type ("DATE NOT NULL") + #pragma db type ("DATE") date_time date_; - #pragma db type ("TIME NOT NULL") + #pragma db type ("TIME") date_time time_; - #pragma db type ("DATETIME NOT NULL") + #pragma db type ("DATETIME") date_time date_time_; - #pragma db type ("TIMESTAMP NOT NULL") + #pragma db type ("TIMESTAMP") date_time timestamp_; - #pragma db type ("YEAR NOT NULL") + #pragma db type ("YEAR") short year_; // String and binary types. // - #pragma db type ("CHAR(128) NOT NULL") + #pragma db type ("CHAR(128)") std::string char_; - #pragma db type ("BINARY(128) NOT NULL") + #pragma db type ("BINARY(128)") buffer binary_; - #pragma db type ("VARCHAR(256) NOT NULL") + #pragma db type ("VARCHAR(256)") std::string varchar_; - #pragma db type ("VARBINARY(256) NOT NULL") + #pragma db type ("VARBINARY(256)") buffer varbinary_; - #pragma db type ("TINYTEXT NOT NULL") + #pragma db type ("TINYTEXT") std::string tinytext_; - #pragma db type ("TINYBLOB NOT NULL") + #pragma db type ("TINYBLOB") buffer tinyblob_; - #pragma db type ("TEXT NOT NULL") + #pragma db type ("TEXT") std::string text_; - #pragma db type ("BLOB NOT NULL") + #pragma db type ("BLOB") buffer blob_; - #pragma db type ("MEDIUMTEXT NOT NULL") + #pragma db type ("MEDIUMTEXT") std::string mediumtext_; - #pragma db type ("MEDIUMBLOB NOT NULL") + #pragma db type ("MEDIUMBLOB") buffer mediumblob_; - #pragma db type ("LONGTEXT NOT NULL") + #pragma db type ("LONGTEXT") std::string longtext_; - #pragma db type ("LONGBLOB NOT NULL") + #pragma db type ("LONGBLOB") buffer longblob_; // Other types. // - // #pragma db type ("BIT(4) NOT NULL") - assigned by #pragma db value + // #pragma db type ("BIT(4)") - assigned by #pragma db value bitfield bit_; // Test ENUM representations (integer and string). // color enum_; - #pragma db type ("ENUM ('red', 'green', 'blue') NOT NULL") + #pragma db type ("ENUM ('red', 'green', 'blue')") std::string enum_str_; - #pragma db type ("SET ('red', 'green', 'blue') NOT NULL") + #pragma db type ("SET ('red', 'green', 'blue')") set set_; // Test NULL value. // - #pragma db type ("TEXT") + #pragma db type ("TEXT") null string_ptr null_; bool diff --git a/pgsql/types/test.hxx b/pgsql/types/test.hxx index 8b42aa1..ac1ed11 100644 --- a/pgsql/types/test.hxx +++ b/pgsql/types/test.hxx @@ -70,7 +70,7 @@ operator== (const varbit& x, const varbit& y) return x.compare (y); } -#pragma db value(bitfield) type ("BIT(4) NOT NULL") +#pragma db value(bitfield) type ("BIT(4)") typedef std::auto_ptr string_ptr; @@ -93,66 +93,66 @@ struct object // Integral types. // - #pragma db type ("BOOL NOT NULL") + #pragma db type ("BOOL") bool bool_; - #pragma db type ("SMALLINT NOT NULL") + #pragma db type ("SMALLINT") short short_; - #pragma db type ("INT NOT NULL") + #pragma db type ("INT") int int_; - #pragma db type ("BIGINT NOT NULL") + #pragma db type ("BIGINT") long long long_long_; // Float types. // - #pragma db type ("REAL NOT NULL") + #pragma db type ("REAL") float float_; - #pragma db type ("FLOAT(32) NOT NULL") + #pragma db type ("FLOAT(32)") double float8_; - #pragma db type ("DOUBLE PRECISION NOT NULL") + #pragma db type ("DOUBLE PRECISION") double double_; - // #pragma db type ("NUMERIC(6,3) NOT NULL") + // #pragma db type ("NUMERIC(6,3)") // std::string numeric_; // Data-time types. // - #pragma db type ("DATE NOT NULL") + #pragma db type ("DATE") int date_; - #pragma db type ("TIME NOT NULL") + #pragma db type ("TIME") long long time_; - #pragma db type ("TIMESTAMP NOT NULL") + #pragma db type ("TIMESTAMP") long long timestamp_; // String and binary types. // - #pragma db type ("CHAR(128) NOT NULL") + #pragma db type ("CHAR(128)") std::string char_; - #pragma db type ("VARCHAR(256) NOT NULL") + #pragma db type ("VARCHAR(256)") std::string varchar_; - #pragma db type ("TEXT NOT NULL") + #pragma db type ("TEXT") std::string text_; - #pragma db type ("BYTEA NOT NULL") + #pragma db type ("BYTEA") buffer bytea_; - #pragma db type ("VARBIT(1024) NOT NULL") + #pragma db type ("VARBIT(1024)") varbit varbit_; - // #pragma db type ("BIT(4) NOT NULL") - assigned by #pragma db value + // #pragma db type ("BIT(4)") - assigned by #pragma db value bitfield bit_; // Other types. // - #pragma db type ("UUID NOT NULL") + #pragma db type ("UUID") unsigned char uuid_[16]; // Test ENUM representation. @@ -161,7 +161,7 @@ struct object // Test NULL value. // - #pragma db type ("TEXT") + #pragma db type ("TEXT") null string_ptr null_; bool diff --git a/qt/common/smart-ptr/test.hxx b/qt/common/smart-ptr/test.hxx index 06c05fa..0a4ce03 100644 --- a/qt/common/smart-ptr/test.hxx +++ b/qt/common/smart-ptr/test.hxx @@ -30,7 +30,7 @@ struct cont typedef std::vector > obj_list; - #pragma db inverse(c) not_null + #pragma db inverse(c) value_not_null obj_list o; }; diff --git a/qt/mysql/date-time/test.hxx b/qt/mysql/date-time/test.hxx index b40f45f..dd0f640 100644 --- a/qt/mysql/date-time/test.hxx +++ b/qt/mysql/date-time/test.hxx @@ -42,11 +42,11 @@ struct object QDate date; QDateTime date_time; - // Specify NULL explicitly to suppress auto-initialization and - // auto-update characteristics of TIMESTAMP datatype, and to allow - // NULL values. + // Make timestamp NULL-able to suppress the auto-initialization and + // auto-update characteristics of the TIMESTAMP datatype, and to + // allow NULL values. // - #pragma db type("TIMESTAMP NULL") + #pragma db type("TIMESTAMP") null QDateTime timestamp; QTime time; diff --git a/sqlite/types/test.hxx b/sqlite/types/test.hxx index 37190a0..22cde8e 100644 --- a/sqlite/types/test.hxx +++ b/sqlite/types/test.hxx @@ -31,24 +31,24 @@ struct object #pragma db id unsigned long id_; - #pragma db type ("BOOL NOT NULL") + #pragma db type ("BOOL") bool bool_; - #pragma db type ("INTEGER NOT NULL") + #pragma db type ("INTEGER") int integer_; - #pragma db type ("REAL NOT NULL") + #pragma db type ("REAL") double real_; - #pragma db type ("TEXT NOT NULL") + #pragma db type ("TEXT") std::string text_; - #pragma db type ("BLOB NOT NULL") + #pragma db type ("BLOB") buffer blob_; // Test NULL value. // - #pragma db type ("TEXT") + #pragma db type ("TEXT") null string_ptr null_; bool -- cgit v1.1