Menu

#18 Datetime hassles

open
core (13)
5
2005-06-06
2005-06-06
No

Is there are way to make the handling of datetime
elements more portable. I am having trouble exporting
data from a MySQL source and importing it into an MSSQL
database.

Actally, I've found with the datetime field, you can't
even import data back into the native database. Here's
why (I think).

The 'T' fields are being put into the INSERT statements
raw, eg:

INSERT INTO table (mydate)
VALUES ( 2001-01-01 00:00:00 )

Problem is that for MySQL I need the value quoted, eg:

INSERT INTO table (mydate)
VALUES ( '2001-01-01 00:00:00' )

and for MS-SQL I need something more elaborate:

INSERT INTO table (mydate)
VALUES ( convert(datetime, '2001-01-01 00:00:00') )

It seems to me that something is needed in the
dbData::create method to handle this field type, maybe
something like:

switch( $table_fields[$field_id]['TYPE'] ) {
case 'T':
$fields[$name] =
$xmls->dict->DateTimeInsert($field_data);
break;

where in the case of MS-SQL:

function DateTimeInsert( $fvalue ) {
return 'convert(datetime,'
. $this->connection->qstr( $fvalue )
. ')';
}

Is that the correct way to handle it?

Discussion


Log in to post a comment.