my $self = shift;
my ($source, $to_insert) = @_;
- my $blob_cols = $self->_remove_blob_cols($source, $to_insert);
-
- my $identity_col = List::Util::first
+ my $identity_col = (List::Util::first
{ $source->column_info($_)->{is_auto_increment} }
- $source->columns;
+ $source->columns) || '';
+
+ # check for empty insert
+ # INSERT INTO foo DEFAULT VALUES -- does not work with Sybase
+ # try to insert explicit 'DEFAULT's instead (except for identity)
+ if (not %$to_insert) {
+ for my $col ($source->columns) {
+ next if $col eq $identity_col;
+ $to_insert->{$col} = \'DEFAULT';
+ }
+ }
+
+ my $blob_cols = $self->_remove_blob_cols($source, $to_insert);
# do we need the horrific SELECT MAX(COL) hack?
my $dumb_last_insert_id =
my $updated_cols = $self->$next ($source, $to_insert);
my $final_row = {
- $identity_col => $self->last_insert_id($source, $identity_col),
+ ($identity_col ?
+ ($identity_col => $self->last_insert_id($source, $identity_col)) : ()),
%$to_insert,
%$updated_cols,
};
my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_SYBASE_${_}" } qw/DSN USER PASS/};
-my $TESTS = 62 + 2;
+my $TESTS = 63 + 2;
if (not ($dsn && $user)) {
plan skip_all =>
} 'blob update to NULL';
}
-# test MONEY column support
+# test MONEY column support (and some other misc. stuff)
$schema->storage->dbh_do (sub {
my ($storage, $dbh) = @_;
eval { $dbh->do("DROP TABLE money_test") };
$dbh->do(<<'SQL');
CREATE TABLE money_test (
id INT IDENTITY PRIMARY KEY,
- amount MONEY NULL
+ amount MONEY DEFAULT $999.99 NULL
)
SQL
});
+ my $rs = $schema->resultset('Money');
+
+# test insert with defaults
+ lives_and {
+ $rs->create({});
+ is((grep $_->amount == 999.99, $rs->all), 1);
+ } 'insert with all defaults works';
+ $rs->delete;
+
# test insert transaction when there's an active cursor
{
my $artist_rs = $schema->resultset('Artist');
}
# Now test money values.
- my $rs = $schema->resultset('Money');
-
my $row;
lives_ok {
$row = $rs->create({ amount => 100 });