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 textsqlite> 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');