Author: wyoung
Date: Tue Mar 24 17:18:35 2009
New Revision: 2492
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2492&view=rev
Log:
- Initializing a SQLTypeAdapter with an FP type equal to infinity or
NaN results in SQL null if the type is also nullable, or 0 otherwise.
Previously, we got an implementation-defined string, which could give
invalid SQL, or could give 0, a different value from NaN, infinity, or
SQL null. This does collapse the notions of NaN and infinity, but the
MySQL reference manual doesn't say how you're supposed to preserve
these differences.
- Modified the examples' stock.price field to be nullable, and purposely
passing an infinite value in one of the examples ("priceless!") to
test this new feature.
Modified:
trunk/bmark.txt
trunk/examples/for_each.cpp
trunk/examples/printdata.cpp
trunk/examples/printdata.h
trunk/examples/resetdb.cpp
trunk/examples/ssqls2.cpp
trunk/examples/stock.h
trunk/lib/stadapter.cpp
Modified: trunk/bmark.txt
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/bmark.txt?rev=2492&r1=2491&r2=2492&view=diff
==============================================================================
--- trunk/bmark.txt (original)
+++ trunk/bmark.txt Tue Mar 24 17:18:35 2009
@@ -135,7 +135,7 @@
================ END ssqls1 OUTPUT ================
---------------- BEGIN ssqls2 OUTPUT ----------------
-Query: INSERT INTO stock (item,num,weight,price,sdate,description) VALUES
('Hot Dogs',100,1.5,1.75,'1998-09-25',NULL)
+Query: INSERT INTO stock (item,num,weight,price,sdate,description) VALUES
('Hot Dogs',100,1.5,NULL,'1998-09-25',NULL)
Query: select * from stock
Records found: 5
@@ -145,7 +145,7 @@
Pickle Relish 87 1.5 1.75 1998-09-04
Hot Mustard 73 0.95 0.97 1998-05-25
Hotdog Buns 65 1.1 1.1 1998-04-23
-Hot Dogs 100 1.5 1.75 1998-09-25
+Hot Dogs 100 1.5 (NULL) 1998-09-25
================ END ssqls2 OUTPUT ================
---------------- BEGIN ssqls3 OUTPUT ----------------
@@ -159,7 +159,7 @@
Pickle Relish 87 1.5 1.75 1998-09-04
Hot Mustard 73 0.95 0.97 1998-05-25
Hotdog Buns 65 1.1 1.1 1998-04-23
-Hot Dogs 100 1.5 1.75 1998-09-25
+Hot Dogs 100 1.5 (NULL) 1998-09-25
================ END ssqls3 OUTPUT ================
---------------- BEGIN ssqls4 OUTPUT ----------------
@@ -167,7 +167,7 @@
Item Num Weight Price Date
-Hot Dogs 100 1.5 1.75 1998-09-25
+Hot Dogs 100 1.5 (NULL) 1998-09-25
Hot Mustard 73 0.95 0.97 1998-05-25
Hotdog Buns 65 1.1 1.1 1998-04-23
Nuerenberger Bratwurst 97 1.5 8.79 2005-03-10
@@ -220,8 +220,8 @@
================ END load_jpeg OUTPUT ================
---------------- BEGIN cgi_jpeg OUTPUT ----------------
-Content-type: text/plain
-
-No image content!
+Content-type: text/plain
+
+No image content!
================ END cgi_jpeg OUTPUT ================
Modified: trunk/examples/for_each.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/for_each.cpp?rev=2492&r1=2491&r2=2492&view=diff
==============================================================================
--- trunk/examples/for_each.cpp (original)
+++ trunk/examples/for_each.cpp Tue Mar 24 17:18:35 2009
@@ -51,7 +51,7 @@
{
items_ += s.num;
weight_ += (s.num * s.weight);
- cost_ += (s.num * s.price);
+ cost_ += (s.num * s.price.data);
}
private:
Modified: trunk/examples/printdata.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/printdata.cpp?rev=2492&r1=2491&r2=2492&view=diff
==============================================================================
--- trunk/examples/printdata.cpp (original)
+++ trunk/examples/printdata.cpp Tue Mar 24 17:18:35 2009
@@ -3,7 +3,7 @@
formats, required by most of the example programs.
Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
- (c) 2004-2007 by Educational Technology Resources, Inc. Others may
+ (c) 2004-2009 by Educational Technology Resources, Inc. Others may
also hold copyrights on code in this file. See the CREDITS.txt file
in the top directory of the distribution for details.
@@ -55,7 +55,8 @@
void
print_stock_row(const mysqlpp::sql_char& item, mysqlpp::sql_bigint num,
- mysqlpp::sql_double weight, mysqlpp::sql_decimal price,
+ mysqlpp::sql_double weight,
+ mysqlpp::Null<mysqlpp::sql_decimal> price,
const mysqlpp::sql_date& date)
{
cout << setw(30) << item << ' ' <<
Modified: trunk/examples/printdata.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/printdata.h?rev=2492&r1=2491&r2=2492&view=diff
==============================================================================
--- trunk/examples/printdata.h (original)
+++ trunk/examples/printdata.h Tue Mar 24 17:18:35 2009
@@ -3,7 +3,7 @@
common forms, used by most of the example programs.
Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
- (c) 2004-2007 by Educational Technology Resources, Inc. Others may
+ (c) 2004-2009 by Educational Technology Resources, Inc. Others may
also hold copyrights on code in this file. See the CREDITS.txt file
in the top directory of the distribution for details.
@@ -34,7 +34,8 @@
void print_stock_row(const mysqlpp::Row& r);
void print_stock_row(const mysqlpp::sql_char& item,
mysqlpp::sql_bigint num, mysqlpp::sql_double weight,
- mysqlpp::sql_decimal price, const mysqlpp::sql_date& date);
+ mysqlpp::Null<mysqlpp::sql_decimal> price,
+ const mysqlpp::sql_date& date);
void print_stock_rows(mysqlpp::StoreQueryResult& res);
void print_stock_table(mysqlpp::Query& query);
Modified: trunk/examples/resetdb.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/resetdb.cpp?rev=2492&r1=2491&r2=2492&view=diff
==============================================================================
--- trunk/examples/resetdb.cpp (original)
+++ trunk/examples/resetdb.cpp Tue Mar 24 17:18:35 2009
@@ -137,7 +137,7 @@
" item CHAR(30) NOT NULL, " <<
" num BIGINT NOT NULL, " <<
" weight DOUBLE NOT NULL, " <<
- " price DECIMAL(6,2) NOT NULL, " <<
+ " price DECIMAL(6,2) NULL, " << // NaN & inf.
== NULL
" sdate DATE NOT NULL, " <<
" description MEDIUMTEXT NULL) " <<
"ENGINE = InnoDB " <<
Modified: trunk/examples/ssqls2.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/ssqls2.cpp?rev=2492&r1=2491&r2=2492&view=diff
==============================================================================
--- trunk/examples/ssqls2.cpp (original)
+++ trunk/examples/ssqls2.cpp Tue Mar 24 17:18:35 2009
@@ -30,6 +30,7 @@
#include "stock.h"
#include <iostream>
+#include <limits>
using namespace std;
@@ -50,7 +51,8 @@
// Create and populate a stock object. We could also have used
// the set() member, which takes the same parameters as this
// constructor.
- stock row("Hot Dogs", 100, 1.5, 1.75,
+ stock row("Hot Dogs", 100, 1.5,
+ numeric_limits<double>::infinity(), //
"priceless," ha!
mysqlpp::sql_date("1998-09-25"), mysqlpp::null);
// Form the query to insert the row into the stock table.
Modified: trunk/examples/stock.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/stock.h?rev=2492&r1=2491&r2=2492&view=diff
==============================================================================
--- trunk/examples/stock.h (original)
+++ trunk/examples/stock.h Tue Mar 24 17:18:35 2009
@@ -2,7 +2,7 @@
stock.h - Declares the stock SSQLS used by several of the examples.
Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
- (c) 2004-2008 by Educational Technology Resources, Inc. Others may
+ (c) 2004-2009 by Educational Technology Resources, Inc. Others may
also hold copyrights on code in this file. See the CREDITS.txt file
in the top directory of the distribution for details.
@@ -41,7 +41,7 @@
mysqlpp::sql_char, item,
mysqlpp::sql_bigint, num,
mysqlpp::sql_double, weight,
- mysqlpp::sql_double, price,
+ mysqlpp::Null<mysqlpp::sql_double>, price,
mysqlpp::sql_date, sdate,
mysqlpp::Null<mysqlpp::sql_mediumtext>, description)
Modified: trunk/lib/stadapter.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/stadapter.cpp?rev=2492&r1=2491&r2=2492&view=diff
==============================================================================
--- trunk/lib/stadapter.cpp (original)
+++ trunk/lib/stadapter.cpp Tue Mar 24 17:18:35 2009
@@ -2,7 +2,7 @@
stadapter.cpp - Implements the SQLTypeAdapter class.
Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
- (c) 2004-2008 by Educational Technology Resources, Inc. Others may
+ (c) 2004-2009 by Educational Technology Resources, Inc. Others may
also hold copyrights on code in this file. See the CREDITS.txt file
in the top directory of the distribution for details.
@@ -31,6 +31,7 @@
#include "stream2string.h"
#include <iomanip>
+#include <limits>
#include <sstream>
using namespace std;
@@ -258,17 +259,32 @@
SQLTypeAdapter::SQLTypeAdapter(float f) :
is_processed_(false)
{
- ostringstream outs;
- outs.precision(9); // max dec digits needed for IEEE 754 32-bit
float
- outs << f;
- buffer_ = new SQLBuffer(outs.str(), typeid(f), false);
+ numeric_limits<float> nlf;
+ if ((nlf.has_infinity && (f == nlf.infinity())) ||
+ (nlf.has_quiet_NaN && (f == nlf.quiet_NaN())) ||
+ (nlf.has_signaling_NaN && (f == nlf.signaling_NaN()))) {
+ // f isn't null-able, but it's infinite or NaN, so store it
+ // as a 0. This at least prevents syntactically-invalid SQL.
+ buffer_ = new SQLBuffer("0", typeid(f), true);
+ }
+ else {
+ ostringstream outs;
+ outs.precision(9); // max dec digits needed for IEEE 754
32-bit float
+ outs << f;
+ buffer_ = new SQLBuffer(outs.str(), typeid(f), false);
+ }
}
#if !defined(DOXYGEN_IGNORE)
SQLTypeAdapter::SQLTypeAdapter(Null<float> f) :
is_processed_(false)
{
- if (f.is_null) {
+ numeric_limits<float> nlf;
+ if (f.is_null ||
+ (nlf.has_infinity && (f.data == nlf.infinity())) ||
+ (nlf.has_quiet_NaN && (f.data == nlf.quiet_NaN())) ||
+ (nlf.has_signaling_NaN && (f.data ==
nlf.signaling_NaN()))) {
+ // MySQL wants infinite and NaN FP values stored as SQL NULL
buffer_ = new SQLBuffer(null_str, typeid(void), true);
}
else {
@@ -283,17 +299,32 @@
SQLTypeAdapter::SQLTypeAdapter(double f) :
is_processed_(false)
{
- ostringstream outs;
- outs.precision(17); // max dec digits needed for IEEE 754 64-bit
float
- outs << f;
- buffer_ = new SQLBuffer(outs.str(), typeid(f), false);
+ numeric_limits<double> nld;
+ if ((nld.has_infinity && (f == nld.infinity())) ||
+ (nld.has_quiet_NaN && (f == nld.quiet_NaN())) ||
+ (nld.has_signaling_NaN && (f == nld.signaling_NaN()))) {
+ // f isn't null-able, but it's infinite or NaN, so store it
+ // as a 0. This at least prevents syntactically-invalid SQL.
+ buffer_ = new SQLBuffer("0", typeid(f), true);
+ }
+ else {
+ ostringstream outs;
+ outs.precision(17); // max dec digits needed for IEEE 754
64-bit float
+ outs << f;
+ buffer_ = new SQLBuffer(outs.str(), typeid(f), false);
+ }
}
#if !defined(DOXYGEN_IGNORE)
SQLTypeAdapter::SQLTypeAdapter(Null<double> f) :
is_processed_(false)
{
- if (f.is_null) {
+ numeric_limits<double> nld;
+ if (f.is_null ||
+ (nld.has_infinity && (f.data == nld.infinity())) ||
+ (nld.has_quiet_NaN && (f.data == nld.quiet_NaN())) ||
+ (nld.has_signaling_NaN && (f.data ==
nld.signaling_NaN()))) {
+ // MySQL wants infinite and NaN FP values stored as SQL NULL
buffer_ = new SQLBuffer(null_str, typeid(void), true);
}
else {
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits