Hello,
I wonder if anyone is using SAPDB timestamp with PHP/ODBC, and has noticed
this:
Data definition:
pncvs_blocks.pn_last_update is timestamp, not null
Example code:
$conn= odbc_connect("postnuke", "pn", "******");
$sql="select pn_last_update from pncvs_blocks";
echo "<BR><b>SQL:</b> $sql<BR>";
$results = odbc_do($conn,$sql);
if ($results) {
while (odbc_fetch_into($results,$row)) {
echo ">>".$row[0]."<<<BR>\n";
}
}
}
Output:
SQL: select pn_last_update from pncvs_blocks
>>2001-11-22 09:07:26n_la!<<
>>0001-01-01 00:00:00n_la!<<
>>0001-01-01 00:00:00n_la!<<
>>0001-01-01 00:00:00n_la!<<
>>0001-01-01 00:00:00n_la!<<
>>0001-01-01 00:00:00n_la!<<
>>0001-01-01 00:00:00n_la!<<
>>0001-01-01 00:00:00n_la!<<
...etc...
"n_la!" is just random rubbish, it can be anything. In most cases, when it ends
up as unprintable, it just chrashes PHP. Lot of fun. All other clients I tried
show correctly "0001-01-01 00:00:00.000000" - including Windows based ones and
on Linux side going via unixODBC.
To make things a bit more confusing, this code:
$conn= odbc_connect($dsn, "pn", "****");
$result=odbc_do($conn, "select pn_last_update from PNCVS_BLOCKS");
odbc_result_all($result);
odbc_free_result($result);
odbc_close($conn);
creates OK output:
PN_LAST_UPDATE
2001-11-22 09:07:26
0001-01-01 00:00:00
0001-01-01 00:00:00
0001-01-01 00:00:00
0001-01-01 00:00:00
0001-01-01 00:00:00
...
...obviously not trying to read micro time.
Looking at PHP code, I see:
#ifdef HAVE_ADABAS
case SQL_TIMESTAMP:
result->values[i].value = (char *)emalloc(27);
SQLBindCol(result->stmt, (UWORD)(i+1), SQL_C_CHAR,
result->values[i].value,
27, &result->values[i].vallen);
break;
#endif /* HAVE_ADABAS */
at http://cvs.php.net/co.php/php4/ext/odbc/php_odbc.c?login=2&r=1.143
Now I wonder: should this be :
#if defined (HAVE_ADABAS) || defined (HAVE_SAPDB)
Additionally: I'm using PHP provided with RedHat 7.3 (4.1.2) that comes with
unixODBC linked PHP ODBC loadable module.
...
REGISTER_LONG_CONSTANT("SQL_TIMESTAMP", SQL_TIMESTAMP, CONST_PERSISTENT |
CONST_CS);
#if defined(ODBCVER) && (ODBCVER >= 0x0300)
REGISTER_LONG_CONSTANT("SQL_TYPE_DATE", SQL_TYPE_DATE, CONST_PERSISTENT |
CONST_CS);
REGISTER_LONG_CONSTANT("SQL_TYPE_TIME", SQL_TYPE_TIME, CONST_PERSISTENT |
CONST_CS);
REGISTER_LONG_CONSTANT("SQL_TYPE_TIMESTAMP", SQL_TYPE_TIMESTAMP,
CONST_PERSISTENT | CONST_CS);
and in sapdb/interfaces/odbc/incl/sql.h:
#if (ODBCVER >= 0x0300)
#define SQL_DATE_LEN 10
#define SQL_TIME_LEN 8 /* add P+1 if precision is nonzero */
#define SQL_TIMESTAMP_LEN 19 /* add P+1 if precision is nonzero */
#endif
Comparing unixODBC and SAP DB ODBC headers, they are completely the same, in
regard to everything timestamp related, including TIMESTAMP_STRUCT. So unless
there is a bug in unixODBC, fact that I'm running PHP with ODBC module compiled
for unixODBC should make no difference? (Selecting same field via unixODBC
tools "isql" shows corect data)
Can somebody with PHP ODBC module compiled agains SAP DB provided ODBC
headers/libraries please confirm this problem?
Thanks,
--
Yours, Andrej Falout, http://www.falout.com/disclaimer.html
Visit the OpenSource alternative, Aubit 4gl: http://aubit4gl.sourceforge.net
PLEASE NOTE: All HTML email sent to me WILL BE DELETED AUTOMATICALLY WITHOUT
READING.
_______________________________________________
sapdb.general mailing list
[EMAIL PROTECTED]
http://listserv.sap.com/mailman/listinfo/sapdb.general