checking select query syntax and semantics via php without executing

Поиск
Список
Период
Сортировка
От Marco Dieckhoff
Тема checking select query syntax and semantics via php without executing
Дата
Msg-id 4ACA6668.2000701@gmx.de
обсуждение исходный текст
Ответы Re: checking select query syntax and semantics via php without executing  (Raymond O'Donnell <rod@iol.ie>)
Re: checking select query syntax and semantics via php without executing  (Bill Moran <wmoran@potentialtech.com>)
Список pgsql-php
Hi there!

Is it possible in PHP to give a sql (select) query to Postgres via pg_*
so that it is NOT executed but merely checked for syntax including
correct, existing field and table names, and data types?


I'm working on a system where users may assemble their own query in a
construction kit, and want that to be checked, so that they don't e.g.
compare UUID "<" datetime or something like this.


If I try to execute the generated query, bad queries are instantly found
by pg_query.


But good ones are fully executed, which can take a long time depending
on joins and aggregations.

It seems that pg_prepare doesn't return errors on bad queries,
pg_last_error() is empty.

The asynchronous pg_send_query (and pg_cancel_query) seem not to return
any errors, either.

I tried with three queries:

"SELECT * FROM tableok"
"SELECT nonexistingfield FROM nonexistingtable"
"SELECT complete bad / sql query FROM nonsense"


Any ideas?

В списке pgsql-php по дате отправления:

Предыдущее
От: Gustavo Amarilla Santacruz
Дата:
Сообщение: Re: Error code
Следующее
От: Raymond O'Donnell
Дата:
Сообщение: Re: checking select query syntax and semantics via php without executing