aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-06-29 16:30:49 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-07-05 14:43:38 +0200
commitf3e3cc697e2981af67d758cb3747d04d1e1b1111 (patch)
treeb6491bb27adbbba0d6f8b98c9f5590edede8ca4e
parente12f2adb8f345ecbff5d92d6bd2ba672769bd410 (diff)
Correct PostgreSQL container statement and types array generation
-rw-r--r--odb/relational/pgsql/header.cxx16
-rw-r--r--odb/relational/pgsql/source.cxx166
2 files changed, 62 insertions, 120 deletions
diff --git a/odb/relational/pgsql/header.cxx b/odb/relational/pgsql/header.cxx
index e66529e..10c910b 100644
--- a/odb/relational/pgsql/header.cxx
+++ b/odb/relational/pgsql/header.cxx
@@ -36,10 +36,10 @@ namespace relational
// Statement types.
//
- os << "static const Oid persist_statement_types[];"
- << "static const Oid find_statement_types[];"
- << "static const Oid update_statement_types[];"
- << "static const Oid erase_statement_types[];"
+ os << "static const unsigned int persist_statement_types[];"
+ << "static const unsigned int find_statement_types[];"
+ << "static const unsigned int update_statement_types[];"
+ << "static const unsigned int erase_statement_types[];"
<< endl;
}
};
@@ -52,7 +52,7 @@ namespace relational
virtual void
container_public_extra_pre (semantics::data_member&)
{
- if (abstract (c_))
+ if (!c_.count ("object") || abstract (c_))
return;
// Container statement names.
@@ -64,9 +64,9 @@ namespace relational
// Container statement types.
//
- os << "static const Oid select_all_types[];"
- << "static const Oid insert_one_types[];"
- << "static const Oid delete_all_types[];"
+ os << "static const unsigned int select_all_types[];"
+ << "static const unsigned int insert_one_types[];"
+ << "static const unsigned int delete_all_types[];"
<< endl;
}
};
diff --git a/odb/relational/pgsql/source.cxx b/odb/relational/pgsql/source.cxx
index 8fb2b0e..29dccfc 100644
--- a/odb/relational/pgsql/source.cxx
+++ b/odb/relational/pgsql/source.cxx
@@ -20,10 +20,6 @@ namespace relational
{
namespace relational = relational::source;
- //
- // query parameters
- //
-
struct query_parameters: relational::query_parameters
{
query_parameters (base const& x)
@@ -106,44 +102,18 @@ namespace relational
// };
}
- //
- // statement oids
- //
-
struct statement_oids: object_columns_base, context
{
- statement_oids (): first_ (true) {}
-
- bool
- container_column (semantics::data_member& m,
- std::string const& key_prefix,
- bool)
- {
- write_oid_ (column_sql_type (m, key_prefix));
- return true;
- }
-
virtual bool
- column (semantics::data_member& m, std::string const&, bool)
+ column (semantics::data_member& m, std::string const&, bool first)
{
- write_oid_ (column_sql_type (m));
- return true;
- }
-
- private:
- void
- write_oid_ (sql_type const& t)
- {
- if (!first_)
+ if (!first)
os << ',' << endl;
- os << oids[t.type];
+ os << oids[column_sql_type (m).type];
- first_ = false;
+ return true;
}
-
- private:
- bool first_;
};
//
@@ -881,25 +851,27 @@ namespace relational
string name_decl ("const char* const " + traits);
os << name_decl << endl
- << "persist_statement_name =" << strlit (fn + "_persist") << ";"
+ << "persist_statement_name = " << strlit (fn + "_persist") << ";"
<< endl
<< name_decl << endl
- << "find_statement_name =" << strlit (fn + "_find") << ";"
+ << "find_statement_name = " << strlit (fn + "_find") << ";"
<< endl
<< name_decl << endl
- << "update_statement_name =" << strlit (fn + "_update") << ";"
+ << "update_statement_name = " << strlit (fn + "_update") << ";"
<< endl
<< name_decl << endl
- << "erase_statement_name =" << strlit (fn + "_erase") << ";"
+ << "erase_statement_name = " << strlit (fn + "_erase") << ";"
<< endl;
- string oid_decl ("const Oid " + traits);
+ string oid_decl ("const unsigned int " + traits);
+ semantics::data_member* id_m (id_member (t));
// persist_statement_types.
//
{
os << oid_decl << endl
- << "persist_statement_types[] ={";
+ << "persist_statement_types[] ="
+ << "{";
instance<statement_oids> st;
st->traverse (t);
@@ -911,10 +883,11 @@ namespace relational
//
{
os << oid_decl << endl
- << "find_statement_types[] ={";
+ << "find_statement_types[] ="
+ << "{";
instance<statement_oids> st;
- st->column (*id_member (t), "", true);
+ st->column (*id_m, "", true);
os << "};";
}
@@ -923,11 +896,12 @@ namespace relational
//
{
os << oid_decl << endl
- << "update_statement_types[] ={";
+ << "update_statement_types[] ="
+ << "{";
instance<statement_oids> st;
st->traverse (t);
- st->column (*id_member (t), "", false);
+ st->column (*id_m, "", false);
os << "};";
}
@@ -936,10 +910,11 @@ namespace relational
//
{
os << oid_decl << endl
- << "erase_statement_types[] ={";
+ << "erase_statement_types[] ="
+ << "{";
instance<statement_oids> st;
- st->column (*id_member (t), "", true);
+ st->column (*id_m, "", true);
os << "};";
}
@@ -947,10 +922,6 @@ namespace relational
};
entry<class_> class_entry_;
- //
- // container traits
- //
-
struct container_traits : relational::container_traits, context
{
container_traits (base const& x): base (x) {}
@@ -963,69 +934,39 @@ namespace relational
string scope (scope_ + "::" + prefix_ + public_name (m) + "_traits");
- //
// Statment names.
//
-
string stmt_decl ("const char* const " + scope + "::");
- string stmt_prefix (flat_name ( m.fq_name ()));
+ string stmt_prefix (flat_name (m.fq_name ()));
os << stmt_decl << endl
- << "insert_one_name = "
- << strlit (stmt_prefix + "_select_all") << ";" << endl
+ << "insert_one_name = " <<
+ strlit (stmt_prefix + "_select_all") << ";"
+ << endl
<< stmt_decl << endl
- << "select_all_name = "
- << strlit (stmt_prefix + "_insert_one") << ";" << endl
+ << "select_all_name = " <<
+ strlit (stmt_prefix + "_insert_one") << ";"
+ << endl
<< stmt_decl << endl
- << "delete_all_name = "
- << strlit (stmt_prefix + "_delete_all") << ";" << endl;
+ << "delete_all_name = " <<
+ strlit (stmt_prefix + "_delete_all") << ";"
+ << endl;
- //
// Statement types.
//
-
- string type_decl ("const Oid " + scope + "::");
+ string type_decl ("const unsigned int " + scope + "::");
semantics::data_member* inv_m (inverse (m, "value"));
bool inv (inv_m != 0);
semantics::type& mt (m.type ());
semantics::type& vt (container_vt (mt));
- semantics::type* kt (0), *it (0);
- container_kind_type ck (container_kind (mt));
- bool ordered (false);
-
- switch (ck)
- {
- case ck_ordered:
- {
- if (!unordered (m))
- {
- it = &container_it (mt);
- ordered = true;
- }
-
- break;
- }
- case ck_map:
- case ck_multimap:
- {
- kt = &container_kt (mt);
- break;
- }
- case ck_set:
- case ck_multiset:
- {
- break;
- }
- }
+ string id_oid (oids[column_sql_type (m, "id").type]);
- //
// select_all statement types.
//
{
- instance<statement_oids> st;
os << type_decl << endl
<< "select_all_types[] ={";
@@ -1036,48 +977,49 @@ namespace relational
// many(i)-to-many
//
if (context::container (inv_m->type ()))
- st->container_column (*inv_m, "id", true);
+ os << oids[column_sql_type (*inv_m, "id").type];
+
// many(i)-to-one
//
else
- st->column (*id_member (*c), "", true);
+ os << oids[column_sql_type (*id_member (*c)).type];
}
else
- {
- st->container_column (m, "id", true);
- }
+ os << id_oid;
os << "};";
}
- //
// insert_one statement types.
//
{
- instance<statement_oids> st;
os << type_decl << endl
<< "insert_one_types[] ={";
if (!inv)
{
- st->container_column (m, "id", true);
+ os << id_oid << ",";
- switch (ck)
+ switch (container_kind (mt))
{
case ck_ordered:
{
- if (ordered)
- st->container_column (m, "index", false);
+ if (!unordered (m))
+ os << oids[column_sql_type (m, "index").type] << ",";
break;
}
case ck_map:
case ck_multimap:
{
- if (semantics::class_* ktc = comp_value (*kt))
+ if (semantics::class_* ktc = comp_value (container_kt (mt)))
+ {
+ instance<statement_oids> st;
st->traverse_composite (m, *ktc, "key", "key");
+ os << ",";
+ }
else
- st->container_column (m, "key", false);
+ os << oids[column_sql_type (m, "key").type] << ",";
break;
}
@@ -1089,26 +1031,26 @@ namespace relational
}
if (semantics::class_* vtc = comp_value (vt))
+ {
+ instance <statement_oids> st;
st->traverse_composite (m, *vtc, "value", "value");
+ }
else
- st->container_column (m, "value", false);
+ os << oids[column_sql_type (m, "value").type];
}
os << "};";
}
- //
// delete_all statement types.
//
{
os << type_decl << endl
- << "delete_all_types[] ={";
+ << "delete_all_types[] ="
+ << "{";
if (!inv)
- {
- instance<statement_oids> st;
- st->container_column (m, "id", true);
- }
+ os << id_oid;
os << "};";
}