laminas-db icon indicating copy to clipboard operation
laminas-db copied to clipboard

PostgresqlMetadata Retrieve trigger throw exception

Open wiryonolau opened this issue 2 years ago • 5 comments
trafficstars

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'

wiryonolau avatar Dec 07 '22 09:12 wiryonolau

Ia this also applicable to previous versions?

Ocramius avatar Dec 07 '22 11:12 Ocramius

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

wiryonolau avatar Dec 07 '22 12:12 wiryonolau

Sorry, I mean lower versions of this library 😁

Ocramius avatar Dec 07 '22 12:12 Ocramius

2.13 2.14 2.15 does not work return same exception

wiryonolau avatar Dec 07 '22 12:12 wiryonolau

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

Ocramius avatar Dec 07 '22 13:12 Ocramius