On Wed, Oct 8, 2008 at 12:56 AM, luke saunders <[EMAIL PROTECTED]>wrote:
> On Tue, Oct 7, 2008 at 6:22 PM, Ashley <[EMAIL PROTECTED]> wrote:
>
>> I'm messing around with writing some tests with DBIx::Class::Fixtures and
>> getting stuck. Trying to see if it's something obvious I'm doing wrong or
>> there is currently an sqlite problem. The code below runs fine except the
>> final step: $fixtures->populate. This is the error it gives-
>>
>> SQL was:
>> DROP TABLE account
>> DBIx::Class::Fixtures::populate(): DBI Exception: DBD::SQLite::db do
>> failed: no such table: account(1) at dbdimp.c line 271 [for Statement "DROP
>> TABLE account"] at ./fixture-test.pl line 40
>> 1..2
>>
>> There is a table "account" and it's in the MyApp-Test-Schema-1-SQLite.sql
>> as well as the dumped $schema object. My DBIC modules are all current.
>>
>> Any ideas?
>>
>
> That's pretty weird. Could you please send me your
> MyApp-Test-Schema-1-SQLite.sql file? Or better still tar up the whole test
> case if it's self-contained (you might have to send it off list). Hopefully
> then I'll be able to replicate it.
>
(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).
That's no good to you now though, so your best option is to change this:
$schema->create_ddl_dir(['SQLite'],1);
to this:
$schema->create_ddl_dir(['SQLite'],1,undef,undef,{ add_drop_table => 0 });
Which would leave out the DROP TABLE part altogether. If you're just using
your DDL for DBIx::Class::Fixtures then that's fine, since it clears the
existing tables anyway before populating.
Cheers,
Luke.
=== 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";
#
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]