[Ocipl-commits] SF.net SVN: ocipl: [36] trunk/ocipl
Brought to you by:
martinfuchs
|
From: <mar...@us...> - 2007-10-28 15:44:31
|
Revision: 36
http://ocipl.svn.sourceforge.net/ocipl/?rev=36&view=rev
Author: martinfuchs
Date: 2007-10-28 08:08:59 -0700 (Sun, 28 Oct 2007)
Log Message:
-----------
18.01.2007:
- _NO_COMMENT -> OCIPL_NO_COMMENT (ocipl.h, ocipl.cpp, ocithrow.cpp)
11.02.2007:
- ocidate_to_short_string(), als R?\195?\188ckgabetyp f?\195?\188r execute...() und fetch() (ocipl.h, ocipl.cpp)
- UNICODE adjustments (ocipl.h)
- reset FETCH state when executing a recycled SqlStatement object to fix SqlStatement::next() (ocipl.h, ocipl.cpp)
01.05.2007:
- move dump_schema() into xmldump module
- definition of default buffer size for strings using OCIPL_DEFAULT_STRING_BUFFER
- NULL parameter for SqlIntArray::get_int()
- OciDateArray::get_date() (ocipl.h, ocipl.cpp)
19.08.2007:
- Parsing of date strings with format specifier
- Rounding of floating point numbers to integer values with Oracle 8.0 (ocipl.h, ocipl.cpp)
14.10.2007:
- use OCI_IND_NULL constant
- SqlValue construktor with indicator (ocipl.h)
- Doxyfile Update (Doxyfile)
28.10.2007:
- destruktor ~SqlIndArray() to fix memory leaks (ocipl.h)
Modified Paths:
--------------
trunk/ocipl/ocipl-license.txt
trunk/ocipl/ocipl-xml.cpp
trunk/ocipl/ocipl.cpp
trunk/ocipl/ocipl.h
trunk/ocipl/ocithrow.cpp
Modified: trunk/ocipl/ocipl-license.txt
===================================================================
--- trunk/ocipl/ocipl-license.txt 2007-10-28 14:50:00 UTC (rev 35)
+++ trunk/ocipl/ocipl-license.txt 2007-10-28 15:08:59 UTC (rev 36)
@@ -2,7 +2,7 @@
//
// OCIPL
//
- // Copyright (c) 2003, 2004, 2005, 2006 Martin Fuchs <mar...@gm...>
+ // Copyright (c) 2003, 2004, 2005, 2006, 2007 Martin Fuchs <mar...@gm...>
//
/*
Modified: trunk/ocipl/ocipl-xml.cpp
===================================================================
--- trunk/ocipl/ocipl-xml.cpp 2007-10-28 14:50:00 UTC (rev 35)
+++ trunk/ocipl/ocipl-xml.cpp 2007-10-28 15:08:59 UTC (rev 36)
@@ -2,7 +2,7 @@
//
// ocipl-xml.cpp
//
- // Copyright (c) 2003, 2004, 2005, 2006 Martin Fuchs <mar...@gm...>
+ // Copyright (c) 2003, 2004, 2005, 2006, 2007 Martin Fuchs <mar...@gm...>
//
// OCIPL Version 1.3
//
@@ -39,8 +39,8 @@
*/
-#ifndef _NO_COMMENT
-#define _NO_COMMENT // no #pragma comment(lib, ...) statements in .lib files
+#ifndef OCIPL_NO_COMMENT
+#define OCIPL_NO_COMMENT // no #pragma comment(lib, ...) statements in .lib files
#endif
#ifndef XS_NO_COMMENT
#define XS_NO_COMMENT // no pragma(lib) in xmlstorage.h
@@ -69,7 +69,7 @@
void SqlStatement::dump_results(XMLPos& pos, const XS_String& element_name)
{
if (!(_state & EXECUTED))
- execute();
+ execute(); // instead of first_bulk()
for(int fetched=fetched_rows(); fetched>0; fetched=next_bulk())
for(int i=0; i<fetched; ++i) {
@@ -114,782 +114,4 @@
}
-static ColumnType* s_pcolTypes;
-
-static int cmp_col(const void* a, const void* b)
-{
- int ia = *(int*)a;
- int ib = *(int*)b;
-
- return s_pcolTypes[ia]._name.compare(s_pcolTypes[ib]._name);
-}
-
-
-typedef pair<tstring, tstring> ObjIdent;
-
- /// object info structure used in OCIPL::Dump::dump_schema()
-struct ObjInfo {
- ub1 _type;
-
- ObjInfo()
- {
- _type = -1;
- }
-};
-
-typedef map<ObjIdent, ObjInfo> ObjNameMap;
-
-
-/*
- // describe schema and dump the information into an XML tree
-void Dump::dump_schema(OciConnection& conn, const TCHAR* schema, XMLPos& pos)
-{
- tstring owner = schema;
-
- _tcsupr((TCHAR*)owner.data());
-
- pos.create("schema");
- pos["name"] = schema;
-
- pos.create("info");
- time_t now = time(NULL); // problems in the year 2038
-#ifdef __STDC_WANT_SECURE_LIB__
- struct tm lct;
- localtime_s(&lct, &now);
- struct tm* plct = &lct;
-#else
- struct tm* plct = localtime(&now);
-#endif
- OciDate date(plct);
- pos["date"] = date.str();
- pos["dump"] = "xmldump 1.0";
- pos.back(); // </info>
-
- OciDescribe descr(conn._env);
- sword res = OCIDescribeAny(conn._svc_ctx, conn._env._errh,
- (void*)schema, strlen(schema), OCI_OTYPE_NAME,
- OCI_DEFAULT, OCI_PTYPE_SCHEMA, descr);
- oci_check_error(conn._env, res);
-
- OciParam paramh(conn._env);
- descr.get_attribute(¶mh, NULL, OCI_ATTR_PARAM, conn._env._errh);
-
- OciParam objlisth(conn._env);
- paramh.get_attribute(&objlisth, NULL, OCI_ATTR_LIST_OBJECTS);
-
- ub2 num;
- objlisth.get_attribute(&num, NULL, OCI_ATTR_NUM_PARAMS);
-
- // automatische Sortierung der Objekte \xFCber ObjNameMap
- ObjNameMap obj_names;
-
- for(int i=0; i<num; ++i) {
- ObjInfo info;
- OciParam objh(conn._env);
- res = OCIParamGet(objlisth, OciParam::get_type_id(), conn._env._errh, (void**)&objh, i);
- oci_check_error(conn._env, res);
-
- OraText* name; ub4 name_len;
- objh.get_attribute(&name, &name_len, OCI_ATTR_OBJ_NAME);
- tstring obj_name((const TCHAR*)name, name_len);
-
- // filter by object name
- if (!_filter.empty() && _filter.find(obj_name)==_filter.end())
- continue;
-
- objh.get_attribute(&info._type, NULL, OCI_ATTR_PTYPE);
-
- if (info._type) { // no "unknown type" nodes
- tstring type_str = get_oci_ptype_str(info._type);
-
- // replace spaces by '-' for XML conformity
- TCHAR* p = (TCHAR*)type_str.data();
- for(; *p; ++p)
- if (istspace(*p))
- *p = '-';
-
- obj_names[make_pair(type_str, obj_name)] = info;
- }
- }
-
- SqlStatement stmt(conn);
- TCHAR buffer[BUFFER_LEN];
-
- for(ObjNameMap::const_iterator it=obj_names.begin(); it!=obj_names.end(); ++it) {
- const ObjIdent& ident = it->first;
- const string& type_str = ident.first;
- const string& obj_name = ident.second;
- const ObjInfo& info = it->second;
-
- pos.create(type_str);
- pos["name"] = obj_name;
-
- // Not avoidable to describe the object here again - now by name:
- // Seems, the descriptor handles overflow at some point, so we get an error (msg_id=-1) after some loops.
- OciDescribe obj_descr(conn._env);
- res = OCIDescribeAny(conn._svc_ctx, conn._env._errh, (OraText*)obj_name.c_str(), obj_name.length(), OCI_OTYPE_NAME, OCI_DEFAULT, info._type, obj_descr);
-
- if (res == OCI_SUCCESS) {
- OciParam paramh(conn._env);
- obj_descr.get_attribute(¶mh, NULL, OCI_ATTR_PARAM, conn._env._errh);
-
- // tables and views
- if (info._type==OCI_PTYPE_TABLE || info._type==OCI_PTYPE_VIEW) {
- // Abfrage des Tabellen-/View-Kommentars
- if (_comments) {
- SqlString comment;
-
- stmt.prepare("select COMMENTS from ALL_TAB_COMMENTS "
- "where OWNER=:0 and TABLE_NAME=:1");
- stmt.bind_param(0, owner);
- stmt.bind_param(1, obj_name);
- stmt.bind_result(0, comment);
-
- if (stmt.fetch()) {
- pos.create("comment");
- pos->set_content(comment.c_str());
- pos.back();
- }
- }
-
- ColumnType* pcolTypes = NULL;
- int* pColIdxs = NULL;
-
- try {
- ub2 num_cols;
- paramh.get_attribute(&num_cols, NULL, OCI_ATTR_NUM_COLS);
-
- OciParam col_listh(conn._env);
- paramh.get_attribute(&col_listh, NULL, OCI_ATTR_LIST_COLUMNS);
-
- pcolTypes = new ColumnType[num_cols]; // Array der Spaltenbeschreibungen
- ColumnType* pColType = pcolTypes;
-
- pColIdxs = new int[num_cols]; // Array der Spalten-Indices
- int* pColIdx = pColIdxs;
-
- int j;
- for(j=0; j<num_cols; ++j) {
- OciParam colh(conn._env);
- res = OCIParamGet(col_listh, OciParam::get_type_id(), conn._env._errh, (void**)&colh, j+1);
- oci_check_error(conn._env, res);
-
- pColType++->init(conn._env._errh, colh);
- *pColIdx++ = j;
- }
-
- if (_sort_cols) {
- s_pcolTypes = pcolTypes; //@@ nicht threadsicher
- qsort(pColIdxs, num_cols, sizeof(int), cmp_col);
- }
-
- pColIdx = pColIdxs;
- for(j=0; j<num_cols; ++j) {
- int k = *pColIdx++;
- pColType = pcolTypes + k;
-
- pos.create("column");
-
- pos["name"] = pColType->_name;
- pos["type"] = pColType->get_type_str();
- XMLIntRef(pos, "pos") = k+1;
-
- pos.back(); // </column>
- }
-
- delete[] pColIdxs; pColIdxs = NULL;
- delete[] pcolTypes; pcolTypes = NULL;
-
-
- // Abfrage der Spaltenkommentare
- if (_comments) {
- SqlString comment, col_name;
-
- stmt.prepare("select COLUMN_NAME, COMMENTS from ALL_COL_COMMENTS "
- "where OWNER=:0 and TABLE_NAME=:1");
- stmt.bind_param(0, owner);
- stmt.bind_param(1, obj_name);
- stmt.bind_result(0, col_name);
- stmt.bind_result(1, comment);
-
- while(stmt.fetch()) {
- pos.smart_create("column", "name", col_name.c_str());
- pos.create("comment");
- pos->set_content(comment.c_str());
- pos.back();
- pos.back();
- }
- }
-
-
- // Abfrage der Dateninhalte
- if (_data) {
- pos.create("data");
-
- try {
- sprintf(buffer, "select * from %s.%s", schema, obj_name.c_str());
- stmt.execute(buffer);
- stmt.dump_results(buffer, pos, "row");
- } catch(exception& e) {
- cerr << "====>\n"
- "exception in dump of '" << obj_name << "' data: " << e.what() << endl <<
- "<====\n";
- }
-
- pos.back(); // </data>
- }
- } catch(exception& e) {
- cerr << "====>\n"
- "exception in getting info about '" << obj_name << "': " << e.what() << endl <<
- "<====\n";
-
- delete[] pColIdxs;
- delete[] pcolTypes;
- }
- }
-
- // tables
- if (info._type == OCI_PTYPE_TABLE) {
- eword tablespace;
- paramh.get_attribute(&tablespace, NULL, OCI_ATTR_TABLESPACE);
- pos["tablespace-nr"] = XMLInt(tablespace);
-
- ub1 typed, clustered, partitioned, index_only, temporary;
- paramh.get_attribute(&typed, NULL, OCI_ATTR_IS_TYPED);
- paramh.get_attribute(&clustered, NULL, OCI_ATTR_CLUSTERED);
- paramh.get_attribute(&partitioned, NULL, OCI_ATTR_PARTITIONED);
- paramh.get_attribute(&index_only, NULL, OCI_ATTR_INDEX_ONLY);
- paramh.get_attribute(&temporary, NULL, OCI_ATTR_IS_TEMPORARY);
-
- if (typed || clustered || partitioned || index_only || temporary) {
- pos["type"] = "extended";
- pos["typed"] = XMLBool(typed? true: false);
- pos["clustered"] = XMLBool(clustered? true: false);
- pos["partitioned"] = XMLBool(partitioned? true: false);
- pos["index_organized"] = XMLBool(index_only? true: false);
-
- if (temporary) {
- pos["temporary"] = XMLBool(temporary? true: false);
-
- OCIDuration duration;
- paramh.get_attribute(&duration, NULL, OCI_ATTR_DURATION);
-
- pos["temporary_duration"] =
- duration==OCI_DURATION_SESSION? "session":
- duration==OCI_DURATION_TRANS? "transaction":
- "NULL";
- }
- } else
- pos["type"] = "normal";
-
- // views
- } else if (info._type == OCI_PTYPE_VIEW) {
- stmt.prepare("select TEXT from ALL_VIEWS where OWNER=:0 and VIEW_NAME=:1");
- stmt.bind_param(0, owner);
- stmt.bind_param(1, obj_name);
- stmt.execute_fetch();
- string view_txt = stmt->get_string(0);
-
- pos.create("sql_text");
- pos->set_content(view_txt);
- pos.back(); // </sql_text>
-
- // synonyms
- } else if (info._type == OCI_PTYPE_SYN) {
- text *syn_schema, *syn_name, *syn_link;
- ub4 syn_schema_len, syn_name_len, syn_link_len;
-
- paramh.get_attribute(&syn_schema, &syn_schema_len, OCI_ATTR_SCHEMA_NAME);
- paramh.get_attribute(&syn_name, &syn_name_len, OCI_ATTR_NAME);
- paramh.get_attribute(&syn_link, &syn_link_len, OCI_ATTR_LINK);
-
- TCHAR* p = buffer + _stprintf(buffer, "%.*s.%.*s", syn_schema_len, syn_schema, syn_name_len, syn_name);
-
- if (syn_link)
- sprintf(p, "@%.*s", syn_link_len, syn_link);
-
- pos["target"] = buffer;
-
- // sequences
- } else if (info._type == OCI_PTYPE_SEQ) {
- ub1* num_ptr;
-
- ub4 num_len = 0;
- paramh.get_attribute(&num_ptr, &num_len, OCI_ATTR_MIN);
- pos["min"] = SqlNumber(num_ptr, num_len).str(conn._env._errh);
-
- num_len = 0;
- paramh.get_attribute(&num_ptr, &num_len, OCI_ATTR_MAX);
- pos["max"] = SqlNumber(num_ptr, num_len).str(conn._env._errh);
-
- num_len = 0;
- paramh.get_attribute(&num_ptr, &num_len, OCI_ATTR_INCR);
- pos["increment"] = SqlNumber(num_ptr, num_len).str(conn._env._errh);
-
- num_len = 0;
- paramh.get_attribute(&num_ptr, &num_len, OCI_ATTR_CACHE);
- pos["cache"] = SqlNumber(num_ptr, num_len).str(conn._env._errh);
-
- num_len = 0;
- paramh.get_attribute(&num_ptr, &num_len, OCI_ATTR_HW_MARK);
- pos["high-water-mark"] = SqlNumber(num_ptr, num_len).str(conn._env._errh);
-
- ub1 ordered;
- paramh.get_attribute(&ordered, NULL, OCI_ATTR_ORDER);
- pos["ordered"] = XMLBool(ordered? true: false);
- }
- } else {
- //cerr << OciException(conn._env._errh, __FILE__, __LINE__).what() << endl;
- }
-
- pos.back(); // </...>
- }
-
- pos.back(); // </objects>
-}
-*/
-
-
- // describe schema and write down the information immediatelly using XMLWriter
-void Dump::dump_schema(OciEnv& env, const LoginPara& lp, const TCHAR* schema, XMLWriter& writer)
-{
- OciLogin login(env, lp._username, lp._password, lp._tnsname);
- OciConnection conn(env, login);
-
- tstring owner = schema;
- _tcsupr_s((TCHAR*)owner.data(), owner.length()+1);
-
- writer.create("schema");
- writer["name"] = schema;
-
- writer.create("objects");
-
- // Erg\xE4nzung um Zusatzinformationen
- if (_info) {
- writer.create("info");
-
- time_t now = time(NULL); // problems in the year 2038
-#ifdef __STDC_WANT_SECURE_LIB__
- struct tm lct;
- localtime_s(&lct, &now);
- struct tm* plct = &lct;
-#else
- struct tm* plct = localtime(&now);
-#endif
- OciDate date(plct);
- writer["date"] = date.str();
- writer["dump"] = "xmldump 1.0";
-
- writer.create("connect");
- writer["username"] = lp._username;
- writer["tnsname"] = lp._tnsname;
- writer.back(); // </connect>
-
- if (_db_version) {
- writer.create("db-version");
- int oracle_ver = login._server._version;
- TCHAR ver_str[32];
- _stprintf(ver_str, _T("%d.%d.%d.%d.%d"),
- oracle_ver>>24, (oracle_ver>>20)&0xF,
- (oracle_ver>>16)&0xF, (oracle_ver>>8)&0xFF, oracle_ver&0xFF);
- writer["number"] = ver_str;
-
- writer.set_content((LPCTSTR)login._server._version_string);
- /*
- SqlStatement stmt(conn, "select BANNER from V$VERSION");
- //writer["main-string"] = stmt->get_string(0));
- while(stmt.fetch()) {
- writer.create("line");
- writer.set_content(stmt->get_string(0));
- writer.back(); </line>
- } */
- writer.back(); // </db-version>
- }
-
- if (_db_options) {
- writer.create("db-options");
- SqlStatement stmt(conn, _T("select PARAMETER, VALUE from V$OPTION"));
- stmt.dump_results(writer, "option");
- writer.back(); // </db-options>
- }
-
- writer.back(); // </info>
- }
-
- OciDescribe descr(conn._env);
- sword res = OCIDescribeAny(conn._svc_ctx, conn._env._errh,
- (void*)schema, _tcslen(schema)*sizeof(TOraText), OCI_OTYPE_NAME,
- OCI_DEFAULT, OCI_PTYPE_SCHEMA, descr);
- oci_check_error(conn._env, res);
-
- OciParam paramh(conn._env);
- descr.get_attribute(¶mh, NULL, OCI_ATTR_PARAM, conn._env._errh);
-
- OciParam objlisth(conn._env);
- paramh.get_attribute(&objlisth, NULL, OCI_ATTR_LIST_OBJECTS);
-
- ub2 num;
- objlisth.get_attribute(&num, NULL, OCI_ATTR_NUM_PARAMS);
-
- // automatische Sortierung der Objekte \xFCber ObjNameMap
- ObjNameMap obj_names;
-
- for(int i=0; i<num; ++i) {
- ObjInfo info;
- OciParam objh(conn._env);
- res = OCIParamGet(objlisth, OciParam::get_type_id(), conn._env._errh, (void**)&objh, i);
- oci_check_error(conn._env, res);
-
- OraText* name; ub4 name_len;
- objh.get_attribute(&name, &name_len, OCI_ATTR_OBJ_NAME);
- tstring obj_name((const TCHAR*)name, name_len);
-
- // filter by object name
- if (!_filter.empty() && _filter.find(obj_name)==_filter.end())
- continue;
-
- objh.get_attribute(&info._type, NULL, OCI_ATTR_PTYPE);
-
- if (info._type) { // no "unknown type" nodes
- tstring type_str = get_oci_ptype_str(info._type);
-
- // replace spaces by '-' for XML conformity
- TCHAR* p = (TCHAR*)type_str.data();
- for(; *p; ++p)
- if (istspace(*p))
- *p = '-';
-
- obj_names[make_pair(type_str, obj_name)] = info;
- }
- }
-
- SqlStatement stmt(conn);
- TCHAR buffer[BUFFER_LEN];
-
- for(ObjNameMap::const_iterator it=obj_names.begin(); it!=obj_names.end(); ++it) {
- const ObjIdent& ident = it->first;
- const tstring& type_str = ident.first;
- const tstring& obj_name = ident.second;
- const ObjInfo& info = it->second;
-
- writer.create(type_str);
- writer["name"] = obj_name;
-
- // Not avoidable to describe the object here again - now by name:
- // Seems, the descriptor handles overflow at some point, so we get an error (msg_id=-1) after some loops.
- OciDescribe obj_descr(conn._env);
- res = OCIDescribeAny(conn._svc_ctx, conn._env._errh, (OraText*)obj_name.c_str(), obj_name.length(), OCI_OTYPE_NAME, OCI_DEFAULT, info._type, obj_descr);
-
- if (res == OCI_SUCCESS) {
- OciParam paramh(conn._env);
- obj_descr.get_attribute(¶mh, NULL, OCI_ATTR_PARAM, conn._env._errh);
-
- // tables (write table attributes before of all subnodes)
- if (info._type == OCI_PTYPE_TABLE) {
- eword tablespace;
- paramh.get_attribute(&tablespace, NULL, OCI_ATTR_TABLESPACE);
- writer["tablespace-nr"] = XMLInt(tablespace);
-
- ub1 typed, clustered, partitioned, index_only, temporary;
- paramh.get_attribute(&typed, NULL, OCI_ATTR_IS_TYPED);
- paramh.get_attribute(&clustered, NULL, OCI_ATTR_CLUSTERED);
- paramh.get_attribute(&partitioned, NULL, OCI_ATTR_PARTITIONED);
- paramh.get_attribute(&index_only, NULL, OCI_ATTR_INDEX_ONLY);
- paramh.get_attribute(&temporary, NULL, OCI_ATTR_IS_TEMPORARY);
-
- if (typed || clustered || partitioned || index_only || temporary) {
- writer["type"] = "extended";
- writer["typed"] = XMLBool(typed? true: false);
- writer["clustered"] = XMLBool(clustered? true: false);
- writer["partitioned"] = XMLBool(partitioned? true: false);
- writer["index_organized"] = XMLBool(index_only? true: false);
-
- if (temporary) {
- writer["temporary"] = XMLBool(temporary? true: false);
-
- OCIDuration duration;
- paramh.get_attribute(&duration, NULL, OCI_ATTR_DURATION);
-
- writer["temporary_duration"] =
- duration==OCI_DURATION_SESSION? "session":
- duration==OCI_DURATION_TRANS? "transaction":
- "NULL";
- }
- } else
- writer["type"] = "normal";
- }
-
- // tables and views
- if (info._type==OCI_PTYPE_TABLE || info._type==OCI_PTYPE_VIEW) {
- // get table/view comments
- if (_comments) {
- SqlString comment;
-
- stmt.prepare(_T("select COMMENTS from ALL_TAB_COMMENTS ")
- _T("where OWNER=:0 and TABLE_NAME=:1"));
- stmt.bind_param(0, owner);
- stmt.bind_param(1, obj_name);
- stmt.bind_result(0, comment);
-
- if (stmt.fetch()) {
- writer.create("comment");
- writer.set_content(comment.c_str());
- writer.back();
- }
- }
-
- ColumnType* pcolTypes = NULL;
- int* pColIdxs = NULL;
-
- try {
- ub2 num_cols;
- paramh.get_attribute(&num_cols, NULL, OCI_ATTR_NUM_COLS);
-
- OciParam col_listh(conn._env);
- paramh.get_attribute(&col_listh, NULL, OCI_ATTR_LIST_COLUMNS);
-
- pcolTypes = new ColumnType[num_cols]; // Array der Spaltenbeschreibungen
- ColumnType* pColType = pcolTypes;
-
- pColIdxs = new int[num_cols]; // Array der Spalten-Indices
- int* pColIdx = pColIdxs;
-
- int j;
- for(j=0; j<num_cols; ++j) {
- OciParam colh(conn._env);
- res = OCIParamGet(col_listh, OciParam::get_type_id(), conn._env._errh, (void**)&colh, j+1);
- oci_check_error(conn._env, res);
-
- pColType++->init(conn._env._errh, colh);
- *pColIdx++ = j;
- }
-
- if (_sort_cols) {
- s_pcolTypes = pcolTypes; //@@ nicht threadsicher
- qsort(pColIdxs, num_cols, sizeof(int), cmp_col);
- }
-
- map<tstring, tstring> col_comments;
- map<tstring, tstring> col_default;
- SqlString col_name, comment, data_default;
-
- // Abfrage der Spaltenkommentare
- if (_comments) {
- stmt.prepare(_T("select COLUMN_NAME, COMMENTS ")
- _T("from ALL_COL_COMMENTS ")
- _T("where OWNER=:0 and TABLE_NAME=:1"));
-
- stmt.bind_param(0, owner);
- stmt.bind_param(1, obj_name);
-
- stmt.bind_result(0, col_name);
- stmt.bind_result(1, comment);
-
- while(stmt.fetch())
- if (comment.is_not_null())
- col_comments[col_name.c_str()] = comment;
- }
-
- if (true) {
- stmt.prepare(_T("select COLUMN_NAME, DATA_DEFAULT ")
- _T("from ALL_TAB_COLUMNS ")
- _T("where OWNER=:0 and TABLE_NAME=:1"));
-
- stmt.bind_param(0, owner);
- stmt.bind_param(1, obj_name);
-
- stmt.bind_result(0, col_name);
- stmt.bind_result(1, data_default);
-
- while(stmt.fetch())
- if (data_default.is_not_null())
- col_default[col_name.c_str()] = data_default;
- }
-
- pColIdx = pColIdxs;
- for(j=0; j<num_cols; ++j) {
- int k = *pColIdx++;
- pColType = pcolTypes + k;
-
- writer.create("column");
-
- writer["name"] = pColType->_name;
- writer["type"] = pColType->get_type_str();
-
- if (_col_pos)
- writer["pos"] = XMLInt(k+1);
-
- map<tstring, tstring>::const_iterator found = col_default.find(pColType->_name);
-
- if (found != col_default.end())
- writer["default"] = found->second.c_str();
-
- // Ausgabe des Spaltenkommentars
- if (_comments) {
- found = col_comments.find(pColType->_name);
-
- if (found != col_comments.end()) {
- writer.create("comment");
- writer.set_content(found->second.c_str());
- writer.back();
- }
- }
-
- writer.back(); // </column>
- }
-
- delete[] pColIdxs; pColIdxs = NULL;
- delete[] pcolTypes; pcolTypes = NULL;
-
-
- // Abfrage der Dateninhalte
- if (_data) {
- writer.create("data");
-
- try {
- _stprintf(buffer, _T("select * from %s.%s"), schema, obj_name.c_str());
- stmt.execute(buffer);
- stmt.dump_results(buffer, writer, "row");
- } catch(exception& e) {
- cerr << "====>\n"
- "exception in dump of '" << ANSI_STRING(obj_name) << "' data: " << e.what() << endl <<
- "<====\n";
- }
-
- writer.back(); // </data>
- }
- } catch(exception& e) {
- cerr << "====>\n"
- "exception in getting info about '" << ANSI_STRING(obj_name) << "': " << e.what() << endl <<
- "<====\n";
-
- delete[] pColIdxs;
- delete[] pcolTypes;
- }
- }
-
- // views
- if (info._type == OCI_PTYPE_VIEW) {
- stmt.prepare(_T("select TEXT from ALL_VIEWS where OWNER=:0 and VIEW_NAME=:1"));
- stmt.bind_param(0, owner);
- stmt.bind_param(1, obj_name);
- stmt.execute_fetch();
- tstring view_txt = stmt->get_string(0, 0);
-
- writer.create("sql_text");
- writer.set_content(view_txt);
- writer.back(); // </sql_text>
-
- // synonyms
- } else if (info._type == OCI_PTYPE_SYN) {
- text *syn_schema, *syn_name, *syn_link;
- ub4 syn_schema_len, syn_name_len, syn_link_len;
-
- paramh.get_attribute(&syn_schema, &syn_schema_len, OCI_ATTR_SCHEMA_NAME);
- paramh.get_attribute(&syn_name, &syn_name_len, OCI_ATTR_NAME);
- paramh.get_attribute(&syn_link, &syn_link_len, OCI_ATTR_LINK);
-
- int l = _stprintf(buffer, _T("%.*s.%.*s"), syn_schema_len, syn_schema, syn_name_len, syn_name);
- TCHAR* p = buffer + l;
-
- if (syn_link)
-#ifdef __STDC_WANT_SECURE_LIB__
- _stprintf_s(p, COUNTOF(buffer)-l,
-#else
- _stprintf(p,
-#endif
- _T("@%.*s"), syn_link_len, syn_link);
-
- writer["target"] = buffer;
-
- // sequences
- } else if (info._type == OCI_PTYPE_SEQ) {
- ub1* num_ptr;
-
- ub4 num_len = 0;
- paramh.get_attribute(&num_ptr, &num_len, OCI_ATTR_MIN);
- writer["min"] = SqlNumber(num_ptr, num_len).str(conn._env._errh);
-
- num_len = 0;
- paramh.get_attribute(&num_ptr, &num_len, OCI_ATTR_MAX);
- writer["max"] = SqlNumber(num_ptr, num_len).str(conn._env._errh);
-
- num_len = 0;
- paramh.get_attribute(&num_ptr, &num_len, OCI_ATTR_INCR);
- writer["increment"] = SqlNumber(num_ptr, num_len).str(conn._env._errh);
-
- num_len = 0;
- paramh.get_attribute(&num_ptr, &num_len, OCI_ATTR_CACHE);
- writer["cache"] = SqlNumber(num_ptr, num_len).str(conn._env._errh);
-
- if (_seq_val) {
- num_len = 0;
- paramh.get_attribute(&num_ptr, &num_len, OCI_ATTR_HW_MARK);
- writer["high-water-mark"] = SqlNumber(num_ptr, num_len).str(conn._env._errh);
- }
-
- ub1 ordered;
- paramh.get_attribute(&ordered, NULL, OCI_ATTR_ORDER);
- writer["ordered"] = XMLBool(ordered? true: false);
- }
- } else {
- //cerr << OciException(conn._env._errh, __FILE__, __LINE__).what() << endl;
- }
-
- if (_grants) {
- // query grants given to this object
- stmt.prepare(_T("select GRANTEE, PRIVILEGE ")
- _T("from ALL_TAB_PRIVS ")
- _T("where GRANTOR=:0 and TABLE_NAME=:1 ")
- _T("order by GRANTEE, PRIVILEGE"));
-
- writer.create("grants");
- SqlString grantee, privilege;
-
- stmt.bind_param(0, owner);
- stmt.bind_param(1, obj_name);
-
- stmt.bind_result(0, grantee);
- stmt.bind_result(1, privilege);
-
- while(stmt.fetch()) {
- writer.create("grant");
- writer["grantee"] = grantee;
- writer["privilege"] = privilege;
- writer.back(); // </grant>
- }
- writer.back(); // </grants>
- }
-
- writer.back(); // </...>
- }
-
- writer.back(); // </objects>
-
- try {
- stmt.prepare(_T("select TS#, NAME from V$TABLESPACE"));
- stmt.execute(); // throw exception immediatelly if we don't have access to the system view
-
- writer.create("tablespaces");
- SqlInt ts_nr;
- SqlString ts_name;
-
- stmt.bind_result(0, ts_nr);
- stmt.bind_result(1, ts_name);
-
- while(stmt.fetch()) {
- writer.create("tablespace");
- writer["nr"] = XMLInt(ts_nr);
- writer["name"] = ts_name;
- writer.back();
- }
- writer.back(); // </tablespaces>
- } catch(exception&) {
- // ignore access right exceptions cerr << "Exception: " << e.what() << "\n";
- }
-
- writer.back(); // </schema>
-}
-
-
} // namespace OCIPL
Modified: trunk/ocipl/ocipl.cpp
===================================================================
--- trunk/ocipl/ocipl.cpp 2007-10-28 14:50:00 UTC (rev 35)
+++ trunk/ocipl/ocipl.cpp 2007-10-28 15:08:59 UTC (rev 36)
@@ -2,7 +2,7 @@
//
// ocipl.cpp
//
- // Copyright (c) 2003, 2004, 2005, 2006 Martin Fuchs <mar...@gm...>
+ // Copyright (c) 2003, 2004, 2005, 2006, 2007 Martin Fuchs <mar...@gm...>
//
// OCIPL Version 1.3
//
@@ -39,8 +39,8 @@
*/
-#ifndef _NO_COMMENT
-#define _NO_COMMENT // no #pragma comment(lib, ...) statements in .lib files -> free selection of orasql library
+#ifndef OCIPL_NO_COMMENT
+#define OCIPL_NO_COMMENT // no #pragma comment(lib, ...) statements in .lib files -> free selection of orasql library
#endif
#define _olint // for #define CONST const
@@ -350,20 +350,24 @@
boolean isInt;
sword res = OCINumberIsInt(errh, (OCINumber*)&val, &isInt);
- if (res==OCI_SUCCESS && isInt) {
+ if (res==OCI_SUCCESS && isInt)
+ {
res = OCINumberToInt(errh, (OCINumber*)&val, sizeof(x), OCI_NUMBER_SIGNED, &x);
oci_check_error(errh, res);
- } else {
- double d = number_to_double(val, errh);
-
- x = int(d + .5);
}
+ else
#else
// OCI.DLL of Oracle Version 8.0
sword res = OCINumberToInt(errh, (OCINumber*)&val, sizeof(x), OCI_NUMBER_SIGNED, &x);
- oci_check_error(errh, res);
+
+ if (res != OCI_SUCCESS)
#endif
+ {
+ double d = number_to_double(val, errh);
+ x = int(d + .5);
+ }
+
//x = atoi(str(true).c_str());
return x;
@@ -421,19 +425,22 @@
SqlNumber::SqlNumber(OCIError* errh, const TCHAR* str, const TCHAR* fmt, const TCHAR* nls_fmt)
{
- while(str && istspace(*str))
- ++str;
+ if (str) {
+ while(istspace(*str))
+ ++str;
- if (str && *str) {
- sword res = OCINumberFromText(errh,
- (const OraText*)str, (ub4)_tcslen(str)*sizeof(TOraText),
- (const OraText*)fmt, (ub4)_tcslen(fmt)*sizeof(TOraText),
- (const OraText*)nls_fmt, (ub4)_tcslen(nls_fmt)*sizeof(TOraText),
- (OCINumber*)&_val);
+ if (*str) {
+ sword res = OCINumberFromText(errh,
+ (const OraText*)str, (ub4)_tcslen(str)*sizeof(TOraText),
+ (const OraText*)fmt, (ub4)_tcslen(fmt)*sizeof(TOraText),
+ (const OraText*)nls_fmt, (ub4)_tcslen(nls_fmt)*sizeof(TOraText),
+ (OCINumber*)&_val);
- oci_check_error(errh, res);
+ oci_check_error(errh, res);
- _ind.set();
+ _ind.set();
+ } else
+ _ind.clear();
} else
_ind.clear();
}
@@ -566,6 +573,21 @@
return buffer;
}
+tstring ocidate_to_short_string(const OCIDate& date)
+{
+ TCHAR buffer[40];
+
+#ifdef __STDC_WANT_SECURE_LIB__
+ _stprintf_s(buffer, _countof(buffer),
+#else
+ _stprintf(buffer,
+#endif
+ _T("%02d.%02d.%04d"),
+ date.OCIDateDD, date.OCIDateMM, date.OCIDateYYYY);
+
+ return buffer;
+}
+
struct tm* ocidate_to_gmt(const OCIDate& date)
{
struct tm ltime = {
@@ -652,17 +674,21 @@
ind().set();
}
-OciDate::OciDate(OCIError* errh, const TCHAR* str)
+OciDate::OciDate(OCIError* errh, const TCHAR* str, const TCHAR* fmt)
{
- while(str && istspace(*str))
- ++str;
+ if (str) {
+ while(istspace(*str))
+ ++str;
- if (str && *str) {
- sword res = OCIDateFromText(errh, (const OraText*)str, (ub4)_tcslen(str)*sizeof(TOraText), NULL/*fmt*/, 0, NULL/*lang*/, 0, this);
+ if (*str) {
+ sword res = OCIDateFromText(errh, (const OraText*)str, (ub4)_tcslen(str)*sizeof(TOraText),
+ (const OraText*)fmt, (ub4)_tcslen(fmt)*sizeof(TOraText), NULL/*lang*/, 0, this);
- oci_check_error(errh, res);
+ oci_check_error(errh, res);
- _ind.set();
+ _ind.set();
+ } else
+ _ind.clear();
} else
_ind.clear();
}
@@ -913,7 +939,7 @@
delete _res;
_res = NULL;
- _state = (_state|DEFINED) & ~FETCHED;
+ _state = (_state|DEFINED) & ~(FETCHED|EOF_DATA);
} else
_state |= DEFINED;
@@ -923,54 +949,43 @@
}
-bool SqlStatement::execute(ub4 rows, ub4 mode)
+void SqlStatement::execute(ub4 rows, ub4 mode)
{
- if (!(_state & DEFINED)) {
- ub2 stmt_type = get_stmt_type();
+ // a SELECT statement without ready defined variables?
+ if (!(_state&DEFINED) && get_stmt_type()==OCI_STMT_SELECT) {
+ execute_internal(0, mode);
- // a SELECT statement without ready define variables?
- if (stmt_type == OCI_STMT_SELECT) {
- bool ret = execute_internal(0, mode);
+ // define resultset variables
+ assert(!_res);
- // define resultset variables
- assert(!_res);
-
- if (rows > 0) {
- _res = new SqlResult(*this, rows);
- return fetch(rows);
- } else {
- _res = new SqlResult(*this, _bulk_rows);
- return ret;
- }
+ if (rows > 0) {
+ _res = new SqlResult(*this, rows);
+ fetch(rows);
+ } else {
+ _res = new SqlResult(*this, _bulk_rows);
}
- }
-
- return execute_internal(rows, mode);
+ } else
+ execute_internal(rows, mode);
}
-bool SqlStatement::execute_fetch(ub4 mode)
+void SqlStatement::execute_fetch(ub4 mode)
{
- if (!(_state & DEFINED)) {
- ub2 stmt_type = get_stmt_type();
+ // A SELECT statement without ready defined variables?
+ if (!(_state&DEFINED) && get_stmt_type()==OCI_STMT_SELECT) {
+ execute_internal(0, mode);
- // A SELECT statement without ready define variables?
- if (stmt_type == OCI_STMT_SELECT) {
- bool ret = execute_internal(0, mode);
+ // define resultset variables
+ assert(!_res);
+ _res = new SqlResult(*this, _bulk_rows);
- // define resultset variables
- assert(!_res);
- _res = new SqlResult(*this, _bulk_rows);
-
- return fetch(_result_buffers);
- }
- }
-
- return execute_internal(_result_buffers, mode);
+ fetch(_result_buffers);
+ } else
+ execute_internal(_result_buffers, mode);
}
-bool SqlStatement::execute_internal(ub4 rows, ub4 mode)
+void SqlStatement::execute_internal(ub4 rows, ub4 mode)
{
if (rows==0 && get_stmt_type()==OCI_STMT_SELECT) {
// Optimizing of TCP packets by transfering multiple datasets in one packet
@@ -991,26 +1006,26 @@
if (res == OCI_NO_DATA) {
_state |= EOF_DATA;
- return false; // There are no additional rows pending to be fetched.
+
+ // There are no additional rows pending to be fetched.
} else if (res == OCI_ERROR) {
_state = STMT_ERROR;
//throw OCI_EXCEPTION(_env._errh, *this, __FILE__, __LINE__);
throw_ocipl_exception(OciException(_env._errh, *this, __FILE__, __LINE__));
- //return false; // not reached
} else {
if (rows > 0)
_state |= EXECUTED|FETCHED;
else
- _state = (_state|EXECUTED) & ~FETCHED;
+ _state = (_state|EXECUTED) & ~(FETCHED|EOF_DATA);
oci_check_error(_env, res);
- return true; // There may be more rows available to be fetched (for queries) or the DML statement succeeded.
+ // There may be more rows available to be fetched (for queries) or the DML statement succeeded.
}
}
-bool SqlStatement::fetch(ub4 rows/*=-1*/)
+void SqlStatement::fetch(ub4 rows/*=-1*/)
{
if (!(_state & EXECUTED)) {
if (rows == -1)
@@ -1019,28 +1034,30 @@
else
rows = _result_buffers;
- return execute(rows);
- }
+ execute(rows);
+ } else {
+ if (rows == -1)
+ rows = _result_buffers;
- if (rows == -1)
- rows = _result_buffers;
-
#if ORACLE_VERSION>=90
- sword res = OCIStmtFetch2(_handle, _env._errh, rows, OCI_FETCH_NEXT, 0, OCI_DEFAULT);
+ sword res = OCIStmtFetch2(_handle, _env._errh, rows, OCI_FETCH_NEXT, 0, OCI_DEFAULT);
#else
- sword res = OCIStmtFetch(_handle, _env._errh, rows, OCI_FETCH_NEXT, OCI_DEFAULT);
+ sword res = OCIStmtFetch(_handle, _env._errh, rows, OCI_FETCH_NEXT, OCI_DEFAULT);
#endif
- _last_row = _last_fetched_row;
- _last_fetched_row = row_count();
+ _last_row = _last_fetched_row;
+ _last_fetched_row = row_count();
- if (res != OCI_NO_DATA) { // more data available or did there occur an error?
- _state |= FETCHED;
- oci_check_error(_env, res);
- return true; // There may be more rows available to be fetched.
- } else {
- _state |= EOF_DATA;
- return false; // There are no additional rows pending to be fetched.
+ if (res != OCI_NO_DATA) { // more data available or did there occur an error?
+ _state |= FETCHED;
+ oci_check_error(_env, res);
+
+ // There may be more rows available to be fetched.
+ } else {
+ _state |= EOF_DATA;
+
+ // There are no additional rows pending to be fetched.
+ }
}
}
@@ -1324,7 +1341,7 @@
break;
case OCI_TYPECODE_VARCHAR:
- _string = new SqlString(*other._string, 2000/*blen*/);
+ _string = new SqlString(*other._string, OCIPL_DEFAULT_STRING_BUFFER/*blen*/);
break;
case OCI_TYPECODE_NUMBER:
@@ -1350,7 +1367,7 @@
break;
*/
case SQLT_LNG:
- _string = new SqlString(*other._string, 2000/*blen*/); //@@
+ _string = new SqlString(*other._string, OCIPL_DEFAULT_STRING_BUFFER/*blen*/); //@@
break;
default:
@@ -1587,7 +1604,7 @@
#endif // SqlVariant
-SqlVariantArray::SqlVariantArray(ub2 data_type, int size)
+SqlVariantArray::SqlVariantArray(ub2 data_type, int size, int blen)
{
_data_type = data_type;
@@ -1597,7 +1614,7 @@
// fall through
case OCI_TYPECODE_VARCHAR:
- _pstring = new SqlStringArray(size);
+ _pstring = new SqlStringArray(size, blen);
break;
case OCI_TYPECODE_NUMBER:
@@ -1623,7 +1640,7 @@
*/
#endif
case SQLT_LNG:
- _pstring = new SqlStringArray(size); //@@
+ _pstring = new SqlStringArray(size, blen); //@@
break;
default:
Modified: trunk/ocipl/ocipl.h
===================================================================
--- trunk/ocipl/ocipl.h 2007-10-28 14:50:00 UTC (rev 35)
+++ trunk/ocipl/ocipl.h 2007-10-28 15:08:59 UTC (rev 36)
@@ -2,7 +2,7 @@
//
// ocipl.h
//
- // Copyright (c) 2003, 2004, 2005, 2006 Martin Fuchs <mar...@gm...>
+ // Copyright (c) 2003, 2004, 2005, 2006, 2007 Martin Fuchs <mar...@gm...>
//
// OCIPL Version 1.3
//
@@ -42,7 +42,17 @@
#ifndef _OCIPL_H
-#ifdef WIN32
+#ifdef UNICODE
+#ifndef _UNICODE
+#define _UNICODE
+#endif
+#else
+#ifdef _UNICODE
+#define UNICODE
+#endif
+#endif
+
+#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
@@ -73,8 +83,8 @@
#define _strupr_s(b, s) strupr(b)
#endif
-#ifndef _itoa_s
-#define _itoa_s(x, b, l, r) (_itoa(x, b, r)? 0: EINVAL)
+#ifndef _itot_s
+#define _itot_s(x, b, l, r) (_itot(x, b, r)? 0: EINVAL)
#endif
#endif
@@ -141,7 +151,7 @@
#ifdef _MSC_VER
#include <minmax.h>
-#ifndef _NO_COMMENT
+#ifndef OCIPL_NO_COMMENT
#pragma comment(lib, "oci")
#if defined(_DEBUG) && defined(_DLL) // DEBUG version only supported with MSVCRTD
@@ -169,7 +179,7 @@
#endif
#endif
-#endif // _NO_COMMENT
+#endif // OCIPL_NO_COMMENT
#endif // _MSC_VER
@@ -179,7 +189,11 @@
// default bulk fetch size
extern int g_OCIPL_BULK_ROWS;
+ // default string buffer size
+#define OCIPL_DEFAULT_STRING_BUFFER 2000
+
+#ifndef istspace
inline int istspace(TCHAR c)
{
#ifdef _UNICODE
@@ -188,6 +202,7 @@
return isspace((unsigned char)c);
#endif
}
+#endif
struct SqlStatement;
@@ -555,13 +570,6 @@
__declspec(noreturn) void throw_ocipl_exception(OciException& e);
-/*
-#ifndef OCI_EXCEPTION
-#define OCI_EXCEPTION OCIPL::OciException
-#endif
-
-#define THROW_OCI_EXCEPTION(par) throw OCI_EXCEPTION(par, __FILE__, __LINE__)
-*/
#define THROW_OCI_EXCEPTION(par) throw_ocipl_exception(OCIPL::OciException(par, __FILE__, __LINE__))
@@ -616,8 +624,10 @@
OracleServer(OciEnv& env)
: super(env)
{
+#if ORACLE_VERSION>=82
+ _version = 0;
+#endif
_version_string[0] = '\0';
- _version = 0;
}
~OracleServer()
@@ -645,7 +655,9 @@
oci_check_error(_env, res);
}
+#if ORACLE_VERSION>=82
ub4 _version; // e.g. 0x9200500
+#endif
TCHAR _version_string[2000];
};
@@ -682,13 +694,13 @@
{
typedef OciHandle<OCISvcCtx> super;
- OciLogin(OciEnv& env, const LoginPara& login_para, ub4 mode=OCI_DEFAULT)
+ OciLogin(OciEnv& env, const LoginPara& login_para)
: super(env),
_server(env),
_session(env),
_connected(false)
{
- connect(login_para._username, login_para._password, login_para._tnsname, mode);
+ connect(login_para._username, login_para._password, login_para._tnsname, login_para._mode);
}
OciLogin(OciEnv& env, const tstring& username, const tstring& password, const tstring& tnsname, ub4 mode=OCI_DEFAULT)
@@ -872,7 +884,7 @@
struct SqlInd
{
- SqlInd(OCIInd ind=-1)
+ SqlInd(OCIInd ind=OCI_IND_NULL)
: _ind(ind)
{
}
@@ -880,11 +892,11 @@
operator OCIInd() const {return _ind;}
operator OCIInd*() {return &_ind;}
- bool is_null() const {return _ind==-1;}
- bool is_not_null() const {return _ind!=-1;}
+ bool is_null() const {return _ind==OCI_IND_NULL;}
+ bool is_not_null() const {return _ind!=OCI_IND_NULL;}
- void clear() {_ind = -1;}
- void set() {_ind = 0;}
+ void clear() {_ind = OCI_IND_NULL;}
+ void set() {_ind = OCI_IND_NOTNULL;}
protected:
OCIInd _ind; // short
@@ -896,6 +908,7 @@
struct SqlValue
{
SqlValue() {}
+ SqlValue(OCIInd ind) : _ind(ind) {}
SqlValue(const SqlValue& other) : _ind(other._ind) {}
bool is_null() const {return _ind.is_null();}
@@ -928,6 +941,11 @@
memcpy(_pind, other._pind, other._count*sizeof(SqlInd));
}
+ ~SqlIndArray()
+ {
+ delete [] _pind;
+ }
+
bool is_null(int idx) const {return _pind[idx].is_null();}
bool is_not_null(int idx) const {return _pind[idx].is_not_null();}
@@ -956,6 +974,12 @@
_ind.set();
}
+ SqlInt(int value, OCIInd ind)
+ : SqlValue(ind),
+ _value(value)
+ {
+ }
+
SqlInt(const SqlInt& other)
: SqlValue(other),
_value(other._value)
@@ -970,7 +994,7 @@
TCHAR buffer[16];
if (_ind.is_not_null()) {
- _itoa_s(_value, buffer, sizeof(buffer)/sizeof(TCHAR), 10);
+ _itot_s(_value, buffer, sizeof(buffer)/sizeof(TCHAR), 10);
return buffer;
} else
return tstring();
@@ -1003,7 +1027,7 @@
free(_pvalues);
}
- int get_int(int row) const {return _pind[row].is_not_null()? _pvalues[row]: INT_NULL;}
+ int get_int(int row, int null=INT_NULL) const {return _pind[row].is_not_null()? _pvalues[row]: null;}
int* get_ref(int row) {return &_pvalues[row];}
tstring str(int row) const
@@ -1011,7 +1035,7 @@
TCHAR buffer[16];
if (_pind[row].is_not_null()) {
- _itoa_s(_pvalues[row], buffer, sizeof(buffer)/sizeof(TCHAR), 10);
+ _itot_s(_pvalues[row], buffer, sizeof(buffer)/sizeof(TCHAR), 10);
return buffer;
} else
return tstring();
@@ -1026,7 +1050,7 @@
struct SqlString : public SqlValue
{
- SqlString(int blen=2000)
+ SqlString(int blen=OCIPL_DEFAULT_STRING_BUFFER)
: _blen(blen),
_str((TCHAR*)malloc((blen+1)*sizeof(TCHAR)))
{
@@ -1045,7 +1069,7 @@
: _blen(blen),
_str((TCHAR*)malloc((blen+1)*sizeof(TCHAR)))
{
- tcscpyn(_str, s, blen+1);
+ ocipl_tcscpyn(_str, s, blen+1);
if (*s)
_ind.set();
@@ -1082,18 +1106,8 @@
friend tostream& operator<<(tostream& os, const SqlString& str)
{if (str.is_not_null()) os << str._str; return os;}
- static inline TCHAR* strcpyn(TCHAR* dest, const TCHAR* source, size_t count)
+ static inline TCHAR* ocipl_tcscpyn(TCHAR* dest, const TCHAR* source, size_t count)
{
- char* d = dest;
-
- for(const char* s=source; count&&(*d++=*s++); )
- count--;
-
- return dest;
- }
-
- static inline TCHAR* tcscpyn(TCHAR* dest, const TCHAR* source, size_t count)
- {
TCHAR* d = dest;
for(const TCHAR* s=source; count&&(*d++=*s++); )
@@ -1112,7 +1126,7 @@
struct SqlStringArray : public SqlIndArray
{
- SqlStringArray(int size=g_OCIPL_BULK_ROWS, int blen=2000)
+ SqlStringArray(int size=g_OCIPL_BULK_ROWS, int blen=OCIPL_DEFAULT_STRING_BUFFER)
: SqlIndArray(size),
_blen(blen),
_buffer((TCHAR*)malloc(size*(blen+1)*sizeof(TCHAR)))
@@ -1149,6 +1163,7 @@
extern tstring ocidate_to_string(const OCIDate& date);
+extern tstring ocidate_to_short_string(const OCIDate& date);
extern struct tm* ocidate_to_gmt(const OCIDate& date);
extern struct tm* ocidate_to_lctime(const OCIDate& date);
extern time_t ocidate_to_time_t(const OCIDate& date);
@@ -1160,7 +1175,7 @@
{
OciDate() {}
OciDate(const OCIDate& date);
- OciDate(OCIError* errh, const TCHAR* str);
+ OciDate(OCIError* errh, const TCHAR* str, const TCHAR* fmt=_T("dd.mm.yyyy"));
OciDate(struct tm* t);
tstring str() const
@@ -1171,6 +1186,14 @@
return tstring();
}
+ tstring short_str() const
+ {
+ if (_ind.is_not_null())
+ return ocidate_to_short_string(*this);
+ else
+ return tstring();
+ }
+
int get_int_date() const
{
if (_ind.is_not_null())
@@ -1222,6 +1245,7 @@
free(_buffers);
}
+ const OCIDate& get_date(int row) const {return _buffers[row];}
OCIDate* get_ref(int row) {return &_buffers[row];}
tstring str(int row) const
@@ -1232,6 +1256,14 @@
return tstring();
}
+ tstring short_str(int row) const
+ {
+ if (_pind[row].is_not_null())
+ return ocidate_to_short_string(_buffers[row]);
+ else
+ return tstring();
+ }
+
int get_int_date(int row) const
{
if (_pind[row].is_not_null()) {
@@ -2416,51 +2448,69 @@
void bind_result(struct SqlRecord& rec);
- bool ensure_execute()
- {
- if (!(_state & EXECUTED))
- return execute();
+ // execute a prepared SQL statement
- return !eof();
- }
-
- bool execute()
+ void execute()
{
int rows = get_stmt_type()==OCI_STMT_SELECT? 0: 1;
- return execute(rows);
+ execute(rows);
}
- bool execute(ub4 rows, ub4 mode=OCI_DEFAULT);
+ void execute(ub4 rows, ub4 mode=OCI_DEFAULT);
- bool execute(const tstring& sql)
+ void execute(const tstring& sql)
{
prepare(sql);
int rows = get_stmt_type()==OCI_STMT_SELECT? 0: 1;
- return execute(rows);
+ execute(rows);
}
- bool execute(const tstring& sql, ub4 rows)
+ void execute(const tstring& sql, ub4 rows)
{
prepare(sql);
- return execute(rows);
+ execute(rows);
}
- bool execute_fetch(ub4 mode=OCI_DEFAULT);
+ void ensure_execute()
+ {
+ if (!(_state & EXECUTED))
+ execute();
+ }
- bool execute_fetch(const tstring& sql, ub4 lang=OCI_NTV_SYNTAX, ub4 mode=OCI_DEFAULT)
+
+ // execute a SQL statement and fetch rows of the result set (default number of rows: _bulk_rows)
+
+ void execute_fetch(ub4 mode=OCI_DEFAULT);
+
+ void execute_fetch(const tstring& sql, ub4 lang=OCI_NTV_SYNTAX, ub4 mode=OCI_DEFAULT)
{
prepare(sql, lang);
- return execute_fetch(mode);
+ execute_fetch(mode);
}
- bool fetch(ub4 rows=-1);
+ // fetch the next rows of a result set (default number of rows: _bulk_rows)
+ void fetch(ub4 rows=-1);
+
+ // next() is used to iterate through result sets without using bulk mode fetching.
+
+ bool next()
+ {
+ if (!eof()) {
+ fetch(1);
+
+ return fetched_rows() > 0;
+ } else
+ return false;
+ }
+
+
// utility functions for bulk mode fetching
int first_bulk()
@@ -2499,7 +2549,9 @@
void print_results(const tstring& sql, tostream& out, bool header=true)
{
- if (execute(sql))
+ execute(sql);
+
+ if (!eof())
print_results(out, header);
}
@@ -2519,13 +2571,17 @@
void dump_results(const tstring& sql, XMLStorage::XMLPos& pos, const XMLStorage::XS_String& element_name)
{
- if (execute(sql))
+ execute(sql);
+
+ if (!eof())
dump_results(pos, element_name);
}
void dump_results(const tstring& sql, XMLStorage::XMLWriter& writer, const XMLStorage::XS_String& element_name)
{
- if (execute(sql))
+ execute(sql);
+
+ if (!eof())
dump_results(writer, element_name);
}
#endif
@@ -2540,7 +2596,7 @@
}
protected:
- bool execute_internal(ub4 rows, ub4 mode);
+ void execute_internal(ub4 rows, ub4 mode);
ub4 _last_row;
ub4 _last_fetched_row;
@@ -2669,7 +2725,7 @@
_punion_ptr = NULL;
}
- SqlVariantArray(ub2 data_type, int size);
+ SqlVariantArray(ub2 data_type, int size, int blen=OCIPL_DEFAULT_STRING_BUFFER);
SqlVariantArray(const SqlVariantArray& other);
~SqlVariantArray() {clear();}
@@ -3070,46 +3126,6 @@
extern const TCHAR* get_oci_ptype_str(ub1 type);
-#ifdef _XMLSTORAGE_H
-
-struct Dump {
- bool _info : 1;
- bool _db_version : 1;
- bool _db_options : 1;
-
- bool _tables : 1;
- bool _views : 1;
- bool _comments : 1;
- bool _grants : 1;
- bool _data : 1;
- bool _col_pos : 1;
- bool _seq_val : 1;
-
- bool _sort_cols : 1;
-
- std::set<tstring> _filter;
-
- Dump()
- {
- _info = true;
- _db_version = true;
- _db_options = false;
- _tables = true;
- _views = true;
- _comments = true;
- _grants = true;
- _data = false;
- _col_pos = true;
- _seq_val = true;
- _sort_cols = true;
- }
-
- //void dump_schema(OciConnection& conn, const TCHAR* schema, XMLStorage::XMLPos& pos);
- void dump_schema(OciEnv& env, const LoginPara& lp, const TCHAR* schema, XMLStorage::XMLWriter& writer);
-};
-
-#endif
-
} // namespace OCIPL
#define _OCIPL_H
Modified: trunk/ocipl/ocithrow.cpp
===================================================================
--- trunk/ocipl/ocithrow.cpp 2007-10-28 14:50:00 UTC (rev 35)
+++ trunk/ocipl/ocithrow.cpp 2007-10-28 15:08:59 UTC (rev 36)
@@ -37,8 +37,8 @@
*/
-#ifndef _NO_COMMENT
-#define _NO_COMMENT // no #pragma comment(lib, ...) statements in .lib files -> free selection of orasql library
+#ifndef OCIPL_NO_COMMENT
+#define OCIPL_NO_COMMENT // no #pragma comment(lib, ...) statements in .lib files -> free selection of orasql library
#endif
#define _olint // for #define CONST const
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|