From 923639283d2bae0b82cb605fa4680a3058c9d973 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 25 Jul 2012 12:13:38 +0200 Subject: Add support for defining indexes New db pragma qualifier: index. New tests: common/index, mysql/index, pgsql/index. --- odb/relational/pgsql/schema.cxx | 51 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'odb/relational/pgsql') diff --git a/odb/relational/pgsql/schema.cxx b/odb/relational/pgsql/schema.cxx index 2113894..5574bdb 100644 --- a/odb/relational/pgsql/schema.cxx +++ b/odb/relational/pgsql/schema.cxx @@ -4,6 +4,7 @@ #include +#include #include #include @@ -74,11 +75,10 @@ namespace relational os << "BIGSERIAL"; else { - semantics::node& n (*c.get ("cxx-node")); + location const& l (c.get ("cxx-location")); - cerr << n.file () << ":" << n.line () << ":" << n.column () - << ": error: automatically assigned object id must map " - << "to PostgreSQL INTEGER or BIGINT" << endl; + error (l) << "automatically assigned object id must map " + << "to PostgreSQL INTEGER or BIGINT" << endl; throw operation_failed (); } @@ -181,6 +181,49 @@ namespace relational static_cast (in.scope ()).name ().uname () + "_" + in.name ()); } + + virtual void + create (sema_rel::index& in) + { + os << "CREATE "; + + if (!in.type ().empty ()) + { + // Handle the CONCURRENTLY keyword. + // + string const& t (in.type ()); + + if (t == "concurrently" || t == "CONCURRENTLY") + { + os << "INDEX " << t; + } + else + { + size_t p (t.rfind (' ')); + string s (t, (p != string::npos ? p + 1 : 0), string::npos); + + if (s == "concurrently" || s == "CONCURRENTLY") + os << string (t, 0, p) << " INDEX " << s; + else + os << t << " INDEX"; + } + } + else + os << "INDEX"; + + os << " " << name (in) << endl + << " ON " << table_name (in); + + if (!in.method ().empty ()) + os << " USING " << in.method (); + + os << " ("; + columns (in); + os << ")" << endl; + + if (!in.options ().empty ()) + os << ' ' << in.options () << endl; + } }; entry create_index_; } -- cgit v1.1