I have an application that allows the user to enter an SQL string with a placeholder for certain values my application produces. The application will the replace the placeholders with values and execute the SQL string through various database backends.
For the ODBC backend, I call SQLExecDirect() on the SQL strin which works nicely on regular queries, but fails for stored procedures with parameters.
Is there a simple way to extend this mechanism to support stored procedures ? A certain way how the SQL must be written ?
The only thing I can think of right now is to start parsing the SQL string and call SQLBindParameter() n times if it conatains a "call". But parsing SQL is tricky.
Any ideas ?
Working SQL example: SELECT columnA from foo where columnB = '%placeholder'
Non-working SQL: CALL StoredFoo('%placeholder')
Как вызвать хранимые процедуры (ODBC) :
Чтобы запустить процедуру как RPC
Создайте оператор SQL, который использует escape-последовательность ODBC CALL. В заявлении используются маркеры параметров. для каждого входа, входа / выхода и выходной параметр, а для возвращаемое значение процедуры (если есть):
{? = CALL procname (?,?)}
Вызов SQLBindParameter для каждого ввода, ввода / вывода и вывода параметр, а для процедуры возвращаемое значение (если есть).
Выполните инструкцию с помощью
SQLExecDirect
.
В противном случае вам нужно выполнить процедуру как обычный пакет (не вызов RPC), т.е. вам необходимо запустить пакет:
EXEC procname @param1, @param2, @param3...;