Subject | Re: API problem with SQL_LONG |
---|---|
Author | burmair |
Post date | 2007-04-10T22:00:48Z |
Thank you for taking the time to look at my problem!
I'm using MS VC++ 6.0. I get a failure with short, int, and __int64.
For these types, the value stored in the database is 0. For float,
double, and text (which all correctly store 99 in the database), FB
seems to understand how to coerce the given value to INTEGER. Here's
an expanded version of the conditional block I used to test the
various SQL_xxx constants:
#if 0
// This WORKS
printf("Encoding age with SQL_FLOAT\n");
float age = 99.0;
in_sqlda->sqlvar[2].sqldata = (char *)&age;
in_sqlda->sqlvar[2].sqllen = sizeof(float);
in_sqlda->sqlvar[2].sqltype = SQL_FLOAT;
in_sqlda->sqlvar[2].sqlind = &flag2;
#elif 0
// This WORKS
printf("Encoding age with SQL_DOUBLE\n");
double age = 99.0;
in_sqlda->sqlvar[2].sqldata = (char *)&age;
in_sqlda->sqlvar[2].sqllen = sizeof(double);
in_sqlda->sqlvar[2].sqltype = SQL_DOUBLE;
in_sqlda->sqlvar[2].sqlind = &flag2;
#elif 0
// This WORKS
printf("Encoding age with SQL_TEXT\n");
char age[3];
strcpy(age, "99");
in_sqlda->sqlvar[2].sqldata = (char *)&age;
in_sqlda->sqlvar[2].sqllen = strlen(age);
in_sqlda->sqlvar[2].sqltype = SQL_TEXT;
in_sqlda->sqlvar[2].sqlind = &flag2;
#elif 0
// This does NOT work
printf("Encoding age with SQL_SHORT\n");
short age = 99;
in_sqlda->sqlvar[2].sqldata = (char *)&age;
in_sqlda->sqlvar[2].sqllen = sizeof(short);
in_sqlda->sqlvar[2].sqltype = SQL_SHORT;
in_sqlda->sqlvar[2].sqlind = &flag2;
#elif 0
// This does NOT work
printf("Encoding age with SQL_LONG/int\n");
int age = 99;
in_sqlda->sqlvar[2].sqldata = (char *)&age;
in_sqlda->sqlvar[2].sqllen = sizeof(int);
in_sqlda->sqlvar[2].sqltype = SQL_LONG;
in_sqlda->sqlvar[2].sqlind = &flag2;
#elif 0
// This does NOT work
printf("Encoding age with SQL_LONG/long\n");
long age = 99;
in_sqlda->sqlvar[2].sqldata = (char *)&age;
in_sqlda->sqlvar[2].sqllen = sizeof(long);
in_sqlda->sqlvar[2].sqltype = SQL_LONG;
in_sqlda->sqlvar[2].sqlind = &flag2;
#else
// This does NOT work
printf("Encoding age with SQL_INT64\n");
__int64 age = 99;
in_sqlda->sqlvar[2].sqldata = (char *)&age;
in_sqlda->sqlvar[2].sqllen = sizeof(__int64);
in_sqlda->sqlvar[2].sqltype = SQL_INT64;
in_sqlda->sqlvar[2].sqlind = &flag2;
#endif
--- In firebird-support@yahoogroups.com, Dmitry Yemanov <dimitr@...>
wrote:
I'm using MS VC++ 6.0. I get a failure with short, int, and __int64.
For these types, the value stored in the database is 0. For float,
double, and text (which all correctly store 99 in the database), FB
seems to understand how to coerce the given value to INTEGER. Here's
an expanded version of the conditional block I used to test the
various SQL_xxx constants:
#if 0
// This WORKS
printf("Encoding age with SQL_FLOAT\n");
float age = 99.0;
in_sqlda->sqlvar[2].sqldata = (char *)&age;
in_sqlda->sqlvar[2].sqllen = sizeof(float);
in_sqlda->sqlvar[2].sqltype = SQL_FLOAT;
in_sqlda->sqlvar[2].sqlind = &flag2;
#elif 0
// This WORKS
printf("Encoding age with SQL_DOUBLE\n");
double age = 99.0;
in_sqlda->sqlvar[2].sqldata = (char *)&age;
in_sqlda->sqlvar[2].sqllen = sizeof(double);
in_sqlda->sqlvar[2].sqltype = SQL_DOUBLE;
in_sqlda->sqlvar[2].sqlind = &flag2;
#elif 0
// This WORKS
printf("Encoding age with SQL_TEXT\n");
char age[3];
strcpy(age, "99");
in_sqlda->sqlvar[2].sqldata = (char *)&age;
in_sqlda->sqlvar[2].sqllen = strlen(age);
in_sqlda->sqlvar[2].sqltype = SQL_TEXT;
in_sqlda->sqlvar[2].sqlind = &flag2;
#elif 0
// This does NOT work
printf("Encoding age with SQL_SHORT\n");
short age = 99;
in_sqlda->sqlvar[2].sqldata = (char *)&age;
in_sqlda->sqlvar[2].sqllen = sizeof(short);
in_sqlda->sqlvar[2].sqltype = SQL_SHORT;
in_sqlda->sqlvar[2].sqlind = &flag2;
#elif 0
// This does NOT work
printf("Encoding age with SQL_LONG/int\n");
int age = 99;
in_sqlda->sqlvar[2].sqldata = (char *)&age;
in_sqlda->sqlvar[2].sqllen = sizeof(int);
in_sqlda->sqlvar[2].sqltype = SQL_LONG;
in_sqlda->sqlvar[2].sqlind = &flag2;
#elif 0
// This does NOT work
printf("Encoding age with SQL_LONG/long\n");
long age = 99;
in_sqlda->sqlvar[2].sqldata = (char *)&age;
in_sqlda->sqlvar[2].sqllen = sizeof(long);
in_sqlda->sqlvar[2].sqltype = SQL_LONG;
in_sqlda->sqlvar[2].sqlind = &flag2;
#else
// This does NOT work
printf("Encoding age with SQL_INT64\n");
__int64 age = 99;
in_sqlda->sqlvar[2].sqldata = (char *)&age;
in_sqlda->sqlvar[2].sqllen = sizeof(__int64);
in_sqlda->sqlvar[2].sqltype = SQL_INT64;
in_sqlda->sqlvar[2].sqlind = &flag2;
#endif
--- In firebird-support@yahoogroups.com, Dmitry Yemanov <dimitr@...>
wrote:
>
> burmair wrote:
> >
> > static char* create_tbl = "CREATE TABLE dbinfo (when_created
> > TIMESTAMP, name VARCHAR(32) PRIMARY KEY, age INTEGER, stuff BLOB)";
> >
> > static char* insert_data = "INSERT INTO dbinfo (when_created, name,
> > age, stuff) VALUES (?, ?, ?, ?)";
> >
> > #if 0
> > // This WORKS
> > float age = 99.0;
> > in_sqlda->sqlvar[2].sqldata = (char *)&age;
> > in_sqlda->sqlvar[2].sqllen = sizeof(float);
> > in_sqlda->sqlvar[2].sqltype = SQL_FLOAT;
> > in_sqlda->sqlvar[2].sqlind = &flag2;
> > #else
> > // This does NOT work
> > long age = 99;
> > in_sqlda->sqlvar[2].sqldata = (char *)&age;
> > in_sqlda->sqlvar[2].sqllen = sizeof(long);
> > in_sqlda->sqlvar[2].sqltype = SQL_LONG;
> > in_sqlda->sqlvar[2].sqlind = &flag2;
> > #endif
>
> What about:
> int age = 99;
> in_sqlda->sqlvar[2].sqldata = (char *)&age;
> in_sqlda->sqlvar[2].sqllen = sizeof(int);
> ?
>
> SQL_LONG means a 32-bit integer and it looks like your compiler defines
> "long" as 64-bit.
>
>
> Dmitry
>