Date: Wednesday, January 11, 2006 @ 10:21:29
  Author: zsolt
    Path: /cvsroot/carob/carob

Modified: include/Connection.hpp (1.44 -> 1.45)
          include/ParameterStatement.hpp (1.3 -> 1.4)
          include/Statement.hpp (1.22 -> 1.23) src/Connection.cpp (1.51 ->
          1.52) src/ParameterStatement.cpp (1.1 -> 1.2)

Implemented ParameterStatement::getMetaData
The metadata is cached and is freed at the destruction of the statement.


--------------------------------+
 include/Connection.hpp         |   10 ++++++++++
 include/ParameterStatement.hpp |   13 +++++++++++++
 include/Statement.hpp          |    4 ++++
 src/Connection.cpp             |   18 ++++++++++++++++++
 src/ParameterStatement.cpp     |   19 ++++++++++++++++++-
 5 files changed, 63 insertions(+), 1 deletion(-)


Index: carob/include/Connection.hpp
diff -u carob/include/Connection.hpp:1.44 carob/include/Connection.hpp:1.45
--- carob/include/Connection.hpp:1.44   Fri Jan  6 14:38:51 2006
+++ carob/include/Connection.hpp        Wed Jan 11 10:21:29 2006
@@ -95,6 +95,7 @@
 //#define DatabaseMetaDataGetUDTs                 72
 //#define DatabaseMetaDataGetVersionColumns       73
 //#define DatabaseStaticMetadata                  80
+#define PreparedStatementGetMetaData            81
 
 class Statement;
 class ParameterStatement;
@@ -107,6 +108,7 @@
 friend class DriverResultSet;
 /** Statements must inform connection about their destruction */
 friend class Statement;
+friend class ParameterStatement;
 public:
   /**
    * Creates a new connection and connects to a controller with the given
@@ -341,6 +343,14 @@
    */
   const DriverSocket& getDriverSocket() { return *driverSocketPtr; }
 
+  /**
+   * Returns the metadata of the sql template as a resultset.
+   * @param sqlTemplate sql template of the PreparedStatement
+   */
+  DriverResultSet     *preparedStatementGetMetaData(const std::wstring 
&sqlTemplate)
+                          throw (SocketIOException, ProtocolException, 
+                            NotImplementedException, UnexpectedException);
+                            
 private:
   /** This connection socket pointer */
   DriverSocket*       driverSocketPtr;
Index: carob/include/ParameterStatement.hpp
diff -u carob/include/ParameterStatement.hpp:1.3 
carob/include/ParameterStatement.hpp:1.4
--- carob/include/ParameterStatement.hpp:1.3    Tue Jan 10 13:38:40 2006
+++ carob/include/ParameterStatement.hpp        Wed Jan 11 10:21:29 2006
@@ -27,6 +27,7 @@
 #include "CarobException.hpp"
 #include "Statement.hpp"
 #include "BigDecimal.hpp"
+#include "ResultSetMetaData.hpp"
 
 namespace CarobNS {
 
@@ -257,6 +258,14 @@
    * @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 *ParameterStatement::getMetaData()
+                          throw (SocketIOException, ProtocolException, 
+                            NotImplementedException, UnexpectedException);
 
 protected:
   /**
@@ -284,6 +293,10 @@
   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.22 carob/include/Statement.hpp:1.23
--- carob/include/Statement.hpp:1.22    Fri Dec 30 17:59:36 2005
+++ carob/include/Statement.hpp Wed Jan 11 10:21:29 2006
@@ -333,6 +333,10 @@
   std::list<ResultSetOrUpdateCount>  resultList;
   /** Iterator on the list of results */
   std::list<ResultSetOrUpdateCount>::const_iterator resultListIterator;
+  /**
+   * Returns the pointer to the connection that created us.
+   */
+  Connection*             getConnectionPtr() {return connectionPtr;}
 private:
   /** Connection that created us */
   Connection*             connectionPtr;
Index: carob/src/Connection.cpp
diff -u carob/src/Connection.cpp:1.51 carob/src/Connection.cpp:1.52
--- carob/src/Connection.cpp:1.51       Fri Jan  6 14:38:51 2006
+++ carob/src/Connection.cpp    Wed Jan 11 10:21:29 2006
@@ -485,6 +485,24 @@
         L"Request cannot be processed : connection is closed!");
 }
 
+DriverResultSet *Connection::preparedStatementGetMetaData(const wstring 
&sqlTemplate)
+    throw (SocketIOException, ProtocolException, NotImplementedException,
+    UnexpectedException)
+{
+  checkIfConnected();
+  wstring fctName(L"Connection::PreparedStatementGetMetaData");
+  
+  LockScope ls(&connectionCS);
+
+  sendCommand(*driverSocketPtr, PreparedStatementGetMetaData);
+  *driverSocketPtr << sqlTemplate;
+
+  if (isDebugEnabled())
+    logDebug(fctName, L"Statement sent successfully");
+
+  return receiveResultSet();
+}
+
 void Connection::setConnectionParametersOnRequest(Request &request)
 {
   request.setIsAutoCommit(autoCommit);
Index: carob/src/ParameterStatement.cpp
diff -u carob/src/ParameterStatement.cpp:1.1 
carob/src/ParameterStatement.cpp:1.2
--- carob/src/ParameterStatement.cpp:1.1        Thu Dec 22 17:02:51 2005
+++ carob/src/ParameterStatement.cpp    Wed Jan 11 10:21:29 2006
@@ -22,13 +22,14 @@
 #include "Common.hpp"
 #include "ParameterStatement.hpp"
 #include "CarobException.hpp"
+#include "Connection.hpp"
 
 using std::wstring;
 
 using namespace CarobNS;
 
 ParameterStatement::ParameterStatement(Connection *c, const wstring 
&sqlStatement) :
-Statement(c)
+Statement(c), mResultSet(0), rsMetaData(0)
 {
   sql = trim(sqlStatement);
 
@@ -67,6 +68,8 @@
 
 ParameterStatement::~ParameterStatement()
 {
+  delete mResultSet;
+  delete rsMetaData;
 }
 
 void ParameterStatement::close()
@@ -180,3 +183,17 @@
   set<wstring>(parameterIndex, STRING_TAG, 
     x == NULL_TAG ? NULL_STRING_TAG : replaceAll(x, TAG_MARKER, 
TAG_MARKER_ESCAPE));
 }
+
+ResultSetMetaData *ParameterStatement::getMetaData()
+    throw (SocketIOException, ProtocolException, NotImplementedException, 
UnexpectedException)
+{
+  if (!rsMetaData)
+  {
+    DriverResultSet *rs = getResultSet();
+    if (!rs)
+      rs = mResultSet = getConnectionPtr()->preparedStatementGetMetaData(sql);
+    if (rs)
+      rsMetaData = new ResultSetMetaData(rs);
+  }
+  return rsMetaData;
+}

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

Reply via email to