PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB_DataObject » Bug #10005

MSSQL-problem finding table with quote_identifiers = 1

Details

Submitted2007-02-01 14:57 UTC
Frompowtac at gmx dot de
StatusNo Feedback
PackageDB_DataObject
PHP Version5.2.0
OSWIN 2000
Roadmaps(Not assigned)

Comments

[2007-02-01 14:57 UTC] powtac at gmx dot de

Description:
------------
When adding quote_identifiers = 1 to the config I get an error for the DataObject, see below.
I think this is a regexp-problem, DO can't find the Table "[dbo.Adressen]" instead of finding "dbo.Adressen" (without quote identifiers).
I'm using MSSQL 2005. The access without quote_identifiers on works perfekt.

Test script:
---------------
Config:
=======
...
$config['db_driver'] = 'DB';
$config['quote_identifiers'] = 1;
...

Script:
=======
DB_DataObject::debugLevel(1);
$CustomerL =& new DataObject_Dbo_Adressen;
$CustomerL->selectAdd();
$CustomerL->selectAdd('Adresse, Mandant');
$CustomerL->whereAdd('Adresse < 20');
if ($CustomerL->find()) {
while ($CustomerL->fetch()) {
// do ....
}
}

Dbo_Adressen.php:
=================
<?php
/**
* Table Definition for dbo.Adressen
*/
require_once 'DB/DataObject.php';

class DataObject_Dbo_Adressen extends DB_DataObject
{
###START_AUTOCODE
/* ... */

public $__table = 'dbo.Adressen'; // table name
public $Adresse; // int identity(10)
public $Mandant; // int(10)
...
?>

Expected result:
----------------
Correct DataObject

Actual result:
--------------
DataObject_Dbo_Adressen: find:
DataObject_Dbo_Adressen: CONNECT: Checking for database database_ in options
DataObject_Dbo_Adressen: databaseStructure: Loaded ini file: C:\www\zugriff\dataObject/AFS_WAWU_DB.ini
DataObject_Dbo_Adressen: QUERY: SELECT Adresse, Mandant
FROM [dbo.Adressen]

WHERE ( Adresse < 20 )

DataObject_Dbo_Adressen: Query Error: [db_error: message="DB Error: no such table" code=-18 mode=return level=notice prefix="" info="SELECT Adresse, Mandant
FROM [dbo.Adressen]

WHERE ( Adresse < 20 )

[nativecode=208 - Ungültiger Objektname 'dbo.Adressen'.]"]
DataObject_Dbo_Adressen: ERROR: DB_Error Object
(
[error_message_prefix] =>
[mode] => 1
[level] => 1024
[code] => -18
[message] => DB Error: no such table
[userinfo] => SELECT Adresse, Mandant
FROM [dbo.Adressen]

WHERE ( Adresse < 20 )

[nativecode=208 - Ungültiger Objektname 'dbo.Adressen'.]
[backtrace] => Array
(
[0] => Array
(
[file] => C:\Programms\xampp\php\pear\DB.php
[line] => 888
[function] => PEAR_Error
[class] => PEAR_Error
[type] => ->
[args] => Array
(
[0] => DB Error: no such table

....

[2007-02-01 16:31 UTC] powtac at gmx dot de

When I disable quote_identifiers, I get this result:

DataObject_Dbo_Adressen: find:
DataObject_Dbo_Adressen: CONNECT: Checking for database database_ in options
DataObject_Dbo_Adressen: databaseStructure: Loaded ini file: C:\www\zugriff\dataObject/AFS_WAWU_DB.ini
DataObject_Dbo_Adressen: QUERY: SELECT Adresse, Mandant
FROM dbo.Adressen

WHERE ( Adresse < 20 )

DataObject_Dbo_Adressen: query: QUERY DONE IN 0.0122919082642 seconds
DataObject_Dbo_Adressen: find: CHECK autofetchd
DataObject_Dbo_Adressen: find: DONE
DataObject_Dbo_Adressen: FETCH: a:2:{s:7:"Adresse";i:1;s:7:"Mandant";i:1;}
NULL

With quote_identifiers I expect a query like:

SELECT [Adresse], [Mandant] FROM [dbo].[Adressen] WHERE ( [Adresse] < 20 )

"[" and "]" seems to be quote_identifiers for MSSQL. This could been added by PEAR::DB!?

I found this bug while searching for an solution for the problem of having a MSSQL table with a column named "Update". This gave me a error like "wrong syntax: found keyword". With "$Object->selectAdd('[Update] as coldate');" I got Update/coldate working on my awful MSSQL table. See also http://pear.php.net/bugs/bug.php?id=9839. :(