freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: Nick Stoughton <nick AT msbit.com>
- To: freetds AT lists.ibiblio.org
- Subject: [freetds] Scalar functions in the ODBC driver
- Date: Mon, 22 Mar 2004 16:36:55 -0800
I discovered a bug in the ODBC driver where calls to scalar functions
(e.g. "{fn now()}") were being incorrectly rewritten for a SQLServer
database (which can understand such calls natively). Essentially, the
ODBC driver was rewriting
{fn xxx()}
as
xxx()
The following patch fixes this problem.
--
Nick Stoughton
(nick AT msbit.com)
--- src/odbc/native.c.orig 2004-03-19 16:24:27.000000000 -0800
+++ src/odbc/native.c 2004-03-19 16:25:21.000000000 -0800
@@ -76,7 +76,7 @@
static SQLRETURN
to_native(struct _hstmt *stmt, char *buf)
{
- char *d, *s, *p, *pcall;
+ char *d, *s, *p;
int nest_syntax = 0;
/* list of bit, used as stack, is call ? FIXME limites size... */
@@ -97,42 +97,39 @@
}
if (*s == '{') {
- pcall = s++;
+ char *pcall;
- while (TDS_ISSPACE(*++pcall));
- if (strncasecmp(pcall, "fn ", 3) == 0) {
- *d++ = '{';
- } else {
- if (*pcall == '?') {
- /* skip spaces after ? */
+ while (TDS_ISSPACE(*++s));
+ pcall = s;
+ if (*pcall == '?') {
+ /* skip spaces after ? */
+ while (TDS_ISSPACE(*++pcall));
+ if (*pcall == '=') {
while (TDS_ISSPACE(*++pcall));
- if (*pcall == '=') {
- while (TDS_ISSPACE(*++pcall));
- } else {
- /* avoid {?call ... syntax */
- pcall = s;
- }
- }
- if (strncasecmp(pcall, "call ", 5) != 0)
- pcall = NULL;
-
- ++nest_syntax;
- is_calls <<= 1;
- if (!pcall) {
- /* assume syntax in the form {type
...} */
- p = strchr(s, ' ');
- if (!p)
- break;
- s = p + 1;
} else {
- if (*s == '?' && stmt)
- stmt->prepared_query_is_func
= 1;
- memcpy(d, "exec ", 5);
- d += 5;
- s = pcall + 5;
- is_calls |= 1;
+ /* avoid {?call ... syntax */
+ pcall = s;
}
}
+ if (strncasecmp(pcall, "call ", 5) != 0)
+ pcall = NULL;
+
+ ++nest_syntax;
+ is_calls <<= 1;
+ if (!pcall) {
+ /* assume syntax in the form {type ...} */
+ p = strchr(s, ' ');
+ if (!p)
+ break;
+ s = p + 1;
+ } else {
+ if (*s == '?' && stmt)
+ stmt->prepared_query_is_func = 1;
+ memcpy(d, "exec ", 5);
+ d += 5;
+ s = pcall + 5;
+ is_calls |= 1;
+ }
} else if (nest_syntax > 0) {
/* do not copy close syntax */
if (*s == '}') {
-
[freetds] Scalar functions in the ODBC driver,
Nick Stoughton, 03/22/2004
- <Possible follow-up(s)>
- RE: [freetds] Scalar functions in the ODBC driver, ZIGLIO, Frediano, VF-IT, 03/24/2004
- RE: [freetds] Scalar functions in the ODBC driver, ZIGLIO, Frediano, VF-IT, 03/24/2004
Archive powered by MHonArc 2.6.24.