3 ms·
have you considered a varargs call for setting parameters with type codes? so something like PreparedStatement_setArgs(p, 's', "a string", 'i', 42, 'f', 3
by andrewcooke 15y ago
have you considered a varargs call for setting parameters with type codes? so something like
PreparedStatement_setArgs(p, 's', "a string", 'i', 42, 'f', 3.1415926);
would set arguments 1-3. i know it's not "OO", but i have done something similar in an internal lib for work and it's very useful and easy to use.
[edit] the number of parameters is assumed equal to the number of '?' in the query. i also have something similar for reading results from the ResultSet, but that required pointers and a count, and was much more likely to lead to errors.
- hauk 15y ago> have you considered a varargs call for setting parameters with type codes? Varargs are supported when building a prepared statement, but not for setting wildcards values. I see what you mean and how the client code can be made more compact. Still, I believe setting one by one value by explicit type may be better for readability, is less error prone and as you say, is more OO and orthogonal.
- andrewcooke 15y agojust trying to make it easier to use... one more thing that i assume must work this way, but you don't seem to have documented, is how to test for exceptions. i guess SQL_Exception (a return value, right?) is false when there's no error? related: do you have any examples that include all the error handling that would be necessary in a real app? how do you display the exception details (it seems to be an opaque type) to the user? perhaps i am missing something here (can't even find exception in the clickable API image)? (wish i had known about this a few months ago as it would have saved me some work - thanks).
- hauk 15y agoThanks. The documentation for exceptions may be some clicks away, but it's there. Here's a direct link. http://www.tildeslash.com/libzdb/api-docs/Exception_8h.html http://www.tildeslash.com/libzdb/api-docs/Exception_8h.html Exceptions are a "true" exception implementation based on the Except code from David Hanson's excellent CII book. This makes it possible to write more compact code without peppering your C code with return code tests.