Martin Jansen wrote:
On Sat Oct 13, 2007 at 11:4625AM +0200, Martin Jansen wrote:
Attached is a patch for the MySQL and SQLite drivers of PDO that
implements the feature request from #42589 by adding the name of the
table where the column is from to the output of getColumnMeta().
Antony already implemented this in PECL's pdo_mysql 4 months ago, but
these changes haven't yet been merged into HEAD. The SQLite driver in
PECL however also lacks this feature.
An updated patch for the SQLite driver in PHP_5_3 is attached.
- Martin
Index: tests/bug_42589.phpt
===================================================================
RCS file: tests/bug_42589.phpt
diff -N tests/bug_42589.phpt
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/bug_42589.phpt 13 Oct 2007 14:44:31 -0000
@@ -0,0 +1,23 @@
+--TEST--
+PDO SQLite Feature Request #42589 (getColumnMeta() should also return table
name)
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo') || !extension_loaded('pdo_sqlite')) die('skip not
loaded');
+?>
+--FILE--
+<?php
+$db = new PDO("sqlite::memory:");
+
+$db->exec('CREATE TABLE test (field1 VARCHAR(10))');
+$db->exec('INSERT INTO test VALUES("test")');
+
+$result = $db->query('SELECT * FROM test t1 LEFT JOIN test t2 ON t1.field1 =
t2.field1');
+$meta1 = $result->getColumnMeta(0);
+$meta2 = $result->getColumnMeta(1);
+
+var_dump(!empty($meta1['table']) && $meta1['table'] == 'test');
+var_dump(!empty($meta2['table']) && $meta2['table'] == 'test');
+?>
+--EXPECTF--
+bool(true)
+bool(true)
Index: config.m4
===================================================================
RCS file: /repository/php-src/ext/pdo_sqlite/config.m4,v
retrieving revision 1.26.2.9.2.7
diff -u -u -r1.26.2.9.2.7 config.m4
--- config.m4 3 Jul 2007 17:25:35 -0000 1.26.2.9.2.7
+++ config.m4 13 Oct 2007 14:44:31 -0000
@@ -91,7 +91,7 @@
PHP_NEW_EXTENSION(pdo_sqlite,
$php_pdo_sqlite_sources_core $pdo_sqlite_sources,
- $ext_shared,,-I$ext_srcdir/sqlite/src -DPDO_SQLITE_BUNDLED=1
-DSQLITE_OMIT_CURSOR $threadsafe_flag -I$pdo_inc_path)
+ $ext_shared,,-I$ext_srcdir/sqlite/src -DPDO_SQLITE_BUNDLED=1
-DSQLITE_OMIT_CURSOR -DSQLITE_ENABLE_COLUMN_METADATA $threadsafe_flag
-I$pdo_inc_path)
PHP_SUBST(PDO_SQLITE_SHARED_LIBADD)
PHP_ADD_BUILD_DIR($ext_builddir/sqlite/src, 1)
Index: sqlite_statement.c
===================================================================
RCS file: /repository/php-src/ext/pdo_sqlite/sqlite_statement.c,v
retrieving revision 1.18.2.4.2.3
diff -u -u -r1.18.2.4.2.3 sqlite_statement.c
--- sqlite_statement.c 1 Aug 2007 22:45:31 -0000 1.18.2.4.2.3
+++ sqlite_statement.c 13 Oct 2007 14:44:32 -0000
@@ -292,6 +292,9 @@
add_assoc_string(return_value, "sqlite:decl_type", str, 1);
}
+#ifdef SQLITE_ENABLE_COLUMN_METADATA
+ add_assoc_string(return_value, "table", sqlite3_column_table_name(S->stmt,
colno), 1);
+#endif
add_assoc_zval(return_value, "flags", flags);
return SUCCESS;
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php