]> granicus.if.org Git - php/commitdiff
Add test for PDOStatement::getColumnMeta().
authorDan Scott <dbs@php.net>
Wed, 9 Mar 2005 00:20:07 +0000 (00:20 +0000)
committerDan Scott <dbs@php.net>
Wed, 9 Mar 2005 00:20:07 +0000 (00:20 +0000)
Note that PDO_ODBC test fails as it is currently unimplemented.

ext/pdo/tests/pdo_022.inc [new file with mode: 0755]
ext/pdo_odbc/tests/pdo_022.phpt [new file with mode: 0755]

diff --git a/ext/pdo/tests/pdo_022.inc b/ext/pdo/tests/pdo_022.inc
new file mode 100755 (executable)
index 0000000..6cf662e
--- /dev/null
@@ -0,0 +1,41 @@
+<?php # vim:ft=php
+
+require_once('pdo.inc');
+
+set_sql('create1',  'CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))');
+set_sql('insert1', "INSERT INTO test VALUES(?, ?, ?)"); 
+set_sql('insert2', "INSERT INTO test VALUES(:first, :second, :third)"); 
+set_sql('select1',  'SELECT id, val, val2 FROM test');
+set_sql('select2',  'SELECT COUNT(*) FROM test');
+
+$data = array(
+    array('10', 'Abc', 'zxy'),
+    array('20', 'Def', 'wvu'),
+    array('30', 'Ghi', 'tsr'),
+    array('40', 'Jkl', 'qpo'),
+    array('50', 'Mno', 'nml'),
+    array('60', 'Pqr', 'kji'),
+);
+
+$DB->exec($SQL['create1']);
+
+// Insert using question mark placeholders
+$stmt = $DB->prepare($SQL['insert1']);
+foreach ($data as $row) {
+    $stmt->execute($row);
+}
+
+// Retrieve column metadata for a result set returned by explicit SELECT
+$select = $DB->query($SQL['select1']);
+$meta = $select->getColumnMeta(0);
+var_dump($meta);
+$meta = $select->getColumnMeta(1);
+var_dump($meta);
+$meta = $select->getColumnMeta(2);
+var_dump($meta);
+
+// Retrieve column metadata for a result set returned by a function
+$select = $DB->query($SQL['select2']);
+$meta = $select->getColumnMeta(0);
+var_dump($meta);
+?>
diff --git a/ext/pdo_odbc/tests/pdo_022.phpt b/ext/pdo_odbc/tests/pdo_022.phpt
new file mode 100755 (executable)
index 0000000..412fe35
--- /dev/null
@@ -0,0 +1,84 @@
+--TEST--
+PDO_ODBC: PDOStatement::columnMeta results.
+--SKIPIF--
+<?php # vim:ft=php
+require_once('skipif.inc'); ?>
+--FILE--
+<?php
+
+require_once('connection.inc');
+require_once('prepare.inc');
+
+require_once($PDO_TESTS . 'pdo_022.inc');
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECT--
+array(7) {
+  ["native_type"]=>
+  string(7) "integer"
+  ["odbc:decl_type"]=>
+  string(3) "INT"
+  ["flags"]=>
+  array(0) {
+  }
+  ["name"]=>
+  string(2) "id"
+  ["len"]=>
+  int(-1)
+  ["precision"]=>
+  int(0)
+  ["pdo_type"]=>
+  int(2)
+}
+array(7) {
+  ["native_type"]=>
+  string(6) "string"
+  ["odbc:decl_type"]=>
+  string(11) "VARCHAR(10)"
+  ["flags"]=>
+  array(0) {
+  }
+  ["name"]=>
+  string(3) "val"
+  ["len"]=>
+  int(-1)
+  ["precision"]=>
+  int(0)
+  ["pdo_type"]=>
+  int(2)
+}
+array(7) {
+  ["native_type"]=>
+  string(6) "string"
+  ["odbc:decl_type"]=>
+  string(11) "VARCHAR(16)"
+  ["flags"]=>
+  array(0) {
+  }
+  ["name"]=>
+  string(4) "val2"
+  ["len"]=>
+  int(-1)
+  ["precision"]=>
+  int(0)
+  ["pdo_type"]=>
+  int(2)
+}
+array(6) {
+  ["native_type"]=>
+  string(7) "integer"
+  ["flags"]=>
+  array(0) {
+  }
+  ["name"]=>
+  string(8) "COUNT(*)"
+  ["len"]=>
+  int(-1)
+  ["precision"]=>
+  int(0)
+  ["pdo_type"]=>
+  int(2)
+}
+===DONE===