diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-07-20 14:26:23 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-07-27 10:30:15 +0200 |
commit | adfa9bbd04cd3571932ee7675344ca723bfa1eab (patch) | |
tree | c47487e8253d71ce0f2dd2e360f872e1e59a6cef /odb/relational/sqlite | |
parent | 526f66e63f23afb40cc01550ca1a3a3592a84254 (diff) |
Move indexes from model scope to table scope
Conceptually, indexes belong to tables and some databases (MySQL, MSSQL)
indeed treat them as such (i.e., you can have indexes with the same name
in different tables).
Diffstat (limited to 'odb/relational/sqlite')
-rw-r--r-- | odb/relational/sqlite/schema.cxx | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/odb/relational/sqlite/schema.cxx b/odb/relational/sqlite/schema.cxx index b20c7da..8efef66 100644 --- a/odb/relational/sqlite/schema.cxx +++ b/odb/relational/sqlite/schema.cxx @@ -54,13 +54,29 @@ namespace relational create_index (base const& x): base (x) {} virtual string + name (sema_rel::index& in) + { + // In SQLite, index names are database-global. Make them unique + // by prefixing the index name with table name (preserving the + // database). + // + sema_rel::qname n ( + static_cast<sema_rel::table&> (in.scope ()).name ()); + + n.uname () += "_" + in.name (); + return quote_id (n); + } + + virtual string table_name (sema_rel::index& in) { // In SQLite, the index table cannot be qualified with the - // database name (it has to be in the same database anyway). + // database name (it has to be in the same database). // - return quote_id (in.table ().name ().uname ()); + return quote_id ( + static_cast<sema_rel::table&> (in.scope ()).name ().uname ()); } + }; entry<create_index> create_index_; } |