Skip to Content.
Sympa Menu

freetds - RE: [freetds] Scalar functions in the ODBC driver

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "ZIGLIO, Frediano, VF-IT" <Frediano.Ziglio AT vodafone.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] Scalar functions in the ODBC driver
  • Date: Wed, 24 Mar 2004 17:19:45 +0100

I'm working on this patch
ODBC syntax is supported from mssql 7 (7 and 2000), not using Sybase or
mssql 6.x.
I reduced your patch to

Index: src/odbc/native.c
===================================================================
RCS file: /cvsroot/freetds/freetds/src/odbc/native.c,v
retrieving revision 1.16
diff -u -1 -0 -b -r1.16 native.c
--- src/odbc/native.c 20 Dec 2003 12:38:36 -0000 1.16
+++ src/odbc/native.c 23 Mar 2004 12:45:43 -0000
@@ -94,20 +94,24 @@
s += len_quote;
d += len_quote;
continue;
}

if (*s == '{') {
char *pcall;

while (TDS_ISSPACE(*++s));
pcall = s;
+ if (strncasecmp(pcall, "fn ", 3) == 0) {
+ *d++ = '{';
+ continue;
+ }
if (*pcall == '?') {
/* skip spaces after ? */
while (TDS_ISSPACE(*++pcall));
if (*pcall == '=') {
while (TDS_ISSPACE(*++pcall));
} else {
/* avoid {?call ... syntax */
pcall = s;
}
}

(should produce same effect)
I'll add test for server version (not that easy however)...

freddy77

>
> 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 mailing list
> FreeTDS AT lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds
>




Archive powered by MHonArc 2.6.24.

Top of Page