[freetds] Begginer question about binding parameters withplaceholders

ZIGLIO, Frediano, VF-IT Frediano.Ziglio at vodafone.com
Fri Jun 9 04:09:03 EDT 2006


> 
> 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!
> 

Thanks

> 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.
> 

Which FreeTDS version are you using?

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

Mmmm... is better if you bind before SQLPrepare but should work (only a
bit slower). I suspect you are using a former version which not returns
some error (but I can confirm). It would be helpful if you enable
logging with

TDSDUMP=stderr ./your_program

(you can use a file name instead of stderr if you prefer). Last rows
will help us to understand better the problem.

> 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!

bye
  freddy77



More information about the FreeTDS mailing list