Author: wyoung
Date: Fri Jul 13 07:30:03 2007
New Revision: 1696

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1696&view=rev
Log:
- Changed all at() and operator[]() methods to take plain int instead of
  unsigned int.  This appears to fix the ambiguity between it and const
  char* for 0.  This means you can now say row[0] and have it do the
  right thing!
- Changed all uses of at(0) to use [0]
- Added operator[] to all classes that only had at()

Modified:
    trunk/Wishlist
    trunk/examples/custom3.cpp
    trunk/examples/dbinfo.cpp
    trunk/examples/simple1.cpp
    trunk/examples/tquery.cpp
    trunk/examples/util.cpp
    trunk/lib/fields.cpp
    trunk/lib/fields.h
    trunk/lib/resiter.h
    trunk/lib/result.h
    trunk/lib/row.cpp
    trunk/lib/row.h

Modified: trunk/Wishlist
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=1696&r1=1695&r2=1696&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Fri Jul 13 07:30:03 2007
@@ -94,14 +94,6 @@
 
           http://lists.mysql.com/plusplus/5617
 
-    o Change operator[](unsigned int) in Row and the iterator classes
-      to take a plain int.  This should fix the ambiguous overload
-      problems, such as with row[0].  Details:
-
-          http://lists.mysql.com/plusplus/4947
-          http://lists.mysql.com/plusplus/4952
-          http://lists.mysql.com/plusplus/4960
-    
     o Apply Waba's patch allowing Null<T> fields in SSQLSes:
       
           http://lists.mysql.com/plusplus/5433

Modified: trunk/examples/custom3.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/custom3.cpp?rev=1696&r1=1695&r2=1696&view=diff
==============================================================================
--- trunk/examples/custom3.cpp (original)
+++ trunk/examples/custom3.cpp Fri Jul 13 07:30:03 2007
@@ -3,7 +3,7 @@
        Specialized SQL Structures feature of MySQL++.
 
  Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
+ MySQL AB, and (c) 2004-2007 by Educational Technology Resources, Inc.
  Others may also hold copyrights on code in this file.  See the CREDITS
  file in the top directory of the distribution for details.
 
@@ -58,7 +58,7 @@
                // there's no point in storing the result in an STL container.
                // We can store the first row directly into a stock structure
                // because one of an SSQLS's constructors takes a Row object.
-               stock row = res.at(0);
+               stock row = res[0];
 
                // Create a copy so that the replace query knows what the
                // original values are.

Modified: trunk/examples/dbinfo.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/dbinfo.cpp?rev=1696&r1=1695&r2=1696&view=diff
==============================================================================
--- trunk/examples/dbinfo.cpp (original)
+++ trunk/examples/dbinfo.cpp Fri Jul 13 07:30:03 2007
@@ -3,7 +3,7 @@
        database schema, such as table names, column types, etc.
 
  Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
+ MySQL AB, and (c) 2004-2007 by Educational Technology Resources, Inc.
  Others may also hold copyrights on code in this file.  See the CREDITS
  file in the top directory of the distribution for details.
 
@@ -69,7 +69,7 @@
                Result::iterator i;
                for (i = res.begin(); i != res.end(); ++i) {
                        row = *i;
-                       cout << endl << '\t' << setw(17) << row.at(0);
+                       cout << endl << '\t' << setw(17) << row[0];
                }
                cout << separator;
                
@@ -86,8 +86,8 @@
                cout.setf(ios::left);
                for (i = res.begin(); i != res.end(); ++i) {
                        row = *i;
-                       string xx(row.at(0));
-                       cout << endl << '\t' << setw(17) << row.at(0);
+                       string xx(row[0]);
+                       cout << endl << '\t' << setw(17) << row[0];
                        yy.push_back(xx);
                }
                cout << separator;

Modified: trunk/examples/simple1.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/simple1.cpp?rev=1696&r1=1695&r2=1696&view=diff
==============================================================================
--- trunk/examples/simple1.cpp (original)
+++ trunk/examples/simple1.cpp Fri Jul 13 07:30:03 2007
@@ -54,7 +54,7 @@
                mysqlpp::Row row;
                mysqlpp::Row::size_type i;
                for (i = 0; row = res.at(i); ++i) {
-                       cout << '\t' << row.at(0) << endl;
+                       cout << '\t' << row[0] << endl;
                }
        }
        else {

Modified: trunk/examples/tquery.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/tquery.cpp?rev=1696&r1=1695&r2=1696&view=diff
==============================================================================
--- trunk/examples/tquery.cpp (original)
+++ trunk/examples/tquery.cpp Fri Jul 13 07:30:03 2007
@@ -61,7 +61,7 @@
                query << "update stock set item = %0q where item = %1q";
                query.parse();
                mysqlpp::ResNSel res2 = query.execute("Nuerenberger Bratwurst",
-                               res1.at(0).at(0).c_str());
+                               res1[0][0].c_str());
 
                // Print the new table contents.
                print_stock_table(query);

Modified: trunk/examples/util.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/util.cpp?rev=1696&r1=1695&r2=1696&view=diff
==============================================================================
--- trunk/examples/util.cpp (original)
+++ trunk/examples/util.cpp Fri Jul 13 07:30:03 2007
@@ -3,7 +3,7 @@
        programs.
 
  Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004-2006 by Educational Technology Resources, Inc.
+ MySQL AB, and (c) 2004-2007 by Educational Technology Resources, Inc.
  Others may also hold copyrights on code in this file.  See the CREDITS
  file in the top directory of the distribution for details.
 
@@ -86,34 +86,7 @@
 void
 print_stock_row(const mysqlpp::Row& row)
 {
-       // The brief code below illustrates several aspects of the library
-       // worth noting:
-       //
-       // 1. You can subscript a row by integer (position of the field in
-       // the row) or by string (name of field in the row).  The former is
-       // more efficient, while the latter trades some efficiency for
-       // robustness in the face of schema changes.  (Consider using SSQLS
-       // if you need a tradeoff in between these two positions.)
-       // 
-       // 2. You can also get at a row's field's with Row::at(), which is
-       // much like Row::operator[](int).  Besides the syntax difference,
-       // the only practical difference is that only at() can access field
-       // 0: this is because '0' can be converted to both int and to const
-       // char*, so the compiler rightly complains that it can't decide
-       // which overload to call.
-       //
-       // 3. Notice that we make an explicit temporary copy of the first
-       // field, which is the only string field.  We must tolerate the
-       // inefficiency of this copy, because Row::operator[] returns a
-       // ColData object, which goes away after it is converted to some
-       // other form.  So, while we could have made print_stock_row()
-       // take a const char* argument (as past versions mistakenly did!)
-       // this would result in a dangling pointer, since it points into the
-       // ColData object, which is dead by the time the pointer is
-       // evaluated in print_stock_row().  It will probably even work this
-       // way, but like any memory bug, it can wreak subtle havoc.
-       std::string item(row.at(0));
-       print_stock_row(item, row["num"], row[2], row[3], row[4]);
+       print_stock_row(string(row[0]), row[1], row[2], row[3], row[4]);
 }
 
 

Modified: trunk/lib/fields.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/fields.cpp?rev=1696&r1=1695&r2=1696&view=diff
==============================================================================
--- trunk/lib/fields.cpp (original)
+++ trunk/lib/fields.cpp Fri Jul 13 07:30:03 2007
@@ -2,7 +2,7 @@
  fields.cpp - Implements the Fields class.
 
  Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
+ MySQL AB, and (c) 2004-2007 by Educational Technology Resources, Inc.
  Others may also hold copyrights on code in this file.  See the CREDITS
  file in the top directory of the distribution for details.
 
@@ -35,7 +35,8 @@
        return res_->num_fields();
 }
 
-const Field& Fields::at(Fields::size_type i) const
+const Field&
+Fields::at(int i) const
 {
        res_->field_seek(i);
        return res_->fetch_field();

Modified: trunk/lib/fields.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/fields.h?rev=1696&r1=1695&r2=1696&view=diff
==============================================================================
--- trunk/lib/fields.h (original)
+++ trunk/lib/fields.h Fri Jul 13 07:30:03 2007
@@ -54,13 +54,12 @@
        }
 
        /// \brief Returns a field given its index.
-       const Field& at(Fields::size_type i) const;
+       const Field& at(int i) const;
 
        /// \brief Returns a field given its index.
-       const Field& at(int i) const
-       {
-               return at(static_cast<size_type>(i));
-       }
+       ///
+       /// Just a synonym for at()
+       const Field& operator [](int i) const { return at(i); }
 
        size_type size() const; ///< get the number of fields
 

Modified: trunk/lib/resiter.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/resiter.h?rev=1696&r1=1695&r2=1696&view=diff
==============================================================================
--- trunk/lib/resiter.h (original)
+++ trunk/lib/resiter.h Fri Jul 13 07:30:03 2007
@@ -8,7 +8,7 @@
 
 /***********************************************************************
  Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
+ MySQL AB, and (c) 2004-2007 by Educational Technology Resources, Inc.
  Others may also hold copyrights on code in this file.  See the CREDITS
  file in the top directory of the distribution for details.
 
@@ -45,7 +45,7 @@
 /// \brief A base class that one derives from to become a random
 /// access container, which can be accessed with subscript notation.
 ///
-/// OnType must have the member functions \c operator[](SizeType) and
+/// OnType must have the member functions \c operator[](int) and
 // \c size() defined for it.
 
 template <class OnType,
@@ -82,7 +82,7 @@
        virtual size_type size() const = 0;     
 
        /// \brief Return element at given index in container
-       virtual ReturnType at(SizeType i) const = 0;
+       virtual ReturnType at(int i) const = 0;
 
        /// \brief Return maximum number of elements that can be stored
        /// in container without resizing.
@@ -182,7 +182,7 @@
        
        /// \brief Return a copy of the element at the given position
        /// within the container.
-       ReturnType operator [](SizeType n) const { return d_->at(n); }
+       ReturnType operator [](int n) const { return d_->at(n); }
        
        /// \brief Move the iterator to the next element, returning an
        /// iterator to that element

Modified: trunk/lib/result.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/result.h?rev=1696&r1=1695&r2=1696&view=diff
==============================================================================
--- trunk/lib/result.h (original)
+++ trunk/lib/result.h Fri Jul 13 07:30:03 2007
@@ -3,7 +3,7 @@
 
 /***********************************************************************
  Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
+ MySQL AB, and (c) 2004-2007 by Educational Technology Resources, Inc.
  Others may also hold copyrights on code in this file.  See the CREDITS
  file in the top directory of the distribution for details.
 
@@ -420,11 +420,16 @@
        }
 
        /// \brief Get the row with an offset of i.
-       const Row at(size_type i) const
+       const Row at(int i) const
        {
                data_seek(i);
                return fetch_row();
        }
+
+       /// \brief Get the row with an offset of i.
+       ///
+       /// Just a synonym for at()
+       const Row operator [](int i) const { return at(i); }
 };
 
 

Modified: trunk/lib/row.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/row.cpp?rev=1696&r1=1695&r2=1696&view=diff
==============================================================================
--- trunk/lib/row.cpp (original)
+++ trunk/lib/row.cpp Fri Jul 13 07:30:03 2007
@@ -2,7 +2,7 @@
  row.cpp - Implements the Row class.
 
  Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
+ MySQL AB, and (c) 2004-2007 by Educational Technology Resources, Inc.
  Others may also hold copyrights on code in this file.  See the CREDITS
  file in the top directory of the distribution for details.
 
@@ -70,7 +70,7 @@
        return res_->num_fields();
 }
 
-const ColData Row::at(size_type i) const
+const ColData Row::at(int i) const
 {
        if (initialized_) {
                const std::string& s = data_.at(i);

Modified: trunk/lib/row.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/row.h?rev=1696&r1=1695&r2=1696&view=diff
==============================================================================
--- trunk/lib/row.h (original)
+++ trunk/lib/row.h Fri Jul 13 07:30:03 2007
@@ -3,7 +3,7 @@
 
 /***********************************************************************
  Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
+ MySQL AB, and (c) 2004-2007 by Educational Technology Resources, Inc.
  Others may also hold copyrights on code in this file.  See the CREDITS
  file in the top directory of the distribution for details.
 
@@ -124,14 +124,11 @@
        /// \brief Get the value of a field given its index.
        ///
        /// This function is just syntactic sugar, wrapping the at() method.
-       /// The at() method is the only way to get at the first field in a
-       /// result set by index, as \c row[0] is ambiguous: it could call
-       /// either \c operator[] overload.
        ///
        /// \sa at() for the full documentation for this operator, and
        /// operator[](const char*) for further caveats about using this
        /// operator.
-       const ColData operator [](size_type i) const
+       const ColData operator [](int i) const
        {
                return at(i);
        }
@@ -147,7 +144,7 @@
        /// retrieving data from this row object.
        ///
        /// See operator[](const char*) for more caveats.
-       const ColData at(size_type i) const;
+       const ColData at(int i) const;
 
        /// \brief Return the value of a field as a C string given its
        /// index, in raw form.


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

Reply via email to