Author: wyoung
Date: Tue Mar 18 06:28:48 2008
New Revision: 2245

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2245&view=rev
Log:
Refraining from single-quoting NOW() call generated for default init of
DateTime type when building queries from SSQLS objects.  (NOW() was
already treated correctly for many other cases.)

Modified:
    trunk/lib/sql_buffer.cpp
    trunk/lib/sql_buffer.h

Modified: trunk/lib/sql_buffer.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/sql_buffer.cpp?rev=2245&r1=2244&r2=2245&view=diff
==============================================================================
--- trunk/lib/sql_buffer.cpp (original)
+++ trunk/lib/sql_buffer.cpp Tue Mar 18 06:28:48 2008
@@ -25,6 +25,9 @@
 
 #include "sql_buffer.h"
 
+#include "datetime.h"
+#include "sql_types.h"
+
 #include <string.h>
 
 namespace mysqlpp {
@@ -47,6 +50,21 @@
        type_ = type;
        is_null_ = is_null;
        return *this;
+}
+
+bool
+SQLBuffer::quote_q() const
+{
+       if ((type_.base_type().c_type() == typeid(mysqlpp::sql_datetime)) &&
+                       data_ && (length_ >= 5) && (memcmp(data_, "NOW()", 5) 
== 0)) {
+               // The default DATETIME value is special-cased as a call to the
+               // SQL NOW() function, which must not be quoted.
+               return false;
+       }
+       else {
+               // Normal case: we can infer the need to quote from the type.
+               return type_.quote_q();
+       }
 }
 
 void

Modified: trunk/lib/sql_buffer.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/sql_buffer.h?rev=2245&r1=2244&r2=2245&view=diff
==============================================================================
--- trunk/lib/sql_buffer.h (original)
+++ trunk/lib/sql_buffer.h Tue Mar 18 06:28:48 2008
@@ -2,7 +2,7 @@
 /// \brief Declares the SQLBuffer class
 
 /***********************************************************************
- Copyright (c) 2007 by Educational Technology Resources, Inc. and
+ Copyright (c) 2007-2008 by Educational Technology Resources, Inc. and
  (c) 2007 by Jonathan Wakely.  Others may also hold copyrights on
  code in this file.  See the CREDITS file in the top directory of
  the distribution for details.
@@ -104,7 +104,7 @@
 
        /// \brief Returns true if we were initialized with a data type
        /// that must be quoted when used in a SQL query
-       bool quote_q() const { return type_.quote_q(); }
+       bool quote_q() const;
 
        /// \brief Sets the internal SQL null flag
        void set_null() { is_null_ = true; }


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

Reply via email to