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'
42 '-join_type' => 'left'
45 'tracks.cd' => 'me.cdid'
51 { count => 'tracks.cd' },
52 { -select => 'me.artist' },
53 { -select => 'me.title', -as => 'name' },
54 { -select => { min => 'me.year' }, -as => 'me.minyear' },
57 'artist.name' => 'Caterwauler McCrae',
68 SELECT `me`.`cdid`, COUNT( `tracks`.`cd` ), `me`.`artist`, `me`.`title` AS `name`, MIN( `me`.`year` ) AS `me`.`minyear`
70 JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` )
71 LEFT JOIN `tracks` `tracks` ON ( `tracks`.`cd` = `me`.`cdid` )
72 WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )
74 [ ['artist.name' => 'Caterwauler McCrae'], ['me.year' => 2001] ],
75 'got correct SQL and bind parameters for complex select query with quoting'
79 ($sql, @bind) = $sql_maker->select(
99 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year DESC`/, [],
100 'scalar ORDER BY okay (single value)'
104 ($sql, @bind) = $sql_maker->select(
127 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year DESC`, `title ASC`/, [],
128 'scalar ORDER BY okay (multiple values)'
132 ($sql, @bind) = $sql_maker->select(
152 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year` DESC/, [],
153 'hashref ORDER BY okay (single value)'
157 ($sql, @bind) = $sql_maker->select(
180 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year` DESC, `title` ASC/, [],
181 'hashref ORDER BY okay (multiple values)'
187 ($sql, @bind) = $sql_maker->select(
207 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY year DESC/, [],
208 'did not quote ORDER BY with scalarref (single value)'
212 ($sql, @bind) = $sql_maker->select(
235 q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY year DESC, title ASC/, [],
236 'did not quote ORDER BY with scalarref (multiple values)'
240 ($sql, @bind) = $sql_maker->update(
250 q/UPDATE `group` SET `name` = ?, `order` = ?/, [ ['name' => 'Bill'], ['order' => '12'] ],
251 'quoted table names for UPDATE'
255 ($sql, @bind) = $sql_maker->select(
272 q/SELECT `me`.* FROM `cd` `me`/, [],
273 'select attr with me.* is right'
278 $sql_maker->quote_char([qw/[ ]/]);
280 ($sql, @bind) = $sql_maker->select(
287 'artist' => 'artist',
291 'artist.artistid' => 'me.artist'
301 'artist.name' => 'Caterwauler McCrae',
311 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] ],
312 'got correct SQL and bind parameters for count query with bracket quoting'
316 ($sql, @bind) = $sql_maker->update(
326 q/UPDATE [group] SET [name] = ?, [order] = ?/, [ ['name' => 'Bill'], ['order' => '12'] ],
327 'bracket quoted table names for UPDATE'