Skip Menu |

This queue is for tickets about the DBD-SQLite CPAN distribution.

Report information
The Basics
Id: 34408
Status: resolved
Priority: 0/
Queue: DBD-SQLite

People
Owner: Nobody in particular
Requestors: ilmari+cpan [...] ilmari.org
pancho [...] pancho.name
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.14
Fixed in: (no value)



Subject: Primary key name wrong with newline in CREATE TABLE
If there's a newline before the opening bracket in CREATE TABLE, DBD::SQLite misparses the name of inline primary keys. Attached is a patch that fixes this by adding /s to the regex that strips off "CREATE TABLE".
Subject: DBD-SQLite-PK.diff
--- a/lib/DBD/SQLite.pm 2008-03-24 23:12:03.000000000 +0000 +++ b/lib/DBD/SQLite.pm 2008-03-24 23:12:42.000000000 +0000 @@ -208,7 +208,7 @@ my @pk = split /\s*,\s*/, $2 || ''; unless (@pk) { my $prefix = $1; - $prefix =~ s/.*create\s+table\s+.*?\(\s*//i; + $prefix =~ s/.*create\s+table\s+.*?\(\s*//si; $prefix = (split /\s*,\s*/, $prefix)[-1]; @pk = (split /\s+/, $prefix)[0]; # take first word as name }
Subject: does not parse apparently correct SQL schema with sqlite
Date: Mon, 11 Aug 2008 21:04:56 +0200
To: bug-DBIx-Class-Schema-Loader [...] rt.cpan.org
From: Pancho Horrillo <pancho [...] pancho.name>
Hi, folks! (Version: DBIx-Class-Schema-Loader-0.04005). I was testing a simple catalyst app, and I found out this: If I create the sqlite database with this sql: CREATE TABLE post ( id integer NOT NULL PRIMARY KEY, person_id integer, text text, FOREIGN KEY(person_id) REFERENCES person(id) ); CREATE TABLE person ( id integer NOT NULL PRIMARY KEY, name text ); sqlite is happy about it, and creates the database correctly. But, trying to create a schema from it fails: # Code taken from the documentation, just adjusted the dsn to point to sqlite instead of pg. $ perl -MDBIx::Class::Schema::Loader=make_schema_at,dump_to_dir:./lib \ -e 'make_schema_at("New::Schema::Name", { debug => 1 }, [ "dbi:SQLite:dbname=db" ])' New::Schema::Name::Post->load_components("Core"); New::Schema::Name::Person->load_components("Core"); New::Schema::Name::Post->table("post"); New::Schema::Name::Post->add_columns( "id", { data_type => "integer", is_nullable => 0, size => undef }, "person_id", { data_type => "integer", is_nullable => 0, size => undef }, "text", { data_type => "text", is_nullable => 0, size => undef }, ); New::Schema::Name::Post->set_primary_key("create"); DBIx::Class::Schema::Loader::make_schema_at(): No such column create on table post at -e line 1 $ N.B.: set_primary_key("create"); makes no sense. If instead I create the database with this code: CREATE TABLE post( id integer NOT NULL PRIMARY KEY, person_id integer, text text, FOREIGN KEY(person_id) REFERENCES person(id) ); CREATE TABLE person( id integer NOT NULL PRIMARY KEY, name text ); everything goes smoothly: $ perl -MDBIx::Class::Schema::Loader=make_schema_at,dump_to_dir:./lib \ -e 'make_schema_at("New::Schema::Name", { debug => 1 }, [ "dbi:SQLite:dbname=db" ])' New::Schema::Name::Post->load_components("Core"); New::Schema::Name::Person->load_components("Core"); New::Schema::Name::Post->table("post"); New::Schema::Name::Post->add_columns( "id", { data_type => "integer", is_nullable => 0, size => undef }, "person_id", { data_type => "integer", is_nullable => 0, size => undef }, "text", { data_type => "text", is_nullable => 0, size => undef }, ); New::Schema::Name::Post->set_primary_key("id"); New::Schema::Name::Person->table("person"); New::Schema::Name::Person->add_columns( "id", { data_type => "integer", is_nullable => 0, size => undef }, "name", { data_type => "text", is_nullable => 0, size => undef }, ); New::Schema::Name::Person->set_primary_key("id"); New::Schema::Name::Person->has_many( "posts", "New::Schema::Name::Post", { "foreign.person_id" => "self.id" }, ); New::Schema::Name::Post->belongs_to( "person_id", "New::Schema::Name::Person", { id => "person_id" }, ); Dumping manual schema for New::Schema::Name to directory ./lib ... Schema dump completed. $ The only difference is the position of the left parentheses. The new line seems to adversely affect the module. I'm not the first struck by this bug: http://perlmonks.org/?node_id=646439 Since catalyst's dummy_create.pl helper uses DBIx-Class-Schema-Loader to do the job: $ myapp_create.pl model DBIC::Schema $ script/dummy_create.pl model DB DBIC::Schema Dummy::Schema create=static dbi:SQLite:dbname=db exists "/home/pancho/catalyst/Dummy/script/../lib/Dummy/Model" exists "/home/pancho/catalyst/Dummy/script/../t" DBIx::Class::Schema::Loader::make_schema_at(): No such column create on table post at /usr/share/perl5/Catalyst/Helper/Model/DBIC/Schema.pm line 126 $ But does the job nicely when using the second sql to create the db. Hope that it helps. If you need more info, please feel free to contact me. My sincere thanks for your work. Friendly, pancho. -- pancho horrillo To be conscious that you are ignorant is a great step to knowledge. Benjamin Disraeli
Download signature.asc
application/pgp-signature 197b

Message body not shown because it is not plain text.

Confirming resolved, and added regression test in 1.19_08