Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table name is double quoted when connecting to Postgres, leading to illegal sql #21

Open
djerius opened this issue Sep 18, 2023 · 0 comments

Comments

@djerius
Copy link

djerius commented Sep 18, 2023

DBIx::Lite::ResultSet outputs illegal syntax for the DELETE command when quote_char is turned on and the connection is to Postgres.

Here's an example:

#! perl

use v5.10;
use DBIx::Lite;

my $dbix = DBIx::Lite->new( abstract => { quote_char => q{"}, name_sep=> q{.} } );
$dbix->connect("dbi:Pg:dbname=$ENV{PGDATABASE};host=$ENV{PGHOST}",q{},q{});

say $dbix->table('foo')->delete_sql;

This outputs:

DELETE FROM """foo"" AS ""me"""

which when fed to Postgres results in

dj=> DELETE FROM """foo"" AS ""me""";
ERROR:  relation ""foo" AS "me"" does not exist
LINE 1: DELETE FROM """foo"" AS ""me""";
                    ^

essentially the q{"foo" as "me"} table alias phrase is being passed as a single string.

This behavior begins in DBIx::Lite::ResultSet::_table_alias_expr where DBIx::Lite::ResultSet::_table_alias is called and returns an alias of "me" for the table, hardwired because of the Pg connection and the delete statement.

It then calls SQL::Abstract::More::table_alias, where it is first quoted (via SQL::Abstract::More::_make_sub_table_alias)
and then again when it calls SQL::Abstract::More::delete, which passes the call on to SQL::Abstract::Classic::delete() where the second quoting happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant