[Bast-commits] r6538 - in DBIx-Class/0.08/trunk: lib/DBIx/Class t
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Sun Jun 7 21:36:43 GMT 2009
Author: ribasushi
Date: 2009-06-07 21:36:43 +0000 (Sun, 07 Jun 2009)
New Revision: 6538
Added:
DBIx-Class/0.08/trunk/t/18insert_default.t
Modified:
DBIx-Class/0.08/trunk/lib/DBIx/Class/SQLAHacks.pm
Log:
Make empty/default inserts use standard SQL
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/SQLAHacks.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/SQLAHacks.pm 2009-06-07 21:07:55 UTC (rev 6537)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/SQLAHacks.pm 2009-06-07 21:36:43 UTC (rev 6538)
@@ -193,6 +193,14 @@
my $self = shift;
my $table = shift;
$table = $self->_quote($table) unless ref($table);
+
+ # SQLA will emit INSERT INTO $table ( ) VALUES ( )
+ # which is sadly understood only by MySQL. Change default behavior here,
+ # until SQLA2 comes with proper dialect support
+ if (! $_[0] or (ref $_[0] eq 'HASH' and !keys %{$_[0]} ) ) {
+ return "INSERT INTO ${table} DEFAULT VALUES"
+ }
+
$self->SUPER::insert($table, @_);
}
Added: DBIx-Class/0.08/trunk/t/18insert_default.t
===================================================================
--- DBIx-Class/0.08/trunk/t/18insert_default.t (rev 0)
+++ DBIx-Class/0.08/trunk/t/18insert_default.t 2009-06-07 21:36:43 UTC (rev 6538)
@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+
+my $tests = 3;
+plan tests => $tests;
+
+my $schema = DBICTest->init_schema();
+my $rs = $schema->resultset ('Artist');
+my $last_obj = $rs->search ({}, { order_by => { -desc => 'artistid' }, rows => 1})->single;
+my $last_id = $last_obj ? $last_obj->artistid : 0;
+
+my $obj;
+eval { $obj = $rs->create ({}) };
+my $err = $@;
+
+ok ($obj, 'Insert defaults ( $rs->create ({}) )' );
+SKIP: {
+ skip "Default insert failed: $err", $tests-1 if $err;
+
+ # this should be picked up without calling the DB again
+ is ($obj->artistid, $last_id + 1, 'Autoinc PK works');
+
+ # for this we need to refresh
+ $obj->discard_changes;
+ is ($obj->rank, 13, 'Default value works');
+}
+
More information about the Bast-commits
mailing list