Quote table name when inserting DEFAULT VALUES
[dbsrgits/DBIx-Class.git] / t / 18insert_default.t
CommitLineData
7a72e5a5 1use strict;
2use warnings;
3
4use Test::More;
20595c02 5use Test::Exception;
7a72e5a5 6use lib qw(t/lib);
7use DBICTest;
20595c02 8use DBIC::DebugObj;
9use DBIC::SqlMakerTest;
7a72e5a5 10
11my $schema = DBICTest->init_schema();
20595c02 12$schema->storage->sql_maker->quote_char('"');
13
7a72e5a5 14my $rs = $schema->resultset ('Artist');
15my $last_obj = $rs->search ({}, { order_by => { -desc => 'artistid' }, rows => 1})->single;
16my $last_id = $last_obj ? $last_obj->artistid : 0;
17
20595c02 18
19my ($sql, @bind);
20my $orig_debugobj = $schema->storage->debugobj;
21my $orig_debug = $schema->storage->debug;
22
23$schema->storage->debugobj (DBIC::DebugObj->new (\$sql, \@bind) );
24$schema->storage->debug (1);
25
7a72e5a5 26my $obj;
20595c02 27lives_ok { $obj = $rs->create ({}) } 'Default insert successful';
28
29$schema->storage->debugobj ($orig_debugobj);
30$schema->storage->debug ($orig_debug);
31
32is_same_sql_bind (
33 $sql,
34 \@bind,
35 'INSERT INTO "artist" DEFAULT VALUES',
36 [],
37 'Default-value insert correct SQL',
38);
7a72e5a5 39
40ok ($obj, 'Insert defaults ( $rs->create ({}) )' );
7a72e5a5 41
20595c02 42# this should be picked up without calling the DB again
43is ($obj->artistid, $last_id + 1, 'Autoinc PK works');
7a72e5a5 44
20595c02 45# for this we need to refresh
46$obj->discard_changes;
47is ($obj->rank, 13, 'Default value works');
7a72e5a5 48
20595c02 49done_testing;