Executing a stored procedure over ODBC

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')

1
задан Gene Vincent 17 August 2010 в 17:09
поделиться

1 ответ

Как вызвать хранимые процедуры (ODBC) :

Чтобы запустить процедуру как RPC

  1. Создайте оператор SQL, который использует escape-последовательность ODBC CALL. В заявлении используются маркеры параметров. для каждого входа, входа / выхода и выходной параметр, а для возвращаемое значение процедуры (если есть):

    {? = CALL procname (?,?)}

  2. Вызов SQLBindParameter для каждого ввода, ввода / вывода и вывода параметр, а для процедуры возвращаемое значение (если есть).

  3. Выполните инструкцию с помощью SQLExecDirect .

В противном случае вам нужно выполнить процедуру как обычный пакет (не вызов RPC), т.е. вам необходимо запустить пакет:

EXEC procname @param1, @param2, @param3...;
2
ответ дан 2 September 2019 в 22:05
поделиться
Другие вопросы по тегам:

Похожие вопросы: