Skip to content

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

@djerius

Description

@djerius

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions