Platform agnostic column buffers

Issues with integer sizes differing between 32 & 64-bit archs
This commit is contained in:
blumf 2015-07-31 15:34:13 +01:00
parent ac557a7fcd
commit fc11132618

View File

@ -280,6 +280,13 @@ static int count_rows_affected(cur_data* cur)
return res;
}
static void *malloc_zero(size_t len)
{
void *res = malloc(len);
memset(res, 0, len);
return res;
}
/*
** Executes a SQL statement.
** Returns
@ -353,37 +360,37 @@ static int conn_execute (lua_State *L) {
dtype = (var->sqltype & ~1); /* drop flag bit for now */
switch(dtype) {
case SQL_VARYING:
var->sqldata = (char *)malloc(sizeof(char)*var->sqllen + 2);
var->sqldata = (char *)malloc_zero(sizeof(char)*var->sqllen + 2);
break;
case SQL_TEXT:
var->sqldata = (char *)malloc(sizeof(char)*var->sqllen);
var->sqldata = (char *)malloc_zero(sizeof(char)*var->sqllen);
break;
case SQL_SHORT:
var->sqldata = (char *)malloc(sizeof(short));
var->sqldata = (char *)malloc_zero(sizeof(ISC_SHORT));
break;
case SQL_LONG:
var->sqldata = (char *)malloc(sizeof(long));
var->sqldata = (char *)malloc_zero(sizeof(ISC_LONG));
break;
case SQL_INT64:
var->sqldata = (char *)malloc(sizeof(ISC_INT64));
var->sqldata = (char *)malloc_zero(sizeof(ISC_INT64));
break;
case SQL_FLOAT:
var->sqldata = (char *)malloc(sizeof(float));
var->sqldata = (char *)malloc_zero(sizeof(float));
break;
case SQL_DOUBLE:
var->sqldata = (char *)malloc(sizeof(double));
var->sqldata = (char *)malloc_zero(sizeof(double));
break;
case SQL_TYPE_TIME:
var->sqldata = (char *)malloc(sizeof(ISC_TIME));
var->sqldata = (char *)malloc_zero(sizeof(ISC_TIME));
break;
case SQL_TYPE_DATE:
var->sqldata = (char *)malloc(sizeof(ISC_DATE));
var->sqldata = (char *)malloc_zero(sizeof(ISC_DATE));
break;
case SQL_TIMESTAMP:
var->sqldata = (char *)malloc(sizeof(ISC_TIMESTAMP));
var->sqldata = (char *)malloc_zero(sizeof(ISC_TIMESTAMP));
break;
case SQL_BLOB:
var->sqldata = (char *)malloc(sizeof(ISC_QUAD));
var->sqldata = (char *)malloc_zero(sizeof(ISC_QUAD));
break;
/* TODO : add extra data type handles here */
}
@ -622,10 +629,10 @@ static void push_column(lua_State *L, int i, cur_data *cur) {
lua_pushlstring(L, cur->out_sqlda->sqlvar[i].sqldata, cur->out_sqlda->sqlvar[i].sqllen);
break;
case SQL_SHORT:
luasql_pushinteger(L, *(short*)(cur->out_sqlda->sqlvar[i].sqldata));
luasql_pushinteger(L, *(ISC_SHORT*)(cur->out_sqlda->sqlvar[i].sqldata));
break;
case SQL_LONG:
luasql_pushinteger(L, *(long*)(cur->out_sqlda->sqlvar[i].sqldata));
luasql_pushinteger(L, *(ISC_LONG*)(cur->out_sqlda->sqlvar[i].sqldata));
break;
case SQL_INT64:
luasql_pushinteger(L, *(ISC_INT64*)(cur->out_sqlda->sqlvar[i].sqldata));