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);
- REGISTER_LONG_CONSTANT("SQL_TYPE_WVARCHAR", SQL_TYPE_WVARCHAR, CONST_PERSISTENT | CONST_CS);
- REGISTER_LONG_CONSTANT("SQL_TYPE_WLONGVARCHAR", SQL_TYPE_WLONGVARCHAR, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("SQL_WCHAR", SQL_WCHAR, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("SQL_WVARCHAR", SQL_WVARCHAR, CONST_PERSISTENT | CONST_CS);
+ REGISTER_LONG_CONSTANT("SQL_WLONGVARCHAR", SQL_WLONGVARCHAR, CONST_PERSISTENT | CONST_CS);
/*
* SQLSpecialColumns values
{
RETCODE rc;
int i;
- SQLSMALLINT colnamelen; /* Not used */
- SQLLEN displaysize;
+ SQLSMALLINT colnamelen; /* Not used */
+ SQLLEN displaysize;
+ SQLUSMALLINT colfieldid;
+ int charextraalloc;
+ colfieldid = SQL_COLUMN_DISPLAY_SIZE;
+ charextraalloc = 0;
result->values = (odbc_result_value *) safe_emalloc(sizeof(odbc_result_value), result->numcols, 0);
result->longreadlen = ODBCG(defaultlrl);
case SQL_VARBINARY:
case SQL_LONGVARBINARY:
case SQL_LONGVARCHAR:
- case SQL_WVARCHAR:
+#if defined(ODBCVER) && (ODBCVER >= 0x0300)
case SQL_WLONGVARCHAR:
+#endif
result->values[i].value = NULL;
break;
27, &result->values[i].vallen);
break;
#endif /* HAVE_ADABAS */
+ case SQL_CHAR:
+ case SQL_VARCHAR:
+#if defined(ODBCVER) && (ODBCVER >= 0x0300)
+ case SQL_WCHAR:
+ case SQL_WVARCHAR:
+ colfieldid = SQL_DESC_OCTET_LENGTH;
+#else
+ charextraalloc = 1;
+#endif
default:
- rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), SQL_COLUMN_DISPLAY_SIZE,
- NULL, 0, NULL, &displaysize);
- displaysize = displaysize <= result->longreadlen ? displaysize :
- result->longreadlen;
+ rc = SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), colfieldid,
+ NULL, 0, NULL, &displaysize);
/* Workaround for Oracle ODBC Driver bug (#50162) when fetching TIMESTAMP column */
if (result->values[i].coltype == SQL_TIMESTAMP) {
displaysize += 3;
}
+
+ if (charextraalloc) {
+ /* Since we don't know the exact # of bytes, allocate extra */
+ displaysize *= 4;
+ }
result->values[i].value = (char *)emalloc(displaysize + 1);
rc = SQLBindCol(result->stmt, (SQLUSMALLINT)(i+1), SQL_C_CHAR, result->values[i].value,
displaysize + 1, &result->values[i].vallen);
if (result->binmode == 1) {
sql_c_type = SQL_C_BINARY;
}
- case SQL_WVARCHAR:
- case SQL_WLONGVARCHAR:
case SQL_LONGVARCHAR:
+#if defined(ODBCVER) && (ODBCVER >= 0x0300)
+ case SQL_WLONGVARCHAR:
+#endif
if (IS_SQL_LONG(result->values[i].coltype) && result->longreadlen <= 0) {
Z_STRVAL_P(tmp) = STR_EMPTY_ALLOC();
break;
break;
}
if (result->binmode == 1) sql_c_type = SQL_C_BINARY;
- case SQL_WVARCHAR:
- case SQL_WLONGVARCHAR:
+
case SQL_LONGVARCHAR:
+#if defined(ODBCVER) && (ODBCVER >= 0x0300)
+ case SQL_WLONGVARCHAR:
+#endif
if (IS_SQL_LONG(result->values[i].coltype) && result->longreadlen <= 0) {
Z_STRVAL_P(tmp) = STR_EMPTY_ALLOC();
break;
break;
}
case SQL_LONGVARCHAR:
- case SQL_WVARCHAR:
+#if defined(ODBCVER) && (ODBCVER >= 0x0300)
case SQL_WLONGVARCHAR:
+#endif
if (IS_SQL_LONG(result->values[field_ind].coltype)) {
if (result->longreadlen <= 0) {
break;
}
/* Reduce fieldlen by 1 if we have char data. One day we might
have binary strings... */
- if ((result->values[field_ind].coltype == SQL_LONGVARCHAR) ||
- (result->values[field_ind].coltype == SQL_WVARCHAR) ||
- (result->values[field_ind].coltype == SQL_WLONGVARCHAR)) {
+ if ((result->values[field_ind].coltype == SQL_LONGVARCHAR)
+#if defined(ODBCVER) && (ODBCVER >= 0x0300)
+ || (result->values[field_ind].coltype == SQL_WLONGVARCHAR)
+#endif
+ ) {
fieldsize -= 1;
}
/* Don't duplicate result, saves one emalloc.
break;
}
if (result->binmode <= 1) sql_c_type = SQL_C_BINARY;
- case SQL_WVARCHAR:
- case SQL_WLONGVARCHAR:
case SQL_LONGVARCHAR:
+#if defined(ODBCVER) && (ODBCVER >= 0x0300)
+ case SQL_WLONGVARCHAR:
+#endif
if (IS_SQL_LONG(result->values[i].coltype) &&
result->longreadlen <= 0) {
php_printf("<td>Not printable</td>");
--- /dev/null
+--TEST--
+odbc_exec(): Getting accurate unicode data from query
+--SKIPIF--
+<?php include 'skipif.inc'; ?>
+--FILE--
+<?php
+
+// Test strings
+mb_internal_encoding("EUC_JP");
+$euc_jp_base64 = 'pdal6aWkpcCl676uyqo=';
+$euc_jp = base64_decode($euc_jp_base64);
+$ascii = 'abcdefghijklmnopqrstuvwxyz;]=#0123456789';
+
+include 'config.inc';
+ini_set("odbc.defaultlrl", 4); // Set artifically low
+
+$conn = odbc_connect($dsn, $user, $pass);
+
+odbc_exec($conn, 'CREATE DATABASE odbcTEST ENCODING=\'EUC_JP\'');
+
+odbc_exec($conn, 'CREATE TABLE FOO (ID INT, CHAR_COL CHAR(200), VARCHAR_COL VARCHAR(200), TEXT_COL TEXT)');
+
+odbc_exec($conn, "INSERT INTO FOO(ID, CHAR_COL, VARCHAR_COL, TEXT_COL) VALUES (1, '$euc_jp', '$euc_jp', '$euc_jp')");
+odbc_exec($conn, "INSERT INTO FOO(ID, CHAR_COL, VARCHAR_COL, TEXT_COL) VALUES (2, '$ascii', '$ascii', '$ascii')");
+
+$res = odbc_exec($conn, 'SELECT * FROM FOO ORDER BY ID ASC');
+
+while(odbc_fetch_row($res)) {
+ $char_col = odbc_result($res, "CHAR_COL");
+ $varchar_col = odbc_result($res, "VARCHAR_COL");
+ $id = odbc_result($res, "ID");
+ $text_col = "";
+ while (($chunk=odbc_result($res, "TEXT_COL")) !== false) {
+ $text_col .= $chunk;
+ }
+
+ if ($id == 1) {
+ $euc_jp_check = $euc_jp . str_repeat(" ", (200 - mb_strlen($euc_jp)));
+ if (strcmp($char_col, $euc_jp_check) == 0 && strcmp($varchar_col, $euc_jp) == 0 &&
+ strcmp($text_col, $euc_jp) == 0) {
+ print "EUC-JP matched\n";
+ } else {
+ print "EUC-JP mismatched\n";
+ }
+ } else {
+ $ascii_check = $ascii . str_repeat(" ", (200 - strlen($ascii)));
+ if (strcmp($char_col, $ascii_check) == 0 && strcmp($varchar_col, $ascii) == 0 &&
+ strcmp($text_col, $ascii) == 0) {
+ print "ASCII matched\n";
+ } else {
+ print "ASCII mismatched\n";
+ }
+ }
+}
+
+?>
+--EXPECT--
+EUC-JP matched
+ASCII matched
+--CLEAN--
+<?php
+include 'config.inc';
+
+$conn = odbc_connect($dsn, $user, $pass);
+
+odbc_exec($conn, 'DROP TABLE FOO');
+odbc_exec($conn, 'DROP DATABASE odbcTEST');
+
+?>