aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-09-13 10:42:46 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-09-13 10:42:46 +0200
commita9d527ffd7e4a2222d5e80c8110f092af0cb5a74 (patch)
treecd190434be960f8bbb8547619b8b97265d844ed9
parentc85f0af82c3abf2e7d2dfa76351a59d9884395c0 (diff)
Change pragma syntax
Change odb pragma namespace to db. Use qualifiers (object, value, and member) to specify type/member name. Add support for mapping C++ types to db types.
-rw-r--r--common/auto/test.hxx4
-rw-r--r--common/lifecycle/test.hxx4
-rw-r--r--common/query/test.hxx10
-rw-r--r--common/schema/test.hxx22
-rw-r--r--common/template/test.hxx4
-rw-r--r--common/threads/test.hxx4
-rw-r--r--mysql/template/test.hxx4
-rw-r--r--mysql/truncation/test.hxx8
-rw-r--r--mysql/types/test.hxx76
-rw-r--r--tracer/makefile1
-rw-r--r--tracer/object/test.hxx4
-rw-r--r--tracer/pragma/driver.cxx26
-rw-r--r--tracer/pragma/makefile101
-rw-r--r--tracer/pragma/test.hxx42
-rw-r--r--tracer/pragma/test.std0
-rw-r--r--tracer/template/test.hxx4
-rw-r--r--tracer/types/test.hxx8
17 files changed, 247 insertions, 75 deletions
diff --git a/common/auto/test.hxx b/common/auto/test.hxx
index c23027e..8c16a21 100644
--- a/common/auto/test.hxx
+++ b/common/auto/test.hxx
@@ -10,7 +10,7 @@
#include <odb/core.hxx>
-#pragma odb object
+#pragma db object
struct object
{
object (const std::string& str)
@@ -18,7 +18,7 @@ struct object
{
}
- #pragma odb auto id
+ #pragma db auto id
unsigned long id_;
std::string str_;
diff --git a/common/lifecycle/test.hxx b/common/lifecycle/test.hxx
index 268678c..6db1c7e 100644
--- a/common/lifecycle/test.hxx
+++ b/common/lifecycle/test.hxx
@@ -9,7 +9,7 @@
#include <string>
#include <odb/core.hxx>
-#pragma odb object
+#pragma db object
struct object
{
object (unsigned long id)
@@ -21,7 +21,7 @@ struct object
{
}
- #pragma odb id
+ #pragma db id
unsigned long id_;
std::string str_;
};
diff --git a/common/query/test.hxx b/common/query/test.hxx
index 59655f6..3d10cc2 100644
--- a/common/query/test.hxx
+++ b/common/query/test.hxx
@@ -12,7 +12,7 @@
#include <odb/core.hxx>
-#pragma odb object
+#pragma db object
struct person
{
person (unsigned long id,
@@ -32,17 +32,17 @@ struct person
{
}
- #pragma odb id
+ #pragma db id
unsigned long id_;
- #pragma odb column ("first")
+ #pragma db column ("first")
std::string first_name_;
typedef std::auto_ptr<std::string> string_ptr; // @@ tmp
- #pragma odb column ("middle") type ("TEXT")
+ #pragma db column ("middle") type ("TEXT")
string_ptr middle_name_;
- #pragma odb column ("last")
+ #pragma db column ("last")
std::string last_name_;
unsigned short age_;
diff --git a/common/schema/test.hxx b/common/schema/test.hxx
index 14c5113..d770d8f 100644
--- a/common/schema/test.hxx
+++ b/common/schema/test.hxx
@@ -11,29 +11,29 @@
// Table names.
//
-#pragma odb object table ("TABLE_EXPLICIT")
+#pragma db object table ("TABLE_EXPLICIT")
struct table_explicit
{
- #pragma odb id
+ #pragma db id
unsigned long id_;
};
-#pragma odb object
+#pragma db object
struct table_implicit
{
- #pragma odb id
+ #pragma db id
unsigned long id_;
};
// Column names.
//
-#pragma odb object
+#pragma db object
struct column
{
- #pragma odb id
+ #pragma db id
int m1;
- #pragma odb column ("foo")
+ #pragma db column ("foo")
int m2;
int m_m3;
@@ -45,10 +45,10 @@ struct column
// Column types.
//
-#pragma odb object
+#pragma db object
struct type
{
- #pragma odb id
+ #pragma db id
std::string id;
// Test default C++ to DB type mapping.
@@ -69,10 +69,10 @@ struct type
double d;
std::string str;
- #pragma odb type ("INTEGER UNSIGNED")
+ #pragma db type ("INTEGER UNSIGNED")
bool m1;
- #pragma odb transient
+ #pragma db transient
char* m2;
};
diff --git a/common/template/test.hxx b/common/template/test.hxx
index cb25360..1b945a6 100644
--- a/common/template/test.hxx
+++ b/common/template/test.hxx
@@ -8,7 +8,7 @@
#include <odb/core.hxx>
-#pragma odb object
+#pragma db object
struct object
{
object (unsigned long id)
@@ -20,7 +20,7 @@ struct object
{
}
- #pragma odb id
+ #pragma db id
unsigned long id_;
};
diff --git a/common/threads/test.hxx b/common/threads/test.hxx
index d02fdfd..b9f7777 100644
--- a/common/threads/test.hxx
+++ b/common/threads/test.hxx
@@ -10,7 +10,7 @@
#include <odb/core.hxx>
-#pragma odb object
+#pragma db object
struct object
{
object (unsigned long id, const std::string& str)
@@ -22,7 +22,7 @@ struct object
{
}
- #pragma odb id
+ #pragma db id
unsigned long id_;
std::string str_;
diff --git a/mysql/template/test.hxx b/mysql/template/test.hxx
index c71a962..abac96e 100644
--- a/mysql/template/test.hxx
+++ b/mysql/template/test.hxx
@@ -8,7 +8,7 @@
#include <odb/core.hxx>
-#pragma odb object
+#pragma db object
struct object
{
object (unsigned long id)
@@ -20,7 +20,7 @@ struct object
{
}
- #pragma odb id
+ #pragma db id
unsigned long id_;
};
diff --git a/mysql/truncation/test.hxx b/mysql/truncation/test.hxx
index 4e1c1bc..05cd028 100644
--- a/mysql/truncation/test.hxx
+++ b/mysql/truncation/test.hxx
@@ -9,7 +9,7 @@
#include <string>
#include <odb/core.hxx>
-#pragma odb object table ("test")
+#pragma db object table ("test")
struct object1
{
object1 (unsigned long id)
@@ -21,13 +21,13 @@ struct object1
{
}
- #pragma odb id
+ #pragma db id
unsigned long id_;
std::string str_;
};
-#pragma odb object table ("test")
+#pragma db object table ("test")
struct object2
{
object2 (unsigned long id)
@@ -39,7 +39,7 @@ struct object2
{
}
- #pragma odb id
+ #pragma db id
unsigned long id_;
std::string str_;
diff --git a/mysql/types/test.hxx b/mysql/types/test.hxx
index f156506..8f3c632 100644
--- a/mysql/types/test.hxx
+++ b/mysql/types/test.hxx
@@ -154,10 +154,12 @@ operator== (bitfield x, bitfield y)
x.d == y.d;
}
+#pragma db value(bitfield) type ("BIT(4) NOT NULL")
+
typedef std::set<std::string> set;
typedef std::auto_ptr<std::string> string_ptr;
-#pragma odb object
+#pragma db object
struct object
{
object (unsigned long id)
@@ -169,124 +171,124 @@ struct object
{
}
- #pragma odb id
+ #pragma db id
unsigned long id_;
// Integral types.
//
- #pragma odb type ("BOOL NOT NULL")
+ #pragma db type ("BOOL NOT NULL")
bool bool_;
- #pragma odb type ("TINYINT NOT NULL")
+ #pragma db type ("TINYINT NOT NULL")
signed char schar_;
- #pragma odb type ("TINYINT UNSIGNED NOT NULL")
+ #pragma db type ("TINYINT UNSIGNED NOT NULL")
unsigned char uchar_;
- #pragma odb type ("SMALLINT NOT NULL")
+ #pragma db type ("SMALLINT NOT NULL")
short short_;
- #pragma odb type ("SMALLINT UNSIGNED NOT NULL")
+ #pragma db type ("SMALLINT UNSIGNED NOT NULL")
unsigned short ushort_;
- #pragma odb type ("MEDIUMINT NOT NULL")
+ #pragma db type ("MEDIUMINT NOT NULL")
int mint_;
- #pragma odb type ("MEDIUMINT UNSIGNED NOT NULL")
+ #pragma db type ("MEDIUMINT UNSIGNED NOT NULL")
unsigned int umint_;
- #pragma odb type ("INT NOT NULL")
+ #pragma db type ("INT NOT NULL")
int int_;
- #pragma odb type ("INT UNSIGNED NOT NULL")
+ #pragma db type ("INT UNSIGNED NOT NULL")
unsigned int uint_;
- #pragma odb type ("BIGINT NOT NULL")
+ #pragma db type ("BIGINT NOT NULL")
long long long_long_;
- #pragma odb type ("BIGINT UNSIGNED NOT NULL")
+ #pragma db type ("BIGINT UNSIGNED NOT NULL")
unsigned long long ulong_long_;
// Float types.
//
- #pragma odb type ("FLOAT NOT NULL")
+ #pragma db type ("FLOAT NOT NULL")
float float_;
- #pragma odb type ("DOUBLE NOT NULL")
+ #pragma db type ("DOUBLE NOT NULL")
double double_;
- #pragma odb type ("DECIMAL(6,3) NOT NULL")
+ #pragma db type ("DECIMAL(6,3) NOT NULL")
std::string decimal_;
// Data-time types.
//
- #pragma odb type ("DATE NOT NULL")
+ #pragma db type ("DATE NOT NULL")
date_time date_;
- #pragma odb type ("TIME NOT NULL")
+ #pragma db type ("TIME NOT NULL")
date_time time_;
- #pragma odb type ("DATETIME NOT NULL")
+ #pragma db type ("DATETIME NOT NULL")
date_time date_time_;
- #pragma odb type ("TIMESTAMP NOT NULL")
+ #pragma db type ("TIMESTAMP NOT NULL")
date_time timestamp_;
- #pragma odb type ("YEAR NOT NULL")
+ #pragma db type ("YEAR NOT NULL")
short year_;
// String and binary types.
//
- #pragma odb type ("CHAR(128) NOT NULL")
+ #pragma db type ("CHAR(128) NOT NULL")
std::string char_;
- #pragma odb type ("BINARY(128) NOT NULL")
+ #pragma db type ("BINARY(128) NOT NULL")
buffer binary_;
- #pragma odb type ("VARCHAR(256) NOT NULL")
+ #pragma db type ("VARCHAR(256) NOT NULL")
std::string varchar_;
- #pragma odb type ("VARBINARY(256) NOT NULL")
+ #pragma db type ("VARBINARY(256) NOT NULL")
buffer varbinary_;
- #pragma odb type ("TINYTEXT NOT NULL")
+ #pragma db type ("TINYTEXT NOT NULL")
std::string tinytext_;
- #pragma odb type ("TINYBLOB NOT NULL")
+ #pragma db type ("TINYBLOB NOT NULL")
buffer tinyblob_;
- #pragma odb type ("TEXT NOT NULL")
+ #pragma db type ("TEXT NOT NULL")
std::string text_;
- #pragma odb type ("BLOB NOT NULL")
+ #pragma db type ("BLOB NOT NULL")
buffer blob_;
- #pragma odb type ("MEDIUMTEXT NOT NULL")
+ #pragma db type ("MEDIUMTEXT NOT NULL")
std::string mediumtext_;
- #pragma odb type ("MEDIUMBLOB NOT NULL")
+ #pragma db type ("MEDIUMBLOB NOT NULL")
buffer mediumblob_;
- #pragma odb type ("LONGTEXT NOT NULL")
+ #pragma db type ("LONGTEXT NOT NULL")
std::string longtext_;
- #pragma odb type ("LONGBLOB NOT NULL")
+ #pragma db type ("LONGBLOB NOT NULL")
buffer longblob_;
// Other types.
//
- #pragma odb type ("BIT(4) NOT NULL")
+ // #pragma db type ("BIT(4) NOT NULL") - assigned by #pragma db value
bitfield bit_;
- #pragma odb type ("ENUM('red', 'green', 'blue') NOT NULL")
+ #pragma db type ("ENUM('red', 'green', 'blue') NOT NULL")
std::string enum_;
- #pragma odb type ("SET('red', 'green', 'blue') NOT NULL")
+ #pragma db type ("SET('red', 'green', 'blue') NOT NULL")
set set_;
// Test NULL value.
//
- #pragma odb type ("TEXT")
+ #pragma db type ("TEXT")
string_ptr null_;
bool
diff --git a/tracer/makefile b/tracer/makefile
index 3e94d91..c94af17 100644
--- a/tracer/makefile
+++ b/tracer/makefile
@@ -8,6 +8,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make
tests := \
template \
object \
+pragma \
transaction \
types
diff --git a/tracer/object/test.hxx b/tracer/object/test.hxx
index dfa6603..e7adee3 100644
--- a/tracer/object/test.hxx
+++ b/tracer/object/test.hxx
@@ -8,7 +8,7 @@
#include <odb/core.hxx>
-#pragma odb object
+#pragma db object
struct object
{
object (unsigned long id)
@@ -20,7 +20,7 @@ struct object
{
}
- #pragma odb id
+ #pragma db id
unsigned long id_;
};
diff --git a/tracer/pragma/driver.cxx b/tracer/pragma/driver.cxx
new file mode 100644
index 0000000..c227d4e
--- /dev/null
+++ b/tracer/pragma/driver.cxx
@@ -0,0 +1,26 @@
+// file : tracer/pragma/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test #pragma db parsing.
+//
+
+#include <memory>
+#include <cassert>
+#include <iostream>
+
+#include <odb/exceptions.hxx>
+#include <odb/transaction.hxx>
+#include <odb/tracer/database.hxx>
+
+#include "test.hxx"
+#include "test-odb.hxx"
+
+using namespace std;
+using namespace odb;
+
+int
+main ()
+{
+}
diff --git a/tracer/pragma/makefile b/tracer/pragma/makefile
new file mode 100644
index 0000000..1994267
--- /dev/null
+++ b/tracer/pragma/makefile
@@ -0,0 +1,101 @@
+# file : tracer/pragma/makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+# license : GNU GPL v2; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
+
+cxx_tun := driver.cxx
+odb_hdr := test.hxx
+cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
+cxx_od := $(cxx_obj:.o=.o.d)
+
+driver := $(out_base)/driver
+dist := $(out_base)/.dist
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+# Import.
+#
+$(call import,\
+ $(scf_root)/import/odb/stub.make,\
+ odb: odb,odb-rules: odb_rules)
+
+$(call import,\
+ $(scf_root)/import/libodb/stub.make,\
+ l: odb.l,cpp-options: odb.l.cpp-options)
+
+$(call import,\
+ $(scf_root)/import/libodb-tracer/stub.make,\
+ l: odb_tracer.l,cpp-options: odb_tracer.l.cpp-options)
+
+# Build.
+#
+$(driver): $(cxx_obj) $(odb_tracer.l) $(odb.l)
+$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base)
+$(cxx_obj) $(cxx_od): $(odb_tracer.l.cpp-options) $(odb.l.cpp-options)
+
+genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx)
+gen := $(addprefix $(out_base)/,$(genf))
+
+$(gen): $(odb)
+$(gen): odb := $(odb)
+$(gen) $(dist): export odb_options += --database tracer
+$(gen): cpp_options := -I$(out_base)
+$(gen): $(odb_tracer.l.cpp-options) $(odb.l.cpp-options)
+
+$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
+
+# Alias for default target.
+#
+$(out_base)/: $(driver)
+
+# Dist
+#
+$(dist): sources := $(cxx_tun)
+$(dist): headers := $(odb_hdr)
+$(dist): data_dist := test.std
+$(dist): export name := $(notdir $(src_base))
+$(dist): export extra_dist := $(data_dist) $(name)-vc9.vcproj \
+$(name)-vc10.vcxproj $(name)-vc10.vcxproj.filters
+$(dist):
+ $(call dist-data,$(sources) $(headers) $(data_dist))
+ $(call meta-automake,../template/Makefile.am)
+ $(call meta-vc9proj,../template/template-vc9.vcproj,$(name)-vc9.vcproj)
+ $(call meta-vc10proj,../template/template-vc10.vcxproj,$(name)-vc10.vcxproj)
+
+# Test.
+#
+$(test): $(driver) $(src_base)/test.std
+ $(call message,test $<,$< | diff -u $(src_base)/test.std -)
+
+# Clean.
+#
+$(clean): \
+ $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(cxx_obj)) \
+ $(addsuffix .cxx.clean,$(cxx_od)) \
+ $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
+
+# Generated .gitignore.
+#
+ifeq ($(out_base),$(src_base))
+$(driver): | $(out_base)/.gitignore
+
+$(out_base)/.gitignore: files := driver $(genf)
+$(clean): $(out_base)/.gitignore.clean
+
+$(call include,$(bld_root)/git/gitignore.make)
+endif
+
+# How to.
+#
+$(call include,$(bld_root)/dist.make)
+$(call include,$(bld_root)/meta/vc9proj.make)
+$(call include,$(bld_root)/meta/vc10proj.make)
+$(call include,$(bld_root)/meta/automake.make)
+
+$(call include,$(odb_rules))
+$(call include,$(bld_root)/cxx/cxx-d.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/o-e.make)
diff --git a/tracer/pragma/test.hxx b/tracer/pragma/test.hxx
new file mode 100644
index 0000000..2dc499d
--- /dev/null
+++ b/tracer/pragma/test.hxx
@@ -0,0 +1,42 @@
+// file : tracer/template/test.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <odb/core.hxx>
+
+#pragma db value(bool) type ("INT")
+
+struct x {};
+#pragma db value (x)
+
+namespace N
+{
+ #pragma db object
+ struct object1
+ {
+ object1 () {}
+
+ #pragma db id
+ unsigned long id_;
+
+ #pragma db member type ("INT")
+ bool b_;
+ };
+
+ struct object2
+ {
+ object2 () {}
+
+ unsigned long id_;
+ };
+
+ #pragma db object (object2)
+}
+
+PRAGMA_DB (member (N::object2::id_) id auto);
+
+#endif // TEST_HXX
diff --git a/tracer/pragma/test.std b/tracer/pragma/test.std
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tracer/pragma/test.std
diff --git a/tracer/template/test.hxx b/tracer/template/test.hxx
index 06d7155..c85ddde 100644
--- a/tracer/template/test.hxx
+++ b/tracer/template/test.hxx
@@ -8,7 +8,7 @@
#include <odb/core.hxx>
-#pragma odb object
+#pragma db object
struct object
{
object (unsigned long id)
@@ -20,7 +20,7 @@ struct object
{
}
- #pragma odb id
+ #pragma db id
unsigned long id_;
};
diff --git a/tracer/types/test.hxx b/tracer/types/test.hxx
index 965f133..8537e16 100644
--- a/tracer/types/test.hxx
+++ b/tracer/types/test.hxx
@@ -15,19 +15,19 @@ typedef int num_t;
typedef num_t num_type;
-#pragma odb object
+#pragma db object
struct object1
{
typedef int int_type;
- #pragma odb id
+ #pragma db id
int_type id_;
};
-#pragma odb object
+#pragma db object
struct object2
{
- #pragma odb id
+ #pragma db id
num_type num_;
};