summaryrefslogtreecommitdiff
path: root/odb/relational/sqlite
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-04-05 07:30:19 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-04-10 18:46:44 +0200
commitc9dbc099d74d92b17724a24823aafe1fcc8ca7e7 (patch)
tree1c536796f06386209cb2331df1d245ed93497ca9 /odb/relational/sqlite
parent6d4b471afd63780b8a8a6c2d3fb8cc529ab5b15d (diff)
Generate add/drop column migration statements
Diffstat (limited to 'odb/relational/sqlite')
-rw-r--r--odb/relational/sqlite/schema.cxx54
1 files changed, 54 insertions, 0 deletions
diff --git a/odb/relational/sqlite/schema.cxx b/odb/relational/sqlite/schema.cxx
index bd694e7..ac19328 100644
--- a/odb/relational/sqlite/schema.cxx
+++ b/odb/relational/sqlite/schema.cxx
@@ -24,6 +24,22 @@ namespace relational
create_column (base const& x): base (x) {}
virtual void
+ traverse (sema_rel::add_column& ac)
+ {
+ using sema_rel::alter_table;
+ alter_table& at (static_cast<alter_table&> (ac.scope ()));
+
+ pre_statement ();
+
+ os << "ALTER TABLE " << quote_id (at.name ()) << endl
+ << " ADD COLUMN ";
+ create (ac);
+ os << endl;
+
+ post_statement ();
+ }
+
+ virtual void
auto_ (sema_rel::column&)
{
if (options.sqlite_lax_auto_id ())
@@ -92,6 +108,44 @@ namespace relational
}
};
entry<drop_index> drop_index_;
+
+ struct alter_table_pre: relational::alter_table_pre, context
+ {
+ alter_table_pre (base const& x): base (x) {}
+
+ virtual void
+ alter (sema_rel::alter_table& at)
+ {
+ // SQLite can only add a single column per ALTER TABLE statement.
+ //
+ instance<create_column> c (emitter (), stream (), format_);
+ trav_rel::unames n;
+ n >> c;
+ names (at, n);
+ }
+ };
+ entry<alter_table_pre> alter_table_pre_;
+
+ struct alter_table_post: relational::alter_table_post, context
+ {
+ alter_table_post (base const& x): base (x) {}
+
+ virtual void
+ alter (sema_rel::alter_table& at)
+ {
+ // SQLite does not support dropping columns.
+ //
+ if (sema_rel::drop_column* dc = check<sema_rel::drop_column> (at))
+ {
+ cerr << "error: SQLite does not support dropping of columns"
+ << endl;
+ cerr << "info: first dropped column is '" << dc->name () <<
+ "' in table '" << at.name () << "'" << endl;
+ throw operation_failed ();
+ }
+ }
+ };
+ entry<alter_table_post> alter_table_post_;
}
}
}