Skip Menu |

This queue is for tickets about the ORLite CPAN distribution.

Report information
The Basics
Id: 80204
Status: open
Priority: 0/
Queue: ORLite

People
Owner: Nobody in particular
Requestors: blue [...] thisisnotmyrealemail.com
Cc:
AdminCc:

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



Subject: bug with column with default value and null
The attached script produces the following error. $ ./test.pl ORLite::VERSION = 1.98 DBD::SQLite::VERSION = 1.37 DBD::SQLite::db do failed: test.create_time may not be NULL at (eval 18) line 197. ORM::Test::insert('ORM::Test=HASH(0x7ffd508267b8)') called at (eval 18) line 191 ORM::Test::create('ORM::Test', 'test', 'foo') called at ./test.pl line 25 I got the column definition from this stackoverflow answer: http://stackoverflow.com/a/11556717 . And it does indeed work fine in the SQLite interpreter: $ sqlite3 /tmp/foo.db SQLite version 3.7.14 2012-09-03 15:42:36 Enter ".help" for instructions Enter SQL statements terminated with a ";" Show quoted text
sqlite> CREATE TABLE test (
...> id INTEGER PRIMARY KEY, ...> test TEXT NOT NULL UNIQUE, ...> create_time INTEGER NOT NULL DEFAULT (STRFTIME('%s', 'NOW')) ...> ) ...> ; Show quoted text
sqlite> insert into test (test) values ('foo'); sqlite> .dump
PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; CREATE TABLE test ( id INTEGER PRIMARY KEY, test TEXT NOT NULL UNIQUE, create_time INTEGER NOT NULL DEFAULT (STRFTIME('%s', 'NOW')) ); INSERT INTO "test" VALUES(1,'foo',1350340027); COMMIT;
Subject: test.pl
#!/usr/bin/env perl use 5.016; use warnings; use Carp::Always; use ORLite { package => "ORM", file => "/tmp/test.db", create => sub { my $dbh = shift; $dbh->do(q{ CREATE TABLE test ( id INTEGER PRIMARY KEY, test TEXT NOT NULL UNIQUE, create_time INTEGER NOT NULL DEFAULT (STRFTIME('%s', 'NOW')) ) }); }, }; for (qw{ ORLite DBD::SQLite }) { say "${_}::VERSION = ", eval "\$${_}::VERSION"; } ORM::Test->create(test => 'foo');
Moved the ticket from DBD::SQLite to ORLite. The point of this problem is inserting a NULL explicitly into a NOT NULL column with a default value causes an error, while inserting nothing into a NOT NULL column with a default value is ok. The following illustrates the problem: $ sqlite3 Show quoted text
sqlite> CREATE TABLE foo (id INTEGER NOT NULL DEFAULT 0, text); sqlite> INSERT INTO foo (id, text) VALUES (NULL, 'a');
Error: foo.id may not be NULL Show quoted text
sqlite> INSERT INTO foo (text) VALUES ('a'); sqlite> SELECT * FROM foo;
0|a Probably ORLite needs to omit columns to which a user doesn't pass a value. On Tue Oct 16 07:42:15 2012, blue wrote: Show quoted text
> The attached script produces the following error. > > $ ./test.pl > ORLite::VERSION = 1.98 > DBD::SQLite::VERSION = 1.37 > DBD::SQLite::db do failed: test.create_time may not be NULL at (eval
18) Show quoted text
> line 197. > ORM::Test::insert('ORM::Test=HASH(0x7ffd508267b8)') called at
(eval 18) Show quoted text
> line 191 > ORM::Test::create('ORM::Test', 'test', 'foo') called at ./
test.pl line 25 Show quoted text
> > I got the column definition from this stackoverflow answer: > http://stackoverflow.com/a/11556717 . And it does indeed work fine in > the SQLite interpreter: > > $ sqlite3 /tmp/foo.db > > SQLite version 3.7.14 2012-09-03 15:42:36 > Enter ".help" for instructions > Enter SQL statements terminated with a ";"
> sqlite> CREATE TABLE test (
> ...> id INTEGER PRIMARY KEY, > ...> test TEXT NOT NULL UNIQUE, > ...> create_time INTEGER NOT NULL DEFAULT > (STRFTIME('%s', 'NOW')) > ...> ) > ...> ;
> sqlite> insert into test (test) values ('foo'); > sqlite> .dump
> PRAGMA foreign_keys=OFF; > BEGIN TRANSACTION; > CREATE TABLE test ( > id INTEGER PRIMARY KEY, > test TEXT NOT NULL UNIQUE, > create_time INTEGER NOT NULL DEFAULT (STRFTIME('%s',
'NOW')) Show quoted text
> ); > INSERT INTO "test" VALUES(1,'foo',1350340027); > COMMIT;