From: <ibr...@us...> - 2010-11-26 18:07:44
|
Revision: 3824 http://tora.svn.sourceforge.net/tora/?rev=3824&view=rev Author: ibre5041 Date: 2010-11-26 18:07:38 +0000 (Fri, 26 Nov 2010) Log Message: ----------- Sync with trotl trunk Better handling of fixed width CHARs Modified Paths: -------------- branches/tora-trotl/src/trotl/src/trotl_stat.cpp branches/tora-trotl/src/trotl/src/trotl_stat.h branches/tora-trotl/src/trotl/src/trotl_string.h Modified: branches/tora-trotl/src/trotl/src/trotl_stat.cpp =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_stat.cpp 2010-11-26 17:51:27 UTC (rev 3823) +++ branches/tora-trotl/src/trotl/src/trotl_stat.cpp 2010-11-26 18:07:38 UTC (rev 3824) @@ -63,7 +63,7 @@ _state(UNINITIALIZED), _stmt_type(STMT_NONE), _param_count(0), _column_count(0), -_in_cnt(0), _out_cnt(0), +_in_cnt(0), _out_cnt(0), _iters(0), _last_row(-1), _last_fetched_row(-1), _in_pos(0), _out_pos(0), @@ -353,41 +353,40 @@ } } - ub4 iters = 0; switch(STMT_TYPE t = get_stmt_type()) { case STMT_OTHER: - iters = 1; + _iters = 1; _state |= EOF_DATA; break; case STMT_SELECT: - iters = rows; + _iters = rows; break; case STMT_UPDATE: - iters = 1; + _iters = 1; break; case STMT_DELETE: - iters = 1; + _iters = 1; break; case STMT_INSERT: - iters = 1; + _iters = 1; if( _in_cnt == 0 ) break; - iters = _all_binds[_in_binds[1]]->_cnt; + _iters = _all_binds[_in_binds[1]]->_cnt; // Loop over input bind vars - insert can have out binds too(i.e. returning clause) for(unsigned i=1; i<=_in_cnt; ++i) - if(_all_binds[_in_binds[i]]->_cnt != iters) + if(_all_binds[_in_binds[i]]->_cnt != _iters) throw OciException(__TROTL_HERE__, "Wrong count of bindvars: (%d vs. %d)\n") - .arg(iters).arg(_all_binds[_in_binds[i]]->_cnt); + .arg(_iters).arg(_all_binds[_in_binds[i]]->_cnt); break; case STMT_BEGIN: case STMT_DECLARE: - iters = 1; + _iters = 1; break; case STMT_CREATE: case STMT_DROP: case STMT_ALTER: - iters = 1; + _iters = 1; _last_buff_row = 0; _state |= EOF_DATA; break; @@ -411,12 +410,12 @@ _conn._svc_ctx, _handle, // *stmtp _errh, // *errhp - iters, //_stmt_type == STMT_SELECT ? rows : 1, // iters + _iters, //_stmt_type == STMT_SELECT ? rows : 1, // _iters 0, // rowoff (CONST OCISnapshot*)0, (OCISnapshot*)0, mode)); //std::cout << std::endl - // << "iters:" << iters << std::endl; + // << "_iters:" << _iters << std::endl; _state |= EXECUTED; _last_row = _last_buff_row = 0; @@ -961,6 +960,8 @@ //CHAR memset(BP.valuep, ' ', BP.value_sz); memcpy(BP.valuep, val, l); + //strcpy((char*)BP.valuep, val); + BP.value_sz = l; } BP.alenp[0] = (ub2)l; BP._cnt = 1; @@ -1206,7 +1207,9 @@ template<> SqlStatement& SqlStatement::operator>> <int>(std::vector<int> &val) { - if( get_stmt_type() != STMT_DECLARE && get_stmt_type() != STMT_BEGIN) + if( get_stmt_type() != STMT_DECLARE && + get_stmt_type() != STMT_BEGIN && + get_stmt_type() != STMT_INSERT ) throw OciException(__TROTL_HERE__, "Reading vectors from SQL statements is not implemented yet"); BindPar const &BP( (get_stmt_type() == STMT_SELECT ? get_next_column() : get_next_out_bindpar() ) ); @@ -1215,12 +1218,12 @@ if((_state & EXECUTED) == 0) execute_internal(g_OCIPL_BULK_ROWS, OCI_DEFAULT); - val.resize(BP._cnt); - //val = BP.get_int( _last_buff_row); - for(unsigned i=0; i < BP._cnt; ++i) + ub4 iters = get_stmt_type() == STMT_INSERT ? _iters : BP._cnt; + val.resize(iters); + + for(unsigned i=0; i < iters; ++i) { val.at(i) = BP2.get_number<int>(i); -// std::cout << "setting:" << BP2.get_number<int>(i) << std::endl; } // if(_out_pos == _column_count && BP._bind_type == BP.DEFINE_SELECT) @@ -1238,7 +1241,9 @@ template<> SqlStatement& SqlStatement::operator>> <unsigned int>(std::vector<unsigned int> &val) { - if( get_stmt_type() != STMT_DECLARE && get_stmt_type() != STMT_BEGIN) + if( get_stmt_type() != STMT_DECLARE && + get_stmt_type() != STMT_BEGIN && + get_stmt_type() != STMT_INSERT ) throw OciException(__TROTL_HERE__, "Reading vectors from SQL statements is not implemented yet"); BindPar const &BP( (get_stmt_type() == STMT_SELECT ? get_next_column() : get_next_out_bindpar() ) ); @@ -1247,9 +1252,10 @@ if((_state & EXECUTED) == 0) execute_internal(g_OCIPL_BULK_ROWS, OCI_DEFAULT); - val.resize(BP._cnt); + ub4 iters = get_stmt_type() == STMT_INSERT ? _iters : BP._cnt; + val.resize(iters); - for(unsigned i=0; i < BP._cnt; ++i) + for(unsigned i=0; i < iters; ++i) val.at(i) = BP2.get_number<unsigned int>(i); if(_out_pos == _out_cnt && get_stmt_type() != STMT_SELECT ) @@ -1261,7 +1267,9 @@ template<> SqlStatement& SqlStatement::operator>> <long>(std::vector<long> &val) { - if( get_stmt_type() != STMT_DECLARE && get_stmt_type() != STMT_BEGIN) + if( get_stmt_type() != STMT_DECLARE && + get_stmt_type() != STMT_BEGIN && + get_stmt_type() != STMT_INSERT ) throw OciException(__TROTL_HERE__, "Reading vectors from SQL statements is not implemented yet"); BindPar const &BP( (get_stmt_type() == STMT_SELECT ? get_next_column() : get_next_out_bindpar() ) ); @@ -1270,7 +1278,8 @@ if((_state & EXECUTED) == 0) execute_internal(g_OCIPL_BULK_ROWS, OCI_DEFAULT); - val.resize(BP._cnt); + ub4 iters = get_stmt_type() == STMT_INSERT ? _iters : BP._cnt; + val.resize(iters); for(unsigned i=0; i < BP._cnt; ++i) val.at(i) = BP2.get_number<long>(i); @@ -1284,7 +1293,9 @@ template<> SqlStatement& SqlStatement::operator>> <unsigned long>(std::vector<unsigned long> &val) { - if( get_stmt_type() != STMT_DECLARE && get_stmt_type() != STMT_BEGIN) + if( get_stmt_type() != STMT_DECLARE && + get_stmt_type() != STMT_BEGIN && + get_stmt_type() != STMT_INSERT ) throw OciException(__TROTL_HERE__, "Reading vectors from SQL statements is not implemented yet"); BindPar const &BP( (get_stmt_type() == STMT_SELECT ? get_next_column() : get_next_out_bindpar() ) ); @@ -1292,10 +1303,11 @@ if((_state & EXECUTED) == 0) execute_internal(g_OCIPL_BULK_ROWS, OCI_DEFAULT); + + ub4 iters = get_stmt_type() == STMT_INSERT ? _iters : BP._cnt; + val.resize(iters); - val.resize(BP._cnt); - - for(unsigned i=0; i < BP._cnt; ++i) + for(unsigned i=0; i < iters; ++i) val.at(i) = BP2.get_number<unsigned long>(i); if(_out_pos == _out_cnt && get_stmt_type() != STMT_SELECT ) @@ -1307,7 +1319,9 @@ template<> SqlStatement& SqlStatement::operator>> <float>(std::vector<float> &val) { - if( get_stmt_type() != STMT_DECLARE && get_stmt_type() != STMT_BEGIN) + if( get_stmt_type() != STMT_DECLARE && + get_stmt_type() != STMT_BEGIN && + get_stmt_type() != STMT_INSERT ) throw OciException(__TROTL_HERE__, "Reading vectors from SQL statements is not implemented yet"); BindPar const &BP( (get_stmt_type() == STMT_SELECT ? get_next_column() : get_next_out_bindpar() ) ); @@ -1316,9 +1330,10 @@ if((_state & EXECUTED) == 0) execute_internal(g_OCIPL_BULK_ROWS, OCI_DEFAULT); - val.resize(BP._cnt); - - for(unsigned i=0; i < BP._cnt; ++i) + ub4 iters = get_stmt_type() == STMT_INSERT ? _iters : BP._cnt; + val.resize(iters); + + for(unsigned i=0; i < iters; ++i) val.at(i) = BP2.get_number<float>(i); if(_out_pos == _out_cnt && get_stmt_type() != STMT_SELECT ) @@ -1330,7 +1345,9 @@ template<> SqlStatement& SqlStatement::operator>> <double>(std::vector<double> &val) { - if( get_stmt_type() != STMT_DECLARE && get_stmt_type() != STMT_BEGIN) + if( get_stmt_type() != STMT_DECLARE && + get_stmt_type() != STMT_BEGIN && + get_stmt_type() != STMT_INSERT ) throw OciException(__TROTL_HERE__, "Reading vectors from SQL statements is not implemented yet"); BindPar const &BP( (get_stmt_type() == STMT_SELECT ? get_next_column() : get_next_out_bindpar() ) ); @@ -1339,21 +1356,24 @@ if((_state & EXECUTED) == 0) execute_internal(g_OCIPL_BULK_ROWS, OCI_DEFAULT); - val.resize(BP._cnt); + ub4 iters = get_stmt_type() == STMT_INSERT ? _iters : BP._cnt; + val.resize(iters); - for(unsigned i=0; i < BP._cnt; ++i) + for(unsigned i=0; i < _iters; ++i) val.at(i) = BP2.get_number<double>(i); if(_out_pos == _out_cnt && get_stmt_type() != STMT_SELECT ) _state |= EOF_DATA; - + return *this; } template<> SqlStatement& SqlStatement::operator>> <tstring>(std::vector<tstring> &val) { - if( get_stmt_type() != STMT_DECLARE && get_stmt_type() != STMT_BEGIN) + if( get_stmt_type() != STMT_DECLARE && + get_stmt_type() != STMT_BEGIN && + get_stmt_type() != STMT_INSERT ) throw OciException(__TROTL_HERE__, "Reading vectors from SQL statements is not implemented yet"); BindPar const &BP( (get_stmt_type() == STMT_SELECT ? get_next_column() : get_next_out_bindpar() ) ); @@ -1361,9 +1381,10 @@ if((_state & EXECUTED) == 0) execute_internal(g_OCIPL_BULK_ROWS, OCI_DEFAULT); - val.resize(BP._cnt); + ub4 iters = get_stmt_type() == STMT_INSERT ? _iters : BP._cnt; + val.resize(iters); - for(unsigned i=0; i < BP._cnt; ++i) + for(unsigned i=0; i < iters; ++i) val.at(i) = BP.get_string(i); if(_out_pos == _out_cnt && get_stmt_type() != STMT_SELECT ) Modified: branches/tora-trotl/src/trotl/src/trotl_stat.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_stat.h 2010-11-26 17:51:27 UTC (rev 3823) +++ branches/tora-trotl/src/trotl/src/trotl_stat.h 2010-11-26 18:07:38 UTC (rev 3824) @@ -401,7 +401,7 @@ int _state; STMT_TYPE _stmt_type; mutable ub4 _param_count, _column_count, _in_cnt, _out_cnt; - ub4 _last_row, _last_fetched_row, _in_pos, _out_pos; + ub4 _last_row, _last_fetched_row, _in_pos, _out_pos, _iters; ub4 _last_buff_row, _buff_size; // used in select statements mutable ub4 _fetched_row; Modified: branches/tora-trotl/src/trotl/src/trotl_string.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_string.h 2010-11-26 17:51:27 UTC (rev 3823) +++ branches/tora-trotl/src/trotl/src/trotl_string.h 2010-11-26 18:07:38 UTC (rev 3824) @@ -85,28 +85,11 @@ ~BindParVarchar() {} -// template<class return_type> -// return_type get_number(unsigned int row) const -// { -// throw_ocipl_exception( -// OciException( -// __TROTL_HERE__, -// "Invalid datatype in conversion(BindParVarchar to %d%s)\n" -// ).arg(sizeof(return_type)).arg(typeid(return_type).name()) -// ); -// } - virtual tstring get_string(unsigned int row) const { return is_null(row) ? "NULL" : tstring(((char*)valuep)+(row * value_sz)); } -// virtual int get_int(unsigned int row) const { return get_number<int>(row); }; -// virtual unsigned int get_uint(unsigned int row) const { return get_number<unsigned int>(row); }; -// virtual long get_long(unsigned int row) const { return get_number<long>(row); }; -// virtual unsigned long get_ulong(unsigned int row) const { return get_number<unsigned long>(row); }; -// virtual float get_float(unsigned int row) const { return get_number<float>(row); }; -// virtual double get_double(unsigned int row) const { return get_number<double>(row); }; protected: BindParVarchar(const BindParVarchar &other); }; @@ -130,7 +113,7 @@ valuep = (void**) calloc(decl.bracket[1], decl.bracket[0]); alenp = (ub2*) calloc(_cnt, sizeof(ub2)); - dty = SQLT_CHR; + dty = SQLT_STR; /* use STR_CHR even if placeholder defined as "char" */ value_sz = decl.bracket[0]; type_name = typeid(tstring).name(); } @@ -140,10 +123,8 @@ virtual tstring get_string(unsigned int row) const { -// std::cout << " S:" << value_sz << ":" << dty << " "; - if(!indp[row]) - return tstring(((char*)valuep)+(row * value_sz), value_sz); + return tstring(((char*)valuep)+(row * value_sz), (_bind_type != DEFINE_SELECT ? alenp[row] : value_sz) ); return ""; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ibr...@us...> - 2010-12-08 14:30:30
|
Revision: 3830 http://tora.svn.sourceforge.net/tora/?rev=3830&view=rev Author: ibre5041 Date: 2010-12-08 14:30:21 +0000 (Wed, 08 Dec 2010) Log Message: ----------- initial support for cursor datatype added, so far this type is not treated as custom/complex datatype Modified Paths: -------------- branches/tora-trotl/src/trotl/src/CMakeLists.txt branches/tora-trotl/src/trotl/src/trotl_base.h branches/tora-trotl/src/trotl/src/trotl_common.h branches/tora-trotl/src/trotl/src/trotl_stat.cpp branches/tora-trotl/src/trotl/src/trotl_stat.h Added Paths: ----------- branches/tora-trotl/src/trotl/src/trotl_cursor.cpp branches/tora-trotl/src/trotl/src/trotl_cursor.h Modified: branches/tora-trotl/src/trotl/src/CMakeLists.txt =================================================================== --- branches/tora-trotl/src/trotl/src/CMakeLists.txt 2010-12-06 18:53:48 UTC (rev 3829) +++ branches/tora-trotl/src/trotl/src/CMakeLists.txt 2010-12-08 14:30:21 UTC (rev 3830) @@ -18,6 +18,7 @@ trotl_conn.cpp trotl_convertor.cpp trotl_collection.cpp + trotl_cursor.cpp trotl_date.cpp trotl_exc.cpp trotl_int.cpp Modified: branches/tora-trotl/src/trotl/src/trotl_base.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_base.h 2010-12-06 18:53:48 UTC (rev 3829) +++ branches/tora-trotl/src/trotl/src/trotl_base.h 2010-12-08 14:30:21 UTC (rev 3830) @@ -174,7 +174,7 @@ // allocate error handle _errh.alloc(_handle); } -#ifdef WIN32 // is ithis really neccessary? +#ifdef WIN32 // is this really neccessary? template struct TROTL_EXPORT OciSimpleHandle<OCIError>; #endif OciError _errh; @@ -198,7 +198,7 @@ OciHandle(const OciHandle& other) : _env(other._env), _handle(other._handle) { - const_cast<HandleType*>(other._handle) = NULL; + const_cast<OciHandle&>(other)._handle = NULL; } ~OciHandle() Modified: branches/tora-trotl/src/trotl/src/trotl_common.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_common.h 2010-12-06 18:53:48 UTC (rev 3829) +++ branches/tora-trotl/src/trotl/src/trotl_common.h 2010-12-08 14:30:21 UTC (rev 3830) @@ -67,21 +67,6 @@ //TODO //thread_safe_log get_log(); -//inline tstring str_backtrace() -//{ -// tostream ret; -//#ifdef __GNUC__ -// void *buffer[TROTL_BACKTRACE_DEPTH]; -// -// int bsize = ::backtrace(buffer, TROTL_BACKTRACE_DEPTH); -// char **names = backtrace_symbols (buffer, bsize); -// for(int i=0; i<bsize; i++) -// ret << names[i] << std::endl; -// free(names); -//#endif -// return ret.str(); -//} - //#define OCICALL(x) x; do { std::cerr << __TROTL_HERE__ << #x << std::endl; } while(0) //#define OCICALL(x) x; do { std::cerr << #x << std::endl; } while(0) #define OCICALL(x) x Added: branches/tora-trotl/src/trotl/src/trotl_cursor.cpp =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_cursor.cpp (rev 0) +++ branches/tora-trotl/src/trotl/src/trotl_cursor.cpp 2010-12-08 14:30:21 UTC (rev 3830) @@ -0,0 +1,139 @@ +// Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...> +// +// forked from OCIPL Version 1.3 +// by Ivan Brezina <iv...@cv...> + +/* + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRES7S OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifdef WIN32 +#include "trotl_parser.h" +#include <stdio.h> +#define snprintf _snprintf +#endif + +#include "trotl_cursor.h" + +namespace trotl { + +// // Register Bind datatypes in factory(Bind - PL/SQL) + Util::RegisterInFactory<BindParCursor, BindParFactTwoParmSing> regBindCursor("cursor"); + +// // Register Bind datatypes in factory(Define - SELECT) +Util::RegisterInFactory<BindParCursor, DefineParFactTwoParmSing, int> regDefineCursor(SQLT_RSET); + +BindParCursor::BindParCursor(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl): BindPar(pos, stmt, decl) +{ + valuep = (void**) calloc(_cnt, sizeof(OCIStmt*)); + value_sz = sizeof(OCIStmt*); + dty = SQLT_RSET; + type_name = "cursor"; + descAlloc(); +}; + +BindParCursor::BindParCursor(unsigned int pos, SqlStatement &stmt, ColumnType &ct) : BindPar(pos, stmt, ct) +{ + valuep = (void**) calloc(_cnt, sizeof(OCIStmt*)); + value_sz = sizeof(OCIStmt*); + dty = SQLT_RSET; + type_name = ct.get_type_str(); + descAlloc(); +} + +void BindParCursor::descAlloc(void) +{ + // Note: If you have retrieved multiple ref cursors, you must take care when fetching them into stm2p. + // If you fetch the first one, you can then perform fetches on it to retrieve its data. + // However, once you fetch the second ref cursor into stm2p, you no longer have access to the data from the first ref cursor. + for(unsigned i=0; i<_cnt; ++i) + { + OciHandle<OCIStmt> handle(_env); + CursorStatement *s = new CursorStatement(_stmt._conn, handle); + ((OCIStmt**)valuep)[i] = s->operator OCIStmt*(); + _cursors.push_back(s); + } +} + +void BindParCursor::descFree(void) +{ + for(unsigned i=0; i<_cnt; ++i) + { + sword res = OCICALL(OCIHandleFree(((void**)valuep)[i], OCI_HTYPE_STMT)); + oci_check_error(__TROTL_HERE__, _env, res); + } +} + +void BindParCursor::redefine(ub4 i) +{ + OciHandle<OCIStmt> handle(_env); + CursorStatement *s = new CursorStatement(_stmt._conn, handle); + ((OCIStmt**)valuep)[i] = s->operator OCIStmt*(); + _cursors.at(i) = s; +} + +tstring BindParCursor::get_string(unsigned int i) const +{ + std::stringstream retval; + if(indp[i] == OCI_IND_NULL) + return ""; + + CursorStatement *c = _cursors.at(i); + + if( (c->_state & BindParCursor::CursorStatement::DEFINED) == 0 ) + c->define_all(); + if( (c->_state & BindParCursor::CursorStatement::FETCHED) == 0 ) + c->fetch(); + + unsigned column = 0; + while(!c->eof()) + { + std::string s; + *c >> s; + retval << s << '\t'; + column++; + if(column==c->get_column_count()) + { + retval << std::endl; + column=0; + } + } + const_cast<BindParCursor*>(this)->redefine(i); + return retval.str(); +} + + +SqlCursor::SqlCursor() : c(NULL) +{ +} + +SqlCursor::~SqlCursor() +{ + if(c) delete c; +} + +}; Added: branches/tora-trotl/src/trotl/src/trotl_cursor.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_cursor.h (rev 0) +++ branches/tora-trotl/src/trotl/src/trotl_cursor.h 2010-12-08 14:30:21 UTC (rev 3830) @@ -0,0 +1,122 @@ +// Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...> +// +// forked from OCIPL Version 1.3 +// by Ivan Brezina <iv...@cv...> + +/* + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef TROTL_CURSOR_H_ +#define TROTL_CURSOR_H_ + +#include "trotl_export.h" +#include "trotl_base.h" +#include "trotl_stat.h" + +namespace trotl { + +struct SqlCursor; + +struct TROTL_EXPORT BindParCursor: public SqlStatement::BindPar +{ + BindParCursor(unsigned int pos, SqlStatement &stmt, ColumnType &ct); + BindParCursor(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl); + ~BindParCursor() + { + descFree(); + }; + + virtual tstring get_string(unsigned int) const; + + friend struct SqlCursor; + class CursorStatement : public SqlStatement + { + public: + CursorStatement(OciConnection& conn, OciHandle<OCIStmt> handle, ub4 lang=OCI_NTV_SYNTAX, int bulk_rows=g_OCIPL_BULK_ROWS) + : SqlStatement(conn, handle, bulk_rows) + { + _stmt_type = STMT_SELECT; + _state |= PREPARED | DESCRIBED | EXECUTED; + }; + + void define_all() + { + SqlStatement::define_all(); + }; + void fetch() + { + SqlStatement::fetch(_buff_size); + }; + }; + void descAlloc(void); + void descFree(void); + void redefine(ub4); + + std::vector<CursorStatement*> _cursors; +protected: + BindParCursor(const BindParCursor &other); +}; + +struct TROTL_EXPORT SqlCursor: public SqlValue +{ + SqlCursor(OciEnv &env); + + template<class wrapped_type> + SqlCursor& operator>>(wrapped_type &val) + { + if( (c->_state & BindParCursor::CursorStatement::DEFINED) == 0 ) + c->define_all(); + if( (c->_state & BindParCursor::CursorStatement::FETCHED) == 0 ) + c->fetch(); + *c >> val; + return *this; + } + + bool eof() + { + return c->eof(); + } + + ub4 get_column_count() + { + return c->get_column_count(); + } +//protected: + OciHandle<OCIStmt> *handle; + + friend struct ConvertorForRead; + friend struct ConvertorForWrite; + + SqlCursor(); + ~SqlCursor(); + BindParCursor::CursorStatement *c; +}; + +}; + +#endif Modified: branches/tora-trotl/src/trotl/src/trotl_stat.cpp =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_stat.cpp 2010-12-06 18:53:48 UTC (rev 3829) +++ branches/tora-trotl/src/trotl/src/trotl_stat.cpp 2010-12-08 14:30:21 UTC (rev 3830) @@ -45,6 +45,7 @@ #include "trotl_stat.h" #include "trotl_convertor.h" +#include "trotl_cursor.h" namespace trotl { @@ -92,53 +93,6 @@ if(get_stmt_type() == STMT_SELECT) { execute_describe(); - _columns.resize(get_column_count()+1); // we do not use zero-th position - - _all_defines= new std::auto_ptr<BindPar> [get_column_count()+1]; - - for(unsigned dpos = 1; dpos <= get_column_count(); ++dpos) - { - std::auto_ptr<BindPar> bp; - OCIParam* parmdp; - sword res = OCICALL(OCIParamGet(_handle, get_type_id(), _errh, (void**)&parmdp, dpos)); - oci_check_error(__TROTL_HERE__, _errh, res); - - _columns[dpos].describe(*this, parmdp); - - res = OCICALL(OCIDescriptorFree(parmdp, OCI_DTYPE_PARAM)); - oci_check_error(__TROTL_HERE__, _env, res); - - //get_log().ts( std::string(__HERE_SHORT__)) - //std::cout - // << "This: " << this << std::endl - // << "Columns:" << _columns[dpos].get_type_str(true) << std::endl; - - // Use column datatype for lookup in a hash table - // and call appropriate create function from the factory - if( _columns[dpos]._data_type != SQLT_NTY) - _all_defines[dpos] = DefineParFactTwoParmSing::Instance().create( - _columns[dpos]._data_type, - dpos, - *this, - _columns[dpos] ); - else - _all_defines[dpos] = CustDefineParFactTwoParmSing::Instance().create( - _columns[dpos]._reg_name.c_str(), - dpos, - *this, - _columns[dpos] ); - - if(_all_defines[dpos].get() == NULL) - throw OciException(__TROTL_HERE__, "DefinePar: Data type not registered: %s(%d:%d:%d:%s:%s)\n") - .arg(_columns[dpos]._data_type_name) - .arg(_columns[dpos]._data_type) - .arg(_columns[dpos]._typecode) - .arg(_columns[dpos]._collection_typecode) - .arg(_columns[dpos]._data_type_name) - .arg(_columns[dpos]._reg_name); - define(*_all_defines[dpos]); - } - _state |= DEFINED; } if(get_bindpar_count()) @@ -177,15 +131,31 @@ if(_out_binds) _out_binds[0]=0; // if(_binds_all) _binds_all[0]=0; -// get_log().ts( std::string(__HERE_SHORT__)) -// std::cout -// << "This: " << this << std::endl -// << "Stat: " << stmt << std::endl -// << "In Binds: " << _in_cnt << std::endl -// << "Out Binds: " << _out_cnt << std::endl -// << "All Binds: " << get_bindpar_count() << std::endl; }; +SqlStatement::SqlStatement(OciConnection& conn, OciHandle<OCIStmt>& handle, ub4 lang, int bulk_rows) +: super(handle), +_conn(conn), +_lang(lang), +_orig_stmt(""), +_parsed_stmt(""), +_state(UNINITIALIZED), +_stmt_type(STMT_NONE), +_param_count(0), _column_count(0), +_in_cnt(0), _out_cnt(0), _iters(0), +_last_row(-1), +_last_fetched_row(-1), +_in_pos(0), _out_pos(0), +_last_buff_row(0), _buff_size(g_OCIPL_BULK_ROWS), +_all_binds(NULL), _in_binds(NULL), _out_binds(NULL), +_bound(false) +// _res(NULL), +// _bulk_rows(bulk_rows), +// _result_buffers(0), +{ + _errh.alloc(_env); +}; + void SqlStatement::prepare(const tstring& sql, ub4 lang) { ub2 stmt_type; // OCI_STMT_SELECT, OCI_STMT_UPDATE, ... @@ -238,6 +208,52 @@ _state |= DESCRIBED; } +void SqlStatement::define_all() +{ + _columns.resize(get_column_count()+1); // we do not use zero-th position + _all_defines= new std::auto_ptr<BindPar> [get_column_count()+1]; + + for(unsigned dpos = 1; dpos <= get_column_count(); ++dpos) + { + std::auto_ptr<BindPar> bp; + OCIParam* parmdp; + sword res = OCICALL(OCIParamGet(_handle, get_type_id(), _errh, (void**)&parmdp, dpos)); + oci_check_error(__TROTL_HERE__, _errh, res); + + _columns[dpos].describe(*this, parmdp); + + res = OCICALL(OCIDescriptorFree(parmdp, OCI_DTYPE_PARAM)); + oci_check_error(__TROTL_HERE__, _env, res); + + // Use column datatype for lookup in a hash table + // and call appropriate create function from the factory + if( _columns[dpos]._data_type != SQLT_NTY) + _all_defines[dpos] = DefineParFactTwoParmSing::Instance().create( + _columns[dpos]._data_type, + dpos, + *this, + _columns[dpos] ); + else + _all_defines[dpos] = CustDefineParFactTwoParmSing::Instance().create( + _columns[dpos]._reg_name.c_str(), + dpos, + *this, + _columns[dpos] ); + + if(_all_defines[dpos].get() == NULL) + throw OciException(__TROTL_HERE__, "DefinePar: Data type not registered: %s(%d:%d:%d:%s:%s)\n") + .arg(_columns[dpos]._data_type_name) + .arg(_columns[dpos]._data_type) + .arg(_columns[dpos]._typecode) + .arg(_columns[dpos]._collection_typecode) + .arg(_columns[dpos]._data_type_name) + .arg(_columns[dpos]._reg_name); + define(*_all_defines[dpos]); + } + _state |= DEFINED; +} + + ub4 SqlStatement::get_column_count() const { if(get_stmt_type() != STMT_SELECT) @@ -251,11 +267,11 @@ res = OCICALL(OCIAttrGet(_handle, get_type_id(), &_column_count, &size, OCI_ATTR_PARAM_COUNT, _errh)); oci_check_error(__TROTL_HERE__, _errh, res); - + //get_log().ts( std::string(__HERE_SHORT__)) -// std::cout -// << "This: " << this << std::endl -// << "Column count:" << _column_count << std::endl; + // std::cout + // << "This: " << this << std::endl + // << "Column count:" << _column_count << std::endl; return _column_count; } @@ -328,8 +344,8 @@ bool SqlStatement::eof() { - if((_state & EXECUTED) == 0) - execute_internal(g_OCIPL_BULK_ROWS, OCI_DEFAULT); + if((_state & EXECUTED) == 0) + execute_internal(g_OCIPL_BULK_ROWS, OCI_DEFAULT); return _state >= EOF_DATA && _last_buff_row >= fetched_rows(); } @@ -360,7 +376,8 @@ _state |= EOF_DATA; break; case STMT_SELECT: - _iters = rows; + //_iters = rows; + _iters = 0; break; case STMT_UPDATE: _iters = 1; @@ -404,14 +421,15 @@ if(!BP._bound) bind(BP); } } - - // execute and fetch + _bound = true; + + // execute and do not fetch sword res = OCICALL(OCIStmtExecute( _conn._svc_ctx, - _handle, // *stmtp - _errh, // *errhp - _iters, //_stmt_type == STMT_SELECT ? rows : 1, // _iters - 0, // rowoff + _handle, // *stmtp + _errh, // *errhp + _iters, + 0, // rowoff (CONST OCISnapshot*)0, (OCISnapshot*)0, mode)); //std::cout << std::endl @@ -420,8 +438,14 @@ _state |= EXECUTED; _last_row = _last_buff_row = 0; if(get_stmt_type() == STMT_SELECT) - _last_fetched_row = row_count(); - _bound = true; + { + if((_state & DEFINED) == 0) + { + define_all(); + } + fetch(_buff_size); + _last_fetched_row = row_count(); + } switch(res) { @@ -455,7 +479,7 @@ _state |= FETCHED; return true; case OCI_NO_DATA: - _state |= EOF_DATA; + _state |= FETCHED | EOF_DATA; return false; default: oci_check_error(__TROTL_HERE__, _errh, res); @@ -1393,4 +1417,26 @@ return *this; } +SqlStatement& SqlStatement::operator>> (SqlCursor &val) +{ + BindPar &BP(get_stmt_type() == STMT_SELECT ? get_next_column() : get_next_out_bindpar()); + BindParCursor &BP2 = dynamic_cast<BindParCursor&>(BP); + + val.c = BP2._cursors.at(_last_buff_row); + BP2.redefine(_last_buff_row); + + if(_out_pos == _column_count && BP._bind_type == BP.DEFINE_SELECT) + ++_last_buff_row; + + if(_out_pos == _out_cnt && get_stmt_type() != STMT_SELECT ) + _state |= EOF_DATA; + + if(_last_buff_row == fetched_rows() && ((_state & EOF_DATA) == 0) && get_stmt_type() == STMT_SELECT) + { + fetch(_buff_size); + } + + return *this; }; + +}; Modified: branches/tora-trotl/src/trotl/src/trotl_stat.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_stat.h 2010-12-06 18:53:48 UTC (rev 3829) +++ branches/tora-trotl/src/trotl/src/trotl_stat.h 2010-12-08 14:30:21 UTC (rev 3830) @@ -52,7 +52,9 @@ namespace trotl { - +class BindParCursor; +class SqlCursor; + inline void oci_check_error(tstring where, SqlStatement &stmt, sword res) { if (res != OCI_SUCCESS) @@ -63,7 +65,7 @@ class TROTL_EXPORT SqlStatement : public OciHandle<OCIStmt> { typedef OciHandle<OCIStmt> super; - + friend class BindParCursor; public: enum STMT_TYPE { STMT_OTHER = 0, // truncate table, ... @@ -202,6 +204,7 @@ }; // class BindPar SqlStatement(OciConnection& conn, const tstring& stmt, ub4 lang=OCI_NTV_SYNTAX, int bulk_rows=g_OCIPL_BULK_ROWS); + SqlStatement(OciConnection& conn, OciHandle<OCIStmt> &handle, ub4 lang=OCI_NTV_SYNTAX, int bulk_rows=g_OCIPL_BULK_ROWS); bool execute_internal(ub4 rows, ub4 mode); ub4 row_count() const; @@ -307,6 +310,7 @@ } SqlStatement& operator>> (SqlValue &val); + SqlStatement& operator>> (SqlCursor &val); template<class wrapped_type> SqlStatement& operator>>(wrapped_type &val) @@ -391,6 +395,7 @@ void bind(BindPar &bp); /* OCIDefineByPos - for SELECT statements */ void define(BindPar &dp); + void define_all(); //OCISvcCtx* _svchp; public: //todo delete me - these fields should not be public This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ibr...@us...> - 2011-08-05 20:17:18
|
Revision: 4008 http://tora.svn.sourceforge.net/tora/?rev=4008&view=rev Author: ibre5041 Date: 2011-08-05 20:17:05 +0000 (Fri, 05 Aug 2011) Log Message: ----------- Trotl library version bump Modified Paths: -------------- branches/tora-trotl/src/trotl/src/CMakeLists.txt branches/tora-trotl/src/trotl/src/Loki/Factory_alt.h branches/tora-trotl/src/trotl/src/Loki/TypeTraits.h branches/tora-trotl/src/trotl/src/trotl_anydata.cpp branches/tora-trotl/src/trotl/src/trotl_anydata.h branches/tora-trotl/src/trotl/src/trotl_aq.cpp branches/tora-trotl/src/trotl/src/trotl_aq.h branches/tora-trotl/src/trotl/src/trotl_collection.cpp branches/tora-trotl/src/trotl/src/trotl_collection.h branches/tora-trotl/src/trotl/src/trotl_common.h branches/tora-trotl/src/trotl/src/trotl_conn.cpp branches/tora-trotl/src/trotl/src/trotl_conn.h branches/tora-trotl/src/trotl/src/trotl_convertor.cpp branches/tora-trotl/src/trotl/src/trotl_convertor.h branches/tora-trotl/src/trotl/src/trotl_cursor.cpp branches/tora-trotl/src/trotl/src/trotl_cursor.h branches/tora-trotl/src/trotl/src/trotl_date.cpp branches/tora-trotl/src/trotl/src/trotl_date.h branches/tora-trotl/src/trotl/src/trotl_export.h branches/tora-trotl/src/trotl/src/trotl_int.cpp branches/tora-trotl/src/trotl/src/trotl_int.h branches/tora-trotl/src/trotl/src/trotl_lob.cpp branches/tora-trotl/src/trotl/src/trotl_lob.h branches/tora-trotl/src/trotl/src/trotl_mfile.h branches/tora-trotl/src/trotl/src/trotl_misc.cpp branches/tora-trotl/src/trotl/src/trotl_misc.h branches/tora-trotl/src/trotl/src/trotl_parser.cpp branches/tora-trotl/src/trotl/src/trotl_parser.h branches/tora-trotl/src/trotl/src/trotl_rid.cpp branches/tora-trotl/src/trotl/src/trotl_rid.h branches/tora-trotl/src/trotl/src/trotl_stat.cpp branches/tora-trotl/src/trotl/src/trotl_stat.h branches/tora-trotl/src/trotl/src/trotl_string.cpp branches/tora-trotl/src/trotl/src/trotl_string.h branches/tora-trotl/src/trotl/src/trotl_var.cpp branches/tora-trotl/src/trotl/src/trotl_var.h branches/tora-trotl/src/trotl/src/trotl_xml.cpp branches/tora-trotl/src/trotl/src/trotl_xml.h Modified: branches/tora-trotl/src/trotl/src/CMakeLists.txt =================================================================== --- branches/tora-trotl/src/trotl/src/CMakeLists.txt 2011-07-23 19:41:31 UTC (rev 4007) +++ branches/tora-trotl/src/trotl/src/CMakeLists.txt 2011-08-05 20:17:05 UTC (rev 4008) @@ -1,59 +1,60 @@ -SET(TROTL_DLL_DEFINES "-DLOKI_STATIC -DEXPLICIT_EXPORT -DTROTL_MAKE_DLL") -SET(TROTL_CLIENT_DEFINES "-DLOKI_STATIC -DEXPLICIT_EXPORT -DTROTL_DLL") - -INCLUDE_DIRECTORIES( - ${ORACLE_INCLUDES} - "D:\\DEVEL\\boost_1_46_1" -) - -# include the stack library in dubug builds only -IF(CMAKE_BUILD_TYPE STREQUAL "Debug") - SET (STACK_LIB "stack_lib") - ADD_SUBDIRECTORY(stack) - INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/stack) - LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src/stack) -ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug") - -SET(TROTL_SOURCES - trotl_anydata.cpp - trotl_conn.cpp - trotl_convertor.cpp - trotl_collection.cpp - trotl_cursor.cpp - trotl_date.cpp - trotl_exc.cpp - trotl_int.cpp - trotl_misc.cpp - trotl_string.cpp - trotl_lob.cpp - trotl_parser.cpp - trotl_rid.cpp - trotl_stat.cpp - trotl_var.cpp -) - -IF(ORACLE_HAS_XML) - LIST(APPEND TROTL_SOURCES trotl_xml.cpp) -ENDIF (ORACLE_HAS_XML) - - -#IF(WIN32) -# IF (MSVC) -# # this is a must to switch off subsystem:console (console window poping up) -# # WinMain wrapper from QT_QTMAIN_LIBRARY is used and liner must be modified -# LINK_LIBRARIES(${QT_QTMAIN_LIBRARY}) -# SET (WIN32_SUBSYSTEM WIN32) -# IF (WANT_DEBUG) -# SET (CMAKE_EXE_LINKER_FLAGS "/NODEFAULTLIB:msvcrtd.lib ${CMAKE_EXE_LINKER_FLAGS}") -# ELSE (WANT_DEBUG) -# SET (CMAKE_EXE_LINKER_FLAGS "/NODEFAULTLIB:msvcrt.lib ${CMAKE_EXE_LINKER_FLAGS}") -# ENDIF (WANT_DEBUG) -# ENDIF (MSVC) -#ENDIF(WIN32) - -SET_SOURCE_FILES_PROPERTIES(${TROTL_SOURCES} COMPILE_FLAGS ${TROTL_DLL_DEFINES}) -ADD_LIBRARY(${LIB_NAME} SHARED ${TROTL_SOURCES}) -TARGET_LINK_LIBRARIES(${LIB_NAME} ${ORACLE_LIBRARIES} ${STACK_LIB}) -INSTALL(TARGETS ${LIB_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}) - - +SET(TROTL_DLL_DEFINES "-DLOKI_STATIC -DEXPLICIT_EXPORT -DTROTL_MAKE_DLL") +SET(TROTL_CLIENT_DEFINES "-DLOKI_STATIC -DEXPLICIT_EXPORT -DTROTL_DLL") + +INCLUDE_DIRECTORIES( + ${ORACLE_INCLUDES} + "D:\\DEVEL\\boost_1_46_1" +) + +# include the stack library in dubug builds only +IF(CMAKE_BUILD_TYPE STREQUAL "Debug") + SET (STACK_LIB "stack_lib") + ADD_SUBDIRECTORY(stack) + INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/stack) + LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src/stack) +ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug") + +SET(TROTL_SOURCES + trotl_anydata.cpp + trotl_collection.cpp + trotl_conn.cpp + trotl_convertor.cpp + trotl_cursor.cpp + trotl_date.cpp + trotl_describe.cpp + trotl_error.cpp + trotl_int.cpp + trotl_lob.cpp + trotl_misc.cpp + trotl_parser.cpp + trotl_rid.cpp + trotl_stat.cpp + trotl_string.cpp + trotl_var.cpp +) + +IF(ORACLE_HAS_XML) + LIST(APPEND TROTL_SOURCES trotl_xml.cpp) +ENDIF (ORACLE_HAS_XML) + + +#IF(WIN32) +# IF (MSVC) +# # this is a must to switch off subsystem:console (console window poping up) +# # WinMain wrapper from QT_QTMAIN_LIBRARY is used and liner must be modified +# LINK_LIBRARIES(${QT_QTMAIN_LIBRARY}) +# SET (WIN32_SUBSYSTEM WIN32) +# IF (WANT_DEBUG) +# SET (CMAKE_EXE_LINKER_FLAGS "/NODEFAULTLIB:msvcrtd.lib ${CMAKE_EXE_LINKER_FLAGS}") +# ELSE (WANT_DEBUG) +# SET (CMAKE_EXE_LINKER_FLAGS "/NODEFAULTLIB:msvcrt.lib ${CMAKE_EXE_LINKER_FLAGS}") +# ENDIF (WANT_DEBUG) +# ENDIF (MSVC) +#ENDIF(WIN32) + +SET_SOURCE_FILES_PROPERTIES(${TROTL_SOURCES} COMPILE_FLAGS ${TROTL_DLL_DEFINES}) +ADD_LIBRARY(${LIB_NAME} SHARED ${TROTL_SOURCES}) +TARGET_LINK_LIBRARIES(${LIB_NAME} ${ORACLE_LIBRARIES} ${STACK_LIB}) +INSTALL(TARGETS ${LIB_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}) + + Modified: branches/tora-trotl/src/trotl/src/Loki/Factory_alt.h =================================================================== --- branches/tora-trotl/src/trotl/src/Loki/Factory_alt.h 2011-07-23 19:41:31 UTC (rev 4007) +++ branches/tora-trotl/src/trotl/src/Loki/Factory_alt.h 2011-08-05 20:17:05 UTC (rev 4008) @@ -290,10 +290,10 @@ void dump() const { typename parent::FctRegistry::const_iterator i; - /* for(i = parent::mRegistry.begin(); i != parent::mRegistry.end(); ++i) */ - /* { */ - /* std::cout << "Key:" << i->first << std::endl; */ - /* } */ + for(i = parent::mRegistry.begin(); i != parent::mRegistry.end(); ++i) + { + //std::cout << "Key:" << i->first << std::endl; + } } private: Modified: branches/tora-trotl/src/trotl/src/Loki/TypeTraits.h =================================================================== --- branches/tora-trotl/src/trotl/src/Loki/TypeTraits.h 2011-07-23 19:41:31 UTC (rev 4007) +++ branches/tora-trotl/src/trotl/src/Loki/TypeTraits.h 2011-08-05 20:17:05 UTC (rev 4008) @@ -93,18 +93,18 @@ namespace Private { #ifndef LOKI_DISABLE_TYPELIST_MACROS - typedef LOKI_TYPELIST_4(unsigned char, unsigned short int,unsigned int, unsigned long int) + typedef LOKI_TYPELIST_5(unsigned char, unsigned short int,unsigned int, unsigned long int, unsigned long long int) StdUnsignedInts; - typedef LOKI_TYPELIST_4(signed char, short int,int, long int) + typedef LOKI_TYPELIST_5(signed char, short int,int, long int, long long int) StdSignedInts; typedef LOKI_TYPELIST_3(bool, char, wchar_t) StdOtherInts; typedef LOKI_TYPELIST_3(float, double, long double) StdFloats; #else - typedef Loki::Seq<unsigned char, unsigned short int,unsigned int, unsigned long int>::Type + typedef Loki::Seq<unsigned char, unsigned short int,unsigned int, unsigned long int, unsigned long long int>::Type StdUnsignedInts; - typedef Loki::Seq<signed char, short int,int, long int>::Type + typedef Loki::Seq<signed char, short int,int, long int, long long int>::Type StdSignedInts; typedef Loki::Seq<bool, char, wchar_t>::Type StdOtherInts; Modified: branches/tora-trotl/src/trotl/src/trotl_anydata.cpp =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_anydata.cpp 2011-07-23 19:41:31 UTC (rev 4007) +++ branches/tora-trotl/src/trotl/src/trotl_anydata.cpp 2011-08-05 20:17:05 UTC (rev 4008) @@ -1,5 +1,5 @@ // Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...> -// +// // forked from OCIPL Version 1.3 // by Ivan Brezina <iv...@cv...> @@ -31,32 +31,66 @@ */ - +#include "trotl_common.h" +#include "trotl_export.h" #include "trotl_anydata.h" -#include <string.h> -namespace trotl { +#include "trotl_stat.h" +#include "trotl_describe.h" +namespace trotl +{ + // TODO //Util::RegisterInFactory<BindParANYDATA, BindParFactTwoParmSing> regBindXML("SYS.ANYDATA"); Util::RegisterInFactory<BindParANYDATA, CustDefineParFactTwoParmSing> regCustDefineNTY_ANYDATA("SYS.ANYDATA"); +BindParANYDATA::BindParANYDATA(unsigned int pos, SqlStatement &stmt, DescribeColumn* ct) : BindPar(pos, stmt, ct) + , _oan_buffer(NULL) + , _any_indp(NULL) +{ + dty = SQLT_NTY; + _type_name = ct->typeName(); + value_sz = sizeof(OCIAnyData*); + for(unsigned i = 0; i < _cnt; ++i) + { + ((ub2*)rlenp)[i] = (ub2) value_sz; + } + + init(); +} + +BindParANYDATA::BindParANYDATA(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl) : BindPar(pos, stmt, decl) + , _oan_buffer(NULL) + , _any_indp(NULL) +{ + dty = SQLT_NTY; + _type_name = "SYS.ANYDATA"; + value_sz = sizeof(OCIAnyData*); + for(unsigned i = 0; i < _cnt; ++i) + { + ((ub4*)rlenp)[i] = (ub4) value_sz; + } + + init(); +} + void BindParANYDATA::init() -{ +{ sword res; _anydatatdo = 0; _oan_buffer = (OCIAnyData**) calloc(_cnt, sizeof(OCIAnyData*)); res = OCICALL(OCITypeByName(_stmt._env, _stmt._errh, _stmt._conn._svc_ctx, - (const oratext*)"SYS", strlen("SYS"), - (const oratext*)"ANYDATA", strlen("ANYDATA"), - 0, 0, - OCI_DURATION_SESSION, OCI_TYPEGET_ALL, - (OCIType**) &_anydatatdo)); + (const oratext*)"SYS", (ub4)strlen("SYS"), + (const oratext*)"ANYDATA", (ub4)strlen("ANYDATA"), + 0, 0, + OCI_DURATION_SESSION, OCI_TYPEGET_ALL, + (OCIType**) &_anydatatdo)); oci_check_error(__TROTL_HERE__, _stmt._errh, res); if(_anydatatdo == NULL) - throw OciException(__TROTL_HERE__, "Unknown datatype in the database: SYS.ANYDATA"); + throw_oci_exception(OciException(__TROTL_HERE__, "Unknown datatype in the database: SYS.ANYDATA")); for(int i=0; i<g_OCIPL_BULK_ROWS; i++) { @@ -67,19 +101,19 @@ void BindParANYDATA::define_hook() { sword res = OCICALL(OCIDefineObject(defnpp, _stmt._errh, - _anydatatdo, - (dvoid **) &(_oan_buffer[0]), //(dvoid **) &_oan_buffer, - (ub4 *) 0, - 0, //(dvoid **) &_any_indp, - (ub4 *) 0)); - oci_check_error(__TROTL_HERE__, _stmt._errh, res); + _anydatatdo, + (dvoid **) &(_oan_buffer[0]), //(dvoid **) &_oan_buffer, + (ub4 *) 0, + 0, //(dvoid **) &_any_indp, + (ub4 *) 0)); + oci_check_error(__TROTL_HERE__, _stmt._errh, res); // // TODO OCIDefineArrayOfStruct here ?? } void BindParANYDATA::bind_hook() { //TODO - throw OciException(__TROTL_HERE__, "Not implemented yet"); + throw_oci_exception(OciException(__TROTL_HERE__, "Not implemented yet")); } // TODO @@ -87,16 +121,16 @@ { OCITypeCode tc; OCIType *type = (OCIType *)NULL; - boolean isNull; + bOOlean isNull; OCIInd ind; - + sword res1 = OCICALL(OCIAnyDataIsNull(_stmt._conn._svc_ctx, _stmt._errh, _oan_buffer[row], &isNull)); oci_check_error(__TROTL_HERE__, _stmt._errh, res1); if(isNull) return ""; - + sword res = OCICALL(OCIAnyDataGetType(_stmt._conn._svc_ctx, - _stmt._errh, _oan_buffer[row], - (OCITypeCode *)&tc, (OCIType **)&type)); + _stmt._errh, _oan_buffer[row], + (OCITypeCode *)&tc, (OCIType **)&type)); oci_check_error(__TROTL_HERE__, _stmt._errh, res); switch (tc) @@ -108,76 +142,76 @@ ub4 len; text str_buf[64]; ub4 str_len = sizeof(str_buf) / sizeof(*str_buf); - - sword res1 = OCICALL(OCIAnyDataAccess(_stmt._conn._svc_ctx, _stmt._errh, - _oan_buffer[row], - (OCITypeCode)OCI_TYPECODE_NUMBER, - (OCIType *)0, - (dvoid *)&ind, - (dvoid **)&num_ptr, &len)); + + sword res1 = OCICALL(OCIAnyDataAccess(_stmt._conn._svc_ctx, _stmt._errh, + _oan_buffer[row], + (OCITypeCode)OCI_TYPECODE_NUMBER, + (OCIType *)0, + (dvoid *)&ind, + (dvoid **)&num_ptr, &len)); oci_check_error(__TROTL_HERE__, _stmt._errh, res1); sword res2 = OCICALL(OCINumberToText(_stmt._errh, - (OCINumber*) &num, - (const oratext*) g_TROTL_DEFAULT_NUM_FTM, - strlen(g_TROTL_DEFAULT_NUM_FTM), - 0, // CONST OraText *nls_params, - 0, // ub4 nls_p_length, - (ub4*)&str_len, - str_buf - )); + (OCINumber*) &num, + (const oratext*) g_TROTL_DEFAULT_NUM_FTM, + (ub4)strlen(g_TROTL_DEFAULT_NUM_FTM), + 0, // CONST OraText *nls_params, + 0, // ub4 nls_p_length, + (ub4*)&str_len, + str_buf + )); oci_check_error(__TROTL_HERE__, _env._errh, res2); return tstring((const char*)str_buf, str_len); } - case OCI_TYPECODE_VARCHAR2: + case OCI_TYPECODE_VARCHAR2: { OCIInd _indp; // TODO check indp here OCIString *str = (OCIString *) 0; ub4 len; - sword res1 = OCICALL(OCIAnyDataAccess(_stmt._conn._svc_ctx, _stmt._errh, - _oan_buffer[row], (OCITypeCode)OCI_TYPECODE_VARCHAR2, - (OCIType *)0, (dvoid *)&_indp, (dvoid *)&str, &len)); + sword res1 = OCICALL(OCIAnyDataAccess(_stmt._conn._svc_ctx, _stmt._errh, + _oan_buffer[row], (OCITypeCode)OCI_TYPECODE_VARCHAR2, + (OCIType *)0, (dvoid *)&_indp, (dvoid *)&str, &len)); oci_check_error(__TROTL_HERE__, _stmt._errh, res1); return tstring( (const char *)OCIStringPtr(_stmt._env, str), OCIStringSize(_stmt._env, str)); } - case OCI_TYPECODE_DATE: + case OCI_TYPECODE_DATE: { // /*checkerr(ctxptr->errhp, OCIAnyDataAccess(ctxptr->svchp, // ctxptr->errhp, oan_buffer, -// (OCITypeCode)OCI_TYPECODE_DATE, +// (OCITypeCode)OCI_TYPECODE_DATE, // (OCIType *)0, (dvoid *)&indp, (dvoid *)&date, &len)); // OCIDateGetDate( (CONST OCIDate *) &date, &year1, &month1, &day1 ); */ OCIInd _indp; // TODO check indp here - OCIDate *date_ptr = 0; + OCIDate *date_ptr = 0; text str_buf[200]; ub4 str_len = sizeof(str_buf) / sizeof( *str_buf); ub4 len; - sword res1= OCICALL(OCIAnyDataAccess(_stmt._conn._svc_ctx, _stmt._errh, - _oan_buffer[row], (OCITypeCode)OCI_TYPECODE_DATE, - (OCIType *)0, (dvoid *)&_indp, - (dvoid **)&date_ptr, &len)); + sword res1= OCICALL(OCIAnyDataAccess(_stmt._conn._svc_ctx, _stmt._errh, + _oan_buffer[row], (OCITypeCode)OCI_TYPECODE_DATE, + (OCIType *)0, (dvoid *)&_indp, + (dvoid **)&date_ptr, &len)); oci_check_error(__TROTL_HERE__, _stmt._errh, res1); // OCIDateGetDate( (CONST OCIDate *) date_ptr, &year1, &month1, &day1 ); - + //const char fmt[] = "YYYY:MM:DD HH24:MI:SS"; - const char lang_fmt[] = "American"; - - res1 = OCICALL(OCIDateToText(_stmt._errh, - date_ptr, - (CONST text*) g_TROTL_DEFAULT_DATE_FTM, - strlen(g_TROTL_DEFAULT_DATE_FTM), - (CONST text*) lang_fmt, - (ub4) sizeof(lang_fmt)-1, - (ub4 *)&str_len, - str_buf - )); + const char lang_fmt[] = "American"; + + res1 = OCICALL(OCIDateToText(_stmt._errh, + date_ptr, + (CONST text*) g_TROTL_DEFAULT_DATE_FTM, + (ub4)strlen(g_TROTL_DEFAULT_DATE_FTM), + (CONST text*) lang_fmt, + (ub4) sizeof(lang_fmt)-1, + (ub4 *)&str_len, + str_buf + )); oci_check_error(__TROTL_HERE__, _stmt._errh, res1); - str_buf[ min( (str_len+1) , (unsigned)sizeof(str_buf) ) ] = '\0'; + str_buf[ min( (str_len+1) , (unsigned)sizeof(str_buf) ) ] = '\0'; return (const char*)str_buf; // printf("c2 is %d/%d/%d\n", day1, month1, year1); @@ -185,35 +219,35 @@ // case OCI_TYPECODE_OBJECT: // checkerr(ctxptr->errhp, OCIAnyDataAccess(ctxptr->svchp, ctxptr->errhp, // oan_buffer, (OCITypeCode) OCI_TYPECODE_OBJECT, -// (OCIType *)addr_tdo, (dvoid *) &ind2p, +// (OCIType *)addr_tdo, (dvoid *) &ind2p, // (dvoid **)&addr_obj, &len)); // printf("state is %s \n", // OCIStringPtr(ctxptr->envhp, addr_obj->state)); // printf("zip is %s \n", // OCIStringPtr(ctxptr->envhp, addr_obj->zip)); // break; - + // case OCI_TYPECODE_CHAR: -// checkerr(ctxptr->errhp, OCIAnyDataAccess(ctxptr->svchp, -// ctxptr->errhp, oan_buffer, -// (OCITypeCode)OCI_TYPECODE_CHAR, +// checkerr(ctxptr->errhp, OCIAnyDataAccess(ctxptr->svchp, +// ctxptr->errhp, oan_buffer, +// (OCITypeCode)OCI_TYPECODE_CHAR, // (OCIType *)0, (dvoid *)&indp, (dvoid *)&str, &len)); - + // printf("c2 is %s \n", OCIStringPtr(ctxptr->envhp, str)); // break; - + // case OCI_TYPECODE_RAW: -// checkerr(ctxptr->errhp, OCIAnyDataAccess(ctxptr->svchp, ctxptr->errhp, -// oan_buffer, (OCITypeCode)OCI_TYPECODE_RAW, +// checkerr(ctxptr->errhp, OCIAnyDataAccess(ctxptr->svchp, ctxptr->errhp, +// oan_buffer, (OCITypeCode)OCI_TYPECODE_RAW, // (OCIType *)0, (dvoid *)&indp, (dvoid *)&raw_col, &len)); - + // raw_ptr = OCIRawPtr(ctxptr->envhp, raw_col); // printf("RAW data is: "); // for(i=0;i<BUFLEN;i++) // printf("%c", (int) *(raw_ptr+i) & 0xFF); // printf("\n"); // break; - + // case OCI_TYPECODE_NAMEDCOLLECTION: // checkerr(ctxptr->errhp, OCITypeByName(ctxptr->envhp, // ctxptr->errhp, ctxptr->svchp, @@ -222,56 +256,56 @@ // (ub4) strlen((const char *) "ADDR_TAB"), // (CONST text *) 0, (ub4) 0, OCI_DURATION_SESSION, // OCI_TYPEGET_ALL, &addr_tab_tdo)); - -// checkerr(ctxptr->errhp, OCIAnyDataAccess(ctxptr->svchp, -// ctxptr->errhp, oan_buffer, -// (OCITypeCode)OCI_TYPECODE_NAMEDCOLLECTION, -// (OCIType *) addr_tab_tdo, (dvoid *) &ind2p, + +// checkerr(ctxptr->errhp, OCIAnyDataAccess(ctxptr->svchp, +// ctxptr->errhp, oan_buffer, +// (OCITypeCode)OCI_TYPECODE_NAMEDCOLLECTION, +// (OCIType *) addr_tab_tdo, (dvoid *) &ind2p, // (dvoid *)&addr_tab, &len)); - + // /* check how many elements in the typed table */ // checkerr(ctxptr->errhp, OCICollSize(ctxptr->envhp, ctxptr->errhp, // (CONST OCIColl *) addr_tab, &collsiz)); // printf("c2 is a typed table with %d elements:\n", collsiz); // if (collsiz == 0) // break; - + // /*Dump the table from the top to the bottom. */ // /* go to the first element and print out the index */ -// checkerr(ctxptr->errhp, OCITableFirst(ctxptr->envhp, +// checkerr(ctxptr->errhp, OCITableFirst(ctxptr->envhp, // ctxptr->errhp, addr_tab, &index)); -// checkerr(ctxptr->errhp, OCICollGetElem(ctxptr->envhp, +// checkerr(ctxptr->errhp, OCICollGetElem(ctxptr->envhp, // ctxptr->errhp, // (CONST OCIColl *) addr_tab, index, // &exist, &elem, &elemind)); // addr = (address *)elem; - + // printf("\tAddress 1 is: %s", // OCIStringPtr(ctxptr->envhp,addr->state)); // printf("\t%s\n", OCIStringPtr(ctxptr->envhp, addr->zip)); - -// for(;!OCITableNext(ctxptr->envhp, ctxptr->errhp, index, + +// for(;!OCITableNext(ctxptr->envhp, ctxptr->errhp, index, // addr_tab, &index, &exist) && exist;) // { -// checkerr(ctxptr->errhp, OCICollGetElem(ctxptr->envhp, +// checkerr(ctxptr->errhp, OCICollGetElem(ctxptr->envhp, // ctxptr->errhp, // (CONST OCIColl *) addr_tab,index, // &exist, &elem, &elemind)); // addr = (address *)elem; -// printf("\tAddress %d is: %s", index+1, +// printf("\tAddress %d is: %s", index+1, // OCIStringPtr(ctxptr->envhp,addr->state)); // printf("\t%s\n", OCIStringPtr(ctxptr->envhp, addr->zip)); -// } +// } // break; - - default: - printf("TYPED DATA CAN'T BE DISPLAYED IN THIS PROGRAM(%d)\n", tc); - break; - } + default: + printf("TYPED DATA CAN'T BE DISPLAYED IN THIS PROGRAM(%d)\n", tc); + break; + } + return _stringrepres.str(); }; - + tstring SqlANYDATA::str() const { return _stringrepres.str(); Modified: branches/tora-trotl/src/trotl/src/trotl_anydata.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_anydata.h 2011-07-23 19:41:31 UTC (rev 4007) +++ branches/tora-trotl/src/trotl/src/trotl_anydata.h 2011-08-05 20:17:05 UTC (rev 4008) @@ -1,5 +1,5 @@ // Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...> -// +// // forked from OCIPL Version 1.3 // by Ivan Brezina <iv...@cv...> @@ -34,58 +34,26 @@ #ifndef TROTL_ANYDATA_H_ #define TROTL_ANYDATA_H_ -#ifdef WIN32 -#include <stdio.h> -#include <wtypes.h> -#define snprintf _snprintf -//#define gmtime gmtime_s -//#define localtime localtime_s -#endif - +#include "trotl_common.h" #include "trotl_export.h" -#include "trotl_base.h" -#include "trotl_stat.h" +#include "trotl_handle.h" +#include "trotl_conn.h" +#include "trotl_var.h" -namespace trotl { +namespace trotl +{ -struct TROTL_EXPORT BindParANYDATA: public SqlStatement::BindPar +struct TROTL_EXPORT BindParANYDATA: public BindPar { friend struct ConvertorForRead; friend struct ConvertorForWrite; // TODO remember OCIConn or at least svcctx in this class - BindParANYDATA(unsigned int pos, SqlStatement &stmt, ColumnType &ct) : SqlStatement::BindPar(pos, stmt, ct) - , _oan_buffer(NULL) - , _any_indp(NULL) - { - dty = SQLT_NTY; - type_name = ct.get_type_str(); - value_sz = sizeof(OCIAnyData*); - for(unsigned i = 0; i < _cnt; ++i) - { - ((ub2*)rlenp)[i] = (ub2) value_sz; - } + BindParANYDATA(unsigned int pos, SqlStatement &stmt, DescribeColumn* ct); + BindParANYDATA(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl); - init(); - } - - BindParANYDATA(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl) : SqlStatement::BindPar(pos, stmt, decl) - , _oan_buffer(NULL) - , _any_indp(NULL) + virtual ~BindParANYDATA() { - dty = SQLT_NTY; - type_name = "SYS.ANYDATA"; - value_sz = sizeof(OCIAnyData*); - for(unsigned i = 0; i < _cnt; ++i) - { - ((ub4*)rlenp)[i] = (ub4) value_sz; - } - - init(); - } - - ~BindParANYDATA() - { // TODO free _any_indp, _oan_buffer } @@ -98,7 +66,7 @@ //private: - std::stringstream _stringrepres; + tostream _stringrepres; OCIType *_anydatatdo; OCIAnyData **_oan_buffer; @@ -113,24 +81,23 @@ SqlANYDATA(OciConnection &conn): _conn(conn) // NULL constructor {} - + SqlANYDATA(const SqlValue &value, OciConnection &conn): _conn(conn) { //_ind.set(); - throw OciException(__TROTL_HERE__, "Not implemented yet"); + throw_oci_exception(OciException(__TROTL_HERE__, "Not implemented yet")); } tstring str() const; - operator tstring() const { return str(); }; + operator tstring() const + { + return str(); + }; -// void set(wrapped_int val) { _value = val; }; - - // int* get_ref() {return &_value;} - //protected: - std::stringstream _stringrepres; + tostream _stringrepres; OCIType *anydatatdo; OciConnection& _conn; Modified: branches/tora-trotl/src/trotl/src/trotl_aq.cpp =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_aq.cpp 2011-07-23 19:41:31 UTC (rev 4007) +++ branches/tora-trotl/src/trotl/src/trotl_aq.cpp 2011-08-05 20:17:05 UTC (rev 4008) @@ -30,16 +30,12 @@ */ -#ifdef WIN32 -#include "trotl_parser.h" -#include <stdio.h> -#define snprintf _snprintf -#endif - +#include "trotl_common.h" +#include "trotl_export.h" #include "trotl_aq.h" -#include "trotl_convertor.h" -namespace trotl { +namespace trotl +{ }; Modified: branches/tora-trotl/src/trotl/src/trotl_aq.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_aq.h 2011-07-23 19:41:31 UTC (rev 4007) +++ branches/tora-trotl/src/trotl/src/trotl_aq.h 2011-08-05 20:17:05 UTC (rev 4008) @@ -34,15 +34,13 @@ #ifndef TROTL_AQ_H_ #define TROTL_AQ_H_ +#include "trotl_common.h" #include "trotl_export.h" -#include "trotl_var.h" -#include "trotl_conn.h" -#include "trotl_parser.h" +#include "trotl_handle.h" -#include "trotl_int.h" +namespace trotl +{ -namespace trotl { - struct TROTL_EXPORT AQStatement : public OciHandle<OCIStmt> { }; Modified: branches/tora-trotl/src/trotl/src/trotl_collection.cpp =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_collection.cpp 2011-07-23 19:41:31 UTC (rev 4007) +++ branches/tora-trotl/src/trotl/src/trotl_collection.cpp 2011-08-05 20:17:05 UTC (rev 4008) @@ -1,5 +1,5 @@ // Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...> -// +// // forked from OCIPL Version 1.3 // by Ivan Brezina <iv...@cv...> @@ -31,11 +31,15 @@ */ - +#include "trotl_export.h" +#include "trotl_common.h" #include "trotl_collection.h" -#include <string.h> -namespace trotl { +#include "trotl_describe.h" +#include "trotl_stat.h" +namespace trotl +{ + //Util::RegisterInFactory<BindParCollectionTabNum, BindParFactTwoParmSing> regBindCollection("???Collection???"); TODO //Util::RegisterInFactory<BindParCollectionTabNum, DefineParFactTwoParmSing, int> regDefineCollection((OCI_TYPECODE_VARRAY << 8) + 2); Util::RegisterInFactory<BindParCollectionTabNum, CustDefineParFactTwoParmSing> regCustDefineNTY_NUM_TAB("TABLE OF NUMBER"); @@ -43,33 +47,65 @@ Util::RegisterInFactory<BindParCollectionTabVarchar, CustDefineParFactTwoParmSing> regCustDefineNTY_VARCHAR_TAB("TABLE OF VARCHAR2"); Util::RegisterInFactory<BindParCollectionTabVarchar, CustDefineParFactTwoParmSing> regCustDefineNTY_CHAR_TAB("TABLE OF CHAR"); +BindParCollectionTabNum::BindParCollectionTabNum(unsigned int pos, SqlStatement &stmt, DescribeColumn* ct) + : BindPar(pos, stmt, ct) + , _collection_indp(NULL) + , _collection_typecode(ct->_collection_typecode) + , _collection_data_type(ct->_collection_data_type) +{ + valuep = (void**) calloc(_cnt, sizeof(void*)); + value_sz = sizeof(OCIColl*); + _collection_indp = (void**)calloc(_cnt, sizeof(void*)); + + dty = SQLT_NTY; // named collection type (varray or nested table) + _type_name = ct->typeName(); + + sword res = OCICALL(OCITypeByRef(stmt._env, stmt._errh, ct->_ref_tdo, OCI_DURATION_SESSION, OCI_TYPEGET_HEADER, &_collection_tdo)); + oci_check_error(__TROTL_HERE__, stmt._errh, res); +} + +BindParCollectionTabNum::BindParCollectionTabNum(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl) + : BindPar(pos, stmt, decl) + , _collection_indp(NULL) + // , _collection_typecode(???) TODO +{ + valuep = (void**) calloc(_cnt, sizeof(void*)); + value_sz = sizeof(OCIColl*); + _collection_indp = (void**)calloc(_cnt, sizeof(void*)); + + dty = SQLT_NTY; + _type_name = "???"; // TODO + + // _collection_tdo = ct._tdo; TODO +}; + void BindParCollectionTabNum::define_hook() { //ub4 *size = 0; sword res; res = OCICALL(OCIDefineObject(defnpp, _stmt._errh, _collection_tdo, - valuep, - (ub4 *) NULL, - (void**) _collection_indp, //(dvoid **) NULL - (ub4 *) 0)); - oci_check_error(__TROTL_HERE__, _stmt._errh, res); + valuep, + (ub4 *) NULL, + (void**) _collection_indp, //(dvoid **) NULL + (ub4 *) 0)); + oci_check_error(__TROTL_HERE__, _stmt._errh, res); } void BindParCollectionTabNum::bind_hook() { //TODO - throw OciException(__TROTL_HERE__, "Not implemented yet"); + throw_oci_exception(OciException(__TROTL_HERE__, "Not implemented yet")); } // TODO tstring BindParCollectionTabNum::get_string(unsigned int row) const { - boolean eoc = false; + bOOlean eoc = false; sword res; OCIIter *itr; _stringrepres.str(""); - + if( *(sb2*)(_collection_indp[row]) == OCI_IND_NULL) { _stringrepres << "<NULL>"; @@ -78,19 +114,19 @@ res = OCICALL(OCIIterCreate (_env, _stmt._errh, (OCIColl*)valuep[row], &itr)); oci_check_error(__TROTL_HERE__, _stmt._errh, res); - - _stringrepres << type_name << "("; + _stringrepres << _type_name << "("; + bool comma=false; while(!eoc) { OCINumber *ocinum = NULL; void *elemind = NULL; res = OCICALL(OCIIterNext (_env, _stmt._errh, - itr, - (void**) &ocinum, - (void**) &elemind, //NULL, //void **elemind, - &eoc)); + itr, + (void**) &ocinum, + (void**) &elemind, //NULL, //void **elemind, + &eoc)); oci_check_error(__TROTL_HERE__, _stmt._errh, res); if(eoc) @@ -99,53 +135,88 @@ if(comma) _stringrepres << ", "; comma = true; - if(*(sb2*)(elemind) == OCI_IND_NULL) + if(*(sb2*)(elemind) == OCI_IND_NULL) { _stringrepres << "NULL"; - } else { + } + else + { text str_buf[64]; - ub4 str_len = sizeof(str_buf) / sizeof(*str_buf); + ub4 str_len = sizeof(str_buf) / sizeof(*str_buf); sword res = OCICALL(OCINumberToText(_stmt._errh, - (OCINumber*) ocinum, - (const oratext*) g_TROTL_DEFAULT_NUM_FTM, - strlen(g_TROTL_DEFAULT_NUM_FTM), - 0, // CONST OraText *nls_params, - 0, // ub4 nls_p_length, - (ub4*)&str_len, - str_buf - )); + (OCINumber*) ocinum, + (const oratext*) g_TROTL_DEFAULT_NUM_FTM, + (ub4)strlen(g_TROTL_DEFAULT_NUM_FTM), + 0, // CONST OraText *nls_params, + 0, // ub4 nls_p_length, + (ub4*)&str_len, + str_buf + )); oci_check_error(__TROTL_HERE__, _env._errh, res); _stringrepres << tstring((const char*)str_buf, str_len); - } + } } _stringrepres << ")"; - + res = sword(OCIIterDelete (_env, _stmt._errh, &itr)); oci_check_error(__TROTL_HERE__, _stmt._errh, res); - + return _stringrepres.str(); }; -void BindParCollectionTabVarchar::define_hook(SqlStatement &stmt) +BindParCollectionTabVarchar::BindParCollectionTabVarchar(unsigned int pos, SqlStatement &stmt, DescribeColumn* ct) + : BindPar(pos, stmt, ct) + , _collection_indp(NULL) + , _collection_typecode(ct->_collection_typecode) + , _collection_data_type(ct->_collection_data_type) { + valuep = (void**) calloc(_cnt, sizeof(void*)); + value_sz = sizeof(OCIColl*); + _collection_indp = (void**)calloc(_cnt, sizeof(void*)); + + dty = SQLT_NTY; // named collection type (varray or nested table) + _type_name = ct->typeName(); + + //_collection_tdo = ct->_ref_tdo; + sword res = OCICALL(OCITypeByRef(stmt._env, stmt._errh, ct->_ref_tdo, OCI_DURATION_SESSION, OCI_TYPEGET_HEADER, &_collection_tdo)); + oci_check_error(__TROTL_HERE__, stmt._errh, res); +} + +BindParCollectionTabVarchar::BindParCollectionTabVarchar(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl) + : BindPar(pos, stmt, decl) + , _collection_indp(NULL) + // , _collection_typecode(???) TODO +{ + valuep = (void**) calloc(_cnt, sizeof(void*)); + value_sz = sizeof(OCIColl*); + indp = (OCIInd*) calloc(_cnt, sizeof(void*)); + _collection_indp = (void**)calloc(_cnt, sizeof(void*)); + + dty = SQLT_NTY; + _type_name = "???"; // TODO + // _collection_tdo = ct._tdo; TODO +}; + +void BindParCollectionTabVarchar::define_hook() +{ sword res; - res = OCICALL(OCIDefineObject(defnpp, stmt._errh, _collection_tdo, - valuep, - (ub4 *) NULL, - (void**) _collection_indp, //(dvoid **) NULL - (ub4 *) 0)); - oci_check_error(__TROTL_HERE__, stmt._errh, res); + res = OCICALL(OCIDefineObject(defnpp, _stmt._errh, _collection_tdo, + valuep, + (ub4 *) NULL, + (void**) _collection_indp, //(dvoid **) NULL + (ub4 *) 0)); + oci_check_error(__TROTL_HERE__, _stmt._errh, res); } -void BindParCollectionTabVarchar::bind_hook(SqlStatement &stmt) +void BindParCollectionTabVarchar::bind_hook() { //TODO - throw OciException(__TROTL_HERE__, "Not implemented yet"); + throw_oci_exception(OciException(__TROTL_HERE__, "Not implemented yet")); } - + tstring BindParCollectionTabVarchar::get_string(unsigned int row) const { - boolean eoc = false; + bOOlean eoc = false; sword res; OCIIter *itr; @@ -159,7 +230,7 @@ oci_check_error(__TROTL_HERE__, _stmt._errh, res); _stringrepres.str(""); - _stringrepres << type_name << "("; + _stringrepres << _type_name << "("; bool comma=false; while(!eoc) @@ -167,10 +238,10 @@ void *ocistring = NULL; void *elemind = NULL; res = OCICALL(OCIIterNext (_env, _stmt._errh, - itr, - (void**) &ocistring, - (void**) &elemind, //NULL, //void **elemind, - &eoc)); + itr, + (void**) &ocistring, + (void**) &elemind, //NULL, //void **elemind, + &eoc)); oci_check_error(__TROTL_HERE__, _stmt._errh, res); if(eoc) @@ -178,41 +249,43 @@ if(comma) _stringrepres << ", "; - - if(*(sb2*)(elemind) == OCI_IND_NULL) + + if(*(sb2*)(elemind) == OCI_IND_NULL) { _stringrepres << "NULL"; - } else { + } + else + { _stringrepres << '\'' << OCIStringPtr(_env, *(OCIString **)ocistring) << '\''; } - + comma = true; } _stringrepres << ")"; - + res = sword(OCIIterDelete (_env, _stmt._errh, &itr)); oci_check_error(__TROTL_HERE__, _stmt._errh, res); - + return _stringrepres.str(); }; tstring SqlCollection::str() const { - boolean eoc = false; + bOOlean eoc = false; sword res; OCIIter *itr; _stringrepres.str(""); - + if( _ind == OCI_IND_NULL) { - _stringrepres << "<NULL>"; + _stringrepres << "<NULL>"; return _stringrepres.str(); } - + res = OCICALL(OCIIterCreate (_conn._env, _conn._env._errh, _valuep, &itr)); oci_check_error(__TROTL_HERE__, _conn._env._errh, res); - + _stringrepres << _data_type_name << "("; bool comma=false; @@ -221,10 +294,10 @@ void *field = NULL; void *elemind = NULL; res = OCICALL(OCIIterNext (_conn._env, _conn._env._errh, - itr, - (void**) &field, - (void**) &elemind, //NULL, //void **elemind, - &eoc)); + itr, + (void**) &field, + (void**) &elemind, //NULL, //void **elemind, + &eoc)); oci_check_error(__TROTL_HERE__, _conn._env._errh, res); if(eoc) @@ -233,25 +306,27 @@ if(comma) _stringrepres << ", "; comma = true; - if(*(sb2*)(elemind) == OCI_IND_NULL) + if(*(sb2*)(elemind) == OCI_IND_NULL) { _stringrepres << "NULL"; - } else { - switch(_collection_typecode) + } + else + { + switch(_collection_data_type) { case SQLT_NUM: { text str_buf[64]; - ub4 str_len = sizeof(str_buf) / sizeof(*str_buf); + ub4 str_len = sizeof(str_buf) / sizeof(*str_buf); sword res = OCICALL(OCINumberToText(_conn._env._errh, - (OCINumber*) field, - (const oratext*) g_TROTL_DEFAULT_NUM_FTM, - strlen(g_TROTL_DEFAULT_NUM_FTM), - 0, // CONST OraText *nls_params, - 0, // ub4 nls_p_length, - (ub4*)&str_len, - str_buf - )); + (OCINumber*) field, + (const oratext*) g_TROTL_DEFAULT_NUM_FTM, + (ub4)strlen(g_TROTL_DEFAULT_NUM_FTM), + 0, // CONST OraText *nls_params, + 0, // ub4 nls_p_length, + (ub4*)&str_len, + str_buf + )); oci_check_error(__TROTL_HERE__, _conn._env._errh, res); _stringrepres << tstring((const char*)str_buf, str_len); } @@ -263,23 +338,20 @@ } break; default: - throw OciException(__TROTL_HERE__, "Collection to string convertorsion - Not implemented yet"); + throw_oci_exception(OciException(__TROTL_HERE__, + "Collection to string convertorsion - Not implemented yet: %d") + .arg(_collection_data_type) + ); } - } + } } _stringrepres << ")"; - + res = sword(OCIIterDelete (_conn._env, _conn._env._errh, &itr)); oci_check_error(__TROTL_HERE__, _conn._env._errh, res); - + return _stringrepres.str(); }; - -// tstring SqlCollection::str() const -// { -// return _stringrepres.str(); -// }; - }; Modified: branches/tora-trotl/src/trotl/src/trotl_collection.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_collection.h 2011-07-23 19:41:31 UTC (rev 4007) +++ branches/tora-trotl/src/trotl/src/trotl_collection.h 2011-08-05 20:17:05 UTC (rev 4008) @@ -1,5 +1,5 @@ // Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...> -// +// // forked from OCIPL Version 1.3 // by Ivan Brezina <iv...@cv...> @@ -34,153 +34,105 @@ #ifndef TROTL_COLLECTION_H_ #define TROTL_COLLECTION_H_ -#ifdef WIN32 -#include <stdio.h> -#include <wtypes.h> -#define snprintf _snprintf -//#define gmtime gmtime_s -//#define localtime localtime_s -#endif - +#include "trotl_common.h" #include "trotl_export.h" -#include "trotl_base.h" -#include "trotl_stat.h" +#include "trotl_handle.h" +#include "trotl_conn.h" +#include "trotl_var.h" -namespace trotl { -struct TROTL_EXPORT BindParCollectionTabNum: public SqlStatement::BindPar +namespace trotl { + +struct TROTL_EXPORT BindParCollectionTabNum: public BindPar +{ friend struct ConvertorForRead; friend struct ConvertorForWrite; - BindParCollectionTabNum(unsigned int pos, SqlStatement &stmt, ColumnType &ct) - : SqlStatement::BindPar(pos, stmt, ct) - , _collection_indp(NULL) - , _collection_typecode(ct._collection_typecode) - { - valuep = (void**) calloc(_cnt, sizeof(void*)); - value_sz = sizeof(OCIColl*); - _collection_indp = (void**)calloc(_cnt, sizeof(void*)); - - dty = SQLT_NTY; // named collection type (varray or nested table) - type_name = ct.get_type_str(); - - _collection_tdo = ct._tdo; - } - - BindParCollectionTabNum(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl) - : SqlStatement::BindPar(pos, stmt, decl) - , _collection_indp(NULL) - // , _collection_typecode(???) TODO - { - valuep = (void**) calloc(_cnt, sizeof(void*)); - value_sz = sizeof(OCIColl*); - _collection_indp = (void**)calloc(_cnt, sizeof(void*)); - - dty = SQLT_NTY; - type_name = "???"; // TODO + BindParCollectionTabNum(unsigned int pos, SqlStatement &stmt, DescribeColumn* ct); + BindParCollectionTabNum(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl); - // _collection_tdo = ct._tdo; TODO - }; + virtual ~BindParCollectionTabNum() {}; - ~BindParCollectionTabNum() {}; - virtual tstring get_string(unsigned int row) const; virtual void define_hook(); virtual void bind_hook(); -//private: - mutable std::stringstream _stringrepres; + //private: + mutable tostream _stringrepres; void **_collection_indp; - OCITypeCode _collection_typecode; + OCITypeCode _collection_typecode; + OCITypeCode _collection_data_type; OCIType *_collection_tdo; }; -struct TROTL_EXPORT BindParCollectionTabVarchar: public SqlStatement::BindPar +struct TROTL_EXPORT BindParCollectionTabVarchar: public BindPar { friend struct ConvertorForRead; friend struct ConvertorForWrite; - BindParCollectionTabVarchar(unsigned int pos, SqlStatement &stmt, ColumnType &ct) - : SqlStatement::BindPar(pos, stmt, ct) - , _collection_indp(NULL) - , _collection_typecode(ct._collection_typecode) - { - valuep = (void**) calloc(_cnt, sizeof(void*)); - value_sz = sizeof(OCIColl*); - _collection_indp = (void**)calloc(_cnt, sizeof(void*)); - - dty = SQLT_NTY; // named collection type (varray or nested table) - type_name = ct.get_type_str(); - - _collection_tdo = ct._tdo; - } - - BindParCollectionTabVarchar(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl) - : SqlStatement::BindPar(pos, stmt, decl) - , _collection_indp(NULL) - // , _collection_typecode(???) TODO - { - valuep = (void**) calloc(_cnt, sizeof(void*)); - value_sz = sizeof(OCIColl*); - indp = (OCIInd*) calloc(_cnt, sizeof(void*)); - _collection_indp = (void**)calloc(_cnt, sizeof(void*)); - - dty = SQLT_NTY; - type_name = "???"; // TODO - // _collection_tdo = ct._tdo; TODO - }; + BindParCollectionTabVarchar(unsigned int pos, SqlStatement &stmt, DescribeColumn* ct); + BindParCollectionTabVarchar(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl); - ~BindParCollectionTabVarchar() {}; + virtual ~BindParCollectionTabVarchar() {}; virtual tstring get_string(unsigned int row) const; - virtual void define_hook(SqlStatement &stmt); - virtual void bind_hook(SqlStatement &stmt); + virtual void define_hook(); + virtual void bind_hook(); - -//private: - mutable std::stringstream _stringrepres; + //private: + mutable tostream _stringrepres; void **_collection_indp; - OCITypeCode _collection_typecode; + OCITypeCode _collection_typecode; + OCITypeCode _collection_data_type; OCIType *_collection_tdo; }; - + struct TROTL_EXPORT SqlCollection : public SqlValue { friend struct ConvertorForRead; friend struct ConvertorForWrite; SqlCollection(OciConnection &conn) - : _conn(conn) - , _collection_typecode(0) - , _collection_tdo(NULL) + : _conn(conn) + , _valuep(0) + , _collection_typecode(0) + , _collection_data_type(0) + , _collection_tdo(NULL) {} - + SqlCollection(const SqlValue &value, OciConnection &conn) - : _conn(conn) - , _collection_tdo(NULL) - { - throw OciException(__TROTL_HERE__, "Not implemented yet"); + : _conn(conn) + , _valuep(0) + , _collection_typecode(0) + , _collection_data_type(0) + , _collection_tdo(NULL) + { + throw_oci_exception(OciException(__TROTL_HERE__, "Not implemented yet")); } - ~SqlCollection() {}; - + virtual ~SqlCollection() {}; + tstring str() const; - operator tstring() const { return str(); }; + operator tstring() const + { + return str(); + }; -//protected: + //protected: OciConnection& _conn; - mutable std::stringstream _stringrepres; + mutable tostream _stringrepres; tstring _data_type_name; - + OCIColl *_valuep; OCITypeCode _collection_typecode; + OCITypeCode _collection_data_type; OCIType *_collection_tdo; OCIInd _ind; }; Modified: branches/tora-trotl/src/trotl/src/trotl_common.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_common.h 2011-07-23 19:41:31 UTC (rev 4007) +++ branches/tora-trotl/src/trotl/src/trotl_common.h 2011-08-05 20:17:05 UTC (rev 4008) @@ -34,79 +34,104 @@ #ifndef TROTL_COMMON_H_ #define TROTL_COMMON_H_ +#include "trotl_export.h" +/* First of all include windows.h on windows + boost::spirit (and others) do include windows.h which includes RpcNdr.h + RpcNdr.h (162):typedef unsigned char boolean; + while oratypes.h does: + #ifndef boolean + # define boolean int + #endif + Therefore windows.h MUST be included before oci.h + We never use datatype boolean in trotl. (see bOOlean) +*/ +#if defined(_MSC_VER) +#include <stdio.h> +#include <wtypes.h> +#include <windows.h> +#define snprintf _snprintf +#endif + +#include <oci.h> +#define bOOlean int + +#ifdef __GNUC__ +#include "Loki/TypeTraits.h" +#include <stdlib.h> // atoi +#endif + #include <iostream> #include <ostream> #include <sstream> -#include <string.h> +#include <string> +#include <string.h> // strrchr +#include <stdio.h> -#ifdef __GNUC__ -#include <execinfo.h> -#include "Loki/TypeTraits.h" +// "multiplatform" sleep - used in trotl_lob.cpp +#if defined(_MSC_VER) +#define MSLEEP(x) Sleep(x) +//#define gmtime gmtime_s +//#define localtime localtime_s +#define __NORETURN __declspec(noreturn) +#else +#include <unistd.h> +#define MSLEEP(x) usleep(1000 * x) +#define __NORETURN __attribute__ ((noreturn)) #endif +namespace trotl +{ +typedef TROTL_EXPORT std::string tstring; +typedef TROTL_EXPORT ::std::ostringstream tostream; +//typedef char tchar; + +//TODO //#include <fstream> //#define USE_BOOST_THREAD_MANAGER //#include "ts_log/critical_section.h" //#include "ts_log/ts_log.h" - -#include "trotl_export.h" -#include "trotl_common.h" - - -#define TROTL_BACKTRACE_DEPTH 10 - -extern "C" { -#include <stdlib.h> -} - -namespace trotl { - typedef TROTL_EXPORT ::std::string tstring; - typedef TROTL_EXPORT ::std::stringstream tostream; - //typedef char tchar; - -//TODO //thread_safe_log get_log(); - //#define OCICALL(x) x; do { std::cerr << __TROTL_HERE__ << #x << std::endl; } while(0) -//#define OCICALL(x) x; do { std::cerr << #x << std::endl; } while(0) +//#define OCICALL(x) x; do { std::cerr << #x << std::endl; } while(0) #define OCICALL(x) x #ifdef __GNUC__ - template <class T> - typename ::Loki::TypeTraits<T>::ParameterType min - ( - T &a, - T &b - ) - { - return (a < b) ? a : b; - }; - template <class T> - typename ::Loki::TypeTraits<T>::ParameterType min - ( - T a, - T b - ) - { - return (a < b) ? a : b; - }; +template <class T> +typename ::Loki::TypeTraits<T>::ParameterType min +( + T &a, + T &b +) +{ + return (a < b) ? a : b; +}; - template <class T> - typename ::Loki::TypeTraits<T>::ParameterType min - ( - typename ::Loki::TypeTraits<T>::ConstParameterType a, - typename ::Loki::TypeTraits<T>::ConstParameterType b - ) - { - return (a < b) ? a : b; - }; +template <class T> +typename ::Loki::TypeTraits<T>::ParameterType min +( + T a, + T b +) +{ + return (a < b) ? a : b; +}; + +template <class T> +typename ::Loki::TypeTraits<T>::ParameterType min +( + typename ::Loki::TypeTraits<T>::ConstParameterType a, + typename ::Loki::TypeTraits<T>::ConstParameterType b +) +{ + return (a < b) ? a : b; +}; #else - //template <class T> - //T min(T a, T b) - //{ - // return (a < b) ? a : b; - //}; +//template <class T> +//T min(T a, T b) +//{ +// return (a < b) ? a : b; +//}; #ifndef min #define min(a, b) ( (a < b) ? a : b ) #endif @@ -114,12 +139,17 @@ }; +// MSVC Debug build +#if defined(_DEBUG) && !defined(DEBUG) +#define DEBUG +#endif + #ifdef DEBUG #ifdef __GNUC__ - #define __TROTL_HERE__ std::string(((strrchr(__FILE__, '/') ?: __FILE__ - 1) + 1)) + ":"__TROTL_HERE1__(__LINE__) -// #define __HERE_SHORT__ std::string(((strrchr(__FILE__, '/') ?: __FILE__ - 1) + 1)) + ":"__HERE1__(__LINE__) +#define __TROTL_HERE__ tstring(((strrchr(__FILE__, '/') ?: __FILE__ - 1) + 1)) + ":"__TROTL_HERE1__(__LINE__) +// #define __HERE_SHORT__ tstring(((strrchr(__FILE__, '/') ?: __FILE__ - 1) + 1)) + ":"__HERE1__(__LINE__) // #define __TROTL_HERE__ ::trotl::str_backtrace() + __HERE3__(__LINE__, __FILE__) - #define __TROTL_HERE1__(x) STR(x)"\t" + __PRETTY_FUNCTION__ +#define __TROTL_HERE1__(x) STR(x)"\t" + __PRETTY_FUNCTION__ // #define __HERE2__(x,y) ::trotl::tstring("("y":" STR(x)"(") + __PRETTY_FUNCTION__ +")" // #define __HERE3__(x,y) ::trotl::tstring("\n(") + __PRETTY_FUNCTION__ + ") " y ":" STR(x) + "\n" #else @@ -127,9 +157,9 @@ // #define __HERE_SHORT__ __HERE3__(__LINE__, __FILE__) // #define __TROTL_HERE__ ::trotl::str_backtrace() + __HERE3__(__LINE__, __FILE__) // #define __HERE2__(x,y) ::trotl::tstring("("y":" STR(x)"(") + __FUNCTION__ +")" -// #define __HERE3__(x,y) std::string("\n(") + __FUNCTION__ + ") " y ":" STR(x) + "\n" - #define __TROTL_HERE__ std::string(__FILE__) + ":"__TROTL_HERE1__(__LINE__) - #define __TROTL_HERE1__(x) STR(x)"\t" + __FUNCSIG__ +// #define __HERE3__(x,y) tstring("\n(") + __FUNCTION__ + ") " y ":" STR(x) + "\n" +#define __TROTL_HERE__ tstring(__FILE__) + ":"__TROTL_HERE1__(__LINE__) +#define __TROTL_HERE1__(x) STR(x)"\t" + __FUNCSIG__ #endif //__GNUC__ #else //DEBUG #define __TROTL_HERE__ "" Modified: branches/tora-trotl/src/trotl/src/trotl_conn.cpp =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_conn.cpp 2011-07-23 19:41:31 UTC (rev 4007) +++ branches/tora-trotl/src/trotl/src/trotl_conn.cpp 2011-08-05 20:17:05 UTC (rev 4008) @@ -1,5 +1,5 @@ // Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...> -// +// // forked from OCIPL Version 1.3 // by Ivan Brezina <iv...@cv...> @@ -31,13 +31,16 @@ */ +#include "trotl_common.h" +#include "trotl_export.h" #include "trotl_conn.h" #if 0 #include <sql2oci.h> #endif -namespace trotl { +namespace trotl +{ // thread_safe_log get_log() // { @@ -46,97 +49,97 @@ // return thread_safe_log( log); // } -#if 0 - OciConnection* OciConnection::CreateFromESqlContext(void* context) - { - OCIEnv* envhp = NULL; - sword res = SQLEnvGet(context, &envhp); +#if 0 +OciConnection* OciConnection::CreateFromESqlContext(void* context) +{ + OCIEnv* envhp = NULL; + sword res = SQLEnvGet(context, &envhp); - if (res != OCI_SUCCESS) - return NULL; + if (res != OCI_SUCCESS) + return NULL; - OCISvcCtx* svchp = NULL; - res = SQLSvcCtxGet(context, NULL, 0, &svchp); - oci_check_error(__TROTL_HERE__, envhp, res); + OCISvcCtx* svchp = NULL; + res = SQLSvcCtxGet(context, NULL, 0, &svchp); + oci_check_error(__TROTL_HERE__, envhp, res); - return new OciConnection(envhp, svchp); - } + return new OciConnection(envhp, svchp); +} #endif - - /// cancel a pending OCI call in the worker thread - void OciConnection::cancel() - { - sword res = OCICALL(OCICALL(OCIBreak(_svc_ctx, _env._errh))); - oci_check_error(__TROTL_HERE__, _env._errh, res); - } +/// cancel a pending OCI call in the worker thread +void OciConnection::cancel() +{ + sword res = OCICALL(OCICALL(OCIBreak(_svc_ctx, _env._errh))); - /// reset() is to be called after handling the cancellation in the calling worker thread. - void OciConnection::reset() - { - sword res = OCICALL(OCIReset(_svc_ctx, _env._errh)); + oci_check_error(__TROTL_HERE__, _env._errh, res); +} - oci_check_error(__TROTL_HERE__, _env._errh, res); - } +/// reset() is to be called after handling the cancellation in the calling worker thread. +void OciConnection::reset() +{ + sword res = OCICALL(OCIReset(_svc_ctx, _env._errh)); - tstring OciConnection::getNLS_LANG() - { - OraText infoBuf[OCI_NLS_MAXBUFSZ]; - sword res; - tostream retval; + oci_check_error(__TROTL_HERE__, _env._errh, res); +} - res = OCICALL(OCINlsGetInfo(_env, /* environment handle */ - _env._errh, /* error handle */ - infoBuf, /* destination buffer */ - (size_t) OCI_NLS_MAXBUFSZ, /* buffer size */ - (ub2) OCI_NLS_LANGUAGE)); /* item */ - oci_check_error(__TROTL_HERE__, _env._errh, res); - - retval << (const char*) infoBuf; - - res = OCICALL(OCINlsGetInfo(_env, /* environment handle */ - _env._errh, /* error handle */ - infoBuf, /* destination buffer */ - (size_t) OCI_NLS_MAXBUFSZ, /* buffer size */ - (ub2) OCI_NLS_TERRITORY)); /* item */ - oci_check_error(__TROTL_HERE__, _env._errh, res); +tstring OciConnection::getNLS_LANG() +{ + OraText infoBuf[OCI_NLS_MAXBUFSZ]; + sword res; + tostream retval; - retval << '_' << (const char *)infoBuf; - - res = OCICALL(OCINlsGetInfo(_env, /* environment handle */ - _env._errh, /* error handle */ - infoBuf, /* destination buffer */ - (size_t) OCI_NLS_MAXBUFSZ, /* buffer size */ - (ub2) OCI_NLS_CHARACTER_SET)); /* item */ - oci_check_error(__TROTL_HERE__, _env._errh, res); - - retval << '.' << (const char *) infoBuf; - return retval.str(); - } + res = OCICALL(OCINlsGetInfo(_env, /* environment handle */ + _env._errh, /* error handle */ + infoBuf, /* destination buffer */ + (size_t) OCI_NLS_MAXBUFSZ, /* buffer size */ + (ub2) OCI_NLS_LANGUAGE)); /* item */ + oci_check_error(__TROTL_HERE__, _env._errh, res); - void OciConnection::changePassword(tstring userid, tstring password, tstring new_password) - { - sword res; - /* - res = OCICALL(OCIAttrSet (reinterpret_cast<dvoid* >(_svc_ctx), + retval << (const char*) infoBuf; + + res = OCICALL(OCINlsGetInfo(_env, /* environment handle */ + _env._errh, /* error handle */ + infoBuf, /* destination buffer */ + (size_t) OCI_NLS_MAXBUFSZ, /* buffer size */ + (ub2) OCI_NLS_TERRITORY)); /* item */ + oci_check_error(__TROTL_HERE__, _env._errh, res); + + retval << '_' << (const char *)infoBuf; + + res = OCICALL(OCINlsGetInfo(_env, /* environment handle */ + _env._errh, /* error handle */ + infoBuf, /* destination buffer */ + (size_t) OCI_NLS_MAXBUFSZ, /* buffer size */ + (ub2) OCI_NLS_CHARACTER_SET)); /* item */ + oci_check_error(__TROTL_HERE__, _env._errh, res); + + retval << '.' << (const char *) infoBuf; + return retval.str(); +} + +void OciConnection::changePassword(tstring userid, tstring password, tstring new_password) +{ + sword res; + /* + res = OCICALL(OCIAttrSet (reinterpret_cast<dvoid* >(_svc_ctx), static_cast<ub4 >(OCI_HTYPE_SVCCTX), reinterpret_cast<dvoid * >(_authp), 0, static_cast<ub4 >(OCI_ATTR_SESSION), _env._errh)); - oci_check_error(__TROTL_HERE__, _env._errh, res); - */ - res = OCICALL(OCIPasswordChange (_svc_ctx, - _env._errh, - (text*)(userid.c_str()), - (ub4)(userid.length()), - (text*)(password.c_str()), - (ub4)(password.length()), - (text*)(new_password.c_str()), - (ub4)(new_password.length()), - //OCI_AUTH); - OCI_DEFAULT)); - oci_check_error(__TROTL_HERE__, _env._errh, res); - } + oci_check_error(__TROTL_HERE__, _env._errh, res); + */ + res = OCICALL(OCIPasswordChange (_svc_ctx, + _env._errh, + (text*)(userid.c_str()), + (ub4)(userid.length()), + (text*)(password.c_str()), + (ub4)(password.length()), + (text*)(new_password.c_str()), + (ub4)(new_password.length()), + //OCI_AUTH); + OCI_DEFAULT)); + oci_check_error(__TROTL_HERE__, _env._errh, res); +} }; //namespace trotl Modified: branches/tora-trotl/src/trotl/src/trotl_conn.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_conn.h 2011-07-23 19:41:31 UTC (rev 4007) +++ branches/tora-trotl/src/trotl/src/trotl_conn.h 2011-08-05 20:17:05 UTC (rev 4008) @@ -34,8 +34,9 @@ #ifndef TROTL_CONN_H_ #define TROTL_CONN_H_ +#include "trotl_common.h" #include "trotl_export.h" -#include "trotl_base.h" +#include "trotl_handle.h" namespace trotl { @@ -47,7 +48,7 @@ typedef OciHandle<OCIServer> super; OracleServer(OciEnv& env) - : super(env) + : super(env) { _version_string[0] = '\0'; _version = 0; @@ -81,11 +82,26 @@ oci_check_error(__TROTL_HERE__, _env._errh, res); } - sword versionNumber() const { return ((sword)(((_version) >> 24) & 0x000000FF)); } - sword releaseNumber() const { return ((sword)(((_version) >> 20) & 0x0000000F)); } - sword updateNumber() const { return ((sword)(((_version) >> 12) & 0x000000FF)); } - sword portReleaseNumber() const { return ((sword)(((_version) >> 8) & 0x0000000F)); } - sword portUpdateNumber() const { return ((sword)(((_version) >> 0) & 0x000000FF)); } + sword versionNumber() const + { + return ((sword)(((_version) >> 24) & 0x000000FF)); + } + sword releaseNumber() const + { + return ((sword)(((_version) >> 20) & 0x0000000F)); + } + sword updateNumber() const + { + return ((sword)(((_version) >> 12) & 0x000000FF)); + } + sword portReleaseNumber() const + { + return ((sword)(((_version) >> 8) & 0x0000000F)); + } + sword portUpdateNumber() const + { + return ((sword)(((_version) >> 0) & 0x000000FF)); + } ub4 _version; // e.g. 0x9200500 char _version_string[2000]; @@ -103,17 +119,45 @@ LoginPara() : _mode(OCI_DEFAULT) {}; LoginPara(const char* username, const char* password, const char* tnsname) - : _username(username), _password(password), _tnsname(tnsname), _mode(OCI_DEFAULT) + : _username(username), _password(password), _tnsname(tnsname), _mode(OCI_DEFAULT) {} - void parse(const char* conn_str); + LoginPara(const char* connect_string) + : _mode(OCI_DEFAULT) + { + parse(connect_string); + } + + void parse(const char* conn_str) + { + const char*i = conn_str; + tstring *cw = &_username; // current word in a split + while(*i) + { + if( *i == '/' ) + { + cw = &_password; + i++; + continue; + } + + if( *i == '@' ) + { + cw = &_tnsname; + i++; + continue; + } + *cw += *i; + i++; + } + } }; struct TROTL_EXPORT LoginAndPChangePara : public LoginPara { tstring _new_password; LoginAndPChangePara(const char* username, const char* password, const char* new_password, const char* tnsname) - : LoginPara(username, password, tnsname), _new_password(new_password) + : LoginPara(username, password, tnsnam... [truncated message content] |
From: <ibr...@us...> - 2011-08-08 09:54:19
|
Revision: 4025 http://tora.svn.sourceforge.net/tora/?rev=4025&view=rev Author: ibre5041 Date: 2011-08-08 09:54:11 +0000 (Mon, 08 Aug 2011) Log Message: ----------- Added Paths: ----------- branches/tora-trotl/src/trotl/src/trotl_describe.cpp branches/tora-trotl/src/trotl/src/trotl_describe.h branches/tora-trotl/src/trotl/src/trotl_error.cpp branches/tora-trotl/src/trotl/src/trotl_error.h Added: branches/tora-trotl/src/trotl/src/trotl_describe.cpp =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_describe.cpp (rev 0) +++ branches/tora-trotl/src/trotl/src/trotl_describe.cpp 2011-08-08 09:54:11 UTC (rev 4025) @@ -0,0 +1,900 @@ +// +// forked from OCIPL Version 1.3 +// by Ivan Brezina <iv...@cv...> + +/* + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include "trotl_common.h" +#include "trotl_export.h" +#include "trotl_describe.h" +#include "trotl_common.h" +#include "trotl_error.h" + +#include <vector> + +namespace trotl +{ + +Describe* Describe::createDescription(OciConnection &con, const tstring &objectName) +{ + sword res; + bool isPublic = false; + OciDescribe desc(con._env); + + try + { + res = OCICALL(OCIDescribeAny(con._svc_ctx, con._env._errh, + (dvoid*)objectName.c_str(), // objptr (IN) (string containing the name of the object + (ub4)objectName.size(), // objnm_len (IN) + OCI_OTYPE_NAME, // objptr_typ (IN) points to the name of a schema object + (ub1)OCI_DEFAULT, // info_level (IN) for future extensions. Pass OCI_DEFAULT. + OCI_PTYPE_UNK, // OCI_PTYPE_TABLE, // + desc + )); + oci_check_error(__TROTL_HERE__, con._env._errh, res); + } + catch(OciException const &e) + { + if(e.get_code() == 4043) + { + sb4 val = -1; // ub2 val = 1; /* size of OCI_ATTR_DESC_PUBLIC is undocumented. */ + desc.set_attribute(OCI_ATTR_DESC_PUBLIC, &val); + isPublic = true; + + res = OCICALL(OCIDescribeAny(con._svc_ctx, con._env._errh, + (dvoid*)objectName.c_str(), // objptr (IN) (string containing the name of the object + (ub4)objectName.size(), // objnm_len (IN) + OCI_OTYPE_NAME, // objptr_typ (IN) points to the name of a schema object + (ub1)OCI_DEFAULT, // info_level (IN) for future extensions. Pass OCI_DEFAULT. + OCI_PTYPE_UNK, // OCI_PTYPE_TABLE, // + desc + )); + oci_check_error(__TROTL_HERE__, con._env._errh, res); + } + else + { + throw e; + } + }; + + OciParam param = desc.get_param(); + ub1 obj_type = param.get_attribute<ub1>(OCI_ATTR_PTYPE); + switch(obj_type) + { + case OCI_PTYPE_SYN: + return new DescribeSynonym(con, desc, objectName, isPublic); + case OCI_PTYPE_VIEW: + return new DescribeView(con, desc, objectName); + case OCI_PTYPE_TABLE: + return new DescribeTable(con, desc, objectName); + case OCI_PTYPE_TYPE: + return new DescribeType(con, desc, objectName); + case OCI_PTYPE_SEQ: + return new DescribeSequence(con, desc, objectName); + case OCI_PTYPE_PROC: + case OCI_PTYPE_FUNC: + case OCI_PTYPE_PKG: + case OCI_PTYPE_TYPE_ATTR: + case OCI_PTYPE_TYPE_COLL: + case OCI_PTYPE_TYPE_METHOD: + case OCI_PTYPE_COL: // - column of a table or view + case OCI_PTYPE_ARG: // - argument of a function or procedure + case OCI_PTYPE_TYPE_ARG: // - argument of a type method + case OCI_PTYPE_TYPE_RESULT: // - results of a method + case OCI_PTYPE_LIST: // - column list for tables and views, argument list for functions and procedures, or subprogram list for packages + case OCI_PTYPE_SCHEMA: // - schema + case OCI_PTYPE_DATABASE: // - database + case OCI_PTYPE_UNK: // - unknown schema object + throw_oci_exception(OciException(__TROTL_HERE__, "Error describing object: %d\n").arg(obj_type)); + default: + throw_oci_exception(OciException(__TROTL_HERE__, "Error describing object: %d\n").arg(obj_type)); + } +}; + +Describe::objectType TROTL_EXPORT Describe::getObjectType(OciConnection &con, const tstring &objectName) +{ + sword res; + OciDescribe desc(con._env); + + try + { + res = OCICALL(OCIDescribeAny(con._svc_ctx, con._env._errh, + (dvoid*)objectName.c_str(), // objptr (IN) (string containing the name of the object, pointer to a REF to the TDO, pointer to a TDO + (ub4)objectName.size(), // objnm_len (IN) + OCI_OTYPE_NAME, // objptr_typ (IN) points to the name of a schema object + (ub1)OCI_DEFAULT, // info_level (IN) for future extensions. Pass OCI_DEFAULT. + OCI_PTYPE_UNK, // OCI_PTYPE_TABLE, // + desc + )); + oci_check_error(__TROTL_HERE__, con._env._errh, res); + } + catch(OciException const &e) + { + if(e.get_code() == 4043) + { + sb4 val = -1; // ub2 val = 1; /* size of OCI_ATTR_DESC_PUBLIC is undocumented. */ + desc.set_attribute(OCI_ATTR_DESC_PUBLIC, &val); + + res = OCICALL(OCIDescribeAny(con._svc_ctx, con._env._errh, + (dvoid*)objectName.c_str(), // objptr (IN) (string containing the name of the object, pointer to a REF to the TDO, pointer to a TDO + (ub4)objectName.size(), // objnm_len (IN) + OCI_OTYPE_NAME, // objptr_typ (IN) points to the name of a schema object + (ub1)OCI_DEFAULT, // info_level (IN) for future extensions. Pass OCI_DEFAULT. + OCI_PTYPE_UNK, // OCI_PTYPE_TABLE, // + desc + )); + oci_check_error(__TROTL_HERE__, con._env._errh, res); + } + else + { + throw e; + } + } + + OciParam param = desc.get_param(); + ub1 obj_type = param.get_attribute<ub1>(OCI_ATTR_PTYPE); + switch(obj_type) + { + case OCI_PTYPE_SYN: + return O_SYNONYM; + case OCI_PTYPE_TABLE: + return O_TABLE; + case OCI_PTYPE_VIEW: + return O_VIEW; + case OCI_PTYPE_PROC: + return O_PROCEDURE; + case OCI_PTYPE_FUNC: + return O_FUNCTION; + case OCI_PTYPE_PKG: + return O_PACKAGE; + case OCI_PTYPE_TYPE: + return O_TYPE; + case OCI_PTYPE_SEQ: + return O_SEQUENCE; + case OCI_PTYPE_TYPE_ATTR: + case OCI_PTYPE_TYPE_COLL: + case OCI_PTYPE_TYPE_METHOD: + case OCI_PTYPE_COL: // - column of a table or view + case OCI_PTYPE_ARG: // - argument of a function or procedure + case OCI_PTYPE_TYPE_ARG: // - argument of a type method + case OCI_PTYPE_TYPE_RESULT: // - results of a method + case OCI_PTYPE_LIST: // - column list for tables and views, argument list for functions and procedures, or subprogram list for packages + case OCI_PTYPE_SCHEMA: // - schema + case OCI_PTYPE_DATABASE: // - database + case OCI_PTYPE_UNK: // - unknown schema object + throw_oci_exception(OciException(__TROTL_HERE__, "Error describing object: %d\n").arg(obj_type)); + default: + throw_oci_exception(OciException(__TROTL_HERE__, "Error describing object: %d\n").arg(obj_type)); + } +}; + + +Describe::Describe(OciConnection& con, OciDescribe &desc, const tstring &objectName) + : _con(con) + , _desc(desc) + , _objName(objectName) +{ + //_desc.alloc(conn._env); +} + +Describe::Describe(OciConnection& con, const tstring &objectName) + : _con(con) + , _desc(_con._env) // NOTE: this descriptor is un-initialized and should be never used + , _objName(objectName) +{ + //_desc.alloc(conn._env); +} + +DescribeSynonym::DescribeSynonym(OciConnection &con, OciDescribe &desc, const tstring &objectName, bool isPublic) + : Describe(con, desc, objectName) + , _public(isPublic) +{ + OciParam param = _desc.get_param(); + + // OCI_ATTR_OBJID Object ID ub4 + _objid = param.get_attribute<ub4>(OCI_ATTR_OBJID); + + // OCI_ATTR_SCHEMA_NAME A string containing the schema name of the synonym translation OraText * + _name = param.get_attribute<tstring>(OCI_ATTR_SCHEMA_NAME); + + // OCI_ATTR_NAME A NULL-terminated string containing the object name of the synonym translation OraText * + _schema = param.get_attribute<tstring>(OCI_ATTR_NAME); + + // OCI_ATTR_LINK A NULL-terminated string containing the database link name of the synonym translation OraText * + _link = param.get_attribute<tstring>(OCI_ATTR_LINK); +}; + +tstring DescribeSynonym::toString() const +{ + tostream retval; + if(_public) + retval << "PUBLIC SYNONYM: " << _objName << std::endl; + else + retval << "SYNONYM: " << objectName() << std::endl; + retval << "target schema: " << _schema << std::endl + << "target name: " << _name << std::endl + << "link: " << _link << std::endl; + return retval.str(); +}; + +tstring DescribeSynonym::_synonym("SYNONYM"); +tstring DescribeSynonym::_public_synonym("PUBLIC SYNONYM"); + + +DescribeView::DescribeView(OciConnection &con, OciDescribe &desc, const tstring &objectName) + : Describe(con, desc, objectName) +{ + OciParam param = _desc.get_param(); + + // OCI_ATTR_OBJID Object ID ub4 + _objid = param.get_attribute<ub4>(OCI_ATTR_OBJID); + + // OCI_ATTR_NUM_COLS Number of columns ub2 + _num_cols = param.get_attribute<ub2>(OCI_ATTR_NUM_COLS); + + // OCI_ATTR_LIST_COLUMNS Column list (type OCI_PTYPE_LIST) void * + //OciParam list_columns(param.get_param(OCI_ATTR_LIST_COLUMNS)); + _list_columns = param.get_param(OCI_ATTR_LIST_COLUMNS); + + // OCI_ATTR_REF_TDO REF to the type description object (TDO) of the base type for extent tables OCIRef* + //OCIRef* ref_tdo; + //param.get_attribute(&ref_tdo, OCI_ATTR_REF_TDO); + // throws: ORA-22804: remote operations not permitted on object tables or user-defined type columns + + // OCI_ATTR_IS_TEMPORARY Indicates that the table is temporary ub1 + //ub1 is_temporary; + //param.get_attribute(&is_temporary, OCI_ATTR_IS_TEMPORARY); + //throws: ORA-24328: illegal attribute value + + // OCI_ATTR_IS_TYPED Indicates that the table is typed ub1 + _is_typed = param.get_attribute<ub1>(OCI_ATTR_IS_TYPED); + + // OCI_ATTR_DURATION Duration of a temporary table. OCIDuration + // Values can be: + // OCI_DURATION_SESSION - session + // OCI_DURATION_TRANS - transaction + // OCI_DURATION_NULL - table not temporary + //OCIDuration duration; + //param.get_attribute(&duration, OCI_ATTR_DURATION); + //throws: ORA-24328: illegal attribute value + + for(ub4 i=1; i<=_num_cols; i++) + { + OciParam col_param = _list_columns.get_sub_param(i); + DescribeColumn *col = new DescribeColumn(_con, col_param, _objName); + _columns.push_back(col); + } +} + +tstring DescribeView::toString() const +{ + tostream retval; + retval << "objid: " << _objid << std::endl + << "num_cols: " << _num_cols << std::endl + << "is_typed: " << (unsigned)_is_typed << std::endl; + + for(std::vector<DescribeColumn*>::const_iterator i = _columns.begin(); i != _columns.end(); i++) + { + retval << (*i)->toString(); + } + + return retval.str(); +} + +tstring DescribeView::_view("VIEW"); + + +DescribeTable::DescribeTable(OciConnection &con, OciDescribe &desc, const tstring &objectName) + : Describe(con, desc, objectName) +{ + OciParam param = _desc.get_param(); + + // OCI_ATTR_OBJID Object ID ub4 + _objid = param.get_attribute<ub4>(OCI_ATTR_OBJID); + + // OCI_ATTR_NUM_COLS Number of columns ub2 + _num_cols = param.get_attribute<ub2>(OCI_ATTR_NUM_COLS); + + // OCI_ATTR_LIST_COLUMNS Column list (type OCI_PTYPE_LIST) void * + _list_columns = param.get_param(OCI_ATTR_LIST_COLUMNS); + + // OCI_ATTR_REF_TDO REF to the type description object (TDO) of the base type for extent tables OCIRef* + //OCIRef* ref_tdo; + //param.get_attribute(&ref_tdo, OCI_ATTR_REF_TDO); + // throws: ORA-22804: remote operations not permitted on object tables or user-defined type columns + + // OCI_ATTR_IS_TEMPORARY Indicates that the table is temporary ub1 + _is_temporary = param.get_attribute<ub1>(OCI_ATTR_IS_TEMPORARY); + + // OCI_ATTR_IS_TYPED Indicates that the table is typed ub1 + _is_typed = param.get_attribute<ub1>(OCI_ATTR_IS_TYPED); + + // OCI_ATTR_DURATION Duration of a temporary table. OCIDuration + // Values can be: + // OCI_DURATION_SESSION - session + // OCI_DURATION_TRANS - transaction + // OCI_DURATION_NULL - table not temporary + _duration = param.get_attribute<OCIDuration>(OCI_ATTR_DURATION); + + // OCI_ATTR_RDBA Data block address of the segment header ub4 + _rdba = param.get_attribute<ub4>(OCI_ATTR_RDBA); + + // OCI_ATTR_TABLESPACE Tablespace that the table resides in word + // word?? huh what is it? + _tablespace = param.get_attribute<uword>(OCI_ATTR_TABLESPACE); + + // OCI_ATTR_CLUSTERED Indicates that the table is clustered ub1 + _clustered = param.get_attribute<ub1>(OCI_ATTR_CLUSTERED); + + // OCI_ATTR_PARTITIONED Indicates that the table is partitioned ub1 + _partitioned = param.get_attribute<ub1>(OCI_ATTR_PARTITIONED); + + // OCI_ATTR_INDEX_ONLY Indicates that the table is index-only ub1 + _index_only = param.get_attribute<ub1>(OCI_ATTR_INDEX_ONLY); + + for(ub4 i=1; i<=_num_cols; i++) + { + OciParam col_param = _list_columns.get_sub_param(i); + DescribeColumn *col = new DescribeColumn(_con, col_param, _objName); + _columns.push_back(col); + } +} + +tstring DescribeTable::toString() const +{ + tostream retval; + retval << "objid: " << _objid << std::endl + << "num_cols: " << _num_cols << std::endl + << "is_temporary: " << (unsigned)_is_temporary << std::endl + << "is_typed: " << (unsigned)_is_typed << std::endl; + switch(_duration) + { + case OCI_DURATION_SESSION: + retval << "duration: " << "DURATION_SESSION" << std::endl; + break; + case OCI_DURATION_TRANS: + retval << "duration: " << "DURATION_TRANS" << std::endl; + break; + case OCI_DURATION_NULL: + retval << "duration: " << "DURATION_NULL" << std::endl; + break; + } + retval << "rdba: " << _rdba << std::endl + << "tablespace: " << _tablespace << std::endl + << "clustered: " << (unsigned)_clustered << std::endl + << "partitioned: " << (unsigned)_partitioned << std::endl + << "index_only: " << (unsigned)_index_only << std::endl + ; + + for(std::vector<DescribeColumn*>::const_iterator i = _columns.begin(); i != _columns.end(); i++) + { + retval << (*i)->toString(); + } + + return retval.str(); +} + +tstring DescribeTable::_table("TABLE"); + +DescribeColumn::DescribeColumn(OciConnection &con, OciParam ¶m, const tstring &tableName) + : Describe(con, "") + , _tableName("") + , _name("") + , _schema_name("") + , _type_name("") + , _data_type(0) + , _typecode(0) + , _collection_typecode(0) + , _collection_data_type(0) + , _precision(0) + , _scale(0) + , _charset_id(0) + , _charset_form(0) + , _char_used(0) + , _char_size(0) + , _data_size(0) + , _fprecision(0) + , _lfprecision(0) + , _is_null(0) + , _ref_tdo(NULL) + , _type(NULL) + , _utf16(false) + , _reg_name("") +{ + // OciParam param = _desc.get_param(); + + _name = param.get_attribute<tstring>(OCI_ATTR_NAME); + + _schema_name = param.get_attribute<tstring>(OCI_ATTR_SCHEMA_NAME); + + _type_name = param.get_attribute<tstring>(OCI_ATTR_TYPE_NAME); + + _data_type = param.get_attribute<ub2>(OCI_ATTR_DATA_TYPE); + + // OCI_ATTR_PRECISION The precision of numeric columns. If the precision is nonzero and scale is -127, + // then it is a FLOAT, else it is a NUMBER(precision, scale). + // For the case when precision is 0, NUMBER(precision, scale) can be represented simply as NUMBER. + // ub1 for explicit describe + // sb2 for implicit describe + _precision = param.get_attribute<ub1>(OCI_ATTR_PRECISION); + + // OCI_ATTR_SCALE The scale of numeric columns. If the precision is nonzero and scale is -127, + // then it is a FLOAT, else it is a NUMBER(precision, scale). + // For the case when precision is 0, NUMBER(precision, scale) can be represented simply as NUMBER. sb1 + _scale = param.get_attribute<sb1>(OCI_ATTR_SCALE); + + // OCI_ATTR_REF_TDO Returns the in-memory REF of the TDO for the type, if the column type is an object type. + // If space has not been reserved for the OCIRef, then it is allocated implicitly in the cache. The caller can then pin the TDO with OCIObjectPin(). + // OCIRef* + + // OCI_ATTR_CHARSET_ID The character set id, if the type attribute is of a string/character type ub2 + _charset_id = param.get_attribute<ub2>(OCI_ATTR_CHARSET_ID); + + // OCI_ATTR_CHARSET_FORM The character set form, if the type attribute is of a string/character type ub1 + _charset_form = param.get_attribute<ub1>(OCI_ATTR_CHARSET_FORM); + _utf16 = (_charset_form == SQLCS_NCHAR); + + // OCI_ATTR_CHAR_USED Returns the type of length semantics of the column. 0 means byte-length semantics and 1 means character-length semantics. + // See "Character Length Semantics Support in Describing". ub4 (well docs says ub4 but it is ub1 in reality) + _char_used = param.get_attribute<ub1>(OCI_ATTR_CHAR_USED); + + // OCI_ATTR_CHAR_SIZE Returns the column character length which is the number of characters allowed in the column. + // It is the counterpart of OCI_ATTR_DATA_SIZE which gets the byte length. See "Character Length Semantics Support in Describing". ub2 + _char_size = param.get_attribute<ub2>(OCI_ATTR_CHAR_SIZE); + + // NOTE: older OCI docs refer OCI_ATTR_DATA_SIZE as ub2. + // In 11gR2 it is ub4, but only ub2 works + // OCI_ATTR_DATA_SIZE The maximum size of the column. This length is returned in bytes and not characters for strings and raws. + // It returns 22 for NUMBERs. ub4 + // see metalink note 332084.1 + _data_size = param.get_attribute<ub2>(OCI_ATTR_DATA_SIZE); + + // OCI_ATTR_FSPRECISION The fractional seconds precision of a datetime or interval. ub1 + _fprecision = param.get_attribute<ub1>(OCI_ATTR_FSPRECISION); + + // OCI_ATTR_LFPRECISION The leading field precision of an interval. ub1 + _lfprecision = param.get_attribute<ub1>(OCI_ATTR_LFPRECISION); + + // get NULL-ability flag + // OCI_ATTR_IS_NULL Returns 0 if null values are not permitted for the column ub1 + _is_null = param.get_attribute<ub1>(OCI_ATTR_IS_NULL); + + if(_data_type == SQLT_NTY) + { + sword res; + // OCI_ATTR_REF_TDO Returns the REF of the TDO for the type, if the arguemnt type is an object OCIRef * + _ref_tdo = param.get_attribute<OCIRef*>(OCI_ATTR_REF_TDO); + + OciDescribe type_desc(con._env); + + res = OCIDescribeAny(con._svc_ctx, con._env._errh, + _ref_tdo, // objptr (IN) pointer to a REF to the TDO + sizeof(_ref_tdo), // objnm_len (IN) + OCI_OTYPE_REF, // objptr_typ (IN) points to the name of a schema object + (ub1)OCI_DEFAULT, // info_level (IN) for future extensions. Pass OCI_DEFAULT. + OCI_PTYPE_TYPE, + type_desc + ); + oci_check_error(__TROTL_HERE__, con._env._errh, res); + + _type = new DescribeType(con, type_desc, _name); + + _reg_name = _type->_reg_name; + + // throws ORA-24328: illegal attribute value on number + _typecode = _type->_typecode; + _collection_typecode = _type->_collection_typecode; + _collection_data_type = _type->_collection_data_type; + } +} + +tstring DescribeColumn::toString() const +{ + tostream retval; + retval << "name: " << _name << '\t' + << "schema_name: " << _schema_name << '\t' + << "type_name: " << _type_name << '\t' + << "data_type: " << _data_type << '\t' + << "scale: " << (int)_scale << '\t' + << "precision: " << (unsigned)_precision << '\t' + << "data_size: " << (unsigned)_data_size << '\t' + << "is_null: " << (unsigned)_is_null << '\t' + << "type: " << typeName() + << std::endl; + + // if(_type != NULL) + // retval << _type->toString(); + return retval.str(); +} + +tstring DescribeColumn::name() const +{ + return _name; +} + +tstring DescribeColumn::typeName() const +{ + tostream str; + + switch(_data_type) + { + case SQLT_AFC: // OCI_TYPECODE_CHAR: + str << (_utf16 ? "N" : "") + << "CHAR(" + << (_char_used ? (ub4)_char_size : (ub4)_data_size) + << ' ' + << (_char_used ? "CHAR" : "BYTES") + << ")"; + break; + case SQLT_CHR: // OCI_TYPECODE_VARCHAR: + // NOTE: uncomment this on older Oracle versions datatype VARCHAR is no more present on 11g + // str << (_utf16 ? "N" : "") << "VARCHAR(" << (_char_used ? (ub4)_char_size : (ub4)_data_size) << ")"; + // break; + case SQLT_VCS: // OCI_TYPECODE_VARCHAR2: + str << (_utf16 ? "N" : "") + << "VARCHAR2(" + << (_char_used ? (ub4)_char_size : (ub4)_data_size) + << ' ' + << (_char_used ? "CHAR" : "BYTES") + << ")"; + break; + case SQLT_BIN: + str << "RAW("<< _data_size << ")"; + break; + case SQLT_NUM: // OCI_TYPECODE_NUMBER: + // When precision is 0, NUMBER(precision, scale) can be represented simply as NUMBER. + // If the precision is nonzero and scale is -127, then it is a FLOAT; + // otherwise, it is a NUMBER(precision, scale). + if (_precision == 0) + str << "NUMBER"; + else if(_precision == 38 && _scale == 0) + str << "INTEGER"; + else if (_scale == -127) + { + if (_precision == 126) + str << "FLOAT"; + else if (_precision == 63) + str << "REAL"; + else + str << "FLOAT(" << (int)_precision << ")"; + } + else if (_precision == 38 && _scale) + str << "NUMBER(" << '*' << "," << (int)_scale << ")"; + else if (_precision != 38 && _scale) + str << "NUMBER(" << (int)_precision << "," << (int)_scale << ")"; + else + str << "NUMBER(" << (int)_precision << ")"; + + break; + case SQLT_DAT: // OCI_TYPECODE_DATE: + str << "DATE"; + break; + case SQLT_BLOB: // OCI_TYPECODE_BLOB: + str << "BLOB"; + break; + case SQLT_BFILE: // OCI_TYPECODE_BFILE: + str << "BFILE"; + break; + case SQLT_CLOB: // OCI_TYPECODE_CLOB: + str << (_utf16 ? "N" : "") << "CLOB"; + break; + case SQLT_CFILE: // OCI_TYPECODE_CFILE: + str << "CFILE"; + break; + case SQLT_LNG: + str << "LONG"; + break; + case SQLT_NTY: + if (!_schema_name.empty()) + str << _schema_name << '.'; + str << _type_name; + break; + case SQLT_LBI: + str << "LONG RAW"; /* !! TODO unsupported yet */ + break; + case SQLT_RDD: + case 208: // 208 = 2 * SQLT_RDD (mentioned only in catalog.sql) + // _width == 4 for ROWID datatype + // _width == 4000 for UROWID datatype + if(_data_size == sizeof(OCIRowid*)) + str << "ROWID"; + else + str << "UROWID"; + break; + case SQLT_IBFLOAT: + str << "BINARY_FLOAT"; + break; + case SQLT_IBDOUBLE: + str << "BINARY_DOUBLE"; + break; + case SQLT_TIMESTAMP: + str << "TIMESTAMP"; + if(_scale != 6) + str << '(' << (int)_scale << ')'; + break; + case SQLT_TIMESTAMP_TZ: + str << "TIMESTAMP"; + if(_scale != 6) + str << '(' << (int)_scale << ')'; + str << " WITH TIME ZONE"; + break; + case SQLT_TIMESTAMP_LTZ: + str << "TIMESTAMP"; + if(_scale != 6) + str << '(' << (int)_scale << ')'; + str << " WITH LOCAL TIME ZONE"; + break; + case SQLT_INTERVAL_YM: + str << "INTERVAL YEAR TO MONTH"; + break; + case SQLT_INTERVAL_DS: + str << "INTERVAL DAY TO SECOND"; + break; + case SQLT_LAB: + str << "MLSLABEL"; + break; + case SQLT_RSET: + str << "CURSOR"; + break; + default: + str << "unknown datatype:" << _data_type; + break; + } + + return str.str(); +} + +// OCIType* DescribeType::getOCIType() +// { +// OCIType *retval; +// res = OCICALL(OCITypeByRef(stat._env, stat._errh, _type_r, OCI_DURATION_SESSION, OCI_TYPEGET_HEADER, &tdo)); +// oci_check_error(__TROTL_HERE__, stat._errh, res); +// return retval; +// } + +bool DescribeColumn::nullable() const +{ + return !!_is_null; +} + +DescribeType* DescribeColumn::getDescribeType() +{ + return _type; +} + +DescribeColumn::~DescribeColumn() +{ + if(_type) + delete _type; + _type = 0; +} + +tstring DescribeColumn::_column("COLUMN"); + +DescribeType::DescribeType(OciConnection &con, OciDescribe &desc, const tstring &tableName) + : Describe(con, "") + , _collection_typecode(0) + , _reg_name("") +{ + OciParam param = desc.get_param(); + + //OCI_ATTR_REF_TDO Returns the in-memory REF of the type descriptor object (TDO) for the type, if the column type is an object type. + //If space has not been reserved for the OCIRef, then it is allocated implicitly in the cache. The caller can then pin the TDO with OCIObjectPin(). OCIRef * + //Throws ORA-22804: remote operations not permitted on object tables or user-defined type columns + //OCIRef *ref_tdo = param.get_attribute<OCIRef*>(OCI_ATTR_REF_TDO); + + //OCI_ATTR_TYPECODE Typecode. See "Data Type Codes". Currently can be only OCI_TYPECODE_OBJECT or OCI_TYPECODE_NAMEDCOLLECTION. OCITypeCode + _typecode = param.get_attribute<OCITypeCode>(OCI_ATTR_TYPECODE); + + //OCI_ATTR_IS_INCOMPLETE_TYPE Indicates that this is an incomplete type ub1 + _is_incomplete_type = param.get_attribute<ub1>(OCI_ATTR_IS_INCOMPLETE_TYPE); + + //OCI_ATTR_IS_SYSTEM_TYPE Indicates that this is a system type ub1 + _is_system_type = param.get_attribute<ub1>(OCI_ATTR_IS_SYSTEM_TYPE); + + //OCI_ATTR_IS_PREDEFINED_TYPE Indicates that this is a predefined type ub1 + _is_predefined_type = param.get_attribute<ub1>(OCI_ATTR_IS_PREDEFINED_TYPE); + + //OCI_ATTR_IS_TRANSIENT_TYPE Indicates that this is a transient type ub1 + _is_transient_type = param.get_attribute<ub1>(OCI_ATTR_IS_TRANSIENT_TYPE); + + //OCI_ATTR_IS_SYSTEM_GENERATED_TYPE Indicates that this is a system-generated type ub1 + _is_system_generated_type = param.get_attribute<ub1>(OCI_ATTR_IS_SYSTEM_GENERATED_TYPE); + + //OCI_ATTR_HAS_NESTED_TABLE This type contains a nested table attribute. ub1 + _has_nested_table = param.get_attribute<ub1>(OCI_ATTR_HAS_NESTED_TABLE); + + //OCI_ATTR_HAS_LOB This type contains a LOB attribute. ub1 + _has_lob = param.get_attribute<ub1>(OCI_ATTR_HAS_LOB); + + //OCI_ATTR_HAS_FILE This type contains a BFILE attribute. ub1 + _has_file = param.get_attribute<ub1>(OCI_ATTR_HAS_FILE); + + //OCI_ATTR_COLLECTION_ELEMENT Handle to collection element. See "Collection Attributes". void * + + //OCI_ATTR_NUM_TYPE_ATTRS Number of type attributes ub2 + _num_type_attrs = param.get_attribute<ub2>(OCI_ATTR_NUM_TYPE_ATTRS); + + //OCI_ATTR_LIST_TYPE_ATTRS List of type attributes. See "List Attributes". void * + + //OCI_ATTR_NUM_TYPE_METHODS Number of type methods ub2 + _num_type_methods = param.get_attribute<ub2>(OCI_ATTR_NUM_TYPE_METHODS); + + //OCI_ATTR_LIST_TYPE_METHODS List of type methods. See "List Attributes". void * + ////_list_type_methods = param.get_param(OCI_ATTR_LIST_TYPE_METHODS); + + //OCI_ATTR_MAP_METHOD Map method of type. See "Type Method Attributes". void * + + //OCI_ATTR_ORDER_METHOD Order method of type. See "Type Method Attributes". void * + + //OCI_ATTR_IS_INVOKER_RIGHTS Indicates that the type has invoker's rights ub1 + _is_invoker_rights = param.get_attribute<ub1>(OCI_ATTR_IS_INVOKER_RIGHTS); + + //OCI_ATTR_NAME A pointer to a string that is the type attribute name OraText * + _name = param.get_attribute<tstring>(OCI_ATTR_NAME); + + //OCI_ATTR_SCHEMA_NAME A string with the schema name where the type has been created OraText * + _schema_name = param.get_attribute<tstring>(OCI_ATTR_SCHEMA_NAME); + + //OCI_ATTR_IS_FINAL_TYPE Indicates that this is a final type ub1 + _is_final_type = param.get_attribute<ub1>(OCI_ATTR_IS_FINAL_TYPE); + + //OCI_ATTR_IS_INSTANTIABLE_TYPE Indicates that this is an instantiable type ub1 + _is_instantiable_type = param.get_attribute<ub1>(OCI_ATTR_IS_INSTANTIABLE_TYPE); + + //OCI_ATTR_IS_SUBTYPE Indicates that this is a subtype ub1 + _is_subtype = param.get_attribute<ub1>(OCI_ATTR_IS_SUBTYPE); + + //OCI_ATTR_SUPERTYPE_SCHEMA_NAME Name of the schema that contains the supertype OraText * + _supertype_schema_name = param.get_attribute<tstring>(OCI_ATTR_SUPERTYPE_SCHEMA_NAME); + + //OCI_ATTR_SUPERTYPE_NAME Name of the supertype OraText * + _supertype_name = param.get_attribute<tstring>(OCI_ATTR_SUPERTYPE_NAME); + + if (_typecode == OCI_TYPECODE_NAMEDCOLLECTION) + { + //OCI_ATTR_COLLECTION_TYPECODE Typecode of collection if type is collection; invalid otherwise. See "Data Type Codes". + //Currently can be only OCI_TYPECODE_VARRAY or OCI_TYPECODE_TABLE. + // If this attribute is queried for a type that is not a collection, an error is returned. + //OCITypeCode + _collection_typecode = param.get_attribute<OCITypeCode>(OCI_ATTR_COLLECTION_TYPECODE); + + OciParam collection_param = param.get_param(OCI_ATTR_COLLECTION_ELEMENT); + + /* get the data size */ + _collection_data_size = collection_param.get_attribute<ub2>(OCI_ATTR_DATA_SIZE); + + /* get the name of the collection */ + _collection_type_name = collection_param.get_attribute<tstring>(OCI_ATTR_TYPE_NAME); + + /* get the name of the schema */ + _collection_schema_name = collection_param.get_attribute<tstring>(OCI_ATTR_SCHEMA_NAME); + + /* get the data type */ + _collection_data_type = collection_param.get_attribute<ub2>(OCI_ATTR_DATA_TYPE); + + if (_collection_typecode == OCI_TYPECODE_VARRAY) + { + /* get the number of elements */ + _collection_num_elems = collection_param.get_attribute<ub4>(OCI_ATTR_NUM_ELEMS); + _reg_name = "VARARRAY OF " + _collection_type_name; + } + else // _collection_typecode == OCI_TYPECODE_TABLE + { + _reg_name = "TABLE OF " + _collection_type_name; + } + } + else + { + _reg_name = _schema_name + '.' + _name; + } + +// if(_typecode == SQLT_NTY) +// { +// // OCI_ATTR_REF_TDO Returns the REF of the TDO for the type, if the arguemnt type is an object OCIRef * +// OCIRef *_ref_tdo = param.get_attribute<OCIRef*>(OCI_ATTR_REF_TDO); +// } +}; + +tstring DescribeType::toString() const +{ + tostream retval; + retval + << "typecode: " << _typecode << std::endl + << "collection_typecode: " << _collection_typecode << std::endl + << "is_incomplete_type: " << (unsigned)_is_incomplete_type << std::endl + << "is_system_type: " << (unsigned)_is_system_type << std::endl + << "is_predefined_type: " << (unsigned)_is_predefined_type << std::endl + << "is_transient_type: " << (unsigned)_is_transient_type << std::endl + << "is_system_generated_type: " << (unsigned)_is_system_generated_type << std::endl + << "has_nested_table: " << (unsigned)_has_nested_table << std::endl + << "has_lob: " << (unsigned)_has_lob << std::endl + << "has_file: " << (unsigned)_has_file << std::endl + << "num_type_attrs: " << _num_type_attrs << std::endl + << "num_type_methods: " << _num_type_methods << std::endl + << "is_invoker_rights: " << (unsigned)_is_invoker_rights << std::endl + << "is_final_type: " << (unsigned)_is_final_type << std::endl + << "is_instantiable_type: " << (unsigned)_is_instantiable_type << std::endl + << "is_subtype: " << (unsigned)_is_subtype << std::endl; + // TODO handle collection here + return retval.str(); +}; + +tstring DescribeType::_type("TYPE"); + + +DescribeSequence::DescribeSequence(OciConnection &con, OciDescribe &desc, const tstring &tableName) + : Describe(con, "") + , _min(con._env) + , _max(con._env) + , _incr(con._env) + , _cache(con._env) + , _hw_marks(con._env) +{ + OciParam param = desc.get_param(); + + //OCI_ATTR_OBJID Object ID ub4 + _objid = param.get_attribute<ub4>(OCI_ATTR_OBJID); + + //OCI_ATTR_MIN Minimum value (in Oracle NUMBER format) ub1 * + _min = param.get_attribute<OCINumber>(OCI_ATTR_MIN); + + //OCI_ATTR_MAX Maximum value (in Oracle NUMBER format) ub1 * + _max = param.get_attribute<OCINumber>(OCI_ATTR_MAX); + + //OCI_ATTR_INCR Increment (in Oracle NUMBER format) ub1 * + _incr = param.get_attribute<OCINumber>(OCI_ATTR_INCR); + + //OCI_ATTR_CACHE Number of sequence numbers cached; zero if the sequence is not a cached sequence (in Oracle NUMBER format) ub1 * + _cache = param.get_attribute<OCINumber>(OCI_ATTR_CACHE); + + //OCI_ATTR_ORDER Whether the sequence is ordered ub1 + _order = param.get_attribute<ub1>(OCI_ATTR_ORDER); + + //OCI_ATTR_HW_MARK High-water mark (in NUMBER format) ub1 * + _hw_marks = param.get_attribute<OCINumber>(OCI_ATTR_HW_MARK); +} + +tstring DescribeSequence::toString() const +{ + tostream retval; + retval + << "Min: " << _min.toString() << std::endl + << "Max: " << _max.toString() << std::endl + << "Increment: " << _incr.toString() << std::endl + << "Cache: " << _cache.toString() << std::endl + << "Order: " << (unsigned)_order << std::endl + << "High water mark: " << _hw_marks.toString() << std::endl + ; + return retval.str(); +}; + +tstring DescribeSequence::_seq("SEQUENCE"); +}; + Added: branches/tora-trotl/src/trotl/src/trotl_describe.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_describe.h (rev 0) +++ branches/tora-trotl/src/trotl/src/trotl_describe.h 2011-08-08 09:54:11 UTC (rev 4025) @@ -0,0 +1,467 @@ +// Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...> +// +// forked from OCIPL Version 1.3 +// by Ivan Brezina <iv...@cv...> + +/* + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef TROTL_DESCRIBE_H_ +#define TROTL_DESCRIBE_H_ + +#include "trotl_export.h" +#include "trotl_common.h" +#include "trotl_handle.h" +#include "trotl_conn.h" +#include "trotl_int.h" + +namespace trotl +{ + +struct OciDescribe; + +struct OciParam : public OciSimpleHandle<OCIParam> +{ + //template <class TYPE> friend struct OciHandle; + friend struct OciDescribe; + friend class SqlStatement; + + OciParam() : OciSimpleHandle<OCIParam>() {}; + ~OciParam() + { + if(_handle) + { + sword res = OCICALL(OCIDescriptorFree(_handle, OCI_DTYPE_PARAM)); + oci_check_error(__TROTL_HERE__, _envhp, res); + // Will be freed while destructing OCIDescriptor + // and should not be freed by parent calling OCIHandleFree + _handle = 0; + } + }; + + template<class RETTYPE> + inline + RETTYPE get_attribute(ub4 attrtype) + { + if( Loki::TypeTraits<RETTYPE>::isIntegral) + { + RETTYPE retval; + sword res = OCICALL(OCIAttrGet(_handle, OciHandleID<OCIParam>::get_type_id(), &retval, 0, attrtype, _errh)); + oci_check_error(__TROTL_HERE__, _errh, res); + return retval; + } + else if( Loki::TypeTraits<RETTYPE>::isPointer) + { + RETTYPE retval; + sword res = OCICALL(OCIAttrGet(_handle, OciHandleID<OCIParam>::get_type_id(), &retval, 0, attrtype, _errh)); + oci_check_error(__TROTL_HERE__, _errh, res); + return retval; + } // TODO throw something else here + throw_oci_exception(OciException(__TROTL_HERE__, "Unsupported datatype: %s").arg(typeid(RETTYPE).name())); + } + + OciParam get_param(ub4 attrtype) + { + OciParam retval(_envhp, NULL); + sword res = OCICALL(OCIAttrGet(_handle, OciHandleID<OCIParam>::get_type_id(), (OCIParam**)retval, 0, attrtype, _errh)); + oci_check_error(__TROTL_HERE__, _errh, res); + return retval; + } + + OciParam get_sub_param(ub4 pos) + { + OciParam retval(_envhp, NULL); + sword res = OCICALL(OCIParamGet(_handle, OciHandleID<OCIParam>::get_type_id(), _errh, (dvoid**)(OCIParam**)retval, pos)); + oci_check_error(__TROTL_HERE__, _errh, res); + return retval; + } + + OciParam(const OciParam& other) : OciSimpleHandle<OCIParam>(other._envhp, other._handle) + { + _errh.alloc(_envhp); // TODO we SHOULD can destructively copy _errh here + const_cast<OciParam&>(other)._handle = NULL; + }; + + OciParam& operator=(const OciParam &other) + { + _envhp = other._envhp; + _handle = other._handle; + _errh.alloc(_envhp); // TODO we can destructively copy _errh here + const_cast<OciParam&>(other)._handle = NULL; + return *this; + }; +private: + operator HandleType**() + { + return &_handle; + } + + OciError _errh; +protected: + OciParam(OCIEnv* envhp, HandleType* handle) + : OciSimpleHandle<OCIParam>(envhp, handle) + { + _errh.alloc(_envhp); + }; + + OciParam(OCIEnv* envh); // : OciSimpleHandle<OCIParam>(envh) {}; +}; + +template<> +inline +tstring OciParam::get_attribute <tstring> (ub4 attrtype) +{ + OraText *retval; + ub4 retval_len; + sword res = OCICALL(OCIAttrGet(_handle, OciHandleID<OCIParam>::get_type_id(), &retval, &retval_len, attrtype, _errh)); + oci_check_error(__TROTL_HERE__, _errh, res); + return tstring((const char*)retval, retval_len); +} + +template<> +inline +OCINumber OciParam::get_attribute <OCINumber> (ub4 attrtype) +{ + void *retvalp = NULL; + ub4 retval_len = 0; + SqlNumber::OracleNumber retval; + + sword res = OCICALL(OCIAttrGet(_handle, OciHandleID<OCIParam>::get_type_id(), &retvalp, &retval_len, attrtype, _errh)); + oci_check_error(__TROTL_HERE__, _errh, res); + + /** Note this OCIAttrGet returns "real" SQLT_NUM, but no OCI functions work + with this datatype. Therefore I use union(see trotl_int.h) and do prepend + one byte for length in order to convert it into SQLT_VNU. + */ + retval.OracleNumberFormat.len = (ub1) retval_len; + memcpy(&retval.OracleNumberFormat.exp, retvalp, retval_len); + + return retval.ocinumber; +} + + +/// OCI Describe Handles +struct OciDescribe: public OciHandle<OCIDescribe> +{ + OciDescribe(OciEnv& env) : OciHandle<OCIDescribe>(env) {}; + OciParam get_param() + { + OciParam retval(_env, NULL); + sword res = OCICALL(OCIAttrGet(_handle, OciHandleID<OCIDescribe>::get_type_id(), (OCIParam**)retval, 0, OCI_ATTR_PARAM, _env._errh)); + oci_check_error(__TROTL_HERE__, _env._errh, res); + return retval; + } +}; + + +// Base class for all Describe* classes +class TROTL_EXPORT Describe +{ +public: + enum objectType + { + O_SYNONYM, + O_PUBLIC_SYNONYM, + O_VIEW, + O_TABLE, + O_COLUMN, + O_TYPE, + O_SEQUENCE, + O_PROCEDURE, + O_FUNCTION, + O_PACKAGE + }; + + virtual const tstring& whatIsThisString() const = 0; + virtual objectType whatIsThis() const = 0; + virtual tstring toString() const = 0; + + const tstring& objectName() const + { + return _objName; + }; + + static objectType getObjectType(OciConnection &con, const tstring &objectName); + static Describe* createDescription(OciConnection &con, const tstring &objectName); +protected: + Describe(const tstring &objectName); + Describe(OciConnection& con, const tstring &objectName); + Describe(OciConnection& con, OciDescribe &desc, const tstring &objectName); + OciConnection &_con; + OciDescribe _desc; + const tstring _objName; + //static objectType objectTypeFromOCI(const tstring &objectName); +}; + +class TROTL_EXPORT DescribeSynonym : public Describe +{ +public: + DescribeSynonym(OciConnection& conn, const tstring &objectName); + + virtual const tstring& whatIsThisString() const + { + return _public ? _public_synonym :_synonym; + }; + virtual objectType whatIsThis() const + { + return _public ? O_PUBLIC_SYNONYM : O_SYNONYM; + }; + virtual tstring toString() const; + + inline const tstring& name() const + { + return _name; + }; + inline const tstring& schema() const + { + return _schema; + }; + inline const tstring& link() const + { + return _link; + }; + inline const bool isPublic() const + { + return _public; + }; + +protected: + friend class Describe; + DescribeSynonym(OciConnection &, OciDescribe&, const tstring &objectName, bool); +private: + tstring _name, _schema, _link; + bool _public; + ub4 _objid; + static tstring _synonym; + static tstring _public_synonym; +}; + +class DescribeColumn; + +class TROTL_EXPORT DescribeView : public Describe +{ +public: + DescribeView(OciDescribe&, const tstring &objectName); + + virtual const tstring& whatIsThisString() const + { + return _view; + }; + virtual objectType whatIsThis() const + { + return O_VIEW; + }; + virtual tstring toString() const; + + DescribeColumn* getColumn(unsigned); +protected: + friend class Describe; + DescribeView(OciConnection &, OciDescribe&, const tstring &objectName); + ub4 _objid; + ub2 _num_cols; + ub1 _is_typed; + OciParam _list_columns; + std::vector<DescribeColumn*> _columns; + static tstring _view; +}; + + +class TROTL_EXPORT DescribeTable : public Describe +{ +public: + DescribeTable(OciDescribe&, const tstring &objectName); + + virtual const tstring& whatIsThisString() const + { + return _table; + }; + virtual objectType whatIsThis() const + { + return O_TABLE; + }; + virtual tstring toString() const; + + DescribeColumn* getColumn(unsigned); +protected: + friend class Describe; + DescribeTable(OciConnection& conn, OciDescribe &desc, const tstring &objectName); + ub4 _objid; + ub2 _num_cols; + OciParam _list_columns; + ub1 _is_temporary; + ub1 _is_typed; + OCIDuration _duration; + ub4 _rdba; + uword _tablespace; + ub1 _clustered; + ub1 _partitioned; + ub1 _index_only; + std::vector<DescribeColumn*> _columns; + static tstring _table; +}; + +class SqlStatement; +class DescribeType; + +class TROTL_EXPORT DescribeColumn: public Describe +{ +public: + virtual const tstring& whatIsThisString() const + { + return _column; + }; + virtual objectType whatIsThis() const + { + return O_COLUMN; + }; + virtual tstring toString() const; + + tstring name() const; + tstring typeName() const; + bool nullable() const; + DescribeType* getDescribeType(); + + virtual ~DescribeColumn(); + +//protected: + friend class Describe; + friend class DescribeView; + friend class DescribeTable; + friend class SqlStatement; + + DescribeColumn(OciConnection& conn, const tstring &objectName); + DescribeColumn(OciConnection &con, OciParam&, const tstring &tableName); + tstring _tableName; + tstring _name; + tstring _schema_name; + tstring _type_name; + ub2 _data_type; + //throws ORA-24328: illegal attribute value on number, valid only for SQLT_NTY + //OCITypeCode typecode = param.get_attribute<OCITypeCode>(OCI_ATTR_TYPECODE); + OCITypeCode _typecode; + OCITypeCode _collection_typecode; + OCITypeCode _collection_data_type; + ub1 _precision; + sb1 _scale; + ub2 _charset_id; + ub1 _charset_form; + ub1 _char_used; + ub2 _char_size; + ub2 _data_size; // NOTE: older OCI docs refer OCI_ATTR_DATA_SIZE as ub2. In 11g it is ub4 + ub1 _fprecision; + ub1 _lfprecision; + ub1 _is_null; + OCIRef *_ref_tdo; + // derived values + DescribeType *_type; + bool _utf16; + tstring _reg_name; + static tstring _column; +}; + + +class TROTL_EXPORT DescribeType: public Describe +{ +public: + virtual const tstring& whatIsThisString() const + { + return _type; + }; + virtual objectType whatIsThis() const + { + return O_TYPE; + }; + virtual tstring toString() const; + + friend class Describe; + friend class DescribeColumn; + +//protected: + DescribeType(OciConnection& conn, const tstring &objectName); + DescribeType(OciConnection &con, OciDescribe &desc, const tstring &objectName); + DescribeType(OciConnection &con, OciParam ¶m, const tstring &columnName); + OCITypeCode _typecode; + OCITypeCode _collection_typecode; + ub1 _is_incomplete_type; + ub1 _is_system_type; + ub1 _is_predefined_type; + ub1 _is_transient_type; + ub1 _is_system_generated_type; + ub1 _has_nested_table; + ub1 _has_lob; + ub1 _has_file; + ub2 _num_type_attrs; + ub2 _num_type_methods; + OciParam _list_type_methods; + ub1 _is_invoker_rights; + tstring _name; + tstring _schema_name; + ub1 _is_final_type; + ub1 _is_instantiable_type; + ub1 _is_subtype; + tstring _supertype_schema_name; + tstring _supertype_name; + ub2 _collection_data_size; + tstring _collection_type_name; + tstring _collection_schema_name; + ub2 _collection_data_type; + ub4 _collection_num_elems; + tstring _reg_name; + static tstring _type; +}; + +class TROTL_EXPORT DescribeSequence: public Describe +{ +public: + virtual const tstring& whatIsThisString() const + { + return _seq; + }; + virtual objectType whatIsThis() const + { + return O_SEQUENCE; + }; + virtual tstring toString() const; + +protected: + friend class Describe; + DescribeSequence(OciConnection &con, OciDescribe &desc, const tstring &objectName); + ub4 _objid; + SqlNumber _min; + SqlNumber _max; + SqlNumber _incr; + SqlNumber _cache; + ub1 _order; + SqlNumber _hw_marks; + static tstring _seq; +}; + +}; + +#endif + Added: branches/tora-trotl/src/trotl/src/trotl_error.cpp =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_error.cpp (rev 0) +++ branches/tora-trotl/src/trotl/src/trotl_error.cpp 2011-08-08 09:54:11 UTC (rev 4025) @@ -0,0 +1,229 @@ +// Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...> +// +// forked from OCIPL Version 1.3 +// by Ivan Brezina <iv...@cv...> + +/* + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include "trotl_common.h" +#include "trotl_export.h" +#include "trotl_error.h" + +#ifdef DEBUG +#include "stack/stack.hpp" +#endif + +#include <iterator> + +namespace trotl +{ + +OciException::OciException(tstring where, OCIEnv* envh) : + _where(where), _mess(where) +{ +#ifdef DEBUG + dbg::stack s; + std::copy(s.begin(), s.end(), std::ostream_iterator<dbg::stack_frame>(_stack, "\n")); + _mess += "\n" + _stack.str(); +#endif + OraText buffer[1024]; + + sb4 errorcode; + sword res = OCICALL(OCIErrorGet(envh, 1, NULL, &errorcode, buffer, sizeof(buffer), OCI_HTYPE_ENV)); + + //TODO loop over OCIErrorGet. + switch(res) + { + case OCI_SUCCESS: + _sql_error_code.push_back(errorcode); + _mess += (const char *)buffer; + break; + case OCI_INVALID_HANDLE: + _sql_error_code.push_back(21001); // my bogus value + _mess += "ORACLE_HOME not found\n"; + break; + case OCI_NO_DATA: + _sql_error_code.push_back(21002); // my bogus value + _mess += "OCIErrorGet: OCI_NO_DATA\n"; + default: + _sql_error_code.push_back(0); + } + + _parse_offset = 0; +} + +OciException::OciException(tstring where, OCIError* errh) : + _where(where), _mess(where) +{ +#ifdef DEBUG + dbg::stack s; + std::copy(s.begin(), s.end(), std::ostream_iterator<dbg::stack_frame>(_stack, "\n")); + _mess += "\n" + _stack.str(); +#endif + char buffer[1024]; + + sb4 errorcode; + sword res = OCICALL(OCIErrorGet(errh, 1, NULL, &errorcode, (OraText*)buffer, sizeof(buffer), OCI_HTYPE_ERROR)); + + switch(res) + { + case OCI_SUCCESS: + { + _sql_error_code.push_back(errorcode); + _mess += buffer; + break; + } + case OCI_NO_DATA: + { + _sql_error_code.push_back(21002); + _mess += "OCIErrorGet: OCI_NO_DATA\n"; + } + default: + { + _sql_error_code.push_back(0); + _mess += "OCIErrorGet: unknown error: \n" + res; + } + } + _parse_offset = 0; +} + +OciException::OciException(tstring where, const char* msg) : + _where(where), _mess(where), _last_sql(""), _parse_offset(0) +{ +#ifdef DEBUG + dbg::stack s; + std::copy(s.begin(), s.end(), std::ostream_iterator<dbg::stack_frame>(_stack, "\n")); + _mess += "\n" + _stack.str(); +#endif + _mess += msg; +} + +OciException::OciException(const OciException& other) + : _sql_error_code(other._sql_error_code) + , _where() //_where(other._where) + , _stack() + , _mess(other._mess) + , _last_sql(other._last_sql) + , _parse_offset() // _parse_offset(other._parse_offset) +{ + //throw std::logic_error("OciException should not be copied"); + //std::cerr << __TROTL_HERE__ << "OciException should not be copied" << std::endl; +} + +OciException& OciException::arg(int d) +{ + size_t pos = _mess.find("%d"); + + if(pos != tstring::npos) + { + tostream o; + o << d; + _mess.replace(pos, 2, o.str()); + } + return *this; +} + +OciException& OciException::arg(unsigned int d) +{ + size_t pos = _mess.find("%d"); + + if(pos != tstring::npos) + { + tostream o; + o << d; + _mess.replace(pos, 2, o.str()); + } + return *this; +} + +OciException& OciException::arg(unsigned long d) +{ + size_t pos = _mess.find("%d"); + + if(pos != tstring::npos) + { + tostream o; + o << d; + _mess.replace(pos, 2, o.str()); + } + return *this; +} + +OciException& OciException::arg(unsigned long long d) +{ + size_t pos = _mess.find("%d"); + + if(pos != tstring::npos) + { + tostream o; + o << d; + _mess.replace(pos, 2, o.str()); + } + return *this; +} + +OciException& OciException::arg(tstring s) +{ + size_t pos = _mess.find("%s"); + + if(pos != tstring::npos) + { + _mess.replace(pos, 2, s); + } + return *this; +} + +__NORETURN void TROTL_EXPORT throw_oci_exception(OciException const & e) +{ + throw(e); +} +// +//void TROTL_EXPORT throw_oci_exception(tstring where, OCIError* errh, sword res) +//{ +// switch(res) { +// case OCI_ERROR: +// throw_ocipl_exception(OciException(where, errh)); +// case OCI_INVALID_HANDLE: +// throw_ocipl_exception(OciException(where, "invalid handle")); +// //@todo handle other error states +// } +//} +// +//void TROTL_EXPORT throw_oci_exception(tstring where, OCIEnv* envh, sword res) +//{ +// switch(res) { +// case OCI_ERROR: +// throw_ocipl_exception(OciException(where, envh)); +// case OCI_INVALID_HANDLE: +// throw_ocipl_exception(OciException(where, envh)); +// //@todo handle other error states +// } +//} + +}; Added: branches/tora-trotl/src/trotl/src/trotl_error.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_error.h (rev 0) +++ branches/tora-trotl/src/trotl/src/trotl_error.h 2011-08-08 09:54:11 UTC (rev 4025) @@ -0,0 +1,145 @@ +// Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...> +// +// forked from OCIPL Version 1.3 +// by Ivan Brezina <iv...@cv...> + +/* + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef TROTL_ERROR_H_ +#define TROTL_ERROR_H_ + +#include "trotl_export.h" +#include "trotl_common.h" + +#include <exception> +#include <vector> + +#define TROTL_BACKTRACE_DEPTH 10 + +namespace trotl +{ +class SqlStatement; +struct OciException; + +void oci_check_error(tstring where, OCIError* errh, sword res); +void oci_check_error(tstring where, OCIEnv* envh, sword res); +void oci_check_error(tstring where, SqlStatement &stmt, sword res); // defined in trotl_stat.cpp + +/// error handling functions +extern __NORETURN void TROTL_EXPORT throw_oci_exception(OciException const & e); + +#ifdef WIN32 +class TROTL_EXPORT ::std::exception; +#endif + +struct TROTL_EXPORT OciException : public std::exception +{ + typedef std::exception super; + + OciException(tstring where, OCIEnv* envh); + OciException(tstring where, OCIError* errh); + OciException(tstring where, const char* msg); + OciException(tstring where, SqlStatement& stmt); // defined in trotl_stat.cpp + OciException(const OciException&); + + OciException& arg(int); + OciException& arg(unsigned int); + OciException& arg(unsigned long); + OciException& arg(unsigned long long); + + OciException& arg(tstring); + + ~OciException() throw() {} + + virtual const char* what() const throw() + { + return _mess.c_str(); + } + + int get_code(int pos = 0) const + { + return _sql_error_code.empty() ? 0 : _sql_error_code.at(pos); + }; + const char* get_mesg() const + { + return _mess.c_str(); + }; + const char* get_sql() const + { + return _last_sql.c_str(); + }; +private: + ::std::vector<int> _sql_error_code; + tstring _where; + tostream _stack; + tstring _mess; + tstring _last_sql; + ub2 _parse_offset; +}; + +inline void oci_check_error(tstring where, OCIError* errh, sword res) +{ + switch(res) + { + case OCI_SUCCESS: + case OCI_SUCCESS_WITH_INFO: + break; + case OCI_ERROR: + throw_oci_exception(OciException(where, errh)); + break; + case OCI_INVALID_HANDLE: + throw_oci_exception(OciException(where, "Invalid handle")); + break; + default: + throw_oci_exception(OciException(where, "Unsupported result code")); + break; + } +} + +inline void oci_check_error(tstring where, OCIEnv* envh, sword res) +{ + switch(res) + { + case OCI_SUCCESS: + case OCI_SUCCESS_WITH_INFO: + break; + case OCI_ERROR: + throw_oci_exception(OciException(where, envh)); + break; + case OCI_INVALID_HANDLE: + throw_oci_exception(OciException(where, "Invalid handle")); + break; + default: + throw_oci_exception(OciException(where, "Unsupported result code")); + break; + } +} + +}; +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ibr...@us...> - 2011-08-08 11:57:39
|
Revision: 4027 http://tora.svn.sourceforge.net/tora/?rev=4027&view=rev Author: ibre5041 Date: 2011-08-08 11:57:32 +0000 (Mon, 08 Aug 2011) Log Message: ----------- memory corruption fix. The precision is sb2 when describing queries column list. Modified Paths: -------------- branches/tora-trotl/src/trotl/src/trotl.h branches/tora-trotl/src/trotl/src/trotl_describe.cpp branches/tora-trotl/src/trotl/src/trotl_describe.h Modified: branches/tora-trotl/src/trotl/src/trotl.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl.h 2011-08-08 09:56:39 UTC (rev 4026) +++ branches/tora-trotl/src/trotl/src/trotl.h 2011-08-08 11:57:32 UTC (rev 4027) @@ -45,6 +45,7 @@ #include "trotl_date.h" #include "trotl_string.h" #include "trotl_rid.h" +#include "trotl_describe.h" #ifdef ORACLE_HAS_XML #include "trotl_xml.h" Modified: branches/tora-trotl/src/trotl/src/trotl_describe.cpp =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_describe.cpp 2011-08-08 09:56:39 UTC (rev 4026) +++ branches/tora-trotl/src/trotl/src/trotl_describe.cpp 2011-08-08 11:57:32 UTC (rev 4027) @@ -442,7 +442,7 @@ // For the case when precision is 0, NUMBER(precision, scale) can be represented simply as NUMBER. // ub1 for explicit describe // sb2 for implicit describe - _precision = param.get_attribute<ub1>(OCI_ATTR_PRECISION); + _precision = param.get_attribute<sb2>(OCI_ATTR_PRECISION); // OCI_ATTR_SCALE The scale of numeric columns. If the precision is nonzero and scale is -127, // then it is a FLOAT, else it is a NUMBER(precision, scale). Modified: branches/tora-trotl/src/trotl/src/trotl_describe.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_describe.h 2011-08-08 09:56:39 UTC (rev 4026) +++ branches/tora-trotl/src/trotl/src/trotl_describe.h 2011-08-08 11:57:32 UTC (rev 4027) @@ -366,7 +366,7 @@ OCITypeCode _typecode; OCITypeCode _collection_typecode; OCITypeCode _collection_data_type; - ub1 _precision; + sb2 _precision; // ub1 for explicit describe // sb2 for implicit describe sb1 _scale; ub2 _charset_id; ub1 _charset_form; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ibr...@us...> - 2011-09-01 06:59:42
|
Revision: 4038 http://tora.svn.sourceforge.net/tora/?rev=4038&view=rev Author: ibre5041 Date: 2011-09-01 06:59:35 +0000 (Thu, 01 Sep 2011) Log Message: ----------- code cleanup Modified Paths: -------------- branches/tora-trotl/src/trotl/src/trotl_common.h branches/tora-trotl/src/trotl/src/trotl_convertor.h branches/tora-trotl/src/trotl/src/trotl_date.cpp branches/tora-trotl/src/trotl/src/trotl_handle.h branches/tora-trotl/src/trotl/src/trotl_int.cpp branches/tora-trotl/src/trotl/src/trotl_int.h Modified: branches/tora-trotl/src/trotl/src/trotl_common.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_common.h 2011-08-09 18:28:24 UTC (rev 4037) +++ branches/tora-trotl/src/trotl/src/trotl_common.h 2011-09-01 06:59:35 UTC (rev 4038) @@ -81,9 +81,8 @@ namespace trotl { -typedef TROTL_EXPORT std::string tstring; +typedef TROTL_EXPORT ::std::string tstring; typedef TROTL_EXPORT ::std::ostringstream tostream; -//typedef char tchar; //TODO //#include <fstream> @@ -146,8 +145,8 @@ #ifdef DEBUG #ifdef __GNUC__ -#define __TROTL_HERE__ tstring(((strrchr(__FILE__, '/') ?: __FILE__ - 1) + 1)) + ":"__TROTL_HERE1__(__LINE__) -// #define __HERE_SHORT__ tstring(((strrchr(__FILE__, '/') ?: __FILE__ - 1) + 1)) + ":"__HERE1__(__LINE__) +#define __TROTL_HERE__ ::trotl::tstring(((strrchr(__FILE__, '/') ?: __FILE__ - 1) + 1)) + ":"__TROTL_HERE1__(__LINE__) +// #define __HERE_SHORT__ ::trotl::tstring(((strrchr(__FILE__, '/') ?: __FILE__ - 1) + 1)) + ":"__HERE1__(__LINE__) // #define __TROTL_HERE__ ::trotl::str_backtrace() + __HERE3__(__LINE__, __FILE__) #define __TROTL_HERE1__(x) STR(x)"\t" + __PRETTY_FUNCTION__ // #define __HERE2__(x,y) ::trotl::tstring("("y":" STR(x)"(") + __PRETTY_FUNCTION__ +")" @@ -157,8 +156,8 @@ // #define __HERE_SHORT__ __HERE3__(__LINE__, __FILE__) // #define __TROTL_HERE__ ::trotl::str_backtrace() + __HERE3__(__LINE__, __FILE__) // #define __HERE2__(x,y) ::trotl::tstring("("y":" STR(x)"(") + __FUNCTION__ +")" -// #define __HERE3__(x,y) tstring("\n(") + __FUNCTION__ + ") " y ":" STR(x) + "\n" -#define __TROTL_HERE__ tstring(__FILE__) + ":"__TROTL_HERE1__(__LINE__) +// #define __HERE3__(x,y) ::trotl::tstring("\n(") + __FUNCTION__ + ") " y ":" STR(x) + "\n" +#define __TROTL_HERE__ ::trotl::tstring(__FILE__) + ":"__TROTL_HERE1__(__LINE__) #define __TROTL_HERE1__(x) STR(x)"\t" + __FUNCSIG__ #endif //__GNUC__ #else //DEBUG Modified: branches/tora-trotl/src/trotl/src/trotl_convertor.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_convertor.h 2011-08-09 18:28:24 UTC (rev 4037) +++ branches/tora-trotl/src/trotl/src/trotl_convertor.h 2011-09-01 06:59:35 UTC (rev 4038) @@ -491,11 +491,6 @@ false, BindPar, -// #ifdef ORACLE_HAS_XML -// LOKI_TYPELIST_5(BindParCInt, BindParClob, BindParBlob, BindParDate, BindParXML), -// #else -// LOKI_TYPELIST_4(BindParCInt, BindParClob, BindParBlob, BindParDate), -// #endif #ifdef ORACLE_HAS_XML LOKI_TYPELIST_4(BindParClob, BindParBlob, BindParDate, BindParXML), #else Modified: branches/tora-trotl/src/trotl/src/trotl_date.cpp =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_date.cpp 2011-08-09 18:28:24 UTC (rev 4037) +++ branches/tora-trotl/src/trotl/src/trotl_date.cpp 2011-09-01 06:59:35 UTC (rev 4038) @@ -63,6 +63,7 @@ ((ub2*)rlenp)[i] = (ub2) value_sz; } _type_name = ct->typeName(); + } BindParDate::BindParDate(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl): BindPar(pos, stmt, decl) Modified: branches/tora-trotl/src/trotl/src/trotl_handle.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_handle.h 2011-08-09 18:28:24 UTC (rev 4037) +++ branches/tora-trotl/src/trotl/src/trotl_handle.h 2011-09-01 06:59:35 UTC (rev 4038) @@ -40,7 +40,6 @@ #ifndef TROTL_BASE_H_ #define TROTL_BASE_H_ -#include <string> #include <typeinfo> #include <oci.h> @@ -50,6 +49,7 @@ #include "Loki/TypeTraits.h" #include "Loki/TypeManip.h" +#include "Loki/static_check.h" namespace trotl { @@ -57,10 +57,6 @@ struct TROTL_EXPORT OciEnv; struct TROTL_EXPORT OciError; -inline void oci_check_error(tstring where, OCIError* errh, sword res); -inline void oci_check_error(tstring where, OCIEnv* envh, sword res); - - template<typename TYPE> struct OciHandleID { @@ -136,22 +132,22 @@ } template <> inline ub4 OciHandleID<OCIEnv>::get_attr_id() { - std::cout << "Error:" << __TROTL_HERE__ << std::endl; + LOKI_STATIC_CHECK(1, UnsupportedHanleOPonENV); return -1; } template <> inline ub4 OciHandleID<OCIError>::get_attr_id() { - std::cout << "Error:" << __TROTL_HERE__ << std::endl; + LOKI_STATIC_CHECK(1, UnsupportedHanleOPonError); return -1; } template <> inline ub4 OciHandleID<OCISvcCtx>::get_attr_id() { - std::cout << "Error:" << __TROTL_HERE__ << std::endl; + LOKI_STATIC_CHECK(1, UnsupportedHanleOPonSvcCtx); return -1; } template <> inline ub4 OciHandleID<OCIStmt>::get_attr_id() { - std::cout << "Error:" << __TROTL_HERE__ << std::endl; + LOKI_STATIC_CHECK(1, UnsupportedHanleOPonSTMT); return -1; } @@ -227,7 +223,7 @@ /// wrapping of OCI handles without freeing them in destructor // subclassed by OciEnv -// TODO some reference counting +// TODO some reference counting template<typename TYPE> struct OciHandleWrapper : public OciHandleID<TYPE> { @@ -265,7 +261,7 @@ /// wrapper for the OCIEnv handle - OCIEnv* holder -struct /*TROTL_EXPORT*/ OciEnvAlloc : public OciSimpleHandle<OCIEnv> +struct TROTL_EXPORT OciEnvAlloc : public OciSimpleHandle<OCIEnv> { typedef OciSimpleHandle<OCIEnv> super; Modified: branches/tora-trotl/src/trotl/src/trotl_int.cpp =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_int.cpp 2011-08-09 18:28:24 UTC (rev 4037) +++ branches/tora-trotl/src/trotl/src/trotl_int.cpp 2011-09-01 06:59:35 UTC (rev 4038) @@ -54,7 +54,7 @@ Util::RegisterInFactory<BindParNumber, DefineParFactTwoParmSing, int> regDefineNumberNUM(SQLT_NUM); Util::RegisterInFactory<BindParNumber, DefineParFactTwoParmSing, int> regDefineNumberVNU(SQLT_VNU); -tstring BindParNumber::get_string(unsigned int row) const +tstring TROTL_EXPORT BindParNumber::get_string(unsigned int row) const { if(!indp[row]) { @@ -81,7 +81,7 @@ } } -BindParNumber::BindParNumber(unsigned int pos, SqlStatement &stmt, DescribeColumn* ct) : BindPar(pos, stmt, ct) +TROTL_EXPORT BindParNumber::BindParNumber(unsigned int pos, SqlStatement &stmt, DescribeColumn* ct) : BindPar(pos, stmt, ct) { _errh.alloc(stmt._env); valuep = (void**) calloc(_cnt, (size_t)OCI_NUMBER_SIZE ); @@ -95,7 +95,7 @@ _type_name = ct->typeName(); } -BindParNumber::BindParNumber(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl): BindPar(pos, stmt, decl) +TROTL_EXPORT BindParNumber::BindParNumber(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl): BindPar(pos, stmt, decl) { _errh.alloc(stmt._env); valuep = (void**) calloc(_cnt, (size_t)OCI_NUMBER_SIZE ); Modified: branches/tora-trotl/src/trotl/src/trotl_int.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_int.h 2011-08-09 18:28:24 UTC (rev 4037) +++ branches/tora-trotl/src/trotl/src/trotl_int.h 2011-09-01 06:59:35 UTC (rev 4038) @@ -245,7 +245,7 @@ }; // namespace Private // wrapper for internal Oracle NUMBER type [length][mantisa][1-20digits] -struct SqlNumber : public SqlValue +struct TROTL_EXPORT SqlNumber : public SqlValue { union OracleNumber { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ibr...@us...> - 2011-09-05 22:01:54
|
Revision: 4062 http://tora.svn.sourceforge.net/tora/?rev=4062&view=rev Author: ibre5041 Date: 2011-09-05 22:01:47 +0000 (Mon, 05 Sep 2011) Log Message: ----------- initial support for spatial datatypes Modified Paths: -------------- branches/tora-trotl/src/trotl/src/CMakeLists.txt branches/tora-trotl/src/trotl/src/trotl_anydata.cpp branches/tora-trotl/src/trotl/src/trotl_anydata.h Added Paths: ----------- branches/tora-trotl/src/trotl/src/trotl_spatial.cpp branches/tora-trotl/src/trotl/src/trotl_spatial.h Modified: branches/tora-trotl/src/trotl/src/CMakeLists.txt =================================================================== --- branches/tora-trotl/src/trotl/src/CMakeLists.txt 2011-09-05 17:20:43 UTC (rev 4061) +++ branches/tora-trotl/src/trotl/src/CMakeLists.txt 2011-09-05 22:01:47 UTC (rev 4062) @@ -26,6 +26,7 @@ trotl_int.cpp trotl_lob.cpp trotl_misc.cpp + trotl_spatial.cpp trotl_parser.cpp trotl_rid.cpp trotl_stat.cpp Modified: branches/tora-trotl/src/trotl/src/trotl_anydata.cpp =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_anydata.cpp 2011-09-05 17:20:43 UTC (rev 4061) +++ branches/tora-trotl/src/trotl/src/trotl_anydata.cpp 2011-09-05 22:01:47 UTC (rev 4062) @@ -92,10 +92,10 @@ if(_anydatatdo == NULL) throw_oci_exception(OciException(__TROTL_HERE__, "Unknown datatype in the database: SYS.ANYDATA")); - for(int i=0; i<g_OCIPL_BULK_ROWS; i++) - { - _oan_buffer[i] = NULL; - } + // for(int i=0; i<g_OCIPL_BULK_ROWS; i++) + // { + // _oan_buffer[i] = NULL; + // } } void BindParANYDATA::define_hook() @@ -303,12 +303,12 @@ break; } - return _stringrepres.str(); + return ""; }; tstring SqlANYDATA::str() const { - return _stringrepres.str(); + return ""; }; Modified: branches/tora-trotl/src/trotl/src/trotl_anydata.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_anydata.h 2011-09-05 17:20:43 UTC (rev 4061) +++ branches/tora-trotl/src/trotl/src/trotl_anydata.h 2011-09-05 22:01:47 UTC (rev 4062) @@ -97,8 +97,6 @@ //protected: - tostream _stringrepres; - OCIType *anydatatdo; OciConnection& _conn; }; Added: branches/tora-trotl/src/trotl/src/trotl_spatial.cpp =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_spatial.cpp (rev 0) +++ branches/tora-trotl/src/trotl/src/trotl_spatial.cpp 2011-09-05 22:01:47 UTC (rev 4062) @@ -0,0 +1,233 @@ +// Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...> +// +// forked from OCIPL Version 1.3 +// by Ivan Brezina <iv...@cv...> + +/* + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include "trotl_common.h" +#include "trotl_export.h" +#include "trotl_spatial.h" +#include "trotl_stat.h" +#include "trotl_describe.h" + + +namespace trotl +{ + +// TODO +//Util::RegisterInFactory<BindParSpatial, BindParFactTwoParmSing> regBindXML("MDSYS.SDO_GEOMETRY"); + +Util::RegisterInFactory<BindParSpatial, CustDefineParFactTwoParmSing> regCustDefineNTY_SPATIAL("MDSYS.SDO_GEOMETRY"); + +BindParSpatial::BindParSpatial(unsigned int pos, SqlStatement &stmt, DescribeColumn* ct) : BindPar(pos, stmt, ct) + , _global_geom_obj(NULL) + , _global_geom_ind(NULL) +{ + dty = SQLT_NTY; + _type_name = ct->typeName(); + value_sz = sizeof(SDO_GEOMETRY_TYPE*); + for(unsigned i = 0; i < _cnt; ++i) + { + ((ub2*)rlenp)[i] = (ub2) value_sz; + } + + init(); +} + +BindParSpatial::BindParSpatial(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl) : BindPar(pos, stmt, decl) + , _global_geom_obj(NULL) + , _global_geom_ind(NULL) +{ + dty = SQLT_NTY; + _type_name = "MDSYS.SDO_GEOMETRY"; + value_sz = sizeof(SDO_GEOMETRY_TYPE*); + for(unsigned i = 0; i < _cnt; ++i) + { + ((ub4*)rlenp)[i] = (ub4) value_sz; + } + + init(); +} + +void BindParSpatial::init() +{ + sword res; + _spatialtdo = NULL; + _global_geom_obj = (SDO_GEOMETRY_TYPE**) calloc(_cnt, sizeof(SDO_GEOMETRY_TYPE*)); + _global_geom_ind = (SDO_GEOMETRY_ind**) calloc(_cnt, sizeof(SDO_GEOMETRY_ind*)); + + res = OCICALL(OCITypeByName(_stmt._env, _stmt._errh, _stmt._conn._svc_ctx, + (const oratext*)"MDSYS", (ub4)strlen("MDSYS"), + (const oratext*)"SDO_GEOMETRY", (ub4)strlen("SDO_GEOMETRY"), + 0, 0, + OCI_DURATION_SESSION, OCI_TYPEGET_ALL, + (OCIType**) &_spatialtdo)); + oci_check_error(__TROTL_HERE__, _stmt._errh, res); + + if(_spatialtdo == NULL) + throw_oci_exception(OciException(__TROTL_HERE__, "Unknown datatype in the database: MDSYS.SDO_GEOMETRY")); +} + +void BindParSpatial::define_hook() +{ + sword res = OCICALL(OCIDefineObject(defnpp, _stmt._errh, + _spatialtdo, + (dvoid **) &(_global_geom_obj[0]), + (ub4 *) 0, + (dvoid **) &(_global_geom_ind[0]), + (ub4 *) 0)); + oci_check_error(__TROTL_HERE__, _stmt._errh, res); +// // TODO OCIDefineArrayOfStruct here ?? +} + +void BindParSpatial::bind_hook() +{ + //TODO + throw_oci_exception(OciException(__TROTL_HERE__, "Not implemented yet")); +} + +// TODO +tstring BindParSpatial::get_string(unsigned int row) const +{ + sword res; + int global_nelems; + int global_nords; + int gtype; + tostream _stringrepres; + double x, y, z; + + if(_global_geom_ind[row]->_atomic == OCI_IND_NULL) + { + return "NULL"; + } + + + /* Get the size of the sdo_elem_info array */ + res = OCICALL(OCICollSize(_stmt._env, + _stmt._errh, + (OCIColl *)(_global_geom_obj[row]->sdo_elem_info), + &global_nelems)); + _stringrepres << " sdo_elem_info size: " << global_nelems; + + /* Get the size of the ordinates array */ + res = OCICALL(OCICollSize(_stmt._env, + _stmt._errh, + (OCIColl *)(_global_geom_obj[row]->sdo_ordinates), + &global_nords)); + _stringrepres << " sdo_ordinates size: " << global_nords; + + /* sc_ops_get_gtype */ + res = OCICALL(OCINumberToInt(_stmt._errh, + &(_global_geom_obj[row]->sdo_gtype), + (uword)sizeof(int), OCI_NUMBER_SIGNED, + (dvoid *)>ype)); + _stringrepres << " -- gtype: " << gtype; + + /* sc_ops_get_sdo_point */ + if (_global_geom_ind[row]->sdo_point._atomic == OCI_IND_NOTNULL) + { + if (_global_geom_ind[row]->sdo_point.x == OCI_IND_NOTNULL) + { + res = OCICALL(OCINumberToReal(_stmt._errh, + &(_global_geom_obj[row]->sdo_point.x), + (uword)sizeof(double), + (dvoid *)&x)); + + _stringrepres << " -- sdo_point.X: " << x; + } + + if (_global_geom_ind[row]->sdo_point.y == OCI_IND_NOTNULL) + { + res = OCICALL(OCINumberToReal(_stmt._errh, + &(_global_geom_obj[row]->sdo_point.y), + (uword)sizeof(double), + (dvoid *)&y)); + + _stringrepres << " -- sdo_point.Y: " << y; + } + + if (_global_geom_ind[row]->sdo_point.z == OCI_IND_NOTNULL) + { + res = OCICALL(OCINumberToReal(_stmt._errh, + &(_global_geom_obj[row]->sdo_point.z), + (uword)sizeof(double), + (dvoid *)&z)); + + _stringrepres << " -- sdo_point.Z: " << z; + } + } + else + _stringrepres << "-- sdo_point IS NULL"; + + /* Loop through and print all the elements for this geometry */ + for(unsigned i=0; i<global_nelems; i+=3) + { + boolean exists; + OCINumber *oci_number; + ub4 element_type; + + res = OCICALL(OCICollGetElem(_stmt._env, + _stmt._errh, + (OCIColl *)(_global_geom_obj[row]->sdo_elem_info), + (sb4)(i), // +1 ?? TODO + (boolean *)&exists, + (dvoid **)&oci_number, (dvoid **)0)); + + res = OCICALL(OCINumberToInt(_stmt._errh, + oci_number, + (uword)sizeof(ub4), OCI_NUMBER_UNSIGNED, + (dvoid *)&element_type)); + + _stringrepres << "-- element type: " << element_type; + + switch (element_type) + { + case 1: + //sc_ops_get_type1(); + break; + case 2: + //sc_ops_get_type2(); + break; + case 3: + //sc_ops_get_type3(); + break; + case 4: + //sc_ops_get_type4(); + break; + case 5: + //sc_ops_get_type5(); + break; + } + } + + return _stringrepres.str(); +}; + +}; Added: branches/tora-trotl/src/trotl/src/trotl_spatial.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_spatial.h (rev 0) +++ branches/tora-trotl/src/trotl/src/trotl_spatial.h 2011-09-05 22:01:47 UTC (rev 4062) @@ -0,0 +1,126 @@ +// Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...> +// +// forked from OCIPL Version 1.3 +// by Ivan Brezina <iv...@cv...> + +/* + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef TROTL_SPATIAL_H_ +#define TROTL_SPATIAL_H_ + +#include "trotl_common.h" +#include "trotl_export.h" +#include "trotl_handle.h" +#include "trotl_conn.h" +#include "trotl_var.h" + +#define SDO_GEOMETRY "MDSYS.SDO_GEOMETRY" + +namespace trotl +{ + + /*************************************************************************/ + /* Type definitions */ + /*************************************************************************/ + struct sdo_point_type + { + OCINumber x; + OCINumber y; + OCINumber z; + }; + typedef struct sdo_point_type sdo_point_type; + + typedef OCIArray sdo_elem_info_array; + typedef OCIArray sdo_ordinate_array; + + struct sdo_geometry + { + OCINumber sdo_gtype; + OCINumber sdo_srid; + sdo_point_type sdo_point; + OCIArray *sdo_elem_info; + OCIArray *sdo_ordinates; + }; + + typedef struct sdo_geometry SDO_GEOMETRY_TYPE; + + /*** + ** Indicator structures for SDO_GEOMETRY_TYPE + ***/ + struct sdo_point_type_ind + { + OCIInd _atomic; + OCIInd x; + OCIInd y; + OCIInd z; + }; + typedef struct sdo_point_type_ind sdo_point_type_ind; + + struct SDO_GEOMETRY_ind + { + OCIInd _atomic; + OCIInd sdo_gtype; + OCIInd sdo_srid; + struct sdo_point_type_ind sdo_point; + OCIInd sdo_elem_info; + OCIInd sdo_ordinates; + }; + typedef struct SDO_GEOMETRY_ind SDO_GEOMETRY_ind; + + struct TROTL_EXPORT BindParSpatial: public BindPar + { + friend struct ConvertorForRead; + friend struct ConvertorForWrite; + + // TODO remember OCIConn or at least svcctx in this class + BindParSpatial(unsigned int pos, SqlStatement &stmt, DescribeColumn* ct); + BindParSpatial(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl); + + virtual ~BindParSpatial() + { + // TODO free _any_indp, _oan_buffer + } + + virtual tstring get_string(unsigned int row) const; + + void init(); + + virtual void define_hook(); + virtual void bind_hook(); + + +//private: + + OCIType *_spatialtdo; + SDO_GEOMETRY_TYPE **_global_geom_obj;/* spatial object buffer */ + SDO_GEOMETRY_ind **_global_geom_ind; /* Object indicator */ + }; + +}; +#endif /*TROTL_SPATIAL_H_*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ibr...@us...> - 2011-09-06 23:06:34
|
Revision: 4065 http://tora.svn.sourceforge.net/tora/?rev=4065&view=rev Author: ibre5041 Date: 2011-09-06 23:06:28 +0000 (Tue, 06 Sep 2011) Log Message: ----------- support for AL32UTF8 placeholders Modified Paths: -------------- branches/tora-trotl/src/trotl/src/trotl_rid.cpp branches/tora-trotl/src/trotl/src/trotl_rid.h branches/tora-trotl/src/trotl/src/trotl_string.cpp Modified: branches/tora-trotl/src/trotl/src/trotl_rid.cpp =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_rid.cpp 2011-09-06 21:03:29 UTC (rev 4064) +++ branches/tora-trotl/src/trotl/src/trotl_rid.cpp 2011-09-06 23:06:28 UTC (rev 4065) @@ -75,6 +75,15 @@ sword res = OCICALL(OCIDescriptorAlloc(_env, &((void**)valuep)[i], OCI_DTYPE_ROWID, 0, NULL)); oci_check_error(__TROTL_HERE__, _env, res); } + // sword res = OCICALL(OCIArrayDescriptorAlloc( + // (void *)envhp, + // (void **)&valuep, + // OCI_DTYPE_ROWID, + // _cnt, + // 0, + // (void **)0)); + + // oci_check_error(__TROTL_HERE__, _env, res); } void BindParRid::descFree(void) @@ -103,6 +112,12 @@ // oci_check_error(__TROTL_HERE__, _stmt._errh, res); } +void BindParRid::fetch_hook(ub4 iter, ub4 idx, ub1 piece, ub4, sb2 ind) +{ + // descFree(); + // descAlloc(); +} + tstring BindParRid::get_string(unsigned int i) const { if(indp[i] == OCI_IND_NULL) Modified: branches/tora-trotl/src/trotl/src/trotl_rid.h =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_rid.h 2011-09-06 21:03:29 UTC (rev 4064) +++ branches/tora-trotl/src/trotl/src/trotl_rid.h 2011-09-06 23:06:28 UTC (rev 4065) @@ -52,7 +52,8 @@ virtual void bind_hook(); virtual void define_hook(); - + virtual void fetch_hook(ub4 iter, ub4 idx, ub1 piece, ub4, sb2 ind); + private: void descAlloc(void); //TODO OCI_DTYPE_FILE for BFILE, CFILE void descFree(void); Modified: branches/tora-trotl/src/trotl/src/trotl_string.cpp =================================================================== --- branches/tora-trotl/src/trotl/src/trotl_string.cpp 2011-09-06 21:03:29 UTC (rev 4064) +++ branches/tora-trotl/src/trotl/src/trotl_string.cpp 2011-09-06 23:06:28 UTC (rev 4065) @@ -53,44 +53,44 @@ BindParVarchar::BindParVarchar(unsigned int pos, SqlStatement &stmt, DescribeColumn* ct) : BindPar(pos, stmt, ct) { - /* amount of bytes = (string length +1 ) * (array length) */ - valuep = (void**) calloc(_cnt, ct->_data_size + 1); + /* amount of bytes = (string length +1 )*4 * (array length) */ + valuep = (void**) calloc(_cnt, (ct->_data_size + 1)*4); alenp = (ub2*) calloc(_cnt, sizeof(ub4)); dty = SQLT_STR; //value_sz = ct->_width + 1; - value_sz = ct->_data_size + 1; + value_sz = (ct->_data_size + 1) * 4; _type_name = typeid(tstring).name(); } BindParVarchar::BindParVarchar(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl) : BindPar(pos, stmt, decl) { - // amount of bytes = (string length +1 ) * (array length) - valuep = (void**) calloc(decl.bracket[0]+1, decl.bracket[1]); + // amount of bytes = (string length +1 )*4 * (array length) + valuep = (void**) calloc(decl.bracket[1], (decl.bracket[0] + 1) * 4); alenp = (ub2*) calloc(_cnt, sizeof(ub2)); dty = SQLT_STR; - value_sz = decl.bracket[0]+1; + value_sz = (decl.bracket[0] + 1) * 4; _type_name = typeid(tstring).name(); } BindParChar::BindParChar(unsigned int pos, SqlStatement &stmt, DescribeColumn* ct) : BindPar(pos, stmt, ct) { - valuep = (void**) calloc(_cnt, ct->_data_size + 1); // TODO +1 ?? why? + valuep = (void**) calloc(_cnt, ct->_data_size * 4); // TODO +1 ?? why? alenp = (ub2*) calloc(_cnt, sizeof(ub4)); dty = SQLT_CHR; - value_sz = ct->_data_size; + value_sz = ct->_data_size * 4; _type_name = typeid(tstring).name(); } BindParChar::BindParChar(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl): BindPar(pos, stmt, decl) { - valuep = (void**) calloc(decl.bracket[1], decl.bracket[0]); + valuep = (void**) calloc(decl.bracket[1], (decl.bracket[0] + 1) * 4); alenp = (ub2*) calloc(_cnt, sizeof(ub2)); dty = SQLT_STR; /* use STR_CHR even if placeholder defined as "char" */ - value_sz = decl.bracket[0]; + value_sz = (decl.bracket[0] + 1) * 4; _type_name = typeid(tstring).name(); } @@ -101,17 +101,17 @@ alenp = (ub2*) calloc(_cnt, sizeof(ub4)); dty = SQLT_BIN; - value_sz = ct->_data_size; + value_sz = ct->_data_size + 1; _type_name = ct->typeName(); } BindParRaw::BindParRaw(unsigned int pos, SqlStatement &stmt, BindVarDecl &decl): BindPar(pos, stmt, decl) { - valuep = (void**) calloc (decl.bracket[1], decl.bracket[0]); + valuep = (void**) calloc (decl.bracket[1], decl.bracket[0] + 1); alenp = (ub2*) calloc(_cnt, sizeof(ub2)); dty = SQLT_BIN; - value_sz = decl.bracket[0]; + value_sz = decl.bracket[0] + 1; _type_name = "RAW"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |