Skip to Content.
Sympa Menu

freetds - [freetds] Begginer question about binding parameters with placeholders

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Leandro Conde" <leandor AT gmail.com>
  • To: freetds AT lists.ibiblio.org
  • Subject: [freetds] Begginer question about binding parameters with placeholders
  • Date: Thu, 8 Jun 2006 18:25:21 -0300

Greetings people! Hi all:

My name is Leandro, and I'm a beginner in the FreeTDS library world,

First of all: thanks you all for producing this excellent product.
It's really nice!

Situation:
I'm trying to create a simple program written in C++ that issues some
simple data operations (SELECT, and INSERTs mostly) to a MSSQL 2000
server.

Problem:
I'm found some problems while executing prepared statements with
parameters binded using placeholders.

I already know that this must be something I am doing wrong, since I
don't found any references to problems or bugs with this feature.

I'm writing a simple test program in C++ using the tdsodbc driver via
the iODBC driver manager, so I'm linking to libiodbc.so, and using
"Driver=FreeTDS;xxx" in the connection string.

This is what I have done, first prepared the statement string:

SQLPrepare(hstm, "{call SomeStoredProc(?, ?)}", SQL_NTS);

Then I called SQLBindParameter to bind some program variables to the
placeholders.

Assuming first param is INT and second is VARCHAR:

// ...
long Param1 = 12345;
SQLINTEGER ind1 = 0;
const char* Param2 = "TESTING";
SQLINTEGER ind2 = SQL_NTS;
// ...
sts = SQLBindParameters(
hstm,
1,
SQL_PARAM_INPUT,
SQL_C_LONG,
SQL_INTEGER,
10,
0,
&Param1,
0,
&ind1);

sts = SQLBindParameters(
hstm,
2,
SQL_PARAM_INPUT,
SQL_C_CHAR,
SQL_VARCHAR,
32,
0,
(SQLCHAR*) Param2,
0,
&ind2);



None of the SQLBindParameters are returning error.

And finally I'm calling:

SQLRETURN sts = SQLExecute(hstm);

And this is returning SQL_ERROR *without* generating any diagnostic
messages ...

I've seen in the freetds source code for the SQLExecute implementation
and didn't get any useful hint for solving this. Only saw that the
only point that is returning SQL_ERROR without generating diagnostic
messages (at least form what I could found) is when checking if all
the parameters required are bound.


SQLSMALLINT NumParams = 0;
SQLNumParams(hstm, &NumParams);

This call is returning 2 params.

So, It seems I'm doing something wrong ... Isn't it?

Thank you for any help! And please forgive me if this problem is a
known issue or something, I've really done some research and found
nothing about it.

Best regards,
Leandro.

PS: If there is any docs or samples about binding parameters
dynamically, please point me in the right direction! I didn't found
anything about it either. Thank you!




Archive powered by MHonArc 2.6.24.

Top of Page