Date: Wednesday, January 11, 2006 @ 20:14:27
  Author: gilles
    Path: /cvsroot/carob/carob

Modified: include/Connection.hpp (1.46 -> 1.47)
          include/ParameterStatement.hpp (1.5 -> 1.6)
          include/Statement.hpp (1.23 -> 1.24) src/Connection.cpp (1.53 ->
          1.54) src/ParameterStatement.cpp (1.3 -> 1.4) src/Statement.cpp
          (1.22 -> 1.23)

put up getMetaData() from parameterStatement to statement in order to be able 
to pseudo-prepare a parameterStatement
*and* a statement. Statements that already hold a resultSet will return the 
current resultset metadata instead
Implications:
-sql query put up in statement too
-sql string setter added in statement (to be able to prepare it)

preparedStatementGetMetaData now returns real metadata instead of a ResultSet

Also updated copyright on modified files (new year + emic->continuent)


--------------------------------+
 include/Connection.hpp         |    6 ++++--
 include/ParameterStatement.hpp |   25 +++++--------------------
 include/Statement.hpp          |   30 +++++++++++++++++++++++++++++-
 src/Connection.cpp             |    8 +++++---
 src/ParameterStatement.cpp     |   31 +++++++------------------------
 src/Statement.cpp              |   35 +++++++++++++++++++++++++++++------
 6 files changed, 79 insertions(+), 56 deletions(-)


Index: carob/include/Connection.hpp
diff -u carob/include/Connection.hpp:1.46 carob/include/Connection.hpp:1.47
--- carob/include/Connection.hpp:1.46   Wed Jan 11 12:04:42 2006
+++ carob/include/Connection.hpp        Wed Jan 11 20:14:27 2006
@@ -1,6 +1,6 @@
 /*
  * Sequoia: Database clustering technology.
- * Copyright (C) 2005 Emic Networks
+ * Copyright (C) 2005-2006 Continuent, Inc.
  * Contact: [EMAIL PROTECTED]
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -99,6 +99,8 @@
 
 class Statement;
 class ParameterStatement;
+class ResultSetMetaData;
+
 /**
  * This class implements the communication protocol to the Controller.
  */
@@ -347,7 +349,7 @@
    * Returns the metadata of the sql template as a resultset.
    * @param sqlTemplate sql template of the PreparedStatement
    */
-  DriverResultSet     *preparedStatementGetMetaData(const std::wstring 
&sqlTemplate)
+  ResultSetMetaData*  preparedStatementGetMetaData(const std::wstring 
&sqlTemplate)
                           throw (SocketIOException, BackendException, 
ProtocolException, 
                             NotImplementedException, UnexpectedException);
                             
Index: carob/include/ParameterStatement.hpp
diff -u carob/include/ParameterStatement.hpp:1.5 
carob/include/ParameterStatement.hpp:1.6
--- carob/include/ParameterStatement.hpp:1.5    Wed Jan 11 12:04:42 2006
+++ carob/include/ParameterStatement.hpp        Wed Jan 11 20:14:27 2006
@@ -1,6 +1,6 @@
 /*
  * Sequoia: Database clustering technology.
- * Copyright (C) 2005 Emic Networks
+ * Copyright (C) 2005-2006 Continuent, Inc.
  * Contact: [EMAIL PROTECTED]
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,7 +16,7 @@
  * limitations under the License.
  *
  * Initial developer(s): Zsolt Simon
- * Contributor(s): 
+ * Contributor(s): Gilles Rayrat
  */
 #ifndef PARAMETERSTATEMENT_HPP_
 #define PARAMETERSTATEMENT_HPP_
@@ -27,7 +27,6 @@
 #include "CarobException.hpp"
 #include "Statement.hpp"
 #include "BigDecimal.hpp"
-#include "ResultSetMetaData.hpp"
 
 namespace CarobNS {
 
@@ -109,7 +108,7 @@
   bool                    execute() throw (DriverException, SocketIOException, 
                               BackendException, ControllerException, 
ProtocolException,
                               NotImplementedException, UnexpectedException)
-                          { return Statement::execute(sql, compileQuery()); }
+                          { return Statement::execute(sql_request, 
compileQuery()); }
 
   /**
    * Executes a SQL statement that returns a single ResultSet
@@ -120,7 +119,7 @@
   DriverResultSet *       executeQuery() throw (DriverException, 
SocketIOException,
                               BackendException, ControllerException,
                               ProtocolException, UnexpectedException)
-                          { return Statement::executeQuery(sql, 
compileQuery()); }
+                          { return Statement::executeQuery(sql_request, 
compileQuery()); }
   /**
    * Execute a SQL INSERT, UPDATE or DELETE statement. In addition SQL
    * statements that return nothing such as SQL DDL statements can be executed
@@ -131,7 +130,7 @@
   int                     executeUpdate() throw (DriverException, 
SocketIOException,
                               BackendException, ControllerException,
                               ProtocolException, UnexpectedException)
-                          { return Statement::executeUpdate(sql, 
compileQuery()); }
+                          { return Statement::executeUpdate(sql_request, 
compileQuery()); }
 
   /**
    * Helper - this compiles the SQL query, inlining the parameters in the
@@ -258,14 +257,6 @@
    * @return the number of <code>?</code> in the statement
    */
   int                     getParameterCount() { return inStrings.size(); }
-  
-  /**
-   * Returns the metadata of the statement.
-   * @return a pointer to a ResultSetMetaData
-   */
-   ResultSetMetaData *getMetaData()
-                          throw (SocketIOException, BackendException, 
ProtocolException, 
-                            NotImplementedException, UnexpectedException);
 
 protected:
   /**
@@ -289,14 +280,8 @@
                               throw (DriverException, UnexpectedException);
 
 private:
-  /** Original, untouched request (only trimmed) */
-  std::wstring                sql;
   /** IN parameters, ready to be sent with the request */
   std::vector<std::wstring>   inStrings;
-  /** Resultset holding metadata */
-  DriverResultSet             *mResultSet;
-  /** Cached metadata of the resultset */
-  ResultSetMetaData           *rsMetaData;
 
   /**
    * Helper - this serializes the parameters into a unique wstring.
Index: carob/include/Statement.hpp
diff -u carob/include/Statement.hpp:1.23 carob/include/Statement.hpp:1.24
--- carob/include/Statement.hpp:1.23    Wed Jan 11 10:21:29 2006
+++ carob/include/Statement.hpp Wed Jan 11 20:14:27 2006
@@ -1,6 +1,6 @@
 /*
  * Sequoia: Database clustering technology.
- * Copyright (C) 2005 Emic Networks
+ * Copyright (C) 2005-2006 Continuent, Inc.
  * Contact: [EMAIL PROTECTED]
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -51,6 +51,7 @@
 const std::wstring emptyString = L"";
 
 class Connection;
+class ResultSetMetaData;
 
 /**
  * A <code>Statement</code> object is used for executing a static SQL
@@ -309,7 +310,26 @@
    * <p>
    */
   virtual void            close();
+  /**
+   * If called before executing request that returned a valid resultset, this
+   * method prepares the current statement and returns the corresponding
+   * metadata.
+   * If called after a read request (ie. if the current resultset pointer is 
non
+   * NULL), returns the current resultset's metadata
+   * @return a pointer to the metadata of this statement or of its resultset
+   */
+   ResultSetMetaData*     getMetaData() throw (SocketIOException,
+                              BackendException, ProtocolException, 
+                              NotImplementedException, UnexpectedException);
+  /**
+   * Sets the sql request string
+   * @param sql string containing the sql statement
+   */
+  void                    setRequest(const std::wstring& sql)
+                              { sql_request = sql; }
 protected:
+  /** Original, untouched request (only trimmed) */
+  std::wstring            sql_request;
   /**
    * Constructs a Statement with the given connection. Protected access so that
    * only Connection class can create a statement
@@ -342,6 +362,14 @@
   Connection*             connectionPtr;
   /** Current result for a read request */
   DriverResultSet*        lastResultPtr;
+  /**
+   * Metadata corresponding either to the lastResultPtr's metadata (if
+   * <code>getMetaData()</code> was called right after a read request) or to 
this
+   * statement metadata (thus becoming a prepared statement) if 
+   * <code>getMetaData()</code> was called before a read query that returned a
+   * valid resultset
+   */
+  ResultSetMetaData*      rs_metadata_ptr;
   /** Update count for a write request */
   int                     lastUpdateCount;
   /** Query timeout in seconds (0 means no timeout) */
Index: carob/src/Connection.cpp
diff -u carob/src/Connection.cpp:1.53 carob/src/Connection.cpp:1.54
--- carob/src/Connection.cpp:1.53       Wed Jan 11 12:04:42 2006
+++ carob/src/Connection.cpp    Wed Jan 11 20:14:27 2006
@@ -1,6 +1,6 @@
 /*
  * Sequoia: Database clustering technology.
- * Copyright (C) 2005 Emic Networks
+ * Copyright (C) 2005-2006 Continuent, Inc.
  * Contact: [EMAIL PROTECTED]
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,7 @@
 #include "Connection.hpp"
 #include "Statement.hpp"
 #include "ParameterStatement.hpp"
+#include "ResultSetMetaData.hpp"
 
 using std::wstring;
 
@@ -485,7 +486,7 @@
         L"Request cannot be processed : connection is closed!");
 }
 
-DriverResultSet *Connection::preparedStatementGetMetaData(const wstring 
&sqlTemplate)
+ResultSetMetaData* Connection::preparedStatementGetMetaData(const wstring 
&sqlTemplate)
     throw (SocketIOException, BackendException, ProtocolException, 
NotImplementedException,
     UnexpectedException)
 {
@@ -500,7 +501,8 @@
   if (isDebugEnabled())
     logDebug(fctName, L"Statement sent successfully");
 
-  return receiveResultSet();
+  DriverResultSet* drsPtr = receiveResultSet();
+  return new ResultSetMetaData(drsPtr);
 }
 
 void Connection::setConnectionParametersOnRequest(Request &request)
Index: carob/src/ParameterStatement.cpp
diff -u carob/src/ParameterStatement.cpp:1.3 
carob/src/ParameterStatement.cpp:1.4
--- carob/src/ParameterStatement.cpp:1.3        Wed Jan 11 12:04:42 2006
+++ carob/src/ParameterStatement.cpp    Wed Jan 11 20:14:27 2006
@@ -1,6 +1,6 @@
 /*
  * Sequoia: Database clustering technology.
- * Copyright (C) 2005 Emic Networks
+ * Copyright (C) 2005-2006 Continuent, Inc.
  * Contact: [EMAIL PROTECTED]
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,7 +16,7 @@
  * limitations under the License.
  *
  * Initial developer(s): Zsolt Simon
- * Contributor(s): 
+ * Contributor(s): Gilles Rayrat
  */
 
 #include "Common.hpp"
@@ -29,9 +29,9 @@
 using namespace CarobNS;
 
 ParameterStatement::ParameterStatement(Connection *c, const wstring 
&sqlStatement) :
-Statement(c), mResultSet(0), rsMetaData(0)
+Statement(c)
 {
-  sql = trim(sqlStatement);
+  sql_request = trim(sqlStatement);
 
   // The following two boolean switches are used to make sure we're not
   // counting "?" in either strings or metadata strings. For instance the
@@ -40,8 +40,8 @@
   // doesn't have any parameters.
   bool inString = false, inMetaString = false; 
 
-  std::wstring::const_iterator isql = sql.begin();
-  std::wstring::const_iterator isql_end = sql.end();
+  std::wstring::const_iterator isql = sql_request.begin();
+  std::wstring::const_iterator isql_end = sql_request.end();
   std::wstring::const_iterator ilast = isql;
   
   inStrings.clear();
@@ -68,15 +68,13 @@
 
 ParameterStatement::~ParameterStatement()
 {
-  delete mResultSet;
-  delete rsMetaData;
 }
 
 void ParameterStatement::close()
 {
   Statement::close();
   
-  sql.clear();
+  sql_request.clear();
   inStrings.clear();
 }
 
@@ -183,18 +181,3 @@
   set<wstring>(parameterIndex, STRING_TAG, 
     x == NULL_TAG ? NULL_STRING_TAG : replaceAll(x, TAG_MARKER, 
TAG_MARKER_ESCAPE));
 }
-
-ResultSetMetaData *ParameterStatement::getMetaData()
-    throw (SocketIOException, BackendException, ProtocolException, 
NotImplementedException, 
-      UnexpectedException)
-{
-  if (!rsMetaData)
-  {
-    DriverResultSet *rs = getResultSet();
-    if (!rs)
-      rs = mResultSet = getConnectionPtr()->preparedStatementGetMetaData(sql);
-    if (rs)
-      rsMetaData = new ResultSetMetaData(rs);
-  }
-  return rsMetaData;
-}
Index: carob/src/Statement.cpp
diff -u carob/src/Statement.cpp:1.22 carob/src/Statement.cpp:1.23
--- carob/src/Statement.cpp:1.22        Fri Dec 30 17:59:36 2005
+++ carob/src/Statement.cpp     Wed Jan 11 20:14:27 2006
@@ -1,6 +1,6 @@
 /*
  * Sequoia: Database clustering technology.
- * Copyright (C) 2005 Emic Networks
+ * Copyright (C) 2005-2006 Continuent, Inc.
  * Contact: [EMAIL PROTECTED]
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,7 @@
 #include "CarobException.hpp"
 #include "Common.hpp"
 #include "Connection.hpp"
+#include "ResultSetMetaData.hpp"
 #include "Statement.hpp"
 
 using std::wstring;
@@ -31,8 +32,10 @@
 const ResultSetOrUpdateCount Statement::endOfResultList = {false, {-1}};
 
 Statement::Statement(Connection* c) :
+sql_request(L""),
 connectionPtr(c),
 lastResultPtr(NULL),
+rs_metadata_ptr(NULL),
 lastUpdateCount(-1),
 timeout(0),
 fetchSize(0),
@@ -63,6 +66,8 @@
   resultList.clear();
   lastResultPtr = NULL;
   lastUpdateCount = -1;
+  delete rs_metadata_ptr;
+  rs_metadata_ptr = NULL;
 }
 
 void Statement::removeResultSetFromList(DriverResultSet* drsPtr)
@@ -94,8 +99,8 @@
   {
     throw DriverException(L"Unable to execute query on a closed statement");
   }
-
-  RequestWithResultSetParameters request(skeleton);
+  sql_request = trim(skeleton);
+  RequestWithResultSetParameters request(sql_request);
   request.setEscapeProcessing(escapeProcessing).setTimeoutInSeconds(timeout);
   if (!parameters.empty())
     request.setParameters(parameters);
@@ -117,8 +122,8 @@
   }
   // invalidate the last write result
   cleanUpResults();
-
-  RequestWithResultSetParameters request(skeleton);
+  sql_request = trim(skeleton);
+  RequestWithResultSetParameters request(sql_request);
   request.setEscapeProcessing(escapeProcessing).setTimeoutInSeconds(timeout);
   if (!parameters.empty())
     request.setParameters(parameters);
@@ -145,8 +150,9 @@
   {
     throw DriverException(L"Unable to execute query on a closed statement");
   }
+  sql_request = trim(skeleton);
   cleanUpResults();
-  Request request(skeleton);
+  Request request(sql_request);
   request.setEscapeProcessing(escapeProcessing).setTimeoutInSeconds(timeout);
   if (!parameters.empty())
     request.setParameters(parameters);
@@ -263,3 +269,20 @@
     catch (...) {} //ignore
   }
 }
+
+ResultSetMetaData* Statement::getMetaData() throw (SocketIOException,
+    BackendException, ProtocolException, NotImplementedException,
+    UnexpectedException)
+{
+  // clean-up old one (if none, won't do anything)
+  delete rs_metadata_ptr; rs_metadata_ptr = NULL;
+  if (lastResultPtr != NULL)
+  {
+    rs_metadata_ptr = new ResultSetMetaData(lastResultPtr);
+  }
+  else
+  {
+    rs_metadata_ptr = connectionPtr->preparedStatementGetMetaData(sql_request);
+  }
+  return rs_metadata_ptr;
+}

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

Reply via email to