FB Proc Support Now Tests
Fixed the driver properly. Added test case for procedure support. Fixed drop table issue with FB.
This commit is contained in:
parent
773139c772
commit
7843cccc5e
@ -41,6 +41,7 @@ typedef struct {
|
||||
env_data* env; /* the DB enviroment this is in */
|
||||
conn_data* conn; /* the DB connection this cursor is from */
|
||||
isc_stmt_handle stmt; /* the statement handle */
|
||||
int stmt_type; /* the type of the statment */
|
||||
XSQLDA *out_sqlda; /* the cursor data array */
|
||||
} cur_data;
|
||||
|
||||
@ -126,6 +127,31 @@ static void free_cur(cur_data* cur)
|
||||
free(cur->out_sqlda);
|
||||
}
|
||||
|
||||
/*
|
||||
** Shuts down a cursor
|
||||
*/
|
||||
static int cur_shut(lua_State *L, cur_data *cur)
|
||||
{
|
||||
isc_dsql_free_statement(cur->env->status_vector, &cur->stmt,
|
||||
DSQL_close);
|
||||
if ( CHECK_DB_ERROR(cur->env->status_vector) ) {
|
||||
return return_db_error(L, cur->env->status_vector);
|
||||
}
|
||||
|
||||
/* free the cursor data */
|
||||
free_cur(cur);
|
||||
|
||||
/* remove cursor from lock count and check if statment can be unregistered */
|
||||
cur->closed = 1;
|
||||
--cur->conn->lock;
|
||||
|
||||
/* check if connection can be unregistered */
|
||||
if(cur->conn->lock == 0)
|
||||
lua_unregisterobj(L, cur->conn);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Check for valid environment.
|
||||
*/
|
||||
@ -300,7 +326,7 @@ static int conn_execute (lua_State *L) {
|
||||
|
||||
XSQLVAR *var;
|
||||
long dtype;
|
||||
int i, n, count, stmt_type;
|
||||
int i, n, count;
|
||||
|
||||
cur_data cur;
|
||||
|
||||
@ -328,14 +354,14 @@ static int conn_execute (lua_State *L) {
|
||||
}
|
||||
|
||||
/* what type of SQL statement is it? */
|
||||
stmt_type = get_statement_type(&cur);
|
||||
if(stmt_type < 0) {
|
||||
cur.stmt_type = get_statement_type(&cur);
|
||||
if(cur.stmt_type < 0) {
|
||||
free(cur.out_sqlda);
|
||||
return return_db_error(L, conn->env->status_vector);
|
||||
}
|
||||
|
||||
/* an unsupported SQL statement (something like COMMIT) */
|
||||
switch(stmt.type) {
|
||||
switch(cur.stmt_type) {
|
||||
case isc_info_sql_stmt_select:
|
||||
case isc_info_sql_stmt_insert:
|
||||
case isc_info_sql_stmt_update:
|
||||
@ -419,7 +445,7 @@ static int conn_execute (lua_State *L) {
|
||||
}
|
||||
|
||||
/* if autocommit is set and it's a non SELECT query, commit change */
|
||||
if(conn->autocommit != 0 && stmt_type > 1) {
|
||||
if(conn->autocommit != 0 && cur.stmt_type > 1) {
|
||||
isc_commit_retaining(conn->env->status_vector, &conn->transaction);
|
||||
if ( CHECK_DB_ERROR(conn->env->status_vector) ) {
|
||||
free_cur(&cur);
|
||||
@ -756,7 +782,7 @@ static int cur_fetch (lua_State *L) {
|
||||
|
||||
/* close cursor for procedures/returnings as they (currently) only
|
||||
return one result, and error on subsequent fetches */
|
||||
if (cur->stmt->type == isc_info_sql_stmt_exec_procedure) {
|
||||
if (cur->stmt_type == isc_info_sql_stmt_exec_procedure) {
|
||||
cur_shut(L, cur);
|
||||
}
|
||||
|
||||
@ -861,22 +887,13 @@ static int cur_coltypes (lua_State *L) {
|
||||
static int cur_close (lua_State *L) {
|
||||
cur_data *cur = (cur_data *)luaL_checkudata(L,1,LUASQL_CURSOR_FIREBIRD);
|
||||
luaL_argcheck (L, cur != NULL, 1, "cursor expected");
|
||||
int shut_res;
|
||||
|
||||
if(cur->closed == 0) {
|
||||
isc_dsql_free_statement(cur->env->status_vector, &cur->stmt, DSQL_drop);
|
||||
if ( CHECK_DB_ERROR(cur->env->status_vector) )
|
||||
return return_db_error(L, cur->env->status_vector);
|
||||
|
||||
/* free the cursor data */
|
||||
free_cur(cur);
|
||||
|
||||
/* remove cursor from lock count */
|
||||
cur->closed = 1;
|
||||
--cur->conn->lock;
|
||||
|
||||
/* check if connection can be unregistered */
|
||||
if(cur->conn->lock == 0)
|
||||
lua_unregisterobj(L, cur->conn);
|
||||
shut_res = cur_shut(L, cur);
|
||||
if(shut_res > 0) {
|
||||
return shut_res;
|
||||
}
|
||||
|
||||
/* return sucsess */
|
||||
lua_pushboolean(L, 1);
|
||||
@ -895,18 +912,7 @@ static int cur_gc (lua_State *L) {
|
||||
luaL_argcheck (L, cur != NULL, 1, "cursor expected");
|
||||
|
||||
if(cur->closed == 0) {
|
||||
isc_dsql_free_statement(cur->env->status_vector, &cur->stmt, DSQL_drop);
|
||||
|
||||
/* free the cursor data */
|
||||
free_cur(cur);
|
||||
|
||||
/* remove cursor from lock count */
|
||||
cur->closed = 1;
|
||||
--cur->conn->lock;
|
||||
|
||||
/* check if connection can be unregistered */
|
||||
if(cur->conn->lock == 0)
|
||||
lua_unregisterobj(L, cur->conn);
|
||||
cur_shut(L, cur);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -15,9 +15,36 @@ function create_table ()
|
||||
end
|
||||
|
||||
function drop_table ()
|
||||
-- Firebird prefers to keep DDL stuff (CREATE TABLE, etc.)
|
||||
-- seperate. So we need a new transaction i.e. connection
|
||||
-- to work in
|
||||
assert(CONN:close ())
|
||||
CONN = assert(ENV:connect (datasource, username, password))
|
||||
orig_drop_table()
|
||||
CONN:commit()
|
||||
end
|
||||
|
||||
table.insert (CONN_METHODS, "escape")
|
||||
table.insert (EXTENSIONS, escape)
|
||||
|
||||
-- Check RETURNING support
|
||||
table.insert (EXTENSIONS, function()
|
||||
local cur = assert (CONN:execute[[
|
||||
EXECUTE BLOCK
|
||||
RETURNS (A INTEGER, B INTEGER)
|
||||
AS
|
||||
BEGIN
|
||||
A = 123;
|
||||
B = 321;
|
||||
SUSPEND;
|
||||
END
|
||||
]])
|
||||
|
||||
local f1, f2 = cur:fetch ()
|
||||
assert2 (123, f1)
|
||||
assert2 (321, f2)
|
||||
cur:close ()
|
||||
|
||||
io.write (" returning")
|
||||
end)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user