7 use DBIC::SqlMakerTest;
10 eval "use DBD::SQLite";
12 ? ( skip_all => 'needs DBD::SQLite for testing' )
18 my $schema = DBICTest->init_schema();
20 my $sql_maker = $schema->storage->sql_maker;
22 $sql_maker->quote_char('`');
23 $sql_maker->name_sep('.');
25 my ($sql, @bind) = $sql_maker->select(
36 'artist.artistid' => 'me.artist'
46 'artist.name' => 'Caterwauler McCrae',
56 q/SELECT COUNT( * ) FROM `cd` `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )/, [ ['artist.name' => 'Caterwauler McCrae'], ['me.year' => 2001] ],
57 'got correct SQL and bind parameters for count query with quoting'
61 ($sql, @bind) = $sql_maker->select(
81 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year DESC`/, [],
82 'scalar ORDER BY okay (single value)'
86 ($sql, @bind) = $sql_maker->select(
109 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year DESC`, `title ASC`/, [],
110 'scalar ORDER BY okay (multiple values)'
114 skip "SQL::Abstract < 1.49 does not support hashrefs in order_by", 2
115 if $SQL::Abstract::VERSION < 1.49;
117 ($sql, @bind) = $sql_maker->select(
137 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year` DESC/, [],
138 'hashref ORDER BY okay (single value)'
142 ($sql, @bind) = $sql_maker->select(
165 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year` DESC, `title` ASC/, [],
166 'hashref ORDER BY okay (multiple values)'
172 ($sql, @bind) = $sql_maker->select(
192 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY year DESC/, [],
193 'did not quote ORDER BY with scalarref (single value)'
197 ($sql, @bind) = $sql_maker->select(
220 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY year DESC, title ASC/, [],
221 'did not quote ORDER BY with scalarref (multiple values)'
225 ($sql, @bind) = $sql_maker->update(
235 q/UPDATE `group` SET `name` = ?, `order` = ?/, [ ['name' => 'Bill'], ['order' => '12'] ],
236 'quoted table names for UPDATE'
240 skip "select attr with star does not work in SQL::Abstract < 1.49", 1
241 if $SQL::Abstract::VERSION < 1.49;
243 ($sql, @bind) = $sql_maker->select(
260 q/SELECT `me`.* FROM `cd` `me`/, [],
261 'select attr with me.* is right'
266 $sql_maker->quote_char([qw/[ ]/]);
268 ($sql, @bind) = $sql_maker->select(
275 'artist' => 'artist',
279 'artist.artistid' => 'me.artist'
289 'artist.name' => 'Caterwauler McCrae',
299 q/SELECT COUNT( * ) FROM [cd] [me] JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )/, [ ['artist.name' => 'Caterwauler McCrae'], ['me.year' => 2001] ],
300 'got correct SQL and bind parameters for count query with bracket quoting'
304 ($sql, @bind) = $sql_maker->update(
314 q/UPDATE [group] SET [name] = ?, [order] = ?/, [ ['name' => 'Bill'], ['order' => '12'] ],
315 'bracket quoted table names for UPDATE'