[freetds] Reusing STMT handle for use with placeholders and data at execution
Frode Nordahl
frode at nordahl.net
Thu Feb 3 03:32:37 EST 2005
Hello,
I have a small application that first does a quick query to check
something, then goes on to insert or update something based on the
results of the first query.
However, the second query fails, without any errors from GetDiagRec,
unless I call SQLFreeStmt with both SQL_CLOSE and SQL_RESET_PARAMS.
I ran SQL Profiler on the server, and saw that the actual query also
changed. Normally the placeholders are replaced with variable names,
but when not calling FreeStmt with SQL_RESET_PARAMS first, they show up
as '?'.
Should I allways call FreeStmt with SQL_RESET_PARAMS before attempting
to run a query using placeholders, or is this a bug somewhere?
Call sequence:
SQLPrepare(hstmt, "SELECT COUNT(x) ...", SQL_NTS);
SQLExecute();
SQLFetch();
SQLGetData();
SQLFreeStmt(hstmt, SQL_CLOSE);
SQLBindParameter
...
SQLPrepare(hstmt, "INSERT INTO x (a, b, c) VALUES (?, ?, ?)", SQL_NTS);
SQLExecute
SQLFreeStmt(hstmt, SQL_RESET_PARAMS);
Regards,
Frode
More information about the FreeTDS
mailing list