From adfa9bbd04cd3571932ee7675344ca723bfa1eab Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 20 Jul 2012 14:26:23 +0200 Subject: 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). --- odb/relational/sqlite/schema.cxx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'odb/relational/sqlite/schema.cxx') 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 (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 (in.scope ()).name ().uname ()); } + }; entry create_index_; } -- cgit v1.1