5 use SQL::Abstract::Test import => ['is_same_sql_bind'];
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.50 does not support hashrefs in order_by", 2 if $SQL::Abstract::VERSION < 1.50;
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 ($sql, @bind) = $sql_maker->select(
257 q/SELECT `me`.* FROM `cd` `me`/, [],
258 'select attr with me.* is right'
262 $sql_maker->quote_char([qw/[ ]/]);
264 ($sql, @bind) = $sql_maker->select(
271 'artist' => 'artist',
275 'artist.artistid' => 'me.artist'
285 'artist.name' => 'Caterwauler McCrae',
295 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] ],
296 'got correct SQL and bind parameters for count query with bracket quoting'
300 ($sql, @bind) = $sql_maker->update(
310 q/UPDATE [group] SET [name] = ?, [order] = ?/, [ ['name' => 'Bill'], ['order' => '12'] ],
311 'bracket quoted table names for UPDATE'