summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/LuaOCCI.cc57
1 files changed, 45 insertions, 12 deletions
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 <typeinfo>
+
#include <LuaHandle.h>
#include <LuaOCCI.h>
using namespace oracle::occi;
+template<class T>
+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<T *>(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<EncapOCCI_Connection *>((Base *) LuaObject::getme(L, 2));
+// conn = dynamic_cast<EncapOCCI_Connection *>((Base *) LuaObject::getme(L, 2));
+ conn = lua_recast<EncapOCCI_Connection>(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<EncapOCCI_Environment *>((Base *) LuaObject::getme(L));
+// env = dynamic_cast<EncapOCCI_Environment *>((Base *) LuaObject::getme(L));
+ env = lua_recast<EncapOCCI_Environment>(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<EncapOCCI_Statement *>((Base *) LuaObject::getme(L, 2));
+// stmt = dynamic_cast<EncapOCCI_Statement *>((Base *) LuaObject::getme(L, 2));
+ stmt = lua_recast<EncapOCCI_Statement>(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<ResultSet *>((Base *) LuaObject::getme(L, 2));
+// rset = dynamic_cast<EncapOCCI_ResultSet *>((Base *) LuaObject::getme(L, 2))->Get();
+ rset = lua_recast<EncapOCCI_ResultSet>(L, 2)->Get();
stmt->closeResultSet(rset);
break;
case STATEMENT_CLOSESTREAM:
- strm = dynamic_cast<Stream *>((Base *) LuaObject::getme(L, 2));
+// strm = dynamic_cast<EncapOCCI_Stream *>((Base *) LuaObject::getme(L, 2))->Get();
+ strm = lua_recast<EncapOCCI_Stream>(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<Buffer *>((Base *) LuaObject::getme(L, 3));
+// Buffer * b = dynamic_cast<Buffer *>((Base *) LuaObject::getme(L, 3));
+ Buffer * b = lua_recast<Buffer>(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<Buffer *>((Base *) LuaObject::getme(L, 3));
+// Buffer * b = dynamic_cast<Buffer *>((Base *) LuaObject::getme(L, 3));
+ Buffer * b = lua_recast<Buffer>(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<Buffer *>((Base *) LuaObject::getme(L, 3));
+// Buffer * b = dynamic_cast<Buffer *>((Base *) LuaObject::getme(L, 3));
+ Buffer * b = lua_recast<Buffer>(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<Buffer *>((Base *) LuaObject::getme(L, 2));
+// b = dynamic_cast<Buffer *>((Base *) LuaObject::getme(L, 2));
+ b = lua_recast<Buffer>(L, 2);
strm->writeBuffer((char *) b->GetBuffer(), L->tonumber(3));
break;
case STREAM_WRITELASTBUFFER:
- b = dynamic_cast<Buffer *>((Base *) LuaObject::getme(L, 2));
+// b = dynamic_cast<Buffer *>((Base *) LuaObject::getme(L, 2));
+ b = lua_recast<Buffer>(L, 2);
strm->writeLastBuffer((char *) b->GetBuffer(), L->tonumber(3));
break;
case STREAM_STATUS: