Expect integers instead of longs within prepared statements
This commit is contained in:
parent
37a7de0001
commit
5758f775f5
|
@ -235,7 +235,7 @@ static int _pgsql_prepare_query(PgSQL * pgsql, PgSQLStatement * statement,
|
||||||
size_t cnt;
|
size_t cnt;
|
||||||
int type;
|
int type;
|
||||||
char const * name;
|
char const * name;
|
||||||
long l;
|
int l;
|
||||||
char buf[32];
|
char buf[32];
|
||||||
time_t t;
|
time_t t;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
|
@ -259,8 +259,8 @@ static int _pgsql_prepare_query(PgSQL * pgsql, PgSQLStatement * statement,
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case DT_INTEGER:
|
case DT_INTEGER:
|
||||||
l = va_arg(args, long);
|
l = va_arg(args, int);
|
||||||
snprintf(buf, sizeof(buf), "%ld", l);
|
snprintf(buf, sizeof(buf), "%d", l);
|
||||||
v[cnt] = strdup(buf);
|
v[cnt] = strdup(buf);
|
||||||
break;
|
break;
|
||||||
case DT_TIMESTAMP:
|
case DT_TIMESTAMP:
|
||||||
|
@ -282,6 +282,10 @@ static int _pgsql_prepare_query(PgSQL * pgsql, PgSQLStatement * statement,
|
||||||
}
|
}
|
||||||
if(v[cnt] == NULL)
|
if(v[cnt] == NULL)
|
||||||
ret = -error_set_code(1, "%s", strerror(errno));
|
ret = -error_set_code(1, "%s", strerror(errno));
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr, "DEBUG: %s() %lu: type %u, \"%s\": \"%s\"\n",
|
||||||
|
__func__, cnt + 1, type, name, v[cnt]);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if(ret != 0)
|
if(ret != 0)
|
||||||
{
|
{
|
||||||
|
@ -293,11 +297,11 @@ static int _pgsql_prepare_query(PgSQL * pgsql, PgSQLStatement * statement,
|
||||||
pgsql->last = InvalidOid;
|
pgsql->last = InvalidOid;
|
||||||
res = PQexecPrepared(pgsql->handle, statement->query, cnt, v, NULL,
|
res = PQexecPrepared(pgsql->handle, statement->query, cnt, v, NULL,
|
||||||
NULL, 0);
|
NULL, 0);
|
||||||
|
ret = _pgsql_process(pgsql, res, callback, data);
|
||||||
|
PQclear(res);
|
||||||
for(i = 0; i < cnt; i++)
|
for(i = 0; i < cnt; i++)
|
||||||
free(v[i]);
|
free(v[i]);
|
||||||
free(v);
|
free(v);
|
||||||
ret = _pgsql_process(pgsql, res, callback, data);
|
|
||||||
PQclear(res);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,7 @@ static int _sqlite3_prepare_query(SQLite3 * sqlite3,
|
||||||
char ** argv;
|
char ** argv;
|
||||||
char ** columns;
|
char ** columns;
|
||||||
char ** p;
|
char ** p;
|
||||||
long l;
|
int l;
|
||||||
time_t t;
|
time_t t;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
char buf[32];
|
char buf[32];
|
||||||
|
@ -191,7 +191,7 @@ static int _sqlite3_prepare_query(SQLite3 * sqlite3,
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case DT_INTEGER:
|
case DT_INTEGER:
|
||||||
l = va_arg(args, long);
|
l = va_arg(args, int);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "DEBUG: %s() %s=\"%ld\"\n",
|
fprintf(stderr, "DEBUG: %s() %s=\"%ld\"\n",
|
||||||
__func__, name, l);
|
__func__, name, l);
|
||||||
|
@ -278,7 +278,7 @@ static int _sqlite3_prepare_query(SQLite3 * sqlite3,
|
||||||
case SQLITE_INTEGER:
|
case SQLITE_INTEGER:
|
||||||
l = sqlite3_column_int(statement->stmt,
|
l = sqlite3_column_int(statement->stmt,
|
||||||
i);
|
i);
|
||||||
snprintf(buf, sizeof(buf), "%ld", l);
|
snprintf(buf, sizeof(buf), "%d", l);
|
||||||
s = buf;
|
s = buf;
|
||||||
break;
|
break;
|
||||||
case SQLITE_TEXT:
|
case SQLITE_TEXT:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user