laminas / laminas-db

Database abstraction layer, SQL abstraction, result set abstraction, and RowDataGateway and TableDataGateway implementations
https://docs.laminas.dev/laminas-db/
BSD 3-Clause "New" or "Revised" License
119 stars 66 forks source link

PostgresqlMetadata Retrieve trigger throw exception #267

Open wiryonolau opened 1 year ago

wiryonolau commented 1 year ago

Bug Report

Incorrect column parameters when retrieving trigger info in sql

Q A
Version(s) 2.15.1
PostgreSQL 10.21

Summary

Incorrect column parameters when retrieving trigger info in sql

Sql produce by PostgresqlMetadata loadTriggerData()

SELECT "trigger_name",
        "event_manipulation",
        "event_object_catalog",
        "event_object_schema",
        "event_object_table",
        "action_order",
        "action_condition",
        "action_statement",
        "action_orientation",
        "condition_timing" "action_timing",
        "condition_reference_old_table" "action_reference_old_table",
        "condition_reference_new_table" "action_reference_new_table",
        "created"
FROM "information_schema"."triggers" WHERE "trigger_schema" = 'public'

condition_timing should be the alias of action_timing condition_reference_old_table should be the alias of action_reference_old_table condition_reference_new_table should be the alias of action_reference_new_table

Current behavior

Exception Thrown

PDOException: SQLSTATE[42703]: Undefined column: 7 ERROR:  column "condition_timing" does not exist
LINE 1: ...ition", "action_statement", "action_orientation", "condition...

How to reproduce

$adapter = new Adapter([
            'driver'   => 'Pdo_Pgsql',
            'hostname' => 'localhost',
            'port'     => 5432,
            'username' => 'postgres',
            'password' => '888888',
            'database' => 'postgres'
 ]);

$metadata = Factory::createSourceFromAdapter($adapter);
$metadata->getTriggers();

Expected behavior

Should produce this sql

SELECT "trigger_name",
    "event_manipulation",
    "event_object_catalog",
    "event_object_schema",
    "event_object_table",
    "action_order",
    "action_condition",
    "action_statement",
    "action_orientation",
    "action_timing" "condition_timing",
    "action_reference_old_table" "condition_reference_old_table",
    "action_reference_new_table" "condition_reference_new_table",
    "created"
FROM "information_schema"."triggers"
WHERE "trigger_schema" = 'public'
Ocramius commented 1 year ago

Ia this also applicable to previous versions?

wiryonolau commented 1 year ago

Ia this also applicable to previous versions?

test on latest version 9 also not working, I don't think anybody use lower then 9

Run using docker

docker run --rm  -p 5432:5432  -e POSTGRES_PASSWORD=888888 postgres:9

I haven't check previous laminas-db version

Ocramius commented 1 year ago

Sorry, I mean lower versions of this library 😁

wiryonolau commented 1 year ago

2.13 2.14 2.15 does not work return same exception

Ocramius commented 1 year ago

Thanks for verifying: was just trying to understand if this was a regression 👍