swoole / ext-postgresql

🐘 Coroutine-based client for PostgreSQL
65 stars 21 forks source link

Wrong/empty error codes for incorrect SQL-queries #57

Open maxvoronov opened 3 years ago

maxvoronov commented 3 years ago

Hi Team,

I faced with strange behaviour when I send incorrect queries. Here are my cases:

// Direct SQL query:
> INSERT INTO fake_table (id) VALUES (1)
[42P01] ERROR: relation "fake_table" does not exist

// Query via extension:
$db = new Swoole\Coroutine\PostgreSQL();
$db->connect($dsn);    
$db->prepare('teststmt', 'INSERT INTO fake_table (id) VALUES ($1)');
echo 'Error code: ' . $db->errCode . PHP_EOL;    // Expect non-zero code
echo 'Error message: ' . $db->error . PHP_EOL;
> Error code: 0
> Error message: ERROR:  relation "fake_table" does not exist
> LINE 1: INSERT INTO fake_table (id) VALUES ($1)

// Direct SQL query:
> INSERT INTO parts (id, fake_field) VALUES (1, 'Some Data');
[42703] ERROR: column "fake_field" of relation "parts" does not exist

// Query via extension:
$db->prepare('teststmt2', 'INSERT INTO parts (id, fake_field) VALUES ($1, $2)');
> Error code: 0
> ERROR:  column "fake_field" of relation "pim_part" does not exist
> LINE 1: INSERT INTO pim_part (id, fake_field) VALUES ($1, $2)

Initially I was expecting an error code like in the PostgreSQL spec. But later I saw that type of errCode variable is integer. And I don't know how extension can pass error codes with letters (for example 42P01). Are there any mapping table or something like that? I'm not sure that this feature works correctly.