From b9fe963646367f2da21ba1053bc086bd17b09967 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 24 Apr 2011 11:27:14 +0200 Subject: Implement id_type value type pragma --- doc/manual.xhtml | 106 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 78 insertions(+), 28 deletions(-) (limited to 'doc') diff --git a/doc/manual.xhtml b/doc/manual.xhtml index 54e6a1e..4242618 100644 --- a/doc/manual.xhtml +++ b/doc/manual.xhtml @@ -411,15 +411,16 @@ for consistency. 9.2Value Type Pragmas - - - - - - - - - + + + + + + + + + +
9.2.1type
9.2.2not_null
9.2.3unordered
9.2.4index_type
9.2.5key_type
9.2.6value_type
9.2.7id_column
9.2.8index_column
9.2.9key_column
9.2.10value_column
9.2.2id_type
9.2.3not_null
9.2.4unordered
9.2.5index_type
9.2.6key_type
9.2.7value_type
9.2.8id_column
9.2.9index_column
9.2.10key_column
9.2.11value_column
@@ -3594,7 +3595,7 @@ private: the order information. In the example above, for instance, the order of person's nicknames is probably not important. To instruct the ODB compiler to ignore the order in ordered containers we can use the - db unordered pragma (Section 9.2.3, + db unordered pragma (Section 9.2.4, "unordered", Section 9.3.8, "unordered"). For example:

@@ -5583,57 +5584,63 @@ class person + id_type + database type for a value type when used as an object id + 9.2.2 + + + not_null object pointer cannot be NULL - 9.2.2 + 9.2.3 unordered ordered container should be stored unordered - 9.2.3 + 9.2.4 index_type database type for a container's index type - 9.2.4 + 9.2.5 key_type database type for a container's key type - 9.2.5 + 9.2.6 value_type database type for a container's value type - 9.2.6 + 9.2.7 id_column column name for a container's table object id - 9.2.7 + 9.2.8 index_column column name for a container's table index - 9.2.8 + 9.2.9 key_column column name for a container's table key - 9.2.9 + 9.2.10 value_column column name for a container's table value - 9.2.10 + 9.2.11 @@ -5696,7 +5703,50 @@ private: mapping example in the odb-examples package shows how to do this for all the supported database systems.

-

9.2.2 not_null

+

9.2.2 id_type

+ +

The id_type specifier specifies the native database type + that should be used for data members of this type that are designated as + object identifiers (Section 9.3.1, + "id"). In combination with the type + specifier (Section 9.2.1, "type") + id_type allows you to map a C++ type differently depending + on whether it is used in an ordinary member or an object id. For + example:

+ +
+#pragma db value(std::string) type("TEXT NOT NULL") \
+                              id_type("VARCHAR(128) NOT NULL")
+
+#pragma db object
+class person
+{
+  ...
+private:
+  #pragma db id
+  std::string email_; // Mapped to VARCHAR(128) NOT NULL.
+
+  std::string name_;  // Mapped to TEXT NOT NULL.
+};
+  
+ +

Note that there is no corresponding member type specifier for + id_type since the desired result can be achieved + with just the type specifier, for example:

+ +
+#pragma db object
+class person
+{
+  ...
+private:
+  #pragma db id type("VARCHAR(128) NOT NULL")
+  std::string email_;
+  ...
+};
+  
+ +

9.2.3 not_null

The not_null specifier specifies that an object pointer or a container of object pointers cannot have or contain the @@ -5727,7 +5777,7 @@ typedef std::vector<shared_ptr<account> > accounts;

For a more detailed discussion of the NULL object pointer semantics, refer to Chapter 6, "Relationships".

-

9.2.3 unordered

+

9.2.4 unordered

The unordered specifier specifies that the ordered container should be stored unordered in the database. The database @@ -5744,7 +5794,7 @@ typedef std::vector<std::string> names; storage in the database, refer to Section 5.1, "Ordered Containers".

-

9.2.4 index_type

+

9.2.5 index_type

The index_type specifier specifies the native database type that should be used for an ordered container's @@ -5758,7 +5808,7 @@ typedef std::vector<std::string> names; #pragma db value(names) index_type("SMALLINT UNSIGNED NOT NULL") -

9.2.5 key_type

+

9.2.6 key_type

The key_type specifier specifies the native database type that should be used for a map container's @@ -5772,7 +5822,7 @@ typedef std::map<unsigned short, float> age_weight_map; #pragma db value(age_weight_map) key_type("INT UNSIGNED NOT NULL") -

9.2.6 value_type

+

9.2.7 value_type

The value_type specifier specifies the native database type that should be used for a container's @@ -5786,7 +5836,7 @@ typedef std::vector<std::string> names; #pragma db value(names) value_type("VARCHAR(255) NOT NULL") -

9.2.7 id_column

+

9.2.8 id_column

The id_column specifier specifies the column name that should be used to store the object id in a @@ -5800,7 +5850,7 @@ typedef std::vector<std::string> names;

If the column name is not specified, then object_id is used by default.

-

9.2.8 index_column

+

9.2.9 index_column

The index_column specifier specifies the column name that should be used to store the element index in an @@ -5814,7 +5864,7 @@ typedef std::vector<std::string> names;

If the column name is not specified, then index is used by default.

-

9.2.9 key_column

+

9.2.10 key_column

The key_column specifier specifies the column name that should be used to store the key in a map @@ -5828,7 +5878,7 @@ typedef std::map<unsigned short, float> age_weight_map;

If the column name is not specified, then key is used by default.

-

9.2.10 value_column

+

9.2.11 value_column

The value_column specifier specifies the column name that should be used to store the element value in a -- cgit v1.1