aboutsummaryrefslogtreecommitdiff
path: root/odb/relational/pgsql
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-07-25 12:13:38 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-07-27 10:30:15 +0200
commit923639283d2bae0b82cb605fa4680a3058c9d973 (patch)
tree3c122b70129cdd2b502e1f7056eac896c109f03a /odb/relational/pgsql
parentadfa9bbd04cd3571932ee7675344ca723bfa1eab (diff)
Add support for defining indexes
New db pragma qualifier: index. New tests: common/index, mysql/index, pgsql/index.
Diffstat (limited to 'odb/relational/pgsql')
-rw-r--r--odb/relational/pgsql/schema.cxx51
1 files changed, 47 insertions, 4 deletions
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 <set>
+#include <odb/diagnostics.hxx>
#include <odb/relational/schema.hxx>
#include <odb/relational/pgsql/common.hxx>
@@ -74,11 +75,10 @@ namespace relational
os << "BIGSERIAL";
else
{
- semantics::node& n (*c.get<semantics::node*> ("cxx-node"));
+ location const& l (c.get<location> ("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<sema_rel::table&> (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> create_index_;
}