Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ct_cursor with ct_param #640

Open
msilewicz opened this issue Mar 3, 2025 · 2 comments
Open

ct_cursor with ct_param #640

msilewicz opened this issue Mar 3, 2025 · 2 comments

Comments

@msilewicz
Copy link

Hello there,

Is it possible to bind input parameter values via ct_param in CS_COMMAND initiated with ct_cursor (CS_CURSOR_DECLARE) ?

I cannot find any examples to do it ?
When I try i receive error from MSSQL server "cursor has not been declared".
ct_param return CS_FAIL because cmd_type after cs_cursor has value that is not listed in swich
in file ct.c around line 3330 (freetds version 1.4.26)

@freddy77
Copy link
Contributor

freddy77 commented Mar 4, 2025

I have no idea. What do you have in mind? What kind of query?
I personally would try to take a look at the tests in src/ctlib/unittests and possibly write some test code and use proprietary libraries to see how to do it (if it makes sense).
Yes, proprietary libraries use only Sybase/SAP databases.

@msilewicz
Copy link
Author

I have no idea. What do you have in mind? What kind of query?

ok. in file ct_cursor.c in src/ctlib/unittests directory there is following snippet of code :

strcpy(text, "select col1 from #test_table where 1 = 1");

ret = ct_cursor(cmd, CS_CURSOR_DECLARE, name, CS_NULLTERM, text, CS_NULLTERM, CS_UNUSED);
ret = ct_cursor(cmd, CS_CURSOR_ROWS, name, CS_NULLTERM, NULL, CS_UNUSED, (CS_INT) 1);
ret = ct_cursor(cmd, CS_CURSOR_OPEN, name, CS_NULLTERM, text, CS_NULLTERM, CS_UNUSED);
...
ret = ct_send(cmd);

...

while ((results_ret = ct_results(cmd, &result_type)) == CS_SUCCEED) ...

I personally would try to take a look at the tests in src/ctlib/unittests and possibly write some test code and use proprietary libraries to see how to do it (if it makes sense). Yes, proprietary libraries use only Sybase/SAP databases.

I was wondering if query was changed to
select col1 from #test_table where col1 = @col1);

it would require me to bind input variable "@col1" in standard way - ie. with ct_param call;
however after declaring cursor
cmd variable has its internal parameter change to CS_CUR_CMD (value 161) which is not handled in switch/case
construct as it comes to parameter binding and as a result call to ct_param fails with CS_FAIL result.

I don't know whether it is by design or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants