[Dbix-class] User error? SQLite problem? with
DBIx::Class::Fixtures and populate
luke saunders
luke.saunders at gmail.com
Wed Oct 8 20:06:17 BST 2008
On Wed, Oct 8, 2008 at 7:48 PM, luke saunders <luke.saunders at gmail.com> wrote:
>
> (Ashley sent me the files offlist)
>
> Your call to create_ddl_dir is producing an SQL file with this:
>
> ...
> DROP TABLE account;
> CREATE TABLE account (
> ...
>
> But that falls over if 'account' doesn't exist. SQLite allows DROP TABLE IF
> EXISTS but only after version 3.3. I have knocked up a patch to the
> SQL::Translator producer which would allow you to specify an SQLite version,
> which, if greater than 3.3 would add the IF EXISTS and all would be well
> (patch appended to email and also sent to Jess).
>
Sorry for the double reply, but I foolishly sent the last email with
'rich formatting', which isn't great for patches. Here's the patch
again:
=== lib/SQL/Translator/Producer/SQLite.pm
==================================================================
--- lib/SQL/Translator/Producer/SQLite.pm (revision 1795)
+++ lib/SQL/Translator/Producer/SQLite.pm (local)
@@ -60,6 +60,8 @@
my $no_comments = $translator->no_comments;
my $add_drop_table = $translator->add_drop_table;
my $schema = $translator->schema;
+ my $producer_args = $translator->producer_args;
+ my $sqlite_version = $producer_args->{sqlite_version} || 0;
debug("PKG: Beginning production\n");
@@ -70,6 +72,7 @@
my @table_defs = ();
for my $table ( $schema->get_tables ) {
my @defs = create_table($table, { no_comments => $no_comments,
+ sqlite_version => $sqlite_version,
add_drop_table => $add_drop_table,});
my $create = shift @defs;
$create .= ";\n";
@@ -124,6 +127,7 @@
my $table_name = $table->name;
my $no_comments = $options->{no_comments};
my $add_drop_table = $options->{add_drop_table};
+ my $sqlite_version = $options->{sqlite_version};
debug("PKG: Looking at table '$table_name'\n");
@@ -135,8 +139,9 @@
# Header.
#
my $create = '';
- $create .= "--\n-- Table: $table_name\n--\n" unless $no_comments;
- $create .= qq[DROP TABLE $table_name;\n] if $add_drop_table;
+ my $exists = ($sqlite_version >= 3.3) ? ' IF EXISTS' : '';
+ $create .= "--\n-- Table: $table_name\n--\n" unless $no_comments;
+ $create .= "DROP TABLE$exists $table_name;\n" if $add_drop_table;
$create .= "CREATE ${temp}TABLE $table_name (\n";
#
More information about the DBIx-Class
mailing list