PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB » Bug #8336

(MS SQL) tableInfo() retuns error for table named "group"

Details

Submitted2006-08-01 12:45 UTC
Fromtommim at freenet dot de
Assigneddanielc
StatusClosed
PackageDB
PHP VersionIrrelevant
OSMS Windows XP
Roadmaps(Not assigned)

Comments

[2006-08-01 12:45 UTC] tommim at freenet dot de

Description:
------------
The function "array DB_mssql::tableInfo(string $table)" fails for certain table names.

This includes tables named "user", "group", ... or something similar. If you don't quote these you get an SQL-error.

This error is in "mssql.php" line 710:
$id = @mssql_query("SELECT * FROM $result WHERE 1=0",

Instead this should be:
$id = @mssql_query("SELECT * FROM ".$this->quoteIdentifier($result)." WHERE 1=0",

I've already tested this. After changing this line everything works as expected. You might want to check the other classes for the same issue as well.

Test script:
---------------
/* create a table named 'group' and run this! */
$tables = $db->getListOf('tables');
foreach ($tables as $table)
{
$test = $db->tableInfo($table);
if (!is_array($test)) {
print "tablename: ".$table."\n";
var_dump($test);
}
}

Expected result:
----------------
There should be no output. As you can see, all table names are provided the dbms itself so they are supposed to be working.

Actual result:
--------------
tablename: group
object(DB_Error)#86 (8) {
...
["userinfo"]=>
string(122) "EXEC SP_COLUMNS[global_metaversion_information] [nativecode=-20 - Falsche Syntax in der Nähe des 'group'-Schlüsselwortes.]"
["backtrace"]=>
...
string(34) "C:\Programme\xampp\php\pear\DB.php"
["line"]=> int(888)
["function"]=> string(10) "PEAR_Error"
...
string(36) "C:\Programme\xampp\php\pear\PEAR.php"
["line"]=> int(557)
["function"]=> string(8) "DB_Error"
...
string(41) "C:\Programme\xampp\php\pear\DB\common.php"
["line"]=> int(1849)
["function"]=>string(10) "raiseError"
...
string(40) "C:\Programme\xampp\php\pear\DB\mssql.php"
["line"]=> int(629)
["function"]=> string(10) "raiseError"
...
}

[2006-08-01 12:55 UTC] tommim at freenet dot de

[EDIT] When looking through other PEAR::DB files I noticed the same issue with tableInfo functions in pear/DB/mysqli.php, pear/DB/odbc.php, pear/DB/pgsql.php, pear/DB/sybase.php, pear/DB/ibase.php, pear/DB/ifx.php.

[2006-08-01 13:05 UTC] tommim at freenet dot de

[EDIT] When looking through other PEAR::DB files I noticed the same
issue with tableInfo functions in pear/DB/mysqli.php, pear/DB/odbc.php,
pear/DB/pgsql.php, pear/DB/sybase.php, pear/DB/ibase.php,
pear/DB/ifx.php.

[EDIT] As if I knew it ... I checked, and found out it's all the same for PEAR::MDB.

[2006-08-01 16:40 UTC] tommim at freenet dot de

*gnarf* Come on - think about it FIRST! You just CAN NOT pass a quoted string $table to tableInfo! I tested this already and it will result in an error message. So leaving this to the user just won't work.

Just fix it! It is just 1 (in words ONE) line to change. I already told you the line number, came up with a tested solution and mentioned all files that need to be fixed. What else do you need? Just to write another comment in this bug section would be more work than just fixing the issue!