From 7001e0ccd9f6f93f2e38572221c223f8adaf0eaf Mon Sep 17 00:00:00 2001 From: randomdan Date: Fri, 11 Feb 2011 14:55:07 +0000 Subject: Support for table patching in different ways according to what the connector says Introduce two proper methods of bulk update Tested against PG 8.4, MySQL 5.1 with single and multiple column keys --- libodbcpp/connection.cpp | 26 ++++++++++++++++++++++++++ libodbcpp/connection.h | 5 +++++ 2 files changed, 31 insertions(+) (limited to 'libodbcpp') diff --git a/libodbcpp/connection.cpp b/libodbcpp/connection.cpp index 0c2dcc8..087fc69 100644 --- a/libodbcpp/connection.cpp +++ b/libodbcpp/connection.cpp @@ -10,6 +10,8 @@ ODBC::Connection::Connection(const DSN& d) : env(0), conn(0), + thinkDelStyle(DB::BulkDeleteUsingUsing), + thinkUpdStyle(DB::BulkUpdateUsingFromSrc), txDepth(0), txAborted(false) { @@ -53,11 +55,23 @@ ODBC::Connection::connectPost() if (!SQL_SUCCEEDED(dberr)) { throw ConnectionError(dberr, SQL_HANDLE_DBC, conn, "Set default auto commit"); } + char info[1024]; + dberr = SQLGetInfo(conn, SQL_DRIVER_NAME, (SQLCHAR*)info, sizeof(info), NULL); + if (!SQL_SUCCEEDED(dberr)) { + throw ConnectionError(dberr, SQL_HANDLE_DBC, conn, "Get info"); + } + // Apply known DB specific tweaks + if (strstr(info, "myodbc") != NULL) { + thinkDelStyle = DB::BulkDeleteUsingUsingAlias; + thinkUpdStyle = DB::BulkUpdateUsingJoin; + } } ODBC::Connection::Connection(const std::string & s) : env(0), conn(0), + thinkDelStyle(DB::BulkDeleteUsingUsing), + thinkUpdStyle(DB::BulkUpdateUsingFromSrc), txDepth(0), txAborted(false) { @@ -162,6 +176,18 @@ ODBC::Connection::inTx() const return (txDepth > 0); } +DB::BulkDeleteStyle +ODBC::Connection::bulkDeleteStyle() const +{ + return thinkDelStyle; +} + +DB::BulkUpdateStyle +ODBC::Connection::bulkUpdateStyle() const +{ + return thinkUpdStyle; +} + DB::SelectCommand * ODBC::Connection::newSelectCommand(const std::string & sql) const { diff --git a/libodbcpp/connection.h b/libodbcpp/connection.h index d37b679..4fc52ca 100644 --- a/libodbcpp/connection.h +++ b/libodbcpp/connection.h @@ -25,11 +25,16 @@ namespace ODBC { void ping() const; std::string getAttrStr(SQLINTEGER) const; SQLINTEGER getAttrInt(SQLINTEGER) const; + DB::BulkDeleteStyle bulkDeleteStyle() const; + DB::BulkUpdateStyle bulkUpdateStyle() const; DB::SelectCommand * newSelectCommand(const std::string & sql) const; DB::ModifyCommand * newModifyCommand(const std::string & sql) const; private: + DB::BulkDeleteStyle thinkDelStyle; + DB::BulkUpdateStyle thinkUpdStyle; + void connectPre(); void connectPost(); mutable unsigned int txDepth; -- cgit v1.2.3