MySQL Forums
Forum List  »  Connector/C++

Re: DateTime field with C++
Posted by: J Jorgenson
Date: July 10, 2008 01:20PM

There are two ways to handle a DateTime field.

For non-prepared statments [mysql_query()], all the data is retrieved across the network in 'STRING' format. **VERY** inefficient if you are processing many records.

At the C/C++ level for prepared statments [mysql_stmt_exec()], you can 'bind' most any database datatype you wish against most any 'C' datatype in your program, and the client library will 'coherce' the value to fit the 'C' data type (sometimes creating bad data).
**Practically** You Will want to 'bind' with either a MYSQL_TYPE_DATETIME structure or a MYSQL_TYPE_STRING.

I prefer just to use a simple string. Its close to be the same number of bytes transfered across the wire, and using 'string' math (strcmp or atoi(str+pos) against it is easy for field/value access.

The MYSQL_TYPE_DATETIME structure provides field-level access to the different date time components in numerical fashion.

-- JJorgenson --

Options: ReplyQuote


Subject
Views
Written By
Posted
14722
June 19, 2008 08:29PM
Re: DateTime field with C++
7527
July 10, 2008 01:20PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.