Author: mysqlpp
Date: Mon Dec  3 13:03:05 2007
New Revision: 1964

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1964&view=rev
Log:
- Passing DBDriver* down from Query to Result and ResUse instances
- Moved several C API wrappers from ResUse/Result into DBDriver, and
  using new DBDriver pointer to provide access to these wrappers

Modified:
    trunk/Wishlist
    trunk/lib/dbdriver.h
    trunk/lib/query.cpp
    trunk/lib/result.cpp
    trunk/lib/result.h

Modified: trunk/Wishlist
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=1964&r1=1963&r2=1964&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Mon Dec  3 13:03:05 2007
@@ -33,8 +33,6 @@
         value semantics.
 
        o Add userman chapter on connection options
-
-       o Still mysql_*() stuff in Row at least.  Check result module too.
 
     o Create an SSQLS base class containing all of the common
       boilerplate, which leaf SSQLSes derive from.  This should in turn

Modified: trunk/lib/dbdriver.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/dbdriver.h?rev=1964&r1=1963&r2=1964&view=diff
==============================================================================
--- trunk/lib/dbdriver.h (original)
+++ trunk/lib/dbdriver.h Mon Dec  3 13:03:05 2007
@@ -122,6 +122,12 @@
        /// \return true if database was created successfully
        bool create_db(const char* db) const;
 
+       /// \brief Seeks to a particualr row within the result set
+       ///
+       /// Wraps mysql_data_seek() in MySQL C API.
+       void data_seek(MYSQL_RES* res, ulonglong offset) const
+                       { mysql_data_seek(res, offset); }
+
        /// \brief Drop the connection to the database server
        ///
        /// This method is protected because it should only be used within
@@ -179,6 +185,36 @@
        /// Wraps \c mysql_real_query() in the MySQL C API.
        bool execute(const char* qstr, size_t length)
                        { return !mysql_real_query(&mysql_, qstr, length); }
+
+       /// \brief Returns the next raw C API row structure from the given
+       /// result set.
+       ///
+       /// This is for "use" query result sets only.  "store" queries have
+       /// all the rows already.
+       ///
+       /// Wraps \c mysql_fetch_row() in MySQL C API.
+       MYSQL_ROW fetch_row(MYSQL_RES* res) const
+                       { return mysql_fetch_row(res); }
+
+       /// \brief Returns the lengths of the fields in the current row
+       /// from a "use" query.
+       ///
+       /// Wraps \c mysql_fetch_lengths() in MySQL C API.
+       const unsigned long* fetch_lengths(MYSQL_RES* res) const
+                       { return mysql_fetch_lengths(res); }
+
+       /// \brief Returns information about a particular field in a result
+       /// set
+       ///
+       /// Wraps \c mysql_fetch_field() in MySQL C API.
+       MYSQL_FIELD* fetch_field(MYSQL_RES* res) const
+                       { return mysql_fetch_field(res); }
+
+       /// \brief Jumps to the given field within the result set
+       ///
+       /// Wraps \c mysql_field_seek() in MySQL C API.
+       void field_seek(MYSQL_RES* res, int field) const
+                       { mysql_field_seek(res, field); }
 
        /// \brief Return the connection options object
        st_mysql_options get_options() const { return mysql_.options; }
@@ -239,6 +275,18 @@
                        default: return nr_error;
                }
        }
+
+       /// \brief Returns the number of fields in the given result set
+       ///
+       /// Wraps \c mysql_num_fields() in MySQL C API.
+       int num_fields(MYSQL_RES* res) const
+                       { return mysql_num_fields(res); }
+       
+       /// \brief Returns the number of rows in the given result set
+       ///
+       /// Wraps \c mysql_num_rows() in MySQL C API.
+       ulonglong num_rows(MYSQL_RES* res) const
+                       { return mysql_num_rows(res); }
 
        /// \brief "Pings" the MySQL database
        ///

Modified: trunk/lib/query.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/query.cpp?rev=1964&r1=1963&r2=1964&view=diff
==============================================================================
--- trunk/lib/query.cpp (original)
+++ trunk/lib/query.cpp Mon Dec  3 13:03:05 2007
@@ -492,7 +492,7 @@
        }
 
        if (res) {
-               return Result(res, throw_exceptions());
+               return Result(res, conn_->driver(), throw_exceptions());
        }
        else {
                // Either result set is empty (which is copacetic), or there
@@ -520,7 +520,7 @@
                // There are more results, so return next result set.
                MYSQL_RES* res = conn_->driver()->store_result();
                if (res) {
-                       return Result(res, throw_exceptions());
+                       return Result(res, conn_->driver(), throw_exceptions());
                } 
                else {
                        // Result set is null, but throw an exception only i it 
is
@@ -608,7 +608,7 @@
        }
 
        if (res) {
-               return ResUse(res, throw_exceptions());
+               return ResUse(res, conn_->driver(), throw_exceptions());
        }
        else {
                // Either result set is empty (which is copacetic), or there

Modified: trunk/lib/result.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/result.cpp?rev=1964&r1=1963&r2=1964&view=diff
==============================================================================
--- trunk/lib/result.cpp (original)
+++ trunk/lib/result.cpp Mon Dec  3 13:03:05 2007
@@ -26,18 +26,19 @@
 
 #include "result.h"
 
+#include "dbdriver.h"
+
 namespace mysqlpp {
 
-ResUse::ResUse(MYSQL_RES* result, bool te) :
+ResUse::ResUse(MYSQL_RES* result, DBDriver* dbd, bool te) :
 OptionalExceptions(te),
-initialized_(false),
+driver_(result ? dbd : 0),
 fields_(this)
 {
        if (result) {
                result_ = result;
                names_ = new FieldNames(this);
                types_ = new FieldTypes(this);
-               initialized_ = true;
        }
 }
 
@@ -57,14 +58,57 @@
                fields_ = Fields(this);
                names_ = other.names_;
                types_ = other.types_;
-               initialized_ = true;
+               driver_ = other.driver_;
        }
        else {
                result_ = 0;
                names_ = 0;
                types_ = 0;
-               initialized_ = other.initialized_;
+               driver_ = 0;
        }
+}
+
+
+void
+Result::data_seek(ulonglong offset) const
+{
+       driver_->data_seek(result_.raw(), offset);
+}
+
+
+const unsigned long*
+ResUse::fetch_lengths() const
+{
+       return driver_->fetch_lengths(result_.raw());
+}
+
+
+Row
+ResUse::fetch_row() const
+{
+       if (!result_) {
+               if (throw_exceptions()) {
+                       throw UseQueryError("Results not fetched");
+               }
+               else {
+                       return Row();
+               }
+       }
+       MYSQL_ROW row = driver_->fetch_row(result_.raw());
+       const unsigned long* lengths = fetch_lengths();
+       if (row && lengths) {
+               return Row(row, this, lengths, throw_exceptions());
+       }
+       else {
+               return Row();
+       }
+}
+
+
+MYSQL_ROW
+ResUse::fetch_raw_row() const
+{
+       return driver_->fetch_row(result_.raw());
 }
 
 
@@ -80,6 +124,20 @@
 }
 
 
+int
+ResUse::num_fields() const
+{
+       return driver_->num_fields(result_.raw());
+}
+
+
+ulonglong
+Result::num_rows() const
+{
+       return driver_ ? driver_->num_rows(result_.raw()) : 0;
+}
+
+
 ResUse&
 ResUse::operator =(const ResUse& other)
 {

Modified: trunk/lib/result.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/result.h?rev=1964&r1=1963&r2=1964&view=diff
==============================================================================
--- trunk/lib/result.h (original)
+++ trunk/lib/result.h Mon Dec  3 13:03:05 2007
@@ -75,18 +75,18 @@
        /// \brief Default constructor
        ResUse() :
        OptionalExceptions(),
-       initialized_(false),
+       driver_(0),
        fields_(this)
        {
        }
        
        /// \brief Create the object, fully initialized
-       ResUse(MYSQL_RES* result, bool te = true);
+       ResUse(MYSQL_RES* result, DBDriver* dbd, bool te = true);
        
        /// \brief Create a copy of another ResUse object
        ResUse(const ResUse& other) :
        OptionalExceptions(),
-       initialized_(false)
+       driver_(0)
        {
                copy(other);
        }
@@ -97,35 +97,25 @@
        /// \brief Copy another ResUse object's data into this object
        ResUse& operator =(const ResUse& other);
 
+       /// \brief Returns the lengths of the fields in the current row of
+       /// the result set.
+       ///
+       /// \internal This should not be terribly useful to end-user code.
+       /// The Row object returned by fetch_row() contains these lengths.
+       const unsigned long* fetch_lengths() const;
+
        /// \brief Returns the next row in a "use" query's result set
        ///
        /// <b>Design weakness warning:</b> Although Result (returned from
        /// "store" queries) contains this method, it is of no use with such
        /// result sets.
        ///
-       /// This is a thick wrapper around mysql_fetch_row() in the MySQL
-       /// C API.  It does a lot of error checking before returning the Row
-       /// object containing the row data.  If you need the underlying C
-       /// API row data, call fetch_raw_row() instead.
-       Row fetch_row() const
-       {
-               if (!result_) {
-                       if (throw_exceptions()) {
-                               throw UseQueryError("Results not fetched");
-                       }
-                       else {
-                               return Row();
-                       }
-               }
-               MYSQL_ROW row = fetch_raw_row();
-               const unsigned long* lengths = fetch_lengths();
-               if (row && lengths) {
-                       return Row(row, this, lengths, throw_exceptions());
-               }
-               else {
-                       return Row();
-               }
-       }
+       /// This is a thick wrapper around DBDriver::fetch_row().  It does a
+       /// lot of error checking before returning the Row object containing
+       /// the row data.
+       ///
+       /// \sa fetch_raw_row()
+       Row fetch_row() const;
 
        /// \brief Wraps mysql_fetch_row() in MySQL C API.
        ///
@@ -133,25 +123,11 @@
        /// It is anticipated that this is only useful within the library,
        /// to implement higher-level query types on top of raw "use"
        /// queries. Query::storein() uses it, for example.
-       MYSQL_ROW fetch_raw_row() const
-                       { return mysql_fetch_row(result_.raw()); }
-
-       /// \brief Wraps mysql_fetch_lengths() in MySQL C API.
-       const unsigned long* fetch_lengths() const
-                       { return mysql_fetch_lengths(result_.raw()); }
-
-       /// \brief Wraps mysql_fetch_field() in MySQL C API.
-       const Field& fetch_field() const
-                       { return *mysql_fetch_field(result_.raw()); }
-
-       /// \brief Wraps mysql_field_seek() in MySQL C API.
-       void field_seek(int field) const
-                       { mysql_field_seek(result_.raw(), field); }
-
-       /// \brief Wraps mysql_num_fields() in MySQL C API.
-       int num_fields() const
-                       { return mysql_num_fields(result_.raw()); }
-       
+       MYSQL_ROW fetch_raw_row() const;
+
+       /// \brief Returns the number of fields in this result set
+       int num_fields() const;
+
        /// \brief Return the pointer to the underlying MySQL C API
        /// result set object.
        ///
@@ -196,8 +172,8 @@
        const RefCountedPointer<FieldNames>& field_names() const
                        { return names_; }
 
-       /// \brief Get the MySQL type for a field given its index.
-       const mysql_type_info& field_type(int i) const
+       /// \brief Get the type of a particular field within this result set.
+       const FieldTypes::value_type& field_type(int i) const
                        { return types_->at(i); }
 
        /// \brief Get a list of the types of the fields within this
@@ -212,8 +188,8 @@
        const Field& field(unsigned int i) const { return fields_.at(i); }
 
 protected:
-       bool initialized_;                      ///< if true, object is fully 
initted
-       Fields fields_;                         ///< list of fields in result
+       DBDriver* driver_;      ///< Access to DB driver; fully initted if 
nonzero
+       Fields fields_;         ///< list of fields in result
 
        /// \brief underlying C API result set
        ///
@@ -308,13 +284,14 @@
        reverse_iterator rend() const { return reverse_iterator(begin()); }
 
        /// \brief Default constructor
-       Result()
+       Result() :
+       ResUse()
        {
        }
        
        /// \brief Fully initialize object
-       Result(MYSQL_RES* result, bool te = true) :
-       ResUse(result, te)
+       Result(MYSQL_RES* result, DBDriver* dbd, bool te = true) :
+       ResUse(result, dbd, te)
        {
        }
 
@@ -327,17 +304,11 @@
        /// \brief Destroy result set
        virtual ~Result() { }
 
-       /// \brief Wraps mysql_num_rows() in MySQL C API.
-       ulonglong num_rows() const
-       {
-               return initialized_ ? mysql_num_rows(result_.raw()) : 0;
-       }
-
-       /// \brief Wraps mysql_data_seek() in MySQL C API.
-       void data_seek(uint offset) const
-       {
-               mysql_data_seek(result_.raw(), offset);
-       }
+       /// \brief Returns the number of rows in this result set
+       ulonglong num_rows() const;
+
+       /// \brief Seeks to a particualr row within the result set
+       void data_seek(ulonglong offset) const;
 
        /// \brief Alias for num_rows(), only with different return type.
        size_type size() const { return static_cast<size_type>(num_rows()); }


_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits

Reply via email to