Date: Thursday, January 5, 2006 @ 21:34:11
  Author: marc
    Path: /cvsroot/carob/odbsequoia/src

   Added: explicit_type.cpp (1.1) stmt.hpp (1.1) util.cpp (1.1) util.hpp
          (1.1)
Modified: GNUmakefile (1.1 -> 1.2) connect.cpp (1.3 -> 1.4) connect.hpp
          (1.2 -> 1.3) env.cpp (1.2 -> 1.3) env.hpp (1.1 -> 1.2) stmt.cpp
          (1.2 -> 1.3)

Big re-org: moving towards a full object-oriented design.


-------------------+
 GNUmakefile       |    2 -
 connect.cpp       |   13 +++++--
 connect.hpp       |   16 +++++----
 env.cpp           |   91 +++++-----------------------------------------------
 env.hpp           |   14 ++++----
 explicit_type.cpp |   87 +++++++++++++++++++++++++++++++++++++++++++++++++
 stmt.cpp          |   29 +---------------
 stmt.hpp          |   50 ++++++++++++++++++++++++++++
 util.cpp          |   77 ++++++++++++++++++++++++++++++++++++++++++++
 util.hpp          |   35 ++++++++++++++++++++
 10 files changed, 288 insertions(+), 126 deletions(-)


Index: odbsequoia/src/GNUmakefile
diff -u odbsequoia/src/GNUmakefile:1.1 odbsequoia/src/GNUmakefile:1.2
--- odbsequoia/src/GNUmakefile:1.1      Thu Dec 22 19:55:20 2005
+++ odbsequoia/src/GNUmakefile  Thu Jan  5 21:34:11 2006
@@ -29,7 +29,7 @@
 CAROB=carob
 
 
-OBJS=env.o connect.o stmt.o
+OBJS=util.o explicit_type.o env.o connect.o stmt.o
 CXXFLAGS=-Wall -g3 -I${CAROB_PATH}/include
 
 
Index: odbsequoia/src/connect.cpp
diff -u odbsequoia/src/connect.cpp:1.3 odbsequoia/src/connect.cpp:1.4
--- odbsequoia/src/connect.cpp:1.3      Wed Jan  4 20:23:02 2006
+++ odbsequoia/src/connect.cpp  Thu Jan  5 21:34:11 2006
@@ -30,6 +30,9 @@
 #include "Connection.hpp"
 
 #include "setup.hpp"
+#include "util.hpp"
+
+#include "stmt.hpp"
 
 #include "connect.hpp"
 
@@ -102,11 +105,13 @@
 
 
 SQLRETURN
-ODBSeqNS::alloc_connect(SQLHANDLE input_handle, SQLHANDLE * output_handle)
+ODBCConnection::AllocStmt(SQLHANDLE * OutputHandle)
 {
-    ODBCConnection *newconn = new ODBCConnection;
-    newconn->env = (ODBCEnv *) input_handle;
-    *output_handle = newconn;
+    ODBCStatement * newstmt = new ODBCStatement;
+    newstmt->conn = this;
+    newstmt->carob_stmt = carob_conn->createStatement();
+    newstmt->state = S1;
+    *OutputHandle = newstmt;
     return SQL_SUCCESS;
 }
 
Index: odbsequoia/src/connect.hpp
diff -u odbsequoia/src/connect.hpp:1.2 odbsequoia/src/connect.hpp:1.3
--- odbsequoia/src/connect.hpp:1.2      Wed Dec 28 18:16:02 2005
+++ odbsequoia/src/connect.hpp  Thu Jan  5 21:34:11 2006
@@ -19,28 +19,30 @@
  * Contributor(s): 
  */
 
+#ifndef ODBSEQ_CONN
+#define ODBSEQ_CONN
+
 #include "Connection.hpp"
 
 #include "env.hpp"
 
 namespace ODBSeqNS {
 
-typedef struct conn_ {
+class ODBCConnection {
+public:
     ODBCEnv *env;
     CarobNS::Connection* carob_conn;
     // TODO: rely on ConnectionParameters instead
     std::wstring serverhost;
     std::wstring vdbname;
-} ODBCConnection;
-
-
-
-SQLRETURN alloc_connect(SQLHANDLE input_handle, SQLHANDLE * output_handle);
-SQLRETURN alloc_statement(SQLHANDLE input_handle, SQLHANDLE * output_handle);
+    SQLRETURN AllocStmt(SQLHANDLE * OutputHandle);
+};
 
 
 } // namespace ODBSeqNS 
 
+#endif // include only once
+
 /*
  * Local Variables:
  * c-file-style: "bsd"
Index: odbsequoia/src/env.cpp
diff -u odbsequoia/src/env.cpp:1.2 odbsequoia/src/env.cpp:1.3
--- odbsequoia/src/env.cpp:1.2  Wed Jan  4 20:24:54 2006
+++ odbsequoia/src/env.cpp      Thu Jan  5 21:34:11 2006
@@ -32,87 +32,6 @@
 using namespace ODBSeqNS;
 using namespace CarobNS;
 
-// should probably move this elsewhere
-namespace {
-int sqlwcstrlen(const SQLWCHAR *instr)
-{
-    int        len = 0;
-    while (instr[len] != 0)
-        len++;
-    return len;
-}
-}
-
-std::wstring
-fromSQLW(const SQLWCHAR * const in, SQLSMALLINT inLen)
-{
-    bool isNTS = (SQL_NTS == inLen);
-
-// this macro belongs to unixodbc. TODO: check about iodbc, windows etc.
-#ifdef SQL_WCHART_CONVERT
-#warning SQLWCHAR == wchar_t: optimized but untested code!
-
-    std::wstring objres;
-    if (isNTS)
-        objres = std::wstring(in);
-    else
-        objres = std::wstring(in, inLen);
-
-#else  // sizeof(SQLWCHAR) != sizeof(wchar_t)
-
-    if (isNTS)
-        inLen = sqlwcstrlen(in);
-    wchar_t *res = new wchar_t[inLen];
-    for (int i=0; i<inLen ; i++)
-        res[i] = in[i]; // FIXME: this is poor man's UCS-4/UTF-16 converter 
indeed!
-
-    std::wstring objres(res, inLen);
-    delete[] res;
-
-#endif
-
-    return objres;
-}
-
-/*  SQLAllocConnect/SQLAllocEnv/SQLAllocStmt mapped to SQLAllocHandle() here 
by DM */
-SQLRETURN              
-SQLAllocHandle(SQLSMALLINT handle_type, SQLHANDLE input_handle,
-               SQLHANDLE * output_handle)
-{
-  SQLRETURN            ret = SQL_SUCCESS;
-
-  switch (handle_type)
-    {
-    case SQL_HANDLE_ENV:
-      *output_handle = new ODBCEnv;
-      break;
-    case SQL_HANDLE_DBC:
-      ret = alloc_connect(input_handle, output_handle);
-      break;
-    case SQL_HANDLE_STMT:
-      ret = alloc_statement(input_handle, output_handle);
-      break;
-    case SQL_HANDLE_DESC:
-      ret = SQL_ERROR;
-      break;
-    default:
-      ret = SQL_ERROR;
-      break;
-    }
-
-  return ret;
-}
-
-
-/*  SQLFreeConnect/SQLFreeEnv/SQLFreeStmt mapped to SQLFreeHandle() here by DM 
*/
-SQLRETURN
-SQLFreeHandle(SQLSMALLINT handle_type, SQLHANDLE handle)
-{
-    SQLRETURN          ret = SQL_SUCCESS;
-    // FIXME: leaking
-    return ret;
-}
-
 
 /* Is there a SQLGetEnvAttrW()? Does not look like. */
 SQLRETURN
@@ -136,6 +55,16 @@
 }
 
 
+SQLRETURN
+ODBCEnv::AllocConnect(SQLHANDLE * OutputHandle)
+{
+    ODBCConnection *newconn = new ODBCConnection;
+    newconn->env = this;
+    *OutputHandle = newconn;
+    return SQL_SUCCESS;
+}
+
+
 /*
  * Local Variables:
  * c-file-style: "bsd"
Index: odbsequoia/src/env.hpp
diff -u odbsequoia/src/env.hpp:1.1 odbsequoia/src/env.hpp:1.2
--- odbsequoia/src/env.hpp:1.1  Thu Dec 22 19:55:20 2005
+++ odbsequoia/src/env.hpp      Thu Jan  5 21:34:11 2006
@@ -20,8 +20,8 @@
  */
 
 
-// #ifndef ODBSEQ_ENV
-// #define ODBSEQ_ENV
+#ifndef ODBSEQ_ENV
+#define ODBSEQ_ENV
 
 #include <string>
 
@@ -29,15 +29,15 @@
 
 namespace ODBSeqNS {
 
-typedef struct env_ {
-    // empty for now
-} ODBCEnv;
+class ODBCEnv {
+public:
+    SQLRETURN ODBCEnv::AllocConnect(SQLHANDLE * OutputHandle);
+};
 
 }
 
-std::wstring fromSQLW(const SQLWCHAR *in, SQLSMALLINT inLen);
 
-// #endif // include only once
+#endif // include only once
 
 /*
  * Local Variables:
Index: odbsequoia/src/explicit_type.cpp
diff -u /dev/null odbsequoia/src/explicit_type.cpp:1.1
--- /dev/null   Thu Jan  5 21:34:11 2006
+++ odbsequoia/src/explicit_type.cpp    Thu Jan  5 21:34:11 2006
@@ -0,0 +1,87 @@
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2006 Continuent, Inc.
+ * Contact: [EMAIL PROTECTED]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Initial developer(s): Marc Herbert
+ * Contributor(s): 
+ */
+
+/*
+ * ODBC functions that have "HandleType" as an argument.
+ *
+ * General implementation idea is: switch(type), cast, method call
+ */
+
+
+#include "env.hpp"
+#include "connect.hpp"
+#include "stmt.hpp"
+
+using namespace ODBSeqNS;
+
+/*  SQLAllocConnect/SQLAllocEnv/SQLAllocStmt mapped to SQLAllocHandle() here 
by DM */
+SQLRETURN              
+SQLAllocHandle(SQLSMALLINT HandleType, SQLHANDLE InputHandle,
+               SQLHANDLE * OutputHandle)
+{
+    SQLRETURN          ret = SQL_SUCCESS;
+
+    switch (HandleType)
+    {
+    case SQL_HANDLE_ENV:
+        OutputHandle = (SQLHANDLE *) new ODBCEnv;
+        break;
+
+    case SQL_HANDLE_DBC:
+        ODBCEnv * env = (ODBCEnv *) InputHandle;
+        return env->AllocConnect(OutputHandle);
+
+    case SQL_HANDLE_STMT:
+        ODBCConnection * conn = (ODBCConnection *) InputHandle;
+        return conn->AllocStmt(OutputHandle);
+
+    case SQL_HANDLE_DESC:
+        ret = SQL_ERROR;
+        break;
+
+    default:
+        ret = SQL_ERROR;
+        break;
+    }
+
+    return ret;
+}
+
+
+
+/*  SQLFreeConnect/SQLFreeEnv/SQLFreeStmt mapped to SQLFreeHandle() here by DM 
*/
+SQLRETURN
+SQLFreeHandle(SQLSMALLINT HandleType, SQLHANDLE Handle)
+{
+    SQLRETURN          ret = SQL_SUCCESS;
+    // FIXME: leaking
+    return ret;
+}
+
+
+
+/*
+ * Local Variables:
+ * c-file-style: "bsd"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Index: odbsequoia/src/stmt.cpp
diff -u odbsequoia/src/stmt.cpp:1.2 odbsequoia/src/stmt.cpp:1.3
--- odbsequoia/src/stmt.cpp:1.2 Thu Jan  5 16:18:33 2006
+++ odbsequoia/src/stmt.cpp     Thu Jan  5 21:34:11 2006
@@ -25,24 +25,10 @@
 
 #include "Statement.hpp"
 
+#include "util.hpp"
 #include "connect.hpp"
 
-enum stmt_state_t { S0, S1, S4, S5 };
-
-namespace ODBSeqNS {
-
-typedef struct odbsequoia_stmt_ {
-    // a ref here instead?
-    ODBCConnection *conn;
-    CarobNS::Statement* carob_stmt;
-    stmt_state_t state;  // state according to "Statement Transitions"
-                         // in the ODBC reference (as far as
-                         // possible).
-    odbsequoia_stmt_() { state = S0; };
-} ODBCStatement;
-
-}
-
+#include "stmt.hpp"
 
 using namespace ODBSeqNS;
 using namespace CarobNS;
@@ -77,7 +63,7 @@
 
     if (S5 != self_p->state
         && S4 != self_p->state)
-        return SQL_ERROR; // TODO: HY010
+        return SQL_ERROR; // TODO: HY010. No: done by DM! Use assert?
 
     *rowcount = self_p->carob_stmt->getUpdateCount();
 
@@ -88,15 +74,6 @@
 }
 
 
-SQLRETURN ODBSeqNS::alloc_statement(SQLHANDLE InputHandle, SQLHANDLE * 
OutputHandle)
-{
-    ODBCStatement *newstmt = new ODBCStatement;
-    newstmt->conn = (ODBCConnection *) InputHandle;
-    newstmt->carob_stmt = newstmt->conn->carob_conn->createStatement();
-    newstmt->state = S1;
-    *OutputHandle = newstmt;
-    return SQL_SUCCESS;
-}
 
 /*
  * Local Variables:
Index: odbsequoia/src/stmt.hpp
diff -u /dev/null odbsequoia/src/stmt.hpp:1.1
--- /dev/null   Thu Jan  5 21:34:11 2006
+++ odbsequoia/src/stmt.hpp     Thu Jan  5 21:34:11 2006
@@ -0,0 +1,50 @@
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2006 Continuent, Inc.
+ * Contact: [EMAIL PROTECTED]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Initial developer(s): Marc Herbert
+ * Contributor(s): 
+ */
+
+#include "connect.hpp"
+
+namespace ODBSeqNS {
+
+enum stmt_state_t { S0, S1, S4, S5 };
+
+class ODBCStatement
+{
+public:
+    // a ref here instead?
+    ODBCConnection *conn;
+    CarobNS::Statement* carob_stmt;
+    stmt_state_t state;  // state according to "Statement Transitions"
+                         // in the ODBC reference (as far as
+                         // possible).
+    ODBCStatement() { state = S0; };
+};
+
+
+}
+
+
+/*
+ * Local Variables:
+ * c-file-style: "bsd"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Index: odbsequoia/src/util.cpp
diff -u /dev/null odbsequoia/src/util.cpp:1.1
--- /dev/null   Thu Jan  5 21:34:11 2006
+++ odbsequoia/src/util.cpp     Thu Jan  5 21:34:11 2006
@@ -0,0 +1,77 @@
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2006 Continuent, Inc.
+ * Contact: [EMAIL PROTECTED]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Initial developer(s): Marc Herbert
+ * Contributor(s): 
+ */
+
+#include "util.hpp"
+
+
+namespace {
+
+int sqlwcstrlen(const SQLWCHAR *instr)
+{
+    int        len = 0;
+    while (instr[len] != 0)
+        len++;
+    return len;
+}
+
+}
+
+std::wstring
+fromSQLW(const SQLWCHAR * const in, SQLSMALLINT inLen)
+{
+    bool isNTS = (SQL_NTS == inLen);
+
+// this macro belongs to unixodbc. TODO: check about iodbc, windows etc.
+// also check for __STDC_ISO_10646__
+#ifdef SQL_WCHART_CONVERT
+#warning SQLWCHAR == wchar_t: optimized but untested code!
+
+    std::wstring objres;
+    if (isNTS)
+        objres = std::wstring(in);
+    else
+        objres = std::wstring(in, inLen);
+
+#else  // sizeof(SQLWCHAR) != sizeof(wchar_t)
+
+    if (isNTS)
+        inLen = sqlwcstrlen(in);
+    wchar_t *res = new wchar_t[inLen];
+    for (int i=0; i<inLen ; i++)
+        res[i] = in[i]; // FIXME: this is poor man's UCS-4/UTF-16 converter 
indeed!
+
+    std::wstring objres(res, inLen);
+    delete[] res;
+
+#endif
+
+    return objres;
+}
+
+
+
+/*
+ * Local Variables:
+ * c-file-style: "bsd"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Index: odbsequoia/src/util.hpp
diff -u /dev/null odbsequoia/src/util.hpp:1.1
--- /dev/null   Thu Jan  5 21:34:11 2006
+++ odbsequoia/src/util.hpp     Thu Jan  5 21:34:11 2006
@@ -0,0 +1,35 @@
+/*
+ * Sequoia: Database clustering technology.
+ * Copyright (C) 2006 Continuent, Inc.
+ * Contact: [EMAIL PROTECTED]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Initial developer(s): Marc Herbert
+ * Contributor(s): 
+ */
+
+#include <sql.h>
+#include <string>
+
+std::wstring
+fromSQLW(const SQLWCHAR * const in, SQLSMALLINT inLen);
+
+
+/*
+ * Local Variables:
+ * c-file-style: "bsd"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to