Subject: | Quote problem in views |
Date: | Sat, 11 Jul 2015 14:03:48 -0700 |
To: | bug-DBIx-DataModel [...] rt.cpan.org |
From: | Amelia Ireland <aireland [...] lbl.gov> |
There is a bug in SQL generation for views that means tables and columns
either do not get quoted at all, or they are over-quoted.
The following code illustrates the issue:
DBIx::DataModel->Schema('DataModel::IMG_Core');
DataModel::IMG_Core->metadm->define_table(
class => 'Fruit',
db_name => 'FRUIT',
primary_key => 'id',
);
DataModel::IMG_Core->metadm->define_table(
class => 'Taxon',
db_name => 'TAXON',
primary_key => 'taxon_oid',
);
DataModel::IMG_Core
->Association(
[qw/Fruit fruit 1 id /],
[qw/Taxon taxa * fruit_id /]);
DataModel::IMG_Core->metadm->define_table(
class => 'FullQuotes',
db_name => '"FRUIT" INNER JOIN "TAXON" ON "FRUIT"."id" =
"TAXON"."fruit_id"',
);
DataModel::IMG_Core->metadm->define_table(
class => 'InnerQuotes',
db_name => 'FRUIT" INNER JOIN "TAXON" ON "FRUIT"."id" = "TAXON"."fruit_id',
);
DataModel::IMG_Core->metadm->define_table(
class => 'NoQuotes',
db_name => 'FRUIT INNER JOIN TAXON ON FRUIT.id = TAXON.fruit_id',
);
# feed the schema with a custom instance of SQL::Abstract::More
my $sqlam = SQL::Abstract::More->new(quote_char => '"', name_sep => '.');
DataModel::IMG_Core->singleton->sql_abstract($sqlam);
for ('FullQuotes','InnerQuotes','NoQuotes') {
my ($sql, @bind) = DataModel::IMG_Core->table($_)
->select(
-columns => [ qw( apple banana clementine ) ],
-result_as => 'sql',
);
say "$_: " . $sql;
}
Results:
FullQuotes: SELECT "apple", "banana", "clementine" FROM """FRUIT"" INNER
JOIN ""TAXON"" ON ""FRUIT"""."""id"" = ""TAXON"""."""fruit_id"""
InnerQuotes: SELECT "apple", "banana", "clementine" FROM "FRUIT"" INNER
JOIN ""TAXON"" ON ""FRUIT"""."""id"" = ""TAXON"""."""fruit_id"
NoQuotes: SELECT "apple", "banana", "clementine" FROM "FRUIT INNER JOIN
TAXON ON FRUIT"."id = TAXON"."fruit_id"