From: Warren Young Date: June 3 2009 6:48pm Subject: Re: ssqls and now() List-Archive: http://lists.mysql.com/plusplus/8590 Message-Id: <4A26C588.5090807@etr-usa.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------020903010807070603050204" --------------020903010807070603050204 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Mike Naylor wrote: > > Here is a small test program which I hope someone will compile and run. I modified examples/simple1.cpp to include your code, differing only in that it uses the MySQL++ examples' DB and command line parsing mechanism instead. (Sorry, my MySQL++ test user doesn't have permission to create new DBs, and I don't want to run your code as root.) Anyway, it works as expected: > $ ./exrun simple1 -utest -ptest > Connecting to server... > Dropping old table... > Creating new table... > Inserting a row... > Using the full declaration - expecting MySQL to update the timestamp... > QUERY: INSERT INTO t_events (id,updated,sometext) VALUES (0,NOW(),'Hello World!') > Selecting the row... > RESULT: id = 1, updated = 2009-06-03 12:40:05, sometext = Hello World! If I understand your complaint, you see "updated = 0000-00-00....", yes? I've attached the modified example. This is with svn MySQL++, but I don't see that 3.0.9 should work differently. MySQL 5.0.81. --------------020903010807070603050204 Content-Type: text/x-c++src; name="simple1.cpp" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="simple1.cpp" /*********************************************************************** simple1.cpp - Example showing the simplest way to get data from a MySQL table with MySQL++. Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and (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. This file is part of MySQL++. MySQL++ is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. MySQL++ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with MySQL++; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ***********************************************************************/ #include "cmdline.h" #include "printdata.h" #include #include #include #include using namespace std; #define USE_FULL_SSQLS_DECLARATION #define kTHE_MYSQL_DECLARATION "t_events ( \ id int auto_increment, \ updated timestamp default current_timestamp, \ sometext varchar(255), \ PRIMARY KEY (id) \ ) ENGINE=MyISAM DEFAULT CHARSET=utf8" #ifdef USE_FULL_SSQLS_DECLARATION sql_create_3(t_events, 1, 3, mysqlpp::sql_int, id, mysqlpp::sql_timestamp, updated, mysqlpp::sql_varchar, sometext); #else // use a sub-table sql_create_2(t_events, 1, 2, mysqlpp::sql_int, id, mysqlpp::sql_varchar, sometext); #endif int main(int argc, char *argv[]) { // Get database access parameters from command line mysqlpp::examples::CommandLine cmdline(argc, argv); if (!cmdline) { return 1; } try { std::cout << "Connecting to server..." << std::endl; mysqlpp::Connection con; con.connect(mysqlpp::examples::db_name, cmdline.server(), cmdline.user(), cmdline.pass()); { mysqlpp::Query query = con.query(); std::cout << "Dropping old table..." << std::endl; query << "drop table if exists t_events"; query.execute(); std::cout << "Creating new table..." << std::endl; query << "create table " << kTHE_MYSQL_DECLARATION; query.execute(); } { std::cout << "Inserting a row..." << std::endl; mysqlpp::Query query = con.query(); t_events row; row.id = 0; #ifdef USE_FULL_SSQLS_DECLARATION std::cout << "Using the full declaration - expecting MySQL to update the timestamp..." << std::endl; row.updated = mysqlpp::sql_timestamp(); #else std::cout << "Using a sub-declaration - letting MySQL do its thing..." << std::endl; #endif row.sometext = "Hello World!"; query.insert(row); std::cout << "QUERY: " << query << std::endl; query.execute(); } { std::cout << "Selecting the row..." << std::endl; mysqlpp::Query query = con.query(); query << "select * from t_events"; mysqlpp::StoreQueryResult res = query.store(); std::cout << "RESULT: id = " << res[0]["id"] << ", updated = " << res[0]["updated"] << ", sometext = " << res[0]["sometext"] << std::endl; } } catch (const mysqlpp::Exception& er) { std::cout << "ERROR: " << er.what() << std::endl; return 1; } return 0; } --------------020903010807070603050204--