5 use DBIC::SqlMakerTest;
9 eval "use DBD::SQLite";
11 ? ( skip_all => 'needs DBD::SQLite for testing' )
19 my $schema = DBICTest->init_schema();
21 my $sql_maker = $schema->storage->sql_maker;
23 $sql_maker->quote_char('`');
24 $sql_maker->name_sep('.');
26 my ($sql, @bind) = $sql_maker->select(
37 'artist.artistid' => 'me.artist'
47 'artist.name' => 'Caterwauler McCrae',
57 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] ],
58 'got correct SQL and bind parameters for count query with quoting'
62 ($sql, @bind) = $sql_maker->select(
82 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year DESC`/, [],
83 'scalar ORDER BY okay (single value)'
87 ($sql, @bind) = $sql_maker->select(
110 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year DESC`, `title ASC`/, [],
111 'scalar ORDER BY okay (multiple values)'
115 skip "SQL::Abstract < 1.49 does not support hashrefs in order_by", 2
116 if $SQL::Abstract::VERSION < 1.49;
118 ($sql, @bind) = $sql_maker->select(
138 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year` DESC/, [],
139 'hashref ORDER BY okay (single value)'
143 ($sql, @bind) = $sql_maker->select(
166 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year` DESC, `title` ASC/, [],
167 'hashref ORDER BY okay (multiple values)'
173 ($sql, @bind) = $sql_maker->select(
193 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY year DESC/, [],
194 'did not quote ORDER BY with scalarref (single value)'
198 ($sql, @bind) = $sql_maker->select(
221 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY year DESC, title ASC/, [],
222 'did not quote ORDER BY with scalarref (multiple values)'
226 ($sql, @bind) = $sql_maker->update(
236 q/UPDATE `group` SET `name` = ?, `order` = ?/, [ ['name' => 'Bill'], ['order' => '12'] ],
237 'quoted table names for UPDATE'
241 skip "select attr with star does not work in SQL::Abstract < 1.49", 1
242 if $SQL::Abstract::VERSION < 1.49;
244 ($sql, @bind) = $sql_maker->select(
261 q/SELECT `me`.* FROM `cd` `me`/, [],
262 'select attr with me.* is right'
267 $sql_maker->quote_char([qw/[ ]/]);
269 ($sql, @bind) = $sql_maker->select(
276 'artist' => 'artist',
280 'artist.artistid' => 'me.artist'
290 'artist.name' => 'Caterwauler McCrae',
300 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] ],
301 'got correct SQL and bind parameters for count query with bracket quoting'
305 ($sql, @bind) = $sql_maker->update(
315 q/UPDATE [group] SET [name] = ?, [order] = ?/, [ ['name' => 'Bill'], ['order' => '12'] ],
316 'bracket quoted table names for UPDATE'