#include #include #include using namespace oracle::occi; static Environment * global_env = 0; #define export_enum(L, n) \ L->push(#n); \ L->push((lua_Number) n); \ L->settable(LUA_GLOBALSINDEX); /*** Environment bindings ***/ /* TODO: getMap (and Map objects) support. ConnectionPool support. */ enum EncapOCCI_Environment_methods_t { ENVIRONMENT_SETEXCEPTIONS = 0, ENVIRONMENT_GETERRORMSG, ENVIRONMENT_GETERRORCODE, ENVIRONMENT_CREATECONNECTION, ENVIRONMENT_GETCACHEMAXSIZE, ENVIRONMENT_GETCACHEOPTSIZE, ENVIRONMENT_GETCURRENTHEAPSIZE, ENVIRONMENT_SETCACHEMAXSIZE, ENVIRONMENT_SETCACHEOPTSIZE, ENVIRONMENT_TERMINATECONNECTION, }; enum EncapOCCI_Environment_functions_t { ENVIRONMENT_CREATEENVIRONMENT = 0, ENVIRONMENT_TERMINATEENVIRONMENT, }; struct lua_functypes_t EncapOCCI_Environment_methods[] = { { ENVIRONMENT_SETEXCEPTIONS, "setExceptions", 1, 1, { BLUA_BOOLEAN } }, { ENVIRONMENT_GETERRORMSG, "getErrorMsg", 0, 0, { } }, { ENVIRONMENT_GETERRORCODE, "getErrorCode", 0, 0, { } }, { ENVIRONMENT_CREATECONNECTION, "createConnection", 2, 3, { BLUA_STRING, BLUA_STRING, BLUA_STRING } }, { ENVIRONMENT_GETCACHEMAXSIZE, "getCacheMaxSize", 0, 0, { } }, { ENVIRONMENT_GETCACHEOPTSIZE, "getCacheOptSize", 0, 0, { } }, { ENVIRONMENT_GETCURRENTHEAPSIZE, "getCurrentHeapSize", 0, 0, { } }, { ENVIRONMENT_SETCACHEMAXSIZE, "setCacheMaxSize", 1, 1, { BLUA_NUMBER } }, { ENVIRONMENT_SETCACHEOPTSIZE, "setCacheOptSize", 1, 1, { BLUA_NUMBER } }, { ENVIRONMENT_TERMINATECONNECTION, "terminateConnection", 1, 1, { BLUA_OBJECT } }, { -1, 0, 0, 0, 0 }, }; struct lua_functypes_t EncapOCCI_Environment_functions[] = { { ENVIRONMENT_CREATEENVIRONMENT, "createEnvironment", 0, 0, { } }, { ENVIRONMENT_TERMINATEENVIRONMENT, "terminateEnvironment", 1, 1, { BLUA_OBJECT } }, { -1, 0, 0, 0, 0 }, }; class sLua_EncapOCCI_Environment : public Base { public: DECLARE_METHOD(EncapOCCI_Environment, ENVIRONMENT_SETEXCEPTIONS); DECLARE_METHOD(EncapOCCI_Environment, ENVIRONMENT_GETERRORMSG); DECLARE_METHOD(EncapOCCI_Environment, ENVIRONMENT_GETERRORCODE); DECLARE_METHOD(EncapOCCI_Environment, ENVIRONMENT_CREATECONNECTION); DECLARE_METHOD(EncapOCCI_Environment, ENVIRONMENT_GETCACHEMAXSIZE); DECLARE_METHOD(EncapOCCI_Environment, ENVIRONMENT_GETCACHEOPTSIZE); DECLARE_METHOD(EncapOCCI_Environment, ENVIRONMENT_GETCURRENTHEAPSIZE); DECLARE_METHOD(EncapOCCI_Environment, ENVIRONMENT_SETCACHEMAXSIZE); DECLARE_METHOD(EncapOCCI_Environment, ENVIRONMENT_SETCACHEOPTSIZE); DECLARE_METHOD(EncapOCCI_Environment, ENVIRONMENT_TERMINATECONNECTION); DECLARE_FUNCTION(EncapOCCI_Environment, ENVIRONMENT_CREATEENVIRONMENT); DECLARE_FUNCTION(EncapOCCI_Environment, ENVIRONMENT_TERMINATEENVIRONMENT); private: static int EncapOCCI_Environment_proceed(Lua * L, int n, EncapOCCI_Environment * obj, int caller); static int EncapOCCI_Environment_proceed_unprotected(Lua * L, int n, EncapOCCI_Environment * obj, int caller); static int EncapOCCI_Environment_proceed_statics(Lua * L, int n, int caller); }; void LuaOCCI_Environment::pushmembers(Lua * L) { pushme(L, o, "OCCI_Environment"); PUSH_METHOD(EncapOCCI_Environment, ENVIRONMENT_SETEXCEPTIONS); PUSH_METHOD(EncapOCCI_Environment, ENVIRONMENT_GETERRORMSG); PUSH_METHOD(EncapOCCI_Environment, ENVIRONMENT_GETERRORCODE); PUSH_METHOD(EncapOCCI_Environment, ENVIRONMENT_CREATECONNECTION); PUSH_METHOD(EncapOCCI_Environment, ENVIRONMENT_GETCACHEMAXSIZE); PUSH_METHOD(EncapOCCI_Environment, ENVIRONMENT_GETCACHEOPTSIZE); PUSH_METHOD(EncapOCCI_Environment, ENVIRONMENT_GETCURRENTHEAPSIZE); PUSH_METHOD(EncapOCCI_Environment, ENVIRONMENT_SETCACHEMAXSIZE); PUSH_METHOD(EncapOCCI_Environment, ENVIRONMENT_SETCACHEOPTSIZE); PUSH_METHOD(EncapOCCI_Environment, ENVIRONMENT_TERMINATECONNECTION); } void LuaOCCI_Environment::pushstatics(Lua * L) throw (GeneralException) { CHECK_METHODS(EncapOCCI_Environment); CHECK_FUNCTIONS(EncapOCCI_Environment); PUSH_FUNCTION(EncapOCCI_Environment, ENVIRONMENT_CREATEENVIRONMENT); PUSH_FUNCTION(EncapOCCI_Environment, ENVIRONMENT_TERMINATEENVIRONMENT); export_enum(L, OCCIBDOUBLE); export_enum(L, OCCIBFILE); export_enum(L, OCCIBFLOAT); export_enum(L, OCCIBLOB); export_enum(L, OCCIBOOL); export_enum(L, OCCIBYTES); export_enum(L, OCCICHAR); export_enum(L, OCCICLOB); export_enum(L, OCCICURSOR); export_enum(L, OCCIDATE); export_enum(L, OCCIDOUBLE); export_enum(L, OCCIFLOAT); export_enum(L, OCCIINT); export_enum(L, OCCIINTERVALDS); export_enum(L, OCCIINTERVALYM); export_enum(L, OCCIMETADATA); export_enum(L, OCCINUMBER); export_enum(L, OCCIPOBJECT); export_enum(L, OCCIREF); export_enum(L, OCCIREFANY); export_enum(L, OCCIROWID); export_enum(L, OCCI_SQLT_AFC); // export_enum(L, OCCI_SQLT_BDOUBLE); // export_enum(L, OCCI_SQLT_BFLOAT); export_enum(L, OCCI_SQLT_BIN); export_enum(L, OCCI_SQLT_BLOB); export_enum(L, OCCI_SQLT_CHR); export_enum(L, OCCI_SQLT_CLOB); export_enum(L, OCCI_SQLT_DAT); export_enum(L, OCCI_SQLT_FILE); export_enum(L, OCCI_SQLT_INTERVAL_DS); export_enum(L, OCCI_SQLT_INTERVAL_YM); export_enum(L, OCCI_SQLT_LBI); export_enum(L, OCCI_SQLT_LNG); export_enum(L, OCCI_SQLT_LVB); export_enum(L, OCCI_SQLT_LVC); export_enum(L, OCCI_SQLT_NTY); export_enum(L, OCCI_SQLT_NUM); export_enum(L, OCCI_SQLT_RDD); export_enum(L, OCCI_SQLT_REF); export_enum(L, OCCI_SQLT_RID); export_enum(L, OCCI_SQLT_STR); export_enum(L, OCCI_SQLT_TIMESTAMP); export_enum(L, OCCI_SQLT_TIMESTAMP_LTZ); export_enum(L, OCCI_SQLT_TIMESTAMP_TZ); export_enum(L, OCCI_SQLT_VBI); export_enum(L, OCCI_SQLT_VCS); export_enum(L, OCCI_SQLT_VNU); export_enum(L, OCCISTRING); export_enum(L, OCCITIMESTAMP); export_enum(L, OCCIUNSIGNED_INT); export_enum(L, OCCIVECTOR); } int sLua_EncapOCCI_Environment::EncapOCCI_Environment_proceed(Lua * L, int n, EncapOCCI_Environment * obj, int caller) { int r = 0; try { r = EncapOCCI_Environment_proceed_unprotected(L, n, obj, caller); } catch (SQLException ex) { if (obj->disableExceptions) { obj->lastError_msg = ex.getMessage().c_str(); obj->lastError_code = ex.getErrorCode(); } else { L->error(String("Got an SQLException: ") + ex.what()); } } return r; } int sLua_EncapOCCI_Environment::EncapOCCI_Environment_proceed_unprotected(Lua * L, int n, EncapOCCI_Environment * obj, int caller) { int r = 0; EncapOCCI_Connection * conn; Environment * env = obj->Get(); String username, password, url; switch (caller) { case ENVIRONMENT_SETEXCEPTIONS: obj->disableExceptions = !L->toboolean(2); break; case ENVIRONMENT_GETERRORMSG: L->push(obj->lastError_msg); r = 1; break; case ENVIRONMENT_GETERRORCODE: L->push((lua_Number) obj->lastError_code); r = 1; break; case ENVIRONMENT_CREATECONNECTION: username = L->tostring(2); password = L->tostring(3); if (n == 2) { conn = new EncapOCCI_Connection(env->createConnection(username.to_charp(), password.to_charp())); } else { url = L->tostring(4); conn = new EncapOCCI_Connection(env->createConnection(username.to_charp(), password.to_charp(), url.to_charp())); } conn->disableExceptions = obj->disableExceptions; { LuaOCCI_Connection lconn(conn); lconn.pushdestruct(L); } r = 1; break; case ENVIRONMENT_GETCACHEMAXSIZE: r = 1; L->push((lua_Number) env->getCacheMaxSize()); break; case ENVIRONMENT_GETCACHEOPTSIZE: r = 1; L->push((lua_Number) env->getCacheOptSize()); break; case ENVIRONMENT_GETCURRENTHEAPSIZE: r = 1; L->push((lua_Number) env->getCurrentHeapSize()); break; case ENVIRONMENT_SETCACHEMAXSIZE: env->setCacheMaxSize(L->tonumber(2)); break; case ENVIRONMENT_SETCACHEOPTSIZE: env->setCacheOptSize(L->tonumber(2)); break; case ENVIRONMENT_TERMINATECONNECTION: // conn = dynamic_cast((Base *) LuaObject::getme(L, 2)); conn = lua_recast(L, 2); env->terminateConnection(conn->Get()); break; } return r; } int sLua_EncapOCCI_Environment::EncapOCCI_Environment_proceed_statics(Lua * L, int n, int caller) { int r = 0; EncapOCCI_Environment * env; try { switch (caller) { case ENVIRONMENT_CREATEENVIRONMENT: env = new EncapOCCI_Environment(Environment::createEnvironment(Environment::THREADED_MUTEXED)); if (!global_env) { global_env = env->Get(); } { LuaOCCI_Environment lenv(env); lenv.pushdestruct(L); } r = 1; break; case ENVIRONMENT_TERMINATEENVIRONMENT: // env = dynamic_cast((Base *) LuaObject::getme(L)); env = lua_recast(L); Environment::terminateEnvironment(env->Get()); break; } } catch (SQLException ex) { L->error(String("Got an SQLException: ") + ex.what()); } return r; } /*** Connection bindings ***/ enum EncapOCCI_Connection_methods_t { CONNECTION_SETEXCEPTIONS = 0, CONNECTION_GETERRORMSG, CONNECTION_GETERRORCODE, CONNECTION_CHANGEPASSWORD, CONNECTION_COMMIT, CONNECTION_CREATESTATEMENT, CONNECTION_FLUSHCACHE, CONNECTION_GETCLIENTCHARSET, CONNECTION_GETCLIENTNCHARCHARSET, // CONNECTION_GETMETADATA CONNECTION_ROLLBACK, CONNECTION_TERMINATESTATEMENT, }; struct lua_functypes_t EncapOCCI_Connection_methods[] = { { CONNECTION_SETEXCEPTIONS, "setExceptions", 1, 1, { BLUA_BOOLEAN } }, { CONNECTION_GETERRORMSG, "getErrorMsg", 0, 0, { } }, { CONNECTION_GETERRORCODE, "getErrorCode", 0, 0, { } }, { CONNECTION_CHANGEPASSWORD, "changePassword", 3, 3, { BLUA_STRING, BLUA_STRING, BLUA_STRING } }, { CONNECTION_COMMIT, "commit", 0, 0, { } }, { CONNECTION_CREATESTATEMENT, "createStatement", 0, 1, { BLUA_STRING } }, { CONNECTION_FLUSHCACHE, "flushCache", 0, 0, { } }, { CONNECTION_GETCLIENTCHARSET, "getClientCharSet", 0, 0, { } }, { CONNECTION_GETCLIENTNCHARCHARSET, "getClientNCHARCharSet", 0, 0, { } }, { CONNECTION_ROLLBACK, "rollback", 0, 0, { } }, { CONNECTION_TERMINATESTATEMENT, "terminateStatement", 1, 1, { BLUA_OBJECT } }, { -1, 0, 0, 0, 0 }, }; struct lua_functypes_t EncapOCCI_Connection_functions[] = { { -1, 0, 0, 0, 0 }, }; class sLua_EncapOCCI_Connection : public Base { public: DECLARE_METHOD(EncapOCCI_Connection, CONNECTION_SETEXCEPTIONS); DECLARE_METHOD(EncapOCCI_Connection, CONNECTION_GETERRORMSG); DECLARE_METHOD(EncapOCCI_Connection, CONNECTION_GETERRORCODE); DECLARE_METHOD(EncapOCCI_Connection, CONNECTION_CHANGEPASSWORD); DECLARE_METHOD(EncapOCCI_Connection, CONNECTION_COMMIT); DECLARE_METHOD(EncapOCCI_Connection, CONNECTION_CREATESTATEMENT); DECLARE_METHOD(EncapOCCI_Connection, CONNECTION_FLUSHCACHE); DECLARE_METHOD(EncapOCCI_Connection, CONNECTION_GETCLIENTCHARSET); DECLARE_METHOD(EncapOCCI_Connection, CONNECTION_GETCLIENTNCHARCHARSET); DECLARE_METHOD(EncapOCCI_Connection, CONNECTION_ROLLBACK); DECLARE_METHOD(EncapOCCI_Connection, CONNECTION_TERMINATESTATEMENT); private: static int EncapOCCI_Connection_proceed(Lua * L, int n, EncapOCCI_Connection * obj, int caller); static int EncapOCCI_Connection_proceed_unprotected(Lua * L, int n, EncapOCCI_Connection * obj, int caller); static int EncapOCCI_Connection_proceed_statics(Lua *L, int n, int caller); }; void LuaOCCI_Connection::pushmembers(Lua * L) { pushme(L, o, "OCCI_Connection"); PUSH_METHOD(EncapOCCI_Connection, CONNECTION_SETEXCEPTIONS); PUSH_METHOD(EncapOCCI_Connection, CONNECTION_GETERRORMSG); PUSH_METHOD(EncapOCCI_Connection, CONNECTION_GETERRORCODE); PUSH_METHOD(EncapOCCI_Connection, CONNECTION_CHANGEPASSWORD); PUSH_METHOD(EncapOCCI_Connection, CONNECTION_COMMIT); PUSH_METHOD(EncapOCCI_Connection, CONNECTION_CREATESTATEMENT); PUSH_METHOD(EncapOCCI_Connection, CONNECTION_FLUSHCACHE); PUSH_METHOD(EncapOCCI_Connection, CONNECTION_GETCLIENTCHARSET); PUSH_METHOD(EncapOCCI_Connection, CONNECTION_GETCLIENTNCHARCHARSET); PUSH_METHOD(EncapOCCI_Connection, CONNECTION_ROLLBACK); PUSH_METHOD(EncapOCCI_Connection, CONNECTION_TERMINATESTATEMENT); } void LuaOCCI_Connection::pushstatics(Lua * L) throw (GeneralException) { CHECK_METHODS(EncapOCCI_Connection); CHECK_FUNCTIONS(EncapOCCI_Connection); } int sLua_EncapOCCI_Connection::EncapOCCI_Connection_proceed(Lua * L, int n, EncapOCCI_Connection * obj, int caller) { int r; try { r = EncapOCCI_Connection_proceed_unprotected(L, n, obj, caller); } catch (SQLException ex) { if (obj->disableExceptions) { obj->lastError_msg = ex.getMessage().c_str(); obj->lastError_code = ex.getErrorCode(); } else { L->error(String("Got an SQLException: ") + ex.what()); } } return r; } int sLua_EncapOCCI_Connection::EncapOCCI_Connection_proceed_unprotected(Lua * L, int n, EncapOCCI_Connection * obj, int caller) { String user, oldpw, newpw, sql; Connection * conn = obj->Get(); EncapOCCI_Statement * stmt; int r = 0; switch(caller) { case CONNECTION_SETEXCEPTIONS: obj->disableExceptions = !L->toboolean(2); break; case CONNECTION_GETERRORMSG: L->push(obj->lastError_msg); r = 1; break; case CONNECTION_GETERRORCODE: L->push((lua_Number) obj->lastError_code); r = 1; break; case CONNECTION_CHANGEPASSWORD: user = L->tostring(2); oldpw = L->tostring(3); newpw = L->tostring(4); conn->changePassword(user.to_charp(), oldpw.to_charp(), newpw.to_charp()); break; case CONNECTION_COMMIT: conn->commit(); break; case CONNECTION_CREATESTATEMENT: if (n == 1) { sql = L->tostring(2); } stmt = new EncapOCCI_Statement(conn->createStatement(sql.to_charp())); stmt->disableExceptions = obj->disableExceptions; { LuaOCCI_Statement lstmt(stmt); lstmt.pushdestruct(L); } r = 1; break; case CONNECTION_FLUSHCACHE: conn->flushCache(); break; case CONNECTION_GETCLIENTCHARSET: L->push(conn->getClientCharSet().c_str()); r = 1; break; case CONNECTION_GETCLIENTNCHARCHARSET: L->push(conn->getClientNCHARCharSet().c_str()); r = 1; break; case CONNECTION_ROLLBACK: conn->rollback(); break; case CONNECTION_TERMINATESTATEMENT: // stmt = dynamic_cast((Base *) LuaObject::getme(L, 2)); stmt = lua_recast(L, 2); conn->terminateStatement(stmt->Get()); break; } return r; } int sLua_EncapOCCI_Connection::EncapOCCI_Connection_proceed_statics(Lua * L, int n, int caller) { return 0; } /*** Statement bindings ***/ #define export_enum_stmt(L, n) \ L->push("STATEMENT_STATUS_" #n); \ L->push((lua_Number) Statement::n); \ L->settable(LUA_GLOBALSINDEX); enum EncapOCCI_Statement_methods_t { STATEMENT_SETEXCEPTIONS = 0, STATEMENT_GETERRORMSG, STATEMENT_GETERRORCODE, STATEMENT_ADDITERATION, STATEMENT_CLOSERESULTSET, STATEMENT_CLOSESTREAM, STATEMENT_EXECUTE, STATEMENT_EXECUTEARRAYUPDATE, STATEMENT_EXECUTEQUERY, STATEMENT_EXECUTEUPDATE, STATEMENT_GETAUTOCOMMIT, // STATEMENT_GETBFILE, STATEMENT_GETBLOB, STATEMENT_GETBYTES, STATEMENT_GETCHARSET, STATEMENT_GETCLOB, STATEMENT_GETCURRENTITERATION, STATEMENT_GETCURRENTSTREAMITERATION, STATEMENT_GETCURRENTSTREAMPARAM, STATEMENT_GETCURSOR, STATEMENT_GETDATABASENCHARPARAM, // STATEMENT_GETDATE, STATEMENT_GETDOUBLE, STATEMENT_GETFLOAT, STATEMENT_GETINT, // STATEMENT_GETINTERVALDS, // STATEMENT_GETINTERVALYM, STATEMENT_GETMAXITERATIONS, STATEMENT_GETMAXPARAMSIZE, STATEMENT_GETNUMBER, // STATEMENT_GETOBJECT, // STATEMENT_GETOCISTATEMENT, // STATEMENT_GETREF, STATEMENT_GETRESULTSET, STATEMENT_GETROWID, STATEMENT_GETSQL, STATEMENT_GETSTREAM, STATEMENT_GETSTRING, // STATEMENT_GETTIMESTAMP, STATEMENT_GETUINT, STATEMENT_GETUPDATECOUNT, // STATEMENT_GETVECTOR, // STATEMENT_GETVECTOROFREFS, STATEMENT_ISNULL, STATEMENT_ISTRUNCATED, STATEMENT_PRETRUNCATIONLENGTH, STATEMENT_REGISTEROUTPARAM, STATEMENT_SETAUTOCOMMIT, // STATEMENT_SETBFILE, STATEMENT_SETBINARYSTREAMMODE, STATEMENT_SETBLOB, STATEMENT_SETBYTES, STATEMENT_SETCHARACTERSTREAMMODE, STATEMENT_SETCHARSET, // STATEMENT_SETCLOB, // STATEMENT_SETDATE, STATEMENT_SETDATABASENCHARPARAM, // STATEMENT_SETDATABUFFER, // STATEMENT_SETDATABUFFERARRAY, STATEMENT_SETDOUBLE, STATEMENT_SETERRORONNULL, STATEMENT_SETERRORONTRUNCATE, STATEMENT_SETFLOAT, STATEMENT_SETINT, // STATEMENT_SETINTERVALDS, // STATEMENT_SETINTERVALYM STATEMENT_SETMAXITERATIONS, STATEMENT_SETMAXPARAMSIZE, STATEMENT_SETNULL, STATEMENT_SETNUMBER, // STATEMENT_SETOBJECT, STATEMENT_SETPREFETCHMEMORYSIZE, STATEMENT_SETPREFETCHROWCOUNT, // STATEMENT_SETREF, STATEMENT_SETROWID, STATEMENT_SETSQL, STATEMENT_SETSTRING, // STATEMENT_SETTIMESTAMP, STATEMENT_SETUINT, // STATEMENT_SETVECTOR, // STATEMENT_SETVECTOROFREFS, STATEMENT_STATUS, }; struct lua_functypes_t EncapOCCI_Statement_methods[] = { { STATEMENT_SETEXCEPTIONS, "setExceptions", 1, 1, { BLUA_BOOLEAN } }, { STATEMENT_GETERRORMSG, "getErrorMsg", 0, 0, { } }, { STATEMENT_GETERRORCODE, "getErrorCode", 0, 0, { } }, { STATEMENT_ADDITERATION, "addIteration", 0, 0, { } }, { STATEMENT_CLOSERESULTSET, "closeResultSet", 1, 1, { BLUA_OBJECT } }, { STATEMENT_CLOSESTREAM, "closeStream", 1, 1, { BLUA_OBJECT } }, { STATEMENT_EXECUTE, "execute", 0, 1, { BLUA_STRING } }, { STATEMENT_EXECUTEARRAYUPDATE, "executeArrayUpdate", 1, 1, { BLUA_NUMBER } }, { STATEMENT_EXECUTEQUERY, "executeQuery", 0, 1, { BLUA_STRING } }, { STATEMENT_EXECUTEUPDATE, "executeUpdate", 0, 1, { BLUA_STRING } }, { STATEMENT_GETAUTOCOMMIT, "getAutoCommit", 0, 0, { } }, { STATEMENT_GETBLOB, "getBlob", 1, 1, { BLUA_NUMBER } }, { STATEMENT_GETBYTES, "getBytes", 1, 1, { BLUA_NUMBER } }, { STATEMENT_GETCHARSET, "getCharSet", 1, 1, { BLUA_NUMBER } }, { STATEMENT_GETCLOB, "getClob", 1, 1, { BLUA_NUMBER } }, { STATEMENT_GETCURRENTITERATION, "getCurrentIteration", 0, 0, { } }, { STATEMENT_GETCURRENTSTREAMITERATION, "getCurrentStreamIteration", 0, 0, { } }, { STATEMENT_GETCURRENTSTREAMPARAM, "getCurrentStreamParam", 0, 0, { } }, { STATEMENT_GETCURSOR, "getCursor", 1, 1, { BLUA_NUMBER } }, { STATEMENT_GETDATABASENCHARPARAM, "getDatabaseNCHARParam", 0, 0, { } }, { STATEMENT_GETDOUBLE, "getDouble", 1, 1, { BLUA_NUMBER } }, { STATEMENT_GETFLOAT, "getFloat", 1, 1, { BLUA_NUMBER } }, { STATEMENT_GETINT, "getInt", 1, 1, { BLUA_NUMBER } }, { STATEMENT_GETMAXITERATIONS, "getMaxIterations", 0, 0, { } }, { STATEMENT_GETMAXPARAMSIZE, "getMaxParamSize", 1, 1, { BLUA_NUMBER } }, { STATEMENT_GETNUMBER, "getNumber", 1, 2, { BLUA_NUMBER, BLUA_STRING } }, { STATEMENT_GETRESULTSET, "getResultSet", 0, 0, { } }, { STATEMENT_GETROWID, "getRowid", 1, 1, { BLUA_NUMBER } }, { STATEMENT_GETSQL, "getSQL", 0, 0, { } }, { STATEMENT_GETSTREAM, "getStream", 1, 1, { BLUA_NUMBER } }, { STATEMENT_GETSTRING, "getString", 1, 1, { BLUA_NUMBER } }, { STATEMENT_GETUINT, "getUInt", 1, 1, { BLUA_NUMBER } }, { STATEMENT_GETUPDATECOUNT, "getUpdateCount", 0, 0, { } }, { STATEMENT_ISNULL, "isNull", 1, 1, { BLUA_NUMBER } }, { STATEMENT_ISTRUNCATED, "isTruncated", 1, 1, { BLUA_NUMBER } }, { STATEMENT_PRETRUNCATIONLENGTH, "preTruncationLength", 1, 1, { BLUA_NUMBER } }, { STATEMENT_REGISTEROUTPARAM, "registerOutParam", 2, 4, { BLUA_NUMBER, BLUA_NUMBER, BLUA_NUMBER, BLUA_STRING } }, { STATEMENT_SETAUTOCOMMIT, "setAutoCommit", 1, 1, { BLUA_BOOLEAN } }, { STATEMENT_SETBINARYSTREAMMODE, "setBinaryStreamMode", 2, 2, { BLUA_NUMBER, BLUA_NUMBER } }, { STATEMENT_SETBLOB, "setBlob", 3, 3, { BLUA_OBJECT, BLUA_NUMBER, BLUA_OBJECT } }, { STATEMENT_SETBYTES, "setBytes", 2, 2, { BLUA_NUMBER, BLUA_OBJECT } }, { STATEMENT_SETCHARACTERSTREAMMODE, "setCharacterStreamMode", 2, 2, { BLUA_NUMBER, BLUA_NUMBER } }, { STATEMENT_SETCHARSET, "setCharSet", 2, 2, { BLUA_NUMBER, BLUA_STRING } }, { STATEMENT_SETDATABASENCHARPARAM, "setDatabaseNCHARParam", 2, 2, { BLUA_NUMBER, BLUA_BOOLEAN } }, { STATEMENT_SETDOUBLE, "setDouble", 2, 2, { BLUA_NUMBER, BLUA_NUMBER } }, { STATEMENT_SETERRORONNULL, "setErrorOnNull", 2, 2, { BLUA_NUMBER, BLUA_BOOLEAN } }, { STATEMENT_SETERRORONTRUNCATE, "setErrorOnTruncate", 2, 2, { BLUA_NUMBER, BLUA_BOOLEAN } }, { STATEMENT_SETFLOAT, "setFloat", 2, 2, { BLUA_NUMBER, BLUA_NUMBER } }, { STATEMENT_SETINT, "setInt", 2, 2, { BLUA_NUMBER, BLUA_NUMBER } }, { STATEMENT_SETMAXITERATIONS, "setMaxIterations", 1, 1, { BLUA_NUMBER } }, { STATEMENT_SETMAXPARAMSIZE, "setMaxParamSize", 2, 2, { BLUA_NUMBER, BLUA_NUMBER } }, { STATEMENT_SETNULL, "setNull", 2, 2, { BLUA_NUMBER, BLUA_NUMBER } }, { STATEMENT_SETNUMBER, "setNumber", 2, 3, { BLUA_NUMBER, BLUA_STRING, BLUA_STRING } }, { STATEMENT_SETPREFETCHMEMORYSIZE, "setPrefetchMemorySize", 1, 1, { BLUA_NUMBER } }, { STATEMENT_SETPREFETCHROWCOUNT, "setPrefetchRowCount", 1, 1, { BLUA_NUMBER } }, { STATEMENT_SETROWID, "SetRowid", 2, 2, { BLUA_NUMBER, BLUA_OBJECT } }, { STATEMENT_SETSQL, "setSQL", 1, 1, { BLUA_STRING } }, { STATEMENT_SETSTRING, "setString", 2, 2, { BLUA_NUMBER, BLUA_STRING } }, { STATEMENT_SETUINT, "setUInt", 2, 2, { BLUA_NUMBER, BLUA_NUMBER } }, { STATEMENT_STATUS, "status", 0, 0, { } }, { -1, 0, 0, 0, 0 }, }; struct lua_functypes_t EncapOCCI_Statement_functions[] = { { -1, 0, 0, 0, 0 }, }; class sLua_EncapOCCI_Statement : public Base { public: DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETEXCEPTIONS); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETERRORMSG); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETERRORCODE); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_ADDITERATION); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_CLOSERESULTSET); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_CLOSESTREAM); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_EXECUTE); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_EXECUTEARRAYUPDATE); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_EXECUTEQUERY); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_EXECUTEUPDATE); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETAUTOCOMMIT); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETBLOB); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETBYTES); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETCHARSET); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETCLOB); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETCURRENTITERATION); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETCURRENTSTREAMITERATION); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETCURRENTSTREAMPARAM); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETCURSOR); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETDATABASENCHARPARAM); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETDOUBLE); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETFLOAT); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETINT); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETMAXITERATIONS); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETMAXPARAMSIZE); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETNUMBER); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETRESULTSET); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETROWID); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETSQL); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETSTREAM); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETSTRING); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETUINT); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_GETUPDATECOUNT); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_ISNULL); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_ISTRUNCATED); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_PRETRUNCATIONLENGTH); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_REGISTEROUTPARAM); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETAUTOCOMMIT); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETBINARYSTREAMMODE); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETBLOB); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETBYTES); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETCHARACTERSTREAMMODE); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETCHARSET); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETDATABASENCHARPARAM); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETDOUBLE); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETERRORONNULL); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETERRORONTRUNCATE); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETFLOAT); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETINT); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETMAXITERATIONS); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETMAXPARAMSIZE); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETNULL); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETNUMBER); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETPREFETCHMEMORYSIZE); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETPREFETCHROWCOUNT); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETROWID); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETSQL); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETSTRING); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETUINT); DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_STATUS); private: static int EncapOCCI_Statement_proceed(Lua * L, int n, EncapOCCI_Statement * obj, int caller); static int EncapOCCI_Statement_proceed_unprotected(Lua * L, int n, EncapOCCI_Statement * obj, int caller); static int EncapOCCI_Statement_proceed_statics(Lua *L, int n, int caller); }; void LuaOCCI_Statement::pushmembers(Lua * L) { pushme(L, o, "OCCI_Statement"); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETEXCEPTIONS); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETERRORMSG); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETERRORCODE); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_ADDITERATION); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_CLOSERESULTSET); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_CLOSESTREAM); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_EXECUTE); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_EXECUTEARRAYUPDATE); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_EXECUTEQUERY); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_EXECUTEUPDATE); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETAUTOCOMMIT); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETBLOB); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETBYTES); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETCHARSET); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETCLOB); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETCURRENTITERATION); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETCURRENTSTREAMITERATION); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETCURRENTSTREAMPARAM); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETCURSOR); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETDATABASENCHARPARAM); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETDOUBLE); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETFLOAT); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETINT); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETMAXITERATIONS); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETMAXPARAMSIZE); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETNUMBER); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETRESULTSET); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETROWID); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETSQL); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETSTREAM); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETSTRING); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETUINT); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_GETUPDATECOUNT); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_ISNULL); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_ISTRUNCATED); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_PRETRUNCATIONLENGTH); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_REGISTEROUTPARAM); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETAUTOCOMMIT); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETBINARYSTREAMMODE); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETBLOB); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETBYTES); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETCHARACTERSTREAMMODE); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETCHARSET); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETDATABASENCHARPARAM); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETDOUBLE); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETERRORONNULL); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETERRORONTRUNCATE); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETFLOAT); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETINT); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETMAXITERATIONS); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETMAXPARAMSIZE); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETNULL); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETNUMBER); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETPREFETCHMEMORYSIZE); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETPREFETCHROWCOUNT); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETROWID); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETSQL); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETSTRING); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETUINT); PUSH_METHOD(EncapOCCI_Statement, STATEMENT_STATUS); } void LuaOCCI_Statement::pushstatics(Lua * L) throw (GeneralException) { CHECK_METHODS(EncapOCCI_Statement); CHECK_FUNCTIONS(EncapOCCI_Statement); export_enum_stmt(L, RESULT_SET_AVAILABLE); export_enum_stmt(L, UPDATE_COUNT_AVAILABLE); export_enum_stmt(L, NEEDS_STREAM_DATA); export_enum_stmt(L, STREAM_DATA_AVAILABLE); export_enum_stmt(L, PREPARED); export_enum_stmt(L, UNPREPARED); } int sLua_EncapOCCI_Statement::EncapOCCI_Statement_proceed(Lua * L, int n, EncapOCCI_Statement * obj, int caller) { int r = 0; try { r = EncapOCCI_Statement_proceed_unprotected(L, n, obj, caller); } catch (SQLException ex) { if (obj->disableExceptions) { obj->lastError_msg = ex.getMessage().c_str(); obj->lastError_code = ex.getErrorCode(); } else { L->error(String("Got an SQLException: ") + ex.what()); } } return r; } int sLua_EncapOCCI_Statement::EncapOCCI_Statement_proceed_unprotected(Lua * L, int n, EncapOCCI_Statement * obj, int caller) { int r = 0; Statement * stmt = obj->Get(); ResultSet * rset; Stream * strm; String SQL; switch (caller) { case STATEMENT_SETEXCEPTIONS: obj->disableExceptions = !L->toboolean(2); break; case STATEMENT_GETERRORMSG: L->push(obj->lastError_msg); r = 1; break; case STATEMENT_GETERRORCODE: L->push((lua_Number) obj->lastError_code); r = 1; break; case STATEMENT_ADDITERATION: stmt->addIteration(); break; case STATEMENT_CLOSERESULTSET: // 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))->Get(); strm = lua_recast(L, 2)->Get(); stmt->closeStream(strm); break; case STATEMENT_EXECUTE: if (n == 1) { SQL = L->tostring(2); L->push((lua_Number) stmt->execute(SQL.to_charp())); } else { L->push((lua_Number) stmt->execute()); } r = 1; break; case STATEMENT_EXECUTEARRAYUPDATE: L->push((lua_Number) stmt->executeArrayUpdate(L->tonumber(2))); r = 1; break; case STATEMENT_EXECUTEQUERY: if (n == 1) { SQL = L->tostring(2); rset = stmt->executeQuery(SQL.to_charp()); EncapOCCI_ResultSet * erset = new EncapOCCI_ResultSet(rset); erset->disableExceptions = obj->disableExceptions; LuaOCCI_ResultSet lrset(erset); lrset.pushdestruct(L); } else { rset = stmt->executeQuery(); EncapOCCI_ResultSet * erset = new EncapOCCI_ResultSet(rset); erset->disableExceptions = obj->disableExceptions; LuaOCCI_ResultSet lrset(erset); lrset.pushdestruct(L); } r = 1; break; case STATEMENT_EXECUTEUPDATE: if (n == 1) { SQL = L->tostring(2); L->push((lua_Number) stmt->executeUpdate(SQL.to_charp())); } else { L->push((lua_Number) stmt->executeUpdate()); } r = 1; break; case STATEMENT_GETAUTOCOMMIT: L->push(stmt->getAutoCommit()); r = 1; break; case STATEMENT_GETBLOB: { Blob blob = stmt->getBlob(L->tonumber(2)); Buffer * b = new Buffer(true); int size = blob.length(); char * x = (char *) malloc(size); strm = blob.getStream(1, 0); strm->readBuffer(x, size); blob.closeStream(strm); b->write(x, size); free(x); LuaBuffer o(b); o.pushdestruct(L); L->push((lua_Number) size); } r = 2; break; case STATEMENT_GETBYTES: { Bytes bytes = stmt->getBytes(L->tonumber(2)); Buffer * b = new Buffer(true); int size = bytes.length(); unsigned char * x = (unsigned char *) malloc(size); bytes.getBytes(x, size); b->write(x, size); free(x); LuaBuffer o(b); o.pushdestruct(L); L->push((lua_Number) size); } r = 2; break; case STATEMENT_GETCHARSET: L->push(stmt->getCharSet(L->tonumber(2)).c_str()); r = 1; break; case STATEMENT_GETCLOB: { Clob clob = stmt->getClob(L->tonumber(2)); Buffer * b = new Buffer(true); int size = clob.length(); char * x = (char *) malloc(size); strm = clob.getStream(1, 0); strm->readBuffer(x, size); clob.closeStream(strm); b->write(x, size); free(x); LuaBuffer o(b); o.pushdestruct(L); L->push((lua_Number) size); } r = 2; break; case STATEMENT_GETCURRENTITERATION: L->push((lua_Number) stmt->getCurrentIteration()); r = 1; break; case STATEMENT_GETCURRENTSTREAMITERATION: L->push((lua_Number) stmt->getCurrentStreamIteration()); r = 1; break; case STATEMENT_GETCURRENTSTREAMPARAM: L->push((lua_Number) stmt->getCurrentStreamParam()); r = 1; break; case STATEMENT_GETCURSOR: { rset = stmt->getCursor(L->tonumber(2)); EncapOCCI_ResultSet * erset = new EncapOCCI_ResultSet(rset); erset->disableExceptions = obj->disableExceptions; LuaOCCI_ResultSet lrset(erset); lrset.pushdestruct(L); } r = 1; break; case STATEMENT_GETDATABASENCHARPARAM: L->push(stmt->getDatabaseNCHARParam(L->tonumber(2))); r = 1; break; case STATEMENT_GETDOUBLE: L->push(stmt->getDouble(L->tonumber(2))); r = 1; break; case STATEMENT_GETFLOAT: L->push(stmt->getFloat(L->tonumber(2))); r = 1; break; case STATEMENT_GETINT: L->push((lua_Number) stmt->getInt(L->tonumber(2))); r = 1; break; case STATEMENT_GETMAXITERATIONS: L->push((lua_Number) stmt->getMaxIterations()); r = 1; break; case STATEMENT_GETMAXPARAMSIZE: L->push((lua_Number) stmt->getMaxParamSize(L->tonumber(2))); r = 1; break; case STATEMENT_GETNUMBER: { Number x = stmt->getNumber(L->tonumber(2)); std::string s = x.toText(global_env, n == 2 ? L->tostring(3).to_charp() : "TM9"); L->push(String(s.c_str())); } r = 1; break; case STATEMENT_GETRESULTSET: { rset = stmt->getResultSet(); EncapOCCI_ResultSet * erset = new EncapOCCI_ResultSet(rset); erset->disableExceptions = obj->disableExceptions; LuaOCCI_ResultSet lrset(erset); lrset.pushdestruct(L); } r = 1; break; case STATEMENT_GETROWID: { Bytes bytes = stmt->getRowid(L->tonumber(2)); Buffer * b = new Buffer(true); int size = bytes.length(); unsigned char * x = (unsigned char *) malloc(size); bytes.getBytes(x, size); b->write(x, size); free(x); LuaBuffer o(b); o.pushdestruct(L); L->push((lua_Number) size); } r = 2; break; case STATEMENT_GETSQL: L->push(stmt->getSQL().c_str()); r = 1; break; case STATEMENT_GETSTREAM: { strm = stmt->getStream(L->tonumber(2)); EncapOCCI_Stream * estrm = new EncapOCCI_Stream(strm); estrm->disableExceptions = obj->disableExceptions; LuaOCCI_Stream lstrm(estrm); lstrm.pushdestruct(L); } r = 1; break; case STATEMENT_GETSTRING: L->push(String(stmt->getString(L->tonumber(2)).c_str())); r = 1; break; case STATEMENT_GETUINT: L->push((lua_Number) stmt->getUInt(L->tonumber(2))); r = 1; break; case STATEMENT_GETUPDATECOUNT: L->push((lua_Number) stmt->getUpdateCount()); r = 1; break; case STATEMENT_ISNULL: L->push(stmt->isNull(L->tonumber(2))); r = 1; break; case STATEMENT_ISTRUNCATED: L->push(stmt->isTruncated(L->tonumber(2))); r = 1; break; case STATEMENT_PRETRUNCATIONLENGTH: L->push((lua_Number) stmt->preTruncationLength(L->tonumber(2))); r = 1; break; case STATEMENT_REGISTEROUTPARAM: if (n == 2) { stmt->registerOutParam(L->tonumber(2), (Type) L->tonumber(3)); } else if (n == 3) { stmt->registerOutParam(L->tonumber(2), (Type) L->tonumber(3), L->tonumber(4)); } else { stmt->registerOutParam(L->tonumber(2), (Type) L->tonumber(3), L->tonumber(4), L->tostring(5).to_charp()); } break; case STATEMENT_SETAUTOCOMMIT: stmt->setAutoCommit(L->toboolean(2)); break; case STATEMENT_SETBINARYSTREAMMODE: stmt->setBinaryStreamMode(L->tonumber(2), L->tonumber(3)); break; case STATEMENT_SETBLOB: { rset = lua_recast(L, 2)->Get(); Blob blob = rset->getBlob(L->tonumber(3)); printm(M_ERROR, "x\n"); blob.open(OCCI_LOB_READWRITE); blob.setEmpty(); Buffer * b = lua_recast(L, 4); blob.writeChunk(b->GetSize(), (unsigned char *) b->GetBuffer(), b->GetSize()); blob.close(); } break; case STATEMENT_SETBYTES: { // 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); } break; case STATEMENT_SETCHARACTERSTREAMMODE: stmt->setCharacterStreamMode(L->tonumber(2), L->tonumber(3)); break; case STATEMENT_SETCHARSET: stmt->setCharSet(L->tonumber(2), L->tostring(3).to_charp()); break; case STATEMENT_SETDATABASENCHARPARAM: stmt->setDatabaseNCHARParam(L->tonumber(2), L->toboolean(3)); break; case STATEMENT_SETDOUBLE: stmt->setDouble(L->tonumber(2), L->tonumber(3)); break; case STATEMENT_SETERRORONNULL: stmt->setErrorOnNull(L->tonumber(2), L->toboolean(3)); break; case STATEMENT_SETERRORONTRUNCATE: stmt->setErrorOnTruncate(L->tonumber(2), L->toboolean(3)); break; case STATEMENT_SETFLOAT: stmt->setFloat(L->tonumber(2), L->tonumber(3)); break; case STATEMENT_SETINT: stmt->setInt(L->tonumber(2), L->tonumber(3)); break; case STATEMENT_SETMAXITERATIONS: stmt->setMaxIterations(L->tonumber(2)); break; case STATEMENT_SETMAXPARAMSIZE: stmt->setMaxParamSize(L->tonumber(2), L->tonumber(3)); break; case STATEMENT_SETNULL: stmt->setNull(L->tonumber(2), (Type) L->tonumber(3)); break; case STATEMENT_SETNUMBER: { Number x(0); String num = L->tostring(3); char format[128]; int dotpos; memset(format, '9', num.strlen()); format[num.strlen()] = 0; dotpos = num.strchr('.'); if (dotpos != -1) { format[dotpos] = '.'; } x.fromText(global_env, L->tostring(3).to_charp(), n == 3 ? L->tostring(4).to_charp() : format); stmt->setNumber(L->tonumber(2), x); std::string s = x.toText(global_env, "TM9"); } break; case STATEMENT_SETPREFETCHMEMORYSIZE: stmt->setPrefetchMemorySize(L->tonumber(2)); break; case STATEMENT_SETPREFETCHROWCOUNT: stmt->setPrefetchRowCount(L->tonumber(2)); break; case STATEMENT_SETROWID: { // 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); } break; case STATEMENT_SETSQL: stmt->setSQL(L->tostring(2).to_charp()); break; case STATEMENT_SETSTRING: stmt->setString(L->tonumber(2), L->tostring(3).to_charp()); break; case STATEMENT_SETUINT: stmt->setUInt(L->tonumber(2), L->tonumber(3)); break; case STATEMENT_STATUS: L->push((lua_Number) stmt->status()); r = 1; break; } return r; } /*** ResultSet bindings ***/ #define export_enum_rset(L, n) \ L->push("RESULTSET_STATUS_" #n); \ L->push((lua_Number) ResultSet::n); \ L->settable(LUA_GLOBALSINDEX); enum EncapOCCI_ResultSet_methods_t { RESULTSET_SETEXCEPTIONS = 0, RESULTSET_GETERRORMSG, RESULTSET_GETERRORCODE, RESULTSET_CANCEL, // RESULTSET_CLOSESTREAM, // RESULTSET_GETBFILE, RESULTSET_GETBLOB, RESULTSET_GETBYTES, RESULTSET_GETCHARSET, RESULTSET_GETCLOB, // RESULTSET_GETCOLUMNLISTMETADATA, RESULTSET_GETCURRENTSTREAMCOLUMN, RESULTSET_GETCURRENTSTREAMROW, RESULTSET_GETCURSOR, // RESULTSET_GETDATE, RESULTSET_GETDOUBLE, RESULTSET_GETFLOAT, RESULTSET_GETINT, // RESULTSET_GETINTERVALDS, // RESULTSET_GETINTERVALYM, RESULTSET_GETMAXCOLUMNSIZE, RESULTSET_GETNUMARRAYROWS, RESULTSET_GETNUMBER, // RESULTSET_GETOBJECT, // RESULTSET_GETREF, RESULTSET_GETROWID, // RESULTSET_GETROWPOSITION, // RESULTSET_GETSTATEMENT, RESULTSET_GETSTREAM, RESULTSET_GETSTRING, // RESULTSET_GETTIMESTAMP, RESULTSET_GETUINT, // RESULTSET_GETVECTOR, RESULTSET_ISNULL, RESULTSET_ISTRUNCATED, RESULTSET_NEXT, RESULTSET_PRETRUNCATIONLENGTH, RESULTSET_SETBINARYSTREAMMODE, RESULTSET_SETCHARACTERSTREAMMODE, RESULTSET_SETCHARSET, RESULTSET_SETDATABASENCHARPARAM, // RESULTSET_SETDATABUFFER, RESULTSET_SETERRORONNULL, RESULTSET_SETERRORONTRUNCATE, RESULTSET_SETMAXCOLUMNSIZE, RESULTSET_STATUS, RESULTSET_SETBLOB, RESULTSET_GETFIELDSINFO, }; struct lua_functypes_t EncapOCCI_ResultSet_methods[] = { { RESULTSET_SETEXCEPTIONS, "setExceptions", 1, 1, { BLUA_BOOLEAN } }, { RESULTSET_GETERRORMSG, "getErrorMsg", 0, 0, { } }, { RESULTSET_GETERRORCODE, "getErrorCode", 0, 0, { } }, { RESULTSET_CANCEL, "cancel", 0, 0, { } }, { RESULTSET_GETBLOB, "getBlob", 1, 1, { BLUA_NUMBER } }, { RESULTSET_GETBYTES, "getBytes", 1, 1, { BLUA_NUMBER } }, { RESULTSET_GETCHARSET, "getCharSet", 1, 1, { BLUA_NUMBER } }, { RESULTSET_GETCLOB, "getClob", 1, 1, { BLUA_NUMBER } }, { RESULTSET_GETCURRENTSTREAMCOLUMN, "getCurrentStreamColumn", 0, 0, { } }, { RESULTSET_GETCURRENTSTREAMROW, "getCurrentStreamRow", 0, 0, { } }, { RESULTSET_GETCURSOR, "getCursor", 1, 1, { BLUA_NUMBER } }, { RESULTSET_GETDOUBLE, "getDouble", 1, 1, { BLUA_NUMBER } }, { RESULTSET_GETFLOAT, "getFloat", 1, 1, { BLUA_NUMBER } }, { RESULTSET_GETINT, "getInt", 1, 1, { BLUA_NUMBER } }, { RESULTSET_GETMAXCOLUMNSIZE, "getMaxColumnSize", 1, 1, { BLUA_NUMBER } }, { RESULTSET_GETNUMARRAYROWS, "getNumArrayRows", 0, 0, { } }, { RESULTSET_GETNUMBER, "getNumber", 1, 2, { BLUA_NUMBER, BLUA_STRING } }, { RESULTSET_GETROWID, "getRowid", 1, 1, { BLUA_NUMBER } }, { RESULTSET_GETSTREAM, "getStream", 1, 1, { BLUA_NUMBER } }, { RESULTSET_GETSTRING, "getString", 1, 1, { BLUA_NUMBER } }, { RESULTSET_GETUINT, "getUInt", 1, 1, { BLUA_NUMBER } }, { RESULTSET_ISNULL, "isNull", 1, 1, { BLUA_NUMBER } }, { RESULTSET_ISTRUNCATED, "isTruncated", 1, 1, { BLUA_NUMBER } }, { RESULTSET_NEXT, "next", 0, 1, { BLUA_NUMBER } }, { RESULTSET_PRETRUNCATIONLENGTH, "preTruncationLength", 1, 1, { BLUA_NUMBER } }, { RESULTSET_SETBINARYSTREAMMODE, "setBinaryStreamMode", 2, 2, { BLUA_NUMBER, BLUA_NUMBER } }, { RESULTSET_SETCHARACTERSTREAMMODE, "setCharacterStreamMode", 2, 2, { BLUA_NUMBER, BLUA_NUMBER } }, { RESULTSET_SETCHARSET, "setCharSet", 2, 2, { BLUA_NUMBER, BLUA_STRING } }, { RESULTSET_SETDATABASENCHARPARAM, "setDatabaseNCHARParam", 2, 2, { BLUA_NUMBER, BLUA_BOOLEAN } }, { RESULTSET_SETERRORONNULL, "setErrorOnNull", 2, 2, { BLUA_NUMBER, BLUA_BOOLEAN } }, { RESULTSET_SETERRORONTRUNCATE, "setErrorOnTruncate", 2, 2, { BLUA_NUMBER, BLUA_BOOLEAN } }, { RESULTSET_SETMAXCOLUMNSIZE, "setMaxColumnSize", 2, 2, { BLUA_NUMBER, BLUA_NUMBER } }, { RESULTSET_STATUS, "status", 0, 0, { } }, { RESULTSET_SETBLOB, "setBlob", 2, 2, { BLUA_NUMBER, BLUA_OBJECT } }, { RESULTSET_GETFIELDSINFO, "getFieldsInfo", 0, 0, { } }, { -1, 0, 0, 0, 0 }, }; struct lua_functypes_t EncapOCCI_ResultSet_functions[] = { { -1, 0, 0, 0, 0 }, }; class sLua_EncapOCCI_ResultSet : public Base { public: DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_SETEXCEPTIONS); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETERRORMSG); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETERRORCODE); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_CANCEL); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETBLOB); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETBYTES); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETCHARSET); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETCLOB); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETCURRENTSTREAMCOLUMN); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETCURRENTSTREAMROW); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETCURSOR); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETDOUBLE); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETFLOAT); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETINT); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETMAXCOLUMNSIZE); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETNUMARRAYROWS); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETNUMBER); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETROWID); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETSTREAM); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETSTRING); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETUINT); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_ISNULL); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_ISTRUNCATED); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_NEXT); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_PRETRUNCATIONLENGTH); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_SETBINARYSTREAMMODE); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_SETCHARACTERSTREAMMODE); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_SETCHARSET); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_SETDATABASENCHARPARAM); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_SETERRORONNULL); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_SETERRORONTRUNCATE); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_SETMAXCOLUMNSIZE); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_STATUS); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_SETBLOB); DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETFIELDSINFO); private: static int EncapOCCI_ResultSet_proceed(Lua * L, int n, EncapOCCI_ResultSet * obj, int caller); static int EncapOCCI_ResultSet_proceed_unprotected(Lua * L, int n, EncapOCCI_ResultSet * obj, int caller); static int EncapOCCI_ResultSet_proceed_statics(Lua *L, int n, int caller); }; void LuaOCCI_ResultSet::pushmembers(Lua * L) { pushme(L, o, "OCCI_ResultSet"); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_SETEXCEPTIONS); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETERRORMSG); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETERRORCODE); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_CANCEL); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETBLOB); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETBYTES); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETCHARSET); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETCLOB); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETCURRENTSTREAMCOLUMN); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETCURRENTSTREAMROW); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETCURSOR); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETDOUBLE); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETFLOAT); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETINT); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETMAXCOLUMNSIZE); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETNUMARRAYROWS); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETNUMBER); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETROWID); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETSTREAM); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETSTRING); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETUINT); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_ISNULL); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_ISTRUNCATED); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_NEXT); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_PRETRUNCATIONLENGTH); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_SETBINARYSTREAMMODE); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_SETCHARACTERSTREAMMODE); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_SETCHARSET); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_SETDATABASENCHARPARAM); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_SETERRORONNULL); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_SETERRORONTRUNCATE); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_SETMAXCOLUMNSIZE); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_STATUS); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_SETBLOB); PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETFIELDSINFO); } void LuaOCCI_ResultSet::pushstatics(Lua * L) throw (GeneralException) { CHECK_METHODS(EncapOCCI_ResultSet); CHECK_FUNCTIONS(EncapOCCI_ResultSet); export_enum_rset(L, END_OF_FETCH); export_enum_rset(L, DATA_AVAILABLE); export_enum_rset(L, STREAM_DATA_AVAILABLE); } int sLua_EncapOCCI_ResultSet::EncapOCCI_ResultSet_proceed(Lua * L, int n, EncapOCCI_ResultSet * obj, int caller) { int r = 0; try { r = EncapOCCI_ResultSet_proceed_unprotected(L, n, obj, caller); } catch (SQLException ex) { if (obj->disableExceptions) { obj->lastError_msg = ex.getMessage().c_str(); obj->lastError_code = ex.getErrorCode(); } else { L->error(String("Got an SQLException: ") + ex.what()); } } return r; } int sLua_EncapOCCI_ResultSet::EncapOCCI_ResultSet_proceed_unprotected(Lua * L, int n, EncapOCCI_ResultSet * obj, int caller) { int r = 0; ResultSet * rset = obj->Get(); Stream * strm; switch (caller) { case RESULTSET_SETEXCEPTIONS: obj->disableExceptions = !L->toboolean(2); break; case RESULTSET_GETERRORMSG: L->push(obj->lastError_msg); r = 1; break; case RESULTSET_GETERRORCODE: L->push((lua_Number) obj->lastError_code); r = 1; break; case RESULTSET_CANCEL: rset->cancel(); break; case RESULTSET_GETCHARSET: L->push(rset->getCharSet(L->tonumber(2)).c_str()); r = 1; break; case RESULTSET_GETBLOB: { Blob blob = rset->getBlob(L->tonumber(2)); Buffer * b = new Buffer(true); int size = blob.length(); char * x = (char *) malloc(size); strm = blob.getStream(1, 0); strm->readBuffer(x, size); blob.closeStream(strm); b->write(x, size); free(x); LuaBuffer o(b); o.pushdestruct(L); L->push((lua_Number) size); } r = 2; break; case RESULTSET_GETBYTES: { Bytes bytes = rset->getBytes(L->tonumber(2)); Buffer * b = new Buffer(true); int size = bytes.length(); unsigned char * x = (unsigned char *) malloc(size); bytes.getBytes(x, size); b->write(x, size); free(x); LuaBuffer o(b); o.pushdestruct(L); L->push((lua_Number) size); } r = 2; break; case RESULTSET_GETCLOB: { Clob clob = rset->getClob(L->tonumber(2)); Buffer * b = new Buffer(true); int size = clob.length(); char * x = (char *) malloc(size); strm = clob.getStream(1, 0); strm->readBuffer(x, size); clob.closeStream(strm); b->write(x, size); free(x); LuaBuffer o(b); o.pushdestruct(L); L->push((lua_Number) size); } r = 2; break; case RESULTSET_GETCURRENTSTREAMCOLUMN: L->push((lua_Number) rset->getCurrentStreamColumn()); r = 1; break; case RESULTSET_GETCURRENTSTREAMROW: L->push((lua_Number) rset->getCurrentStreamRow()); r = 1; break; case RESULTSET_GETCURSOR: { rset = rset->getCursor(L->tonumber(2)); EncapOCCI_ResultSet * erset = new EncapOCCI_ResultSet(rset); erset->disableExceptions = obj->disableExceptions; LuaOCCI_ResultSet lrset(erset); lrset.pushdestruct(L); } r = 1; break; case RESULTSET_GETDOUBLE: L->push(rset->getDouble(L->tonumber(2))); r = 1; break; case RESULTSET_GETFLOAT: L->push(rset->getFloat(L->tonumber(2))); r = 1; break; case RESULTSET_GETINT: L->push((lua_Number) rset->getInt(L->tonumber(2))); r = 1; break; case RESULTSET_GETMAXCOLUMNSIZE: L->push((lua_Number) rset->getMaxColumnSize(L->tonumber(2))); r = 1; break; case RESULTSET_GETNUMARRAYROWS: L->push((lua_Number) rset->getNumArrayRows()); r = 1; break; case RESULTSET_GETNUMBER: { Number x = rset->getNumber(L->tonumber(2)); std::string s = x.toText(global_env, n == 2 ? L->tostring(3).to_charp() : "TM9"); L->push(String(s.c_str())); } r = 1; break; case RESULTSET_GETROWID: { Bytes bytes = rset->getRowid(L->tonumber(2)); Buffer * b = new Buffer(true); int size = bytes.length(); unsigned char * x = (unsigned char *) malloc(size); bytes.getBytes(x, size); b->write(x, size); free(x); LuaBuffer o(b); o.pushdestruct(L); L->push((lua_Number) size); } r = 2; break; case RESULTSET_GETSTREAM: { strm = rset->getStream(L->tonumber(2)); EncapOCCI_Stream * estrm = new EncapOCCI_Stream(strm); estrm->disableExceptions = obj->disableExceptions; LuaOCCI_Stream lstrm(estrm); lstrm.pushdestruct(L); } r = 1; break; case RESULTSET_GETSTRING: L->push(String(rset->getString(L->tonumber(2)).c_str())); r = 1; break; case RESULTSET_GETUINT: L->push((lua_Number) rset->getUInt(L->tonumber(2))); r = 1; break; case RESULTSET_ISNULL: L->push(rset->isNull(L->tonumber(2))); r = 1; break; case RESULTSET_ISTRUNCATED: L->push(rset->isTruncated(L->tonumber(2))); r = 1; break; case RESULTSET_NEXT: if (n == 1) { L->push((lua_Number) rset->next(L->tonumber(2))); } else { L->push((lua_Number) rset->next()); } r = 1; break; case RESULTSET_PRETRUNCATIONLENGTH: L->push((lua_Number) rset->preTruncationLength(L->tonumber(2))); r = 1; break; case RESULTSET_SETBINARYSTREAMMODE: rset->setBinaryStreamMode(L->tonumber(2), L->tonumber(3)); break; case RESULTSET_SETCHARACTERSTREAMMODE: rset->setCharacterStreamMode(L->tonumber(2), L->tonumber(3)); break; case RESULTSET_SETCHARSET: rset->setCharSet(L->tonumber(2), L->tostring(3).to_charp()); break; case RESULTSET_SETDATABASENCHARPARAM: rset->setDatabaseNCHARParam(L->tonumber(2), L->toboolean(3)); break; case RESULTSET_SETERRORONNULL: rset->setErrorOnNull(L->tonumber(2), L->toboolean(3)); break; case RESULTSET_SETERRORONTRUNCATE: rset->setErrorOnTruncate(L->tonumber(2), L->toboolean(3)); break; case RESULTSET_SETMAXCOLUMNSIZE: rset->setMaxColumnSize(L->tonumber(2), L->tonumber(3)); break; case RESULTSET_STATUS: L->push((lua_Number) rset->status()); r = 1; break; case RESULTSET_SETBLOB: { Blob blob = rset->getBlob(L->tonumber(2)); blob.open(OCCI_LOB_READWRITE); Buffer * b = lua_recast(L, 3); Stream * outstream = blob.getStream(1, 0); outstream->writeBuffer((char *) b->GetBuffer(), b->GetSize()); char *c = (char *) ""; outstream->writeLastBuffer(c, 0); blob.closeStream(outstream); blob.close(); } break; case RESULTSET_GETFIELDSINFO: { std::vector meta = rset->getColumnListMetaData(); L->push((lua_Number) meta.size()); int c = 1; L->newtable(); for (std::vector::iterator i = meta.begin(); i != meta.end(); i++, c++) { L->push((lua_Number) c); L->push(String(i->getString(MetaData::ATTR_NAME).c_str())); L->settable(); } r = 2; } break; } return r; } /*** Stream bindings ***/ #define export_enum_strm(L, n) \ L->push("STREAM_STATUS_" #n); \ L->push((lua_Number) Stream::n); \ L->settable(LUA_GLOBALSINDEX); enum EncapOCCI_Stream_methods_t { STREAM_SETEXCEPTIONS = 0, STREAM_GETERRORMSG, STREAM_GETERRORCODE, STREAM_READBUFFER, STREAM_READLASTBUFFER, STREAM_WRITEBUFFER, STREAM_WRITELASTBUFFER, STREAM_STATUS, }; struct lua_functypes_t EncapOCCI_Stream_methods[] = { { STREAM_SETEXCEPTIONS, "setExceptions", 1, 1, { BLUA_BOOLEAN } }, { STREAM_GETERRORMSG, "getErrorMsg", 0, 0, { } }, { STREAM_GETERRORCODE, "getErrorCode", 0, 0, { } }, { STREAM_READBUFFER, "readBuffer", 1, 1, { BLUA_NUMBER } }, { STREAM_READLASTBUFFER, "readLastBuffer", 1, 1, { BLUA_NUMBER } }, { STREAM_WRITEBUFFER, "writeBuffer", 2, 2, { BLUA_OBJECT, BLUA_NUMBER } }, { STREAM_WRITELASTBUFFER, "writeLastBuffer", 2, 2, { BLUA_OBJECT, BLUA_NUMBER } }, { STREAM_STATUS, "status", 0, 0, { } }, { -1, 0, 0, 0, 0 }, }; struct lua_functypes_t EncapOCCI_Stream_functions[] = { { -1, 0, 0, 0, 0 }, }; class sLua_EncapOCCI_Stream : public Base { public: DECLARE_METHOD(EncapOCCI_Stream, STREAM_SETEXCEPTIONS); DECLARE_METHOD(EncapOCCI_Stream, STREAM_GETERRORMSG); DECLARE_METHOD(EncapOCCI_Stream, STREAM_GETERRORCODE); DECLARE_METHOD(EncapOCCI_Stream, STREAM_READBUFFER); DECLARE_METHOD(EncapOCCI_Stream, STREAM_READLASTBUFFER); DECLARE_METHOD(EncapOCCI_Stream, STREAM_WRITEBUFFER); DECLARE_METHOD(EncapOCCI_Stream, STREAM_WRITELASTBUFFER); DECLARE_METHOD(EncapOCCI_Stream, STREAM_STATUS); private: static int EncapOCCI_Stream_proceed(Lua * L, int n, EncapOCCI_Stream * obj, int caller); static int EncapOCCI_Stream_proceed_unprotected(Lua * L, int n, EncapOCCI_Stream * obj, int caller); static int EncapOCCI_Stream_proceed_statics(Lua *L, int n, int caller); }; void LuaOCCI_Stream::pushmembers(Lua * L) { pushme(L, o, "OCCI_Stream"); PUSH_METHOD(EncapOCCI_Stream, STREAM_SETEXCEPTIONS); PUSH_METHOD(EncapOCCI_Stream, STREAM_GETERRORMSG); PUSH_METHOD(EncapOCCI_Stream, STREAM_GETERRORCODE); PUSH_METHOD(EncapOCCI_Stream, STREAM_READBUFFER); PUSH_METHOD(EncapOCCI_Stream, STREAM_READLASTBUFFER); PUSH_METHOD(EncapOCCI_Stream, STREAM_WRITEBUFFER); PUSH_METHOD(EncapOCCI_Stream, STREAM_WRITELASTBUFFER); PUSH_METHOD(EncapOCCI_Stream, STREAM_STATUS); } void LuaOCCI_Stream::pushstatics(Lua * L) throw (GeneralException) { CHECK_METHODS(EncapOCCI_Stream); CHECK_FUNCTIONS(EncapOCCI_Stream); export_enum_strm(L, READY_FOR_READ); export_enum_strm(L, READY_FOR_WRITE); export_enum_strm(L, INACTIVE); } int sLua_EncapOCCI_Stream::EncapOCCI_Stream_proceed(Lua * L, int n, EncapOCCI_Stream * obj, int caller) { int r = 0; try { r = EncapOCCI_Stream_proceed_unprotected(L, n, obj, caller); } catch (SQLException ex) { if (obj->disableExceptions) { obj->lastError_msg = ex.getMessage().c_str(); obj->lastError_code = ex.getErrorCode(); } else { L->error(String("Got an SQLException: ") + ex.what()); } } return r; } int sLua_EncapOCCI_Stream::EncapOCCI_Stream_proceed_unprotected(Lua * L, int n, EncapOCCI_Stream * obj, int caller) { int r = 0; int size; char * buffer; Stream * strm = obj->Get(); Buffer * b; switch (caller) { case STREAM_SETEXCEPTIONS: obj->disableExceptions = !L->toboolean(2); break; case STREAM_GETERRORMSG: L->push(obj->lastError_msg); r = 1; break; case STREAM_GETERRORCODE: L->push((lua_Number) obj->lastError_code); r = 1; break; case STREAM_READBUFFER: size = L->tonumber(2); if (size == -1) { L->error("Stream:ReadBuffer - negative sizes not supported."); } b = new Buffer(true); { LuaBuffer o(b); o.pushdestruct(L); } buffer = (char *) malloc(size); L->push((lua_Number) strm->readBuffer(buffer, size)); b->write(buffer, size); free(buffer); r = 2; break; case STREAM_READLASTBUFFER: size = L->tonumber(2); if (size == -1) { L->error("Stream:ReadLastBuffer - negative sizes not supported."); } b = new Buffer(true); { LuaBuffer o(b); o.pushdestruct(L); } buffer = (char *) malloc(size); L->push((lua_Number) strm->readLastBuffer(buffer, size)); b->write(buffer, size); free(buffer); r = 2; break; case STREAM_WRITEBUFFER: // 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 = lua_recast(L, 2); strm->writeLastBuffer((char *) b->GetBuffer(), L->tonumber(3)); break; case STREAM_STATUS: L->push((lua_Number) strm->status()); r = 1; break; } return r; }