From 6b637fa40e97409d70d28aef19d42e093700f5a7 Mon Sep 17 00:00:00 2001 From: pixel Date: Mon, 17 Mar 2008 17:18:30 +0000 Subject: Adding first version of the Lua <--> OCCI bindings. --- include/LuaOCCI.h | 43 ++ lib/LuaOCCI.cc | 1269 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1312 insertions(+) create mode 100644 include/LuaOCCI.h create mode 100644 lib/LuaOCCI.cc diff --git a/include/LuaOCCI.h b/include/LuaOCCI.h new file mode 100644 index 0000000..683d60e --- /dev/null +++ b/include/LuaOCCI.h @@ -0,0 +1,43 @@ +#ifndef __LUAOCCI_H__ +#define __LUAOCCI_H__ + +#include + +#include +#include + +#define DECLARE_OCCI_ENCAP(clname) \ +class EncapOCCI_##clname : public Base { \ + public: \ + EncapOCCI_##clname(oracle::occi::clname * _o) : o(_o) { } \ + ~EncapOCCI_##clname() { } \ + oracle::occi::clname * Get() { return o; } \ + private: \ + oracle::occi::clname * o; \ +}; \ +\ +class LuaOCCI_##clname : public LuaObject { \ + public: \ + static void pushstatics(Lua *) throw (GeneralException); \ + LuaOCCI_##clname(EncapOCCI_##clname * _o) : o(_o) { } \ + ~LuaOCCI_##clname() { } \ + private: \ + virtual void pushmembers(Lua *); \ + EncapOCCI_##clname * o; \ +}; + +DECLARE_OCCI_ENCAP(Environment); +DECLARE_OCCI_ENCAP(Connection); +DECLARE_OCCI_ENCAP(Statement); +DECLARE_OCCI_ENCAP(ResultSet); +DECLARE_OCCI_ENCAP(Stream); + +#define LuaOCCI_pushstatics(L) {\ + LuaOCCI_Environment::pushstatics(L);\ + LuaOCCI_Connection::pushstatics(L);\ + LuaOCCI_Statement::pushstatics(L);\ + LuaOCCI_ResultSet::pushstatics(L);\ + LuaOCCI_Stream::pushstatics(L);\ +} + +#endif diff --git a/lib/LuaOCCI.cc b/lib/LuaOCCI.cc new file mode 100644 index 0000000..cc0b2af --- /dev/null +++ b/lib/LuaOCCI.cc @@ -0,0 +1,1269 @@ +#include +#include + +using namespace oracle::occi; + +#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_CREATECONNECTION = 0, + 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_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_CREATECONNECTION); + 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_CREATECONNECTION); + 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) { + 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_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())); + } + { + 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)); + 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::DEFAULT)); + { + LuaOCCI_Environment lenv(env); + lenv.pushdestruct(L); + } + r = 1; + break; + case ENVIRONMENT_TERMINATEENVIRONMENT: + env = dynamic_cast((Base *) LuaObject::getme(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_CHANGEPASSWORD = 0, + CONNECTION_COMMIT, + CONNECTION_CREATESTATEMENT, + CONNECTION_FLUSHCACHE, + CONNECTION_GETCLIENTCHARSET, + CONNECTION_GETCLIENTNCHARCHARSET, +// CONNECTION_GETMETADATA + CONNECTION_ROLLBACK, + CONNECTION_TERMINATESTATEMENT, +}; + +struct lua_functypes_t EncapOCCI_Connection_methods[] = { + { 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_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_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) { + 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_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())); + { + 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)); + 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_ADDITERATION = 0, + 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_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_GETCHARSET, "getCharSet", 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_GETRESULTSET, "getResultSet", 0, 0, { } }, + { 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_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_SETPREFETCHMEMORYSIZE, "setPrefetchMemorySize", 1, 1, { BLUA_NUMBER } }, + { STATEMENT_SETPREFETCHROWCOUNT, "setPrefetchRowCount", 1, 1, { BLUA_NUMBER } }, + { 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_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_GETCHARSET); + 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_GETRESULTSET); + 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_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_SETPREFETCHMEMORYSIZE); + DECLARE_METHOD(EncapOCCI_Statement, STATEMENT_SETPREFETCHROWCOUNT); + 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_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_GETCHARSET); + 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_GETRESULTSET); + 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_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_SETPREFETCHMEMORYSIZE); + PUSH_METHOD(EncapOCCI_Statement, STATEMENT_SETPREFETCHROWCOUNT); + 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) { + 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_ADDITERATION: + stmt->addIteration(); + break; + case STATEMENT_CLOSERESULTSET: + rset = dynamic_cast((Base *) LuaObject::getme(L, 2)); + stmt->closeResultSet(rset); + break; + case STATEMENT_CLOSESTREAM: + strm = dynamic_cast((Base *) LuaObject::getme(L, 2)); + 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()); + LuaOCCI_ResultSet lrset(new EncapOCCI_ResultSet(rset)); + lrset.pushdestruct(L); + } else { + rset = stmt->executeQuery(); + LuaOCCI_ResultSet lrset(new EncapOCCI_ResultSet(rset)); + 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_GETCHARSET: + L->push(stmt->getCharSet(L->tonumber(2)).c_str()); + r = 1; + 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)); + LuaOCCI_ResultSet lrset(new EncapOCCI_ResultSet(rset)); + 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_GETRESULTSET: + { + rset = stmt->getResultSet(); + LuaOCCI_ResultSet lrset(new EncapOCCI_ResultSet(rset)); + lrset.pushdestruct(L); + } + r = 1; + break; + case STATEMENT_GETSQL: + L->push(stmt->getSQL().c_str()); + r = 1; + break; + case STATEMENT_GETSTREAM: + { + strm = stmt->getStream(L->tonumber(2)); + LuaOCCI_Stream lstrm(new EncapOCCI_Stream(strm)); + lstrm.pushdestruct(L); + } + r = 1; + break; + case STATEMENT_GETSTRING: + L->push(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_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_SETPREFETCHMEMORYSIZE: + stmt->setPrefetchMemorySize(L->tonumber(2)); + break; + case STATEMENT_SETPREFETCHROWCOUNT: + stmt->setPrefetchRowCount(L->tonumber(2)); + 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_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_SETBLOB, +// RESULTSET_SETBYTES, + RESULTSET_SETCHARACTERSTREAMMODE, + RESULTSET_SETCHARSET, +// RESULTSET_SETCLOB, +// RESULTSET_SETDATE, + RESULTSET_SETDATABASENCHARPARAM, +// RESULTSET_SETDATABUFFER, + RESULTSET_SETERRORONNULL, + RESULTSET_SETERRORONTRUNCATE, + RESULTSET_SETMAXCOLUMNSIZE, + RESULTSET_STATUS, +}; + +struct lua_functypes_t EncapOCCI_ResultSet_methods[] = { + { RESULTSET_CANCEL, "cancel", 0, 0, { } }, + { RESULTSET_GETCHARSET, "getCharSet", 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_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, { } }, + { -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_CANCEL); + DECLARE_METHOD(EncapOCCI_ResultSet, RESULTSET_GETCHARSET); + 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_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); + + 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_CANCEL); + PUSH_METHOD(EncapOCCI_ResultSet, RESULTSET_GETCHARSET); + 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_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); +} + +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) { + 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_CANCEL: + rset->cancel(); + break; + case RESULTSET_GETCHARSET: + L->push(rset->getCharSet(L->tonumber(2)).c_str()); + r = 1; + 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)); + LuaOCCI_ResultSet lrset(new EncapOCCI_ResultSet(rset)); + 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_GETSTREAM: + { + strm = rset->getStream(L->tonumber(2)); + LuaOCCI_Stream lstrm(new EncapOCCI_Stream(strm)); + lstrm.pushdestruct(L); + } + r = 1; + break; + case RESULTSET_GETSTRING: + L->push(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()); + } + 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; + } + + 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_READBUFFER, + STREAM_READLASTBUFFER, + STREAM_WRITEBUFFER, + STREAM_WRITELASTBUFFER, + STREAM_STATUS, +}; + +struct lua_functypes_t EncapOCCI_Stream_methods[] = { + { 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_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_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) { + 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_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)); + strm->writeBuffer((char *) b->GetBuffer(), L->tonumber(3)); + break; + case STREAM_WRITELASTBUFFER: + b = dynamic_cast((Base *) LuaObject::getme(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; +} -- cgit v1.2.3