Date: Tuesday, March 21, 2006 @ 23:50:12
  Author: marc
    Path: /cvsroot/carob/odbsequoia/src

Modified: stmt.cpp (1.22 -> 1.23) stmt.hpp (1.17 -> 1.18)

Implemented SQLPrepare() and SQLExecute(). See CAROB-81 and SEQUOIA-262.


----------+
 stmt.cpp |   72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 stmt.hpp |   18 +++++++++++++--
 2 files changed, 86 insertions(+), 4 deletions(-)


Index: odbsequoia/src/stmt.cpp
diff -u odbsequoia/src/stmt.cpp:1.22 odbsequoia/src/stmt.cpp:1.23
--- odbsequoia/src/stmt.cpp:1.22        Mon Mar 20 22:02:42 2006
+++ odbsequoia/src/stmt.cpp     Tue Mar 21 23:50:12 2006
@@ -205,18 +205,86 @@
 ODBCStatement::close_cursor()
 {
     if (!in_state_cursor())
-        throw ODBSeqException(L"24000", L"Invalid state");
+        throw ODBSeqException(L"24000", L"Not in cursor state for 
SQLCloseCursor()");
 
     state = S1;
 
     // TODO: close carob_stmt->getResultSet() IF ANY
 
-    // FIXME: state = S3 if was prepared ?!
+    if (was_prepared)
+        state = S3;
+
     return SQL_SUCCESS;
 
 }
 
 SQLRETURN
+SQLPrepareW(SQLHSTMT StatementHandle,
+            SQLWCHAR * StatementText,
+            SQLINTEGER TextLength)
+{
+    ODBCStatement * self_p = objectify(StatementHandle);
+    self_p->clear_diags();
+
+    _PROTECT_SQLRETURN(self_p, prepare(StatementText, TextLength));
+}
+
+SQLRETURN
+ODBCStatement::prepare(const SQLWCHAR * req, SQLINTEGER ntslen)
+{
+    if (in_state_cursor())
+        throw ODBSeqException(L"24000", L"Invalid cursor state for 
SQLPrepare()");
+
+    // FIXME: we must throw 24000 in S4 if we are not on the last result
+
+    // see CAROB-81
+    this->sql_request = fromSQLW(req, ntslen);
+    carob_stmt->setRequest(this->sql_request);
+
+    ResultSetMetaData * rsmd = carob_stmt->getMetaData();
+
+    if (0 == rsmd)
+        state = S2; // no result set
+    else {
+        // workaround for bug SEQUOIA-262
+        if (0 == rsmd->getColumnCount())
+            state = S2;
+        else
+            state = S3;
+    }
+    was_prepared = true;
+
+    return SQL_SUCCESS;
+}
+
+SQLRETURN
+SQLExecute(SQLHSTMT StatementHandle)
+{
+    ODBCStatement * self_p = objectify(StatementHandle);
+    self_p->clear_diags();
+
+    _PROTECT_SQLRETURN(self_p, execute());
+}
+
+SQLRETURN
+ODBCStatement::execute()
+{
+    if (! in_state_prepared())
+        throw ODBSeqException(L"24000", L"Invalid non-prepared state for 
SQLExecute()");
+
+    // see CAROB-81
+    bool isRS = carob_stmt->execute(this->sql_request);
+
+    if (isRS)
+        state = S5; // hopefully we were in S3
+    else
+        state = S4; // hopefully we were in S2
+
+    return SQL_SUCCESS;
+}
+
+
+SQLRETURN
 ODBCStatement::get_header_diag_fieldw(SQLSMALLINT DiagIdentifier,
                                       SQLPOINTER DiagInfoPtr,
                                       SQLSMALLINT BufferLength,
Index: odbsequoia/src/stmt.hpp
diff -u odbsequoia/src/stmt.hpp:1.17 odbsequoia/src/stmt.hpp:1.18
--- odbsequoia/src/stmt.hpp:1.17        Mon Mar 20 22:02:42 2006
+++ odbsequoia/src/stmt.hpp     Tue Mar 21 23:50:12 2006
@@ -48,7 +48,7 @@
 
     ODBCStatement(const ODBCConnection& creator) : 
         ODBCItem(creator),
-        carob_stmt(0), state(S0),
+        carob_stmt(0), state(S0), was_prepared(false),
         IRD(*this), IPD(*this),
         implicit_ARD(*this, false), implicit_APD(*this, false),
         ARD(&implicit_ARD), APD(&implicit_APD)
@@ -56,7 +56,13 @@
 
     SQLRETURN
     exec_directw(const SQLWCHAR *StatementText, SQLINTEGER TextLength);
-    
+
+    SQLRETURN
+    prepare(const SQLWCHAR *request, SQLINTEGER len);
+
+    SQLRETURN
+    execute();
+
     SQLRETURN
     bind_col(SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType,
              SQLPOINTER TargetValuePtr, SQLINTEGER BufferLength,
@@ -105,6 +111,14 @@
     in_state_cursor() const
     { return (state == S5 || state == S6 || state == S7); }
 
+    bool
+    in_state_prepared() const
+    { return (state == S2 || state == S3); }
+
+    bool was_prepared;
+    // major ugliness until CAROB-81 is fixed
+    std::wstring sql_request;
+
     ODBCImplParamDesc IRD;
     ODBCImplRowDesc IPD;
     ODBCAppDesc implicit_ARD;

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

Reply via email to