From 9e4fa0a8e01c5b3e91c71fbdc713e37a98094b25 Mon Sep 17 00:00:00 2001 From: pixel Date: Fri, 28 Mar 2008 15:35:08 +0000 Subject: Forgot a break; --- lib/LuaOCCI.cc | 57 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/LuaOCCI.cc b/lib/LuaOCCI.cc index 0aa304f..6e695d8 100644 --- a/lib/LuaOCCI.cc +++ b/lib/LuaOCCI.cc @@ -1,8 +1,29 @@ +#include + #include #include using namespace oracle::occi; +template +T * lua_recast(Lua * L, int n = 1) { + Base * b; + T * r; + + b = (Base *) LuaObject::getme(L, n); + if (!b) { + L->error("Base object required; got null."); + } + + r = dynamic_cast(b); + + if (!r) { + L->error(String("Object not compatible; expecting ") + typeid(r).name() + " but got *" + typeid(*b).name() + " instead."); + } + + return r; +} + #define export_enum(L, n) \ L->push(#n); \ L->push((lua_Number) n); \ @@ -180,7 +201,8 @@ int sLua_EncapOCCI_Environment::EncapOCCI_Environment_proceed_unprotected(Lua * env->setCacheOptSize(L->tonumber(2)); break; case ENVIRONMENT_TERMINATECONNECTION: - conn = dynamic_cast((Base *) LuaObject::getme(L, 2)); +// conn = dynamic_cast((Base *) LuaObject::getme(L, 2)); + conn = lua_recast(L, 2); env->terminateConnection(conn->Get()); break; } @@ -202,7 +224,8 @@ int sLua_EncapOCCI_Environment::EncapOCCI_Environment_proceed_statics(Lua * L, i r = 1; break; case ENVIRONMENT_TERMINATEENVIRONMENT: - env = dynamic_cast((Base *) LuaObject::getme(L)); +// env = dynamic_cast((Base *) LuaObject::getme(L)); + env = lua_recast(L); Environment::terminateEnvironment(env->Get()); break; } @@ -332,7 +355,8 @@ int sLua_EncapOCCI_Connection::EncapOCCI_Connection_proceed_unprotected(Lua * L, conn->rollback(); break; case CONNECTION_TERMINATESTATEMENT: - stmt = dynamic_cast((Base *) LuaObject::getme(L, 2)); +// stmt = dynamic_cast((Base *) LuaObject::getme(L, 2)); + stmt = lua_recast(L, 2); conn->terminateStatement(stmt->Get()); break; } @@ -654,11 +678,13 @@ int sLua_EncapOCCI_Statement::EncapOCCI_Statement_proceed_unprotected(Lua * L, i stmt->addIteration(); break; case STATEMENT_CLOSERESULTSET: - rset = dynamic_cast((Base *) LuaObject::getme(L, 2)); +// rset = dynamic_cast((Base *) LuaObject::getme(L, 2))->Get(); + rset = lua_recast(L, 2)->Get(); stmt->closeResultSet(rset); break; case STATEMENT_CLOSESTREAM: - strm = dynamic_cast((Base *) LuaObject::getme(L, 2)); +// strm = dynamic_cast((Base *) LuaObject::getme(L, 2))->Get(); + strm = lua_recast(L, 2)->Get(); stmt->closeStream(strm); break; case STATEMENT_EXECUTE: @@ -816,7 +842,7 @@ int sLua_EncapOCCI_Statement::EncapOCCI_Statement_proceed_unprotected(Lua * L, i r = 1; break; case STATEMENT_GETSTRING: - L->push(stmt->getString(L->tonumber(2)).c_str()); + L->push(String(stmt->getString(L->tonumber(2)).c_str())); r = 1; break; case STATEMENT_GETUINT: @@ -859,7 +885,8 @@ int sLua_EncapOCCI_Statement::EncapOCCI_Statement_proceed_unprotected(Lua * L, i Blob blob; blob.setEmpty(); strm = blob.getStream(1, 0); - Buffer * b = dynamic_cast((Base *) LuaObject::getme(L, 3)); +// Buffer * b = dynamic_cast((Base *) LuaObject::getme(L, 3)); + Buffer * b = lua_recast(L, 3); strm->writeBuffer((char *) b->GetBuffer(), b->GetSize()); strm->writeLastBuffer((char *) b->GetBuffer(), 0); blob.closeStream(strm); @@ -868,7 +895,8 @@ int sLua_EncapOCCI_Statement::EncapOCCI_Statement_proceed_unprotected(Lua * L, i break; case STATEMENT_SETBYTES: { - Buffer * b = dynamic_cast((Base *) LuaObject::getme(L, 3)); +// Buffer * b = dynamic_cast((Base *) LuaObject::getme(L, 3)); + Buffer * b = lua_recast(L, 3); Bytes bytes((unsigned char *) b->GetBuffer(), b->GetSize()); stmt->setBytes(L->tonumber(2), bytes); } @@ -914,7 +942,8 @@ int sLua_EncapOCCI_Statement::EncapOCCI_Statement_proceed_unprotected(Lua * L, i break; case STATEMENT_SETROWID: { - Buffer * b = dynamic_cast((Base *) LuaObject::getme(L, 3)); +// Buffer * b = dynamic_cast((Base *) LuaObject::getme(L, 3)); + Buffer * b = lua_recast(L, 3); Bytes bytes((unsigned char *) b->GetBuffer(), b->GetSize()); stmt->setRowid(L->tonumber(2), bytes); } @@ -1224,7 +1253,7 @@ int sLua_EncapOCCI_ResultSet::EncapOCCI_ResultSet_proceed_unprotected(Lua * L, i r = 1; break; case RESULTSET_GETSTRING: - L->push(rset->getString(L->tonumber(2)).c_str()); + L->push(String(rset->getString(L->tonumber(2)).c_str())); r = 1; break; case RESULTSET_GETUINT: @@ -1245,6 +1274,8 @@ int sLua_EncapOCCI_ResultSet::EncapOCCI_ResultSet_proceed_unprotected(Lua * L, i } else { L->push((lua_Number) rset->next()); } + r = 1; + break; case RESULTSET_PRETRUNCATIONLENGTH: L->push((lua_Number) rset->preTruncationLength(L->tonumber(2))); r = 1; @@ -1395,11 +1426,13 @@ int sLua_EncapOCCI_Stream::EncapOCCI_Stream_proceed_unprotected(Lua * L, int n, r = 2; break; case STREAM_WRITEBUFFER: - b = dynamic_cast((Base *) LuaObject::getme(L, 2)); +// b = dynamic_cast((Base *) LuaObject::getme(L, 2)); + b = lua_recast(L, 2); strm->writeBuffer((char *) b->GetBuffer(), L->tonumber(3)); break; case STREAM_WRITELASTBUFFER: - b = dynamic_cast((Base *) LuaObject::getme(L, 2)); +// b = dynamic_cast((Base *) LuaObject::getme(L, 2)); + b = lua_recast(L, 2); strm->writeLastBuffer((char *) b->GetBuffer(), L->tonumber(3)); break; case STREAM_STATUS: -- cgit v1.2.3