Joanne Pham wrote:
My application is used C++ to insert/select the data from this table. So if I 
defined it as
  create table mytable (
 Then I can use sqlite3_bind_real to bind the column but what is the datatype 
that I should use in C++ code.Do you have any example code that work for C++ in 
this case.


If you define your table using the "default current_timestamp" clause, SQLite will insert the data and time as a string, not as a floating point real value.

sqlite> create table t(a int, b real default current_timestamp);
sqlite> insert into t(a) values(1);
sqlite> select a, b, typeof(b) from t;
a           b                    typeof(b)
----------  -------------------  ----------
1 2007-12-17 21:56:48 text sqlite> insert into t values(2, julianday('now'));
sqlite> select a, b, typeof(b), datetime(b) from t;
a           b                    typeof(b)   datetime(b)
----------  -------------------  ----------  -------------------
1           2007-12-17 21:56:48  text        2007-12-17 21:56:48
2           2454452.42202395     real        2007-12-17 22:07:42

SQLite calls it's internal floating point type REAL, but the C API function used to bind such values is sqlite3_bind_double(), and it binds a standard C or C++ double value. Some sample code is shown below. The first inserts a julian day number directly, the second uses the julianday() function to convert a text string inserted by the code into a julian day number in the database.

   sqlite3_stmt* s;
   sqlite3_prepare_v2(db, "insert into t values(:a, :b)", -1, &s, 0);

   double tomorrow = 2454453.5;
   sqlite3_bind_int(s, 1, 3);
   sqlite3_bind_double(s, 2, tomorrow);


sqlite3_prepare_v2(db, "insert into t values(:a, julianday(:b))", -1, &s, 0);

   char* yesterday = "2007-12-16 00:00:00";
   sqlite3_bind_int(s, 1, 4);
   sqlite3_bind_text(s, 2, yesterday, -1, SQLITE_STATIC);


Dennis Cote

To unsubscribe, send email to [EMAIL PROTECTED]

Reply via email to