From: Mike Naylor Date: June 2 2009 10:19am Subject: Re: ssqls and now() List-Archive: http://lists.mysql.com/plusplus/8588 Message-Id: <6B00608B-2B86-4A33-A593-0597C5804F6B@mac.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7BIT > or you can distill your code down to something small enough that me > or someone else on the list will be willing to build and test it, > and thereby convince us that it can't work. Here is a small test program which I hope someone will compile and run. Regards Mike. ####################################################### // // testdatetime.cpp // // Created by: Mike Naylor on 2009-06-02. // // Purpose: to test if an sql_timestamp field can be set to a 'null' value (so that MySQL will ignore it) // in the same way a zero value for an auto-increment field is ignored. // // When I run this program with USE_FULL_SSQLS_DECLARATION defined, this does not work for me. Why? // // Compile: just edit the next 4 #defines #define kServer "localhost" #define kUser "username" #define kPassword "password" #define kDatabase "testtimedate" #define USE_FULL_SSQLS_DECLARATION #import #import #import #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, const char *argv[]) { mysqlpp::Connection con; try { { std::cout << "Connecting to server..." << std::endl; con.connect(0, kServer, kUser, kPassword); mysqlpp::Query query = con.query(); std::cout << "Dropping the old database (if exists)..." << std::endl; query << "drop database if exists " << kDatabase; query.execute(); std::cout << "Creating a new database..." << std::endl; query << "create database " << kDatabase; query.execute(); std::cout << "Connecting to the new database..." << std::endl; con.connect(kDatabase, kServer, kUser, kPassword); std::cout << "Creating the 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 it's 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; } #######################################################