and $self->schema and $self->storage )
{
$self->{_columns_info_loaded}++;
- my $info;
- my $lc_info;
+ my $info = {};
+ my $lc_info = {};
# eval for the case of storage without table
eval { $info = $self->storage->columns_info_for( $self->from ) };
unless ($@) {
$lc_info->{lc $realcol} = $info->{$realcol};
}
foreach my $col ( keys %{$self->_columns} ) {
- $self->_columns->{$col} = { %{ $self->_columns->{$col}}, %{$info->{$col} || $lc_info->{lc $col}} };
+ $self->_columns->{$col} = {
+ %{ $self->_columns->{$col} },
+ %{ $info->{$col} || $lc_info->{lc $col} || {} }
+ };
}
}
}
# tests run on windows as well
my $employees = $schema->resultset('Employee');
-my $cmd = qq|perl script/dbicadmin --schema=DBICTest::Schema --class=Employee --tlibs --connect="['dbi:SQLite:dbname=t/var/DBIxClass.db','','']" --force --tlibs|;
+my $cmd = qq|$^X script/dbicadmin --schema=DBICTest::Schema --class=Employee --tlibs --connect="['dbi:SQLite:dbname=t/var/DBIxClass.db','','']" --force --tlibs|;
`$cmd --op=insert --set="{name:'Matt'}"`;
ok( ($employees->count()==1), 'insert count' );
+++ /dev/null
-use strict;
-use warnings;
-
-use Test::More;
-use lib qw(t/lib);
-use DBICTest;
-
-my $schema = DBICTest->init_schema();
-
-plan tests => 5;
-
-my $old_artistid = 1;
-my $new_artistid = $schema->resultset("Artist")->get_column('artistid')->max + 1;
-
-# Update the PK
-{
- my $artist = $schema->resultset("Artist")->find($old_artistid);
- ok(defined $artist, 'found an artist with the new PK');
-
- $artist->update({ artistid => $new_artistid });
- is($artist->artistid, $new_artistid, 'artist ID matches');
-}
-
-# Look for the old PK
-{
- my $artist = $schema->resultset("Artist")->find($old_artistid);
- ok(!defined $artist, 'no artist found with the old PK');
-}
-
-# Look for the new PK
-{
- my $artist = $schema->resultset("Artist")->find($new_artistid);
- ok(defined $artist, 'found an artist with the new PK');
- is($artist->artistid, $new_artistid, 'artist ID matches');
-}
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More;
+
+
+BEGIN {
+ eval "use DBD::SQLite";
+ plan $@
+ ? ( skip_all => 'needs DBD::SQLite for testing' )
+ : ( tests => 8 );
+}
+
+use lib qw(t/lib);
+
+use_ok('DBICTest');
+
+DBICTest->init_schema();
+
+my $sql_maker = DBICTest->schema->storage->sql_maker;
+
+$sql_maker->quote_char('`');
+$sql_maker->name_sep('.');
+
+my ($sql,) = $sql_maker->select(
+ [
+ {
+ 'me' => 'cd'
+ },
+ [
+ {
+ 'artist' => 'artist',
+ '-join_type' => ''
+ },
+ {
+ 'artist.artistid' => 'me.artist'
+ }
+ ]
+ ],
+ [
+ {
+ 'count' => '*'
+ }
+ ],
+ {
+ 'artist.name' => 'Caterwauler McCrae',
+ 'me.year' => 2001
+ },
+ [],
+ undef,
+ undef
+);
+
+is($sql,
+ q/SELECT COUNT( * ) FROM `cd` `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )/,
+ 'got correct SQL for count query with quoting');
+
+($sql,) = $sql_maker->select(
+ [
+ {
+ 'me' => 'cd'
+ }
+ ],
+ [
+ 'me.cdid',
+ 'me.artist',
+ 'me.title',
+ 'me.year'
+ ],
+ undef,
+ [
+ 'year DESC'
+ ],
+ undef,
+ undef
+);
+
+TODO: {
+ local $TODO = "order_by with quoting needs fixing (ash/castaway)";
+
+ is($sql,
+ q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year` DESC/,
+ 'quoted ORDER BY with DESC okay');
+}
+
+TODO: {
+ local $TODO = "select attr with star needs fixing (mst/nate)";
+
+ ($sql,) = $sql_maker->select(
+ [
+ {
+ 'me' => 'cd'
+ }
+ ],
+ [
+ 'me.*'
+ ],
+ undef,
+ [],
+ undef,
+ undef
+ );
+
+ is($sql, q/SELECT `me`.* FROM `cd` `me`/, 'select attr with me.* is right');
+}
+
+($sql,) = $sql_maker->select(
+ [
+ {
+ 'me' => 'cd'
+ }
+ ],
+ [
+ 'me.cdid',
+ 'me.artist',
+ 'me.title',
+ 'me.year'
+ ],
+ undef,
+ [
+ \'year DESC'
+ ],
+ undef,
+ undef
+);
+
+is($sql,
+ q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY year DESC/,
+ 'did not quote ORDER BY with scalarref');
+
+my %data = (
+ name => 'Bill',
+ order => 12
+);
+
+my @binds;
+
+($sql,@binds) = $sql_maker->update(
+ 'group',
+ {
+ 'order' => '12',
+ 'name' => 'Bill'
+ }
+);
+
+is($sql,
+ q/UPDATE `group` SET `name` = ?, `order` = ?/,
+ 'quoted table names for UPDATE');
+
+$sql_maker->quote_char([qw/[ ]/]);
+
+($sql,) = $sql_maker->select(
+ [
+ {
+ 'me' => 'cd'
+ },
+ [
+ {
+ 'artist' => 'artist',
+ '-join_type' => ''
+ },
+ {
+ 'artist.artistid' => 'me.artist'
+ }
+ ]
+ ],
+ [
+ {
+ 'count' => '*'
+ }
+ ],
+ {
+ 'artist.name' => 'Caterwauler McCrae',
+ 'me.year' => 2001
+ },
+ [],
+ undef,
+ undef
+);
+
+is($sql,
+ q/SELECT COUNT( * ) FROM [cd] [me] JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )/,
+ 'got correct SQL for count query with bracket quoting');
+
+
+($sql,@binds) = $sql_maker->update(
+ 'group',
+ {
+ 'order' => '12',
+ 'name' => 'Bill'
+ }
+);
+
+is($sql,
+ q/UPDATE [group] SET [name] = ?, [order] = ?/,
+ 'bracket quoted table names for UPDATE');