[Dbix-class] DBIx-Class-Schema-Loader bug: SQLite schema w/ "extra"
newline bombs out the Loader
Jay Hannah
jay at jays.net
Sat Mar 22 00:56:19 GMT 2008
Hola --
Penfold and I think we found a bug. sqlite3 doesn't care about an extra
newline when creating a table, but DBIx-Class-Schema-Loader pukes.
I haven't patched it (yet?), but it's pretty easy to reproduce.
Straight from a fresh download, everything goes OK (ignoring a couple warnings):
$ pwd
/home/jhannah/src/DBIx-Class-Schema-Loader-0.04004
$ prove t/10sqlite_common.t
t/10sqlite_common....ok 1/88DBI::db=HASH(0x87767ec)->disconnect invalidates 1 active statement handle (either destroy statement handles or call finish on them before disconnecting) at /usr/lib/perl5/site_perl/5.8.8/DBIx/Class/Storage/DBI.pm line 691.
closing dbh with active statement handles at /usr/lib/perl5/site_perl/5.8.8/DBIx/Class/Storage/DBI.pm line 691.
t/10sqlite_common....ok
8/88 skipped: SQLite cannot do the advanced tests
All tests successful, 8 subtests skipped.
Files=1, Tests=88, 1 wallclock secs ( 0.76 cusr + 0.21 csys = 0.97 CPU)
Let's demonstrate the bug.
$ vi t/lib/dbixcsl_common_tests.pm
hop down to line 531, and add a newline before the paren:
Before:
CREATE TABLE loader_test1 (
After:
CREATE TABLE loader_test1
(
Now when we run the same tests, things go horribly wrong:
prove t/10sqlite_common.t
t/10sqlite_common....NOK 1
# Failed test 'Loader initialization'
# at t/lib/dbixcsl_common_tests.pm line 87.
# DBIx::Class::Schema::Loader::connection(): No such column create on table loader_test1 at (eval 19) line 6
t/10sqlite_common....NOK 2
# Failed test at t/lib/dbixcsl_common_tests.pm line 95.
# got: '0'
# expected: '1'
# Did not get the expected 1 warning. Warnings are:
t/10sqlite_common....NOK 3
# Failed test at t/lib/dbixcsl_common_tests.pm line 98.
# undef
# doesn't match '(?i-xsm:loader_test9 has no primary key)'
Use of uninitialized value in exists at /usr/lib/perl5/site_perl/5.8.8/DBIx/Class/Schema.pm line 170.
Use of uninitialized value in hash element at /usr/lib/perl5/site_perl/5.8.8/DBIx/Class/Schema.pm line 173.
Use of uninitialized value in concatenation (.) or string at /usr/lib/perl5/site_perl/5.8.8/DBIx/Class/Schema.pm line 174.
DBIx::Class::Schema::resultset(): Can't find source for at t/lib/dbixcsl_common_tests.pm line 113
# Looks like you planned 88 tests but only ran 3.
# Looks like you failed 3 tests of 3 run.
# Looks like your test died just after 3.
t/10sqlite_common....dubious
Test returned status 255 (wstat 65280, 0xff00)
DIED. FAILED tests 1-88
Failed 88/88 tests, 0.00% okay
Failed Test Stat Wstat Total Fail Failed List of Failed
-------------------------------------------------------------------------------
t/10sqlite_common.t 255 65280 88 173 196.59% 1-88
Failed 1/1 test scripts, 0.00% okay. 88/88 subtests failed, 0.00% okay.
sqlite3 is perfectly happy with that create table syntax, but DBIx-Class-Schema-Loader is not.
This is bad, since valid .schema's inside SQLite render
DBIx-Class-Schema-Loader useless. And hopefully this is an easy fix for an
eye more trained than mine?
So where's the bug?
Maybe it's around _sqlite_parse_table() in DBIx/Class/Schema/Loader/DBI/SQLite.pm line 65?:
# Cut "CREATE TABLE ( )" blabla...
$sql =~ /^[\w\s']+\((.*)\)$/si;
I tried a couple patch attempts but didn't seem to figure it out...
Want me to keep chasing a patch?
Thanks all,
j
http://clab.ist.unomaha.edu/CLAB/index.php/User:Jhannah
More information about the DBIx-Class
mailing list