Date: Thursday, January 19, 2006 @ 17:39:36
Author: marc
Path: /cvsroot/carob/odbsequoia
Modified: odbc.ini (1.1 -> 1.2) src/abstract_item.cpp (1.5 -> 1.6)
src/abstract_item.hpp (1.9 -> 1.10) src/connect.cpp (1.9 ->
1.10) src/inst.hpp (1.2 -> 1.3) src/simpletest.c (1.9 -> 1.10)
src/stmt.cpp (1.10 -> 1.11) src/stmt.hpp (1.7 -> 1.8)
Major GetDiag rework. Implemented _PROTECT_SQLRETURN generic exception catcher
(as a macro). Added brackets [vendor][driver][DSN] prefixes.
-----------------------+
odbc.ini | 2 -
src/abstract_item.cpp | 11 ++++++++++
src/abstract_item.hpp | 51 +++++++++++++++++++++++++++++++++++++++++++-----
src/connect.cpp | 32 +++++++++++++++++++++---------
src/inst.hpp | 2 +
src/simpletest.c | 27 +++++++++++++++++++------
src/stmt.cpp | 31 +++++++++++------------------
src/stmt.hpp | 10 ++++++++-
8 files changed, 125 insertions(+), 41 deletions(-)
Index: odbsequoia/odbc.ini
diff -u odbsequoia/odbc.ini:1.1 odbsequoia/odbc.ini:1.2
--- odbsequoia/odbc.ini:1.1 Thu Jan 12 21:25:13 2006
+++ odbsequoia/odbc.ini Thu Jan 19 17:39:36 2006
@@ -22,4 +22,4 @@
UserName = user
Password =
Port = 25322
-
+BackendIdentifiers = [postgresql.org][PG]
Index: odbsequoia/src/abstract_item.cpp
diff -u odbsequoia/src/abstract_item.cpp:1.5
odbsequoia/src/abstract_item.cpp:1.6
--- odbsequoia/src/abstract_item.cpp:1.5 Tue Jan 17 14:23:04 2006
+++ odbsequoia/src/abstract_item.cpp Thu Jan 19 17:39:36 2006
@@ -156,6 +156,17 @@
return SQL_ERROR;
}
+
+void
+ODBCItem::push_diag_chain(const std::wstring& prefix, const
CarobNS::CarobException& ce)
+{
+ for (const CarobNS::CarobException *current = &ce;
+ NULL != current; current = current->getNext())
+ diag_records.push_back(
+ DiagRecord::DiagRecord(prefix, *current)
+ );
+}
+
/*
* Local Variables:
* c-file-style: "bsd"
Index: odbsequoia/src/abstract_item.hpp
diff -u odbsequoia/src/abstract_item.hpp:1.9
odbsequoia/src/abstract_item.hpp:1.10
--- odbsequoia/src/abstract_item.hpp:1.9 Tue Jan 17 16:19:15 2006
+++ odbsequoia/src/abstract_item.hpp Thu Jan 19 17:39:36 2006
@@ -20,12 +20,33 @@
* Contributor(s):
*/
+#include "CarobException.hpp"
+
#include <sql.h>
#include <sqlucode.h>
#include <vector>
#include <string>
+
+// STL's <functional> is a joke. Check Boost?
+// "method" MUST return some SQLRETURN code
+
+#define _PROTECT_SQLRETURN(slf, method) \
+ try { return slf->method; } \
+ catch (const BackendException& ce) \
+ { \
+ slf->push_diag_chain(slf->get_backend_diagids(), ce); \
+ return SQL_ERROR; \
+ } \
+ catch (const CarobException& ce) \
+ { \
+ slf->push_diag_chain(slf->get_diagids(), ce); \
+ return SQL_ERROR; \
+ }
+
+
+
namespace ODBSeqNS {
class DiagRecord
@@ -35,14 +56,21 @@
SQLINTEGER native_err;
std::wstring message;
public:
- DiagRecord(const std::wstring& st, SQLINTEGER nat, const std::wstring& msg)
- : sql_state(st), native_err(nat), message(msg) { };
+ DiagRecord::DiagRecord(const std::wstring& prefix, const
CarobNS::CarobException& ce) :
+ sql_state(ce.getSQLState()),
+ native_err((SQLINTEGER) ce.getErrorCode()),
+ message(prefix + ce.description())
+ { };
};
class ODBCItem
{
public:
- ODBCItem(const ODBCItem& creator) : owner(creator) { }
+ ODBCItem(const ODBCItem& creator) :
+ owner(creator),
+ diagids(L"[Continuent][odbsequoia]"),
+ backend_diagids(L"[INVALID_NOT_CONNECTED]")
+ { }
virtual SQLRETURN
get_diag_recw(SQLSMALLINT RecNumber,
@@ -61,8 +89,21 @@
const ODBCItem& owner;
- void clear_diags() { diag_records.clear(); };
- void push_diag(const DiagRecord& diag) { diag_records.push_back(diag); };
+ void
+ clear_diags() { diag_records.clear(); };
+
+ void
+ push_diag_chain(const std::wstring& prefix, const CarobNS::CarobException&
ce);
+
+ virtual const std::wstring&
+ get_diagids() const { return diagids; };
+
+ virtual const std::wstring&
+ get_backend_diagids() const { return backend_diagids; };
+
+// TODO make these fields protected (implies SQLConnectW rework)
+ std::wstring diagids;
+ std::wstring backend_diagids;
protected:
virtual SQLRETURN
Index: odbsequoia/src/connect.cpp
diff -u odbsequoia/src/connect.cpp:1.9 odbsequoia/src/connect.cpp:1.10
--- odbsequoia/src/connect.cpp:1.9 Tue Jan 17 16:36:54 2006
+++ odbsequoia/src/connect.cpp Thu Jan 19 17:39:36 2006
@@ -42,27 +42,33 @@
SQLRETURN
SQLConnectW(SQLHDBC conn_hdle,
- SQLWCHAR *wdsn, SQLSMALLINT dsnlen,
+ SQLWCHAR *sqlwdsn, SQLSMALLINT dsnlen,
SQLWCHAR *user, SQLSMALLINT userlen,
SQLWCHAR *pass, SQLSMALLINT passlen)
{
- SQLRETURN ret = SQL_SUCCESS;
+ // TODO: make diagids field private and move this function to a new
connectw() method
+
ODBCConnection * self_p = static_cast<ODBCConnection *>(conn_hdle);
self_p->clear_diags();
+
+ std::wstring wide_dsn(fromSQLW(sqlwdsn, dsnlen));
+ self_p->diagids += L"[";
+ self_p->diagids += wide_dsn + L"]";
+
char temp[MAX_VALUE_LEN];
// Get a narrow, C-style DSN
// Waiting for SQLGetPrivateProfileStringW() ?
- std::string dsn = toString(fromSQLW(wdsn, dsnlen));
+ std::string narrow_dsn = toString(wide_dsn);
#if 0 // looks like LPCSTR is const after all. Are we sure about this?
- dsnlen = dsn.length(); // fixing NTS
+ dsnlen = narrow_dsn.length(); // fixing NTS
char *cdsn = new char[dsnlen+1];
- dsn.copy(cdsn, dsnlen);
+ narrow_dsn.copy(cdsn, dsnlen);
cdsn[dsnlen] = 0;
#else
- LPCSTR cdsn = dsn.c_str();
+ LPCSTR cdsn = narrow_dsn.c_str();
#endif
// Slurp DSN information from odbc.ini into ConnectionParameters
@@ -81,23 +87,31 @@
return SQL_ERROR; // TODO: diags
std::wstring vdbname = fromString(std::string(temp));
+ if (!SQLGetPrivateProfileString(cdsn, BACKEND_IDS_INI,
DEFAULT_BACKEND_IDS_INI,
+ temp, MAX_VALUE_LEN, ODBC_INI))
+ return SQL_ERROR; // TODO: diags
+ self_p->backend_diagids = fromString(std::string(temp));
+
+
#if 0
delete[] cdsn;
#endif
- try
+ try // TODO: use _PROTECT_SQLRETURN() instead
{
CarobNS::ConnectionParameters
connectionPrms(serverhost, port, vdbname,
fromSQLW(user, userlen), fromSQLW(pass, passlen),
DEBUG_LEVEL_DEBUG);
self_p->carob_conn = new Connection(connectionPrms);
+ // TODO: SQLWarnings -> SUCCESS_WITH_INFO
+ return SQL_SUCCESS;
}
catch (CarobNS::CarobException& ce)
{
- ret = SQL_ERROR;
+ self_p->push_diag_chain(L"[FIXME: USE PROTECTOR]", ce);
+ return SQL_ERROR;
}
- return ret;
}
Index: odbsequoia/src/inst.hpp
diff -u odbsequoia/src/inst.hpp:1.2 odbsequoia/src/inst.hpp:1.3
--- odbsequoia/src/inst.hpp:1.2 Thu Jan 12 21:15:20 2006
+++ odbsequoia/src/inst.hpp Thu Jan 19 17:39:36 2006
@@ -35,6 +35,8 @@
#define SERVER_INI "Servername"
#define DATABASE_INI "Database"
#define PORT_INI "Port"
+#define BACKEND_IDS_INI "BackendIdentifiers"
+#define DEFAULT_BACKEND_IDS_INI "[BackendIdentifiers undefined in INI file]"
#endif // include only once
Index: odbsequoia/src/simpletest.c
diff -u odbsequoia/src/simpletest.c:1.9 odbsequoia/src/simpletest.c:1.10
--- odbsequoia/src/simpletest.c:1.9 Tue Jan 17 18:12:25 2006
+++ odbsequoia/src/simpletest.c Thu Jan 19 17:39:36 2006
@@ -73,6 +73,11 @@
#if SEQTEST // sequoia
EXEC_AND_DIAGS(
SQLConnect(hdbc, (SQLCHAR *) "seqsource", SQL_NTS, (SQLCHAR *) "user",
SQL_NTS,
+ (SQLCHAR *) "a", SQL_NTS),
+ SQL_HANDLE_DBC, hdbc, 1);
+
+ EXEC_AND_DIAGS(
+ SQLConnect(hdbc, (SQLCHAR *) "seqsource", SQL_NTS, (SQLCHAR *) "user",
SQL_NTS,
(SQLCHAR *) "", SQL_NTS),
SQL_HANDLE_DBC, hdbc, 0);
@@ -120,7 +125,7 @@
SQLSMALLINT statesize, msgsize;
SQLCHAR state[12]; // twice what needed because of this under-estimating
bug:
//
<http://permalink.gmane.org/gmane.comp.db.unixodbc.devel/1760>
- SQLINTEGER nativecode;
+ SQLINTEGER nativecode = -1000;
SQLCHAR msg[201];
@@ -132,7 +137,9 @@
SQLGetDiagRec(hdletype, hdle,
irec, state, &nativecode, msg, 200, &msgsize);
- printf ("step %d: sqlstate: %s, ", pc, state);
+ printf (" --> diag rec number: %ld ", irec);
+ printf ("(step %d) <--\n sqlstate: %s, ", pc, state);
+ printf ("statesize: %d, ", statesize);
printf ("native errr: %ld, ", nativecode);
printf ("%s, ", msg);
printf ("msgsize: %d\n", msgsize);
@@ -140,8 +147,15 @@
// cleanup
strcpy ((char *)state, "nop"); statesize = -1000; nativecode = -1000;
strcpy((char *)msg, "nop"); msgsize = -1000 ;
+ }
// get the same thing through SQLGetDiagField thrice
+ if (recmax > 0)
+ printf (" ----> same diags but through SQLGetDiagField <----\n");
+
+ for (irec = 1; irec <= recmax; irec++) {
+
+ printf (" --> diag rec number: %ld ", irec);
SQLGetDiagField(hdletype, hdle, irec, SQL_DIAG_SQLSTATE,
state, 12*sizeof(SQLCHAR), &statesize);
@@ -151,14 +165,15 @@
SQLGetDiagField(hdletype, hdle, irec, SQL_DIAG_MESSAGE_TEXT,
msg, 201, &msgsize);
-
- printf ("same diags but through SQLGetDiagField:\n");
- printf ("step %d: sqlstate: %s, ", pc, state);
- printf ("statesize: %d\n", statesize);
+ printf ("sqlstate: %s, ", state);
+ printf ("statesize: %d, ", statesize);
printf ("native errr: %ld, ", nativecode);
printf ("%s, ", msg);
printf ("msgsize: %d\n", msgsize);
+ // cleanup
+ strcpy ((char *)state, "nop"); statesize = -1000; nativecode = -1000;
+ strcpy((char *)msg, "nop"); msgsize = -1000 ;
}
}
Index: odbsequoia/src/stmt.cpp
diff -u odbsequoia/src/stmt.cpp:1.10 odbsequoia/src/stmt.cpp:1.11
--- odbsequoia/src/stmt.cpp:1.10 Tue Jan 17 16:36:54 2006
+++ odbsequoia/src/stmt.cpp Thu Jan 19 17:39:36 2006
@@ -34,30 +34,23 @@
{
ODBCStatement * self_p = static_cast<ODBCStatement *>(StatementHandle);
self_p->clear_diags();
- return self_p->exec_directw(StatementText, TextLength);
+
+ _PROTECT_SQLRETURN(self_p, exec_directw(StatementText, TextLength));
+
}
SQLRETURN
ODBCStatement::exec_directw(const SQLWCHAR *StatementText, SQLINTEGER
TextLength)
+ throw (CarobException)
{
- try
- {
- const std::wstring wstext = fromSQLW(StatementText, TextLength);
- bool resultIsSet = carob_stmt->execute(wstext);
- if (resultIsSet)
- state = S5;
- else
- state = S4;
- return SQL_SUCCESS;
- }
- catch (const CarobException& ce)
- {
- DiagRecord diag(ce.getSQLState(),
- ce.getErrorCode(),
- ce.description());
- this->push_diag(diag);
- return SQL_ERROR;
- }
+ const std::wstring wstext = fromSQLW(StatementText, TextLength);
+ bool resultIsSet = carob_stmt->execute(wstext);
+ if (resultIsSet)
+ state = S5;
+ else
+ state = S4;
+
+ return SQL_SUCCESS;
}
SQLRETURN
Index: odbsequoia/src/stmt.hpp
diff -u odbsequoia/src/stmt.hpp:1.7 odbsequoia/src/stmt.hpp:1.8
--- odbsequoia/src/stmt.hpp:1.7 Tue Jan 17 16:01:45 2006
+++ odbsequoia/src/stmt.hpp Thu Jan 19 17:39:36 2006
@@ -38,7 +38,15 @@
ODBCStatement(const ODBCConnection& creator) : ODBCItem(creator)
{ state = S0; };
SQLRETURN
- exec_directw(const SQLWCHAR *StatementText, SQLINTEGER TextLength);
+ exec_directw(const SQLWCHAR *StatementText, SQLINTEGER TextLength)
+ throw (CarobNS::CarobException);
+
+ const std::wstring&
+ get_diagids() const { return owner.get_diagids(); }; // connection has the
prefix/knows the source
+
+ const std::wstring&
+ get_backend_diagids() const { return owner.get_backend_diagids(); }; //
idem
+
protected:
SQLRETURN
get_header_diag_fieldw(SQLSMALLINT DiagIdentifier,
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits