got mysql::execute() and mysql::fetch() working
This commit is contained in:
parent
49b7896ba0
commit
e2af46cabe
@ -1374,7 +1374,7 @@ static int fnc_stmt_execute (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
data->u.dv = fv;
|
data->u.dv = fv;
|
||||||
data->is_null = hawk_rtx_isnilval(rtx, va);
|
data->is_null = hawk_rtx_isnilval(rtx, va);
|
||||||
|
|
||||||
bind->buffer_type = MYSQL_TYPE_LONGLONG;
|
bind->buffer_type = MYSQL_TYPE_DOUBLE;
|
||||||
bind->buffer = &data->u.dv;
|
bind->buffer = &data->u.dv;
|
||||||
bind->is_null = &data->is_null;
|
bind->is_null = &data->is_null;
|
||||||
break;
|
break;
|
||||||
@ -1468,23 +1468,29 @@ static int fnc_stmt_execute (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
HAWK_MEMSET (stmt_node->res_binds, 0, HAWK_SIZEOF(MYSQL_BIND)* stmt_node->res_capa);
|
HAWK_MEMSET (stmt_node->res_binds, 0, HAWK_SIZEOF(MYSQL_BIND)* stmt_node->res_capa);
|
||||||
HAWK_MEMSET (stmt_node->res_data, 0, HAWK_SIZEOF(res_data_t)* stmt_node->res_capa);
|
HAWK_MEMSET (stmt_node->res_data, 0, HAWK_SIZEOF(res_data_t)* stmt_node->res_capa);
|
||||||
|
|
||||||
bind = &stmt_node->res_binds[i];
|
|
||||||
data = &stmt_node->res_data[i];
|
|
||||||
for (i = 0; i < ncols; i++)
|
for (i = 0; i < ncols; i++)
|
||||||
{
|
{
|
||||||
/* TOOD: more types... */
|
/* TOOD: more types... */
|
||||||
|
bind = &stmt_node->res_binds[i];
|
||||||
|
data = &stmt_node->res_data[i];
|
||||||
|
|
||||||
switch(cinfo[i].type)
|
switch(cinfo[i].type)
|
||||||
{
|
{
|
||||||
|
case MYSQL_TYPE_LONGLONG:
|
||||||
case MYSQL_TYPE_LONG:
|
case MYSQL_TYPE_LONG:
|
||||||
case MYSQL_TYPE_SHORT:
|
case MYSQL_TYPE_SHORT:
|
||||||
bind->buffer_type = MYSQL_TYPE_LONG;
|
case MYSQL_TYPE_TINY:
|
||||||
bind->buffer = &data[i].u.llv;
|
case MYSQL_TYPE_BIT:
|
||||||
|
case MYSQL_TYPE_INT24:
|
||||||
|
bind->buffer_type = MYSQL_TYPE_LONGLONG;
|
||||||
|
bind->buffer = &data->u.llv;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MYSQL_TYPE_FLOAT:
|
case MYSQL_TYPE_FLOAT:
|
||||||
case MYSQL_TYPE_DOUBLE:
|
case MYSQL_TYPE_DOUBLE:
|
||||||
bind->buffer_type = MYSQL_TYPE_DOUBLE;
|
bind->buffer_type = MYSQL_TYPE_DOUBLE;
|
||||||
bind->buffer = &data[i].u.dv;
|
bind->buffer = &data->u.dv;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MYSQL_TYPE_STRING:
|
case MYSQL_TYPE_STRING:
|
||||||
@ -1493,23 +1499,25 @@ static int fnc_stmt_execute (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
bind->buffer_type = MYSQL_TYPE_STRING;
|
bind->buffer_type = MYSQL_TYPE_STRING;
|
||||||
|
|
||||||
res_string:
|
res_string:
|
||||||
data[i].u.sv.ptr = hawk_rtx_allocmem(rtx, cinfo[i].length + 1);
|
data->u.sv.ptr = hawk_rtx_allocmem(rtx, cinfo[i].length + 1);
|
||||||
if (!data[i].u.sv.ptr) { take_rtx_err = 1; goto done; }
|
if (!data->u.sv.ptr) { take_rtx_err = 1; goto done; }
|
||||||
data[i].u.sv.len = cinfo[i].length + 1;
|
data->u.sv.len = 0;
|
||||||
|
|
||||||
printf ("XX %d XX\n", data[i].u.sv.len);
|
bind->buffer = data->u.sv.ptr;
|
||||||
|
|
||||||
|
|
||||||
bind->buffer = data[i].u.sv.ptr;
|
|
||||||
bind->buffer_length = cinfo[i].length + 1;
|
bind->buffer_length = cinfo[i].length + 1;
|
||||||
bind->length = &data[i].u.sv.len;
|
bind->length = &data->u.sv.len;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MYSQL_TYPE_BLOB:
|
case MYSQL_TYPE_BLOB:
|
||||||
|
case MYSQL_TYPE_TINY_BLOB:
|
||||||
|
case MYSQL_TYPE_MEDIUM_BLOB:
|
||||||
|
case MYSQL_TYPE_LONG_BLOB:
|
||||||
default: /* TOOD: i must not do this.... treat others properly */
|
default: /* TOOD: i must not do this.... treat others properly */
|
||||||
bind->buffer_type = MYSQL_TYPE_BLOB;
|
bind->buffer_type = MYSQL_TYPE_BLOB;
|
||||||
goto res_string;
|
goto res_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bind->is_null = &data->is_null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mysql_stmt_bind_result(stmt_node->stmt, stmt_node->res_binds) != 0)
|
if (mysql_stmt_bind_result(stmt_node->stmt, stmt_node->res_binds) != 0)
|
||||||
@ -1552,7 +1560,7 @@ static int fnc_stmt_fetch (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
if (n == MYSQL_NO_DATA) ret = 0; /* no more data */
|
if (n == MYSQL_NO_DATA) ret = 0; /* no more data */
|
||||||
else if (n == 0)
|
else if (n == 0)
|
||||||
{
|
{
|
||||||
hawk_oow_t i, nargs;
|
hawk_oow_t i, j, nargs;
|
||||||
MYSQL_BIND* bind;
|
MYSQL_BIND* bind;
|
||||||
res_data_t* data;
|
res_data_t* data;
|
||||||
/* there is data */
|
/* there is data */
|
||||||
@ -1564,29 +1572,33 @@ static int fnc_stmt_fetch (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
{
|
{
|
||||||
hawk_val_t* cv;
|
hawk_val_t* cv;
|
||||||
|
|
||||||
bind = &stmt_node->res_binds[i];
|
j = i - 1;
|
||||||
data = &stmt_node->res_data[i];
|
bind = &stmt_node->res_binds[j];
|
||||||
|
data = &stmt_node->res_data[j];
|
||||||
|
|
||||||
/* TODO: is_null?? */
|
if (data->is_null) cv = hawk_rtx_makenilval(rtx);
|
||||||
switch (bind->buffer_type)
|
else
|
||||||
{
|
{
|
||||||
case MYSQL_TYPE_LONG:
|
switch (bind->buffer_type)
|
||||||
cv = hawk_rtx_makeintval(rtx, data->u.llv);
|
{
|
||||||
break;
|
case MYSQL_TYPE_LONGLONG:
|
||||||
case MYSQL_TYPE_DOUBLE:
|
cv = hawk_rtx_makeintval(rtx, data->u.llv);
|
||||||
cv = hawk_rtx_makefltval(rtx, data->u.dv);
|
break;
|
||||||
break;
|
case MYSQL_TYPE_DOUBLE:
|
||||||
case MYSQL_TYPE_STRING:
|
cv = hawk_rtx_makefltval(rtx, data->u.dv);
|
||||||
cv = hawk_rtx_makestrvalwithbchars(rtx, data->u.sv.ptr, data->u.sv.len);
|
break;
|
||||||
break;
|
case MYSQL_TYPE_STRING:
|
||||||
case MYSQL_TYPE_BLOB:
|
cv = hawk_rtx_makestrvalwithbchars(rtx, data->u.sv.ptr, data->u.sv.len);
|
||||||
cv = hawk_rtx_makembsval(rtx, data->u.sv.ptr, data->u.sv.len);
|
break;
|
||||||
break;
|
case MYSQL_TYPE_BLOB:
|
||||||
|
cv = hawk_rtx_makembsval(rtx, data->u.sv.ptr, data->u.sv.len);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* this must not happen */
|
/* this must not happen */
|
||||||
set_error_on_sql_list (rtx, sql_list, HAWK_T("internal error"));
|
set_error_on_sql_list (rtx, sql_list, HAWK_T("internal error - invalid buffer_type %d"), (int)bind->buffer_type);
|
||||||
goto done;
|
goto done;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cv || hawk_rtx_setrefval(rtx, (hawk_val_ref_t*)hawk_rtx_getarg(rtx, i), cv) <= -1)
|
if (!cv || hawk_rtx_setrefval(rtx, (hawk_val_ref_t*)hawk_rtx_getarg(rtx, i), cv) <= -1)
|
||||||
@ -1596,7 +1608,7 @@ static int fnc_stmt_fetch (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 1;
|
ret = 1; /* have data */
|
||||||
}
|
}
|
||||||
else if (n == MYSQL_DATA_TRUNCATED)
|
else if (n == MYSQL_DATA_TRUNCATED)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user