summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2008-03-17 18:23:59 +0000
committerpixel <pixel>2008-03-17 18:23:59 +0000
commit44a7787711acd906c1bc137a9af1ccb68ae0370d (patch)
tree3a179030e73d5e23faa4dc5e6de48562af54dd50
parente1d6f8ecc200efeb7d46749677f5368d854f8f17 (diff)
Partial Blob support; no real streaming.
-rw-r--r--lib/LuaOCCI.cc61
1 files changed, 58 insertions, 3 deletions
diff --git a/lib/LuaOCCI.cc b/lib/LuaOCCI.cc
index 9151982..0f0c2f7 100644
--- a/lib/LuaOCCI.cc
+++ b/lib/LuaOCCI.cc
@@ -361,7 +361,7 @@ enum EncapOCCI_Statement_methods_t {
STATEMENT_EXECUTEUPDATE,
STATEMENT_GETAUTOCOMMIT,
// STATEMENT_GETBFILE,
-// STATEMENT_GETBLOB,
+ STATEMENT_GETBLOB,
STATEMENT_GETBYTES,
STATEMENT_GETCHARSET,
// STATEMENT_GETCLOB,
@@ -399,7 +399,7 @@ enum EncapOCCI_Statement_methods_t {
STATEMENT_SETAUTOCOMMIT,
// STATEMENT_SETBFILE,
STATEMENT_SETBINARYSTREAMMODE,
-// STATEMENT_SETBLOB,
+ STATEMENT_SETBLOB,
STATEMENT_SETBYTES,
STATEMENT_SETCHARACTERSTREAMMODE,
STATEMENT_SETCHARSET,
@@ -442,6 +442,7 @@ struct lua_functypes_t EncapOCCI_Statement_methods[] = {
{ 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_GETCURRENTITERATION, "getCurrentIteration", 0, 0, { } },
@@ -467,6 +468,7 @@ struct lua_functypes_t EncapOCCI_Statement_methods[] = {
{ 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", 2, 2, { 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 } },
@@ -503,6 +505,7 @@ class sLua_EncapOCCI_Statement : public Base {
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_GETCURRENTITERATION);
@@ -528,6 +531,7 @@ class sLua_EncapOCCI_Statement : public Base {
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);
@@ -565,6 +569,7 @@ void LuaOCCI_Statement::pushmembers(Lua * L) {
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_GETCURRENTITERATION);
@@ -590,6 +595,7 @@ void LuaOCCI_Statement::pushmembers(Lua * L) {
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);
@@ -694,6 +700,23 @@ int sLua_EncapOCCI_Statement::EncapOCCI_Statement_proceed_unprotected(Lua * L, i
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));
@@ -831,6 +854,18 @@ int sLua_EncapOCCI_Statement::EncapOCCI_Statement_proceed_unprotected(Lua * L, i
case STATEMENT_SETBINARYSTREAMMODE:
stmt->setBinaryStreamMode(L->tonumber(2), L->tonumber(3));
break;
+ case STATEMENT_SETBLOB:
+ {
+ Blob blob;
+ blob.setEmpty();
+ strm = blob.getStream(1, 0);
+ Buffer * b = dynamic_cast<Buffer *>((Base *) LuaObject::getme(L, 3));
+ strm->writeBuffer((char *) b->GetBuffer(), b->GetSize());
+ strm->writeLastBuffer((char *) b->GetBuffer(), 0);
+ blob.closeStream(strm);
+ stmt->setBlob(L->tonumber(2), blob);
+ }
+ break;
case STATEMENT_SETBYTES:
{
Buffer * b = dynamic_cast<Buffer *>((Base *) LuaObject::getme(L, 3));
@@ -914,7 +949,7 @@ enum EncapOCCI_ResultSet_methods_t {
RESULTSET_CANCEL,
// RESULTSET_CLOSESTREAM,
// RESULTSET_GETBFILE,
-// RESULTSET_GETBLOB,
+ RESULTSET_GETBLOB,
RESULTSET_GETBYTES,
RESULTSET_GETCHARSET,
// RESULTSET_GETCLOB,
@@ -958,6 +993,7 @@ enum EncapOCCI_ResultSet_methods_t {
struct lua_functypes_t EncapOCCI_ResultSet_methods[] = {
{ 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_GETCURRENTSTREAMCOLUMN, "getCurrentStreamColumn", 0, 0, { } },
@@ -993,6 +1029,7 @@ struct lua_functypes_t EncapOCCI_ResultSet_functions[] = {
class sLua_EncapOCCI_ResultSet : public Base {
public:
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_GETCURRENTSTREAMCOLUMN);
@@ -1029,6 +1066,7 @@ void LuaOCCI_ResultSet::pushmembers(Lua * L) {
pushme(L, o, "OCCI_ResultSet");
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_GETCURRENTSTREAMCOLUMN);
@@ -1091,6 +1129,23 @@ int sLua_EncapOCCI_ResultSet::EncapOCCI_ResultSet_proceed_unprotected(Lua * L, i
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));