List:MySQL++« Previous MessageNext Message »
From:lists Date:September 19 2008 6:59am
Subject:Trouble with datatype 'TIME'
View as plain text  
Hello, 

I just have started using mysql++ on Fedora Core 9 with gcc-4.3.0 and have run into a
first problem: I am simply storing a single datum with type "TIME" using
mysqlpp::sql_time into a test table and querying it again which fails.

My code:


#include <string>

#include <mysql++.h>
#include <ssqls.h>

sql_create_1(time_test,1,0,
	     mysqlpp::sql_time,     ptime)

int main()
{
  	using namespace std;
  	mysqlpp::Connection connection("test_db","host","user","pass"); // pls adopt

	// drop && create table
	string sql_drop_table_string = "DROP TABLE IF EXISTS time_test;";	
	string sql_create_table_string = "CREATE TABLE IF NOT EXISTS time_test (ptime TIME NOT
NULL);";

 	mysqlpp::Query query1 = connection.query(sql_drop_table_string);
	query1.execute();
	mysqlpp::Query query2 = connection.query(sql_create_table_string);
	query2.execute();

	// insert
	time_test ts(mysqlpp::sql_time("07:42:43"));
	mysqlpp::Query query3 = connection.query();
	query3.insert(ts);
	query3.execute();

	// query
 	mysqlpp::Query query4 = connection.query();
	query4 << "SELECT * FROM time_test";
 	mysqlpp::StoreQueryResult res = query4.store();

	
	cout << res.field_name(0) << endl;
 	mysqlpp::Field f = res.field(0);
	mysqlpp::mysql_type_info ti =f.type();	
	cout << ti.name() << endl;
	cout << ti.sql_name() << endl;
	int nr = res.num_rows();
	cout << nr << endl;
	mysqlpp::sql_time bt = res[0][0];
	cout << bt.hour() << ":" << bt.minute() << ":" <<
bt.second() << endl; 
}


Running the program returns:

ptime
N7mysqlpp4TimeE
TIME NOT NULL
1
:*:+

How can I retrieve the correct data for bt, i.e. 07:42:43 instead of :*:+?

Thanks in advance.
Thread
Trouble with datatype 'TIME'lists19 Sep
RE: Trouble with datatype 'TIME'lists19 Sep
  • Re: Trouble with datatype 'TIME'Warren Young19 Sep