PEAR is archived and read-only

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

Home » Database » DB_DataObject » Bug #43

Table names need quoting.

Details

Submitted2003-09-28 22:13 UTC
Fromjon at jellybob dot co dot uk
Assignedalan_k
StatusClosed
PackageDB_DataObject
PHP Version4.3.3
OSLinux
Roadmaps(Not assigned)

Comments

[2003-09-28 22:13 UTC] jon at jellybob dot co dot uk

Description:
------------
While trying to use a data object on a table named group (I also noticed that this table name is used in the docs), no records were retrieved despite there being records in the database.

Once I set __table by hand to `group` instead of group, records were returned.

Reproduce code:
---------------
// Dataobject Definition
[...snip...]
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
var $__table = 'group'; // table name
var $id; // int(9) not_null primary_key auto_increment
var $name; // string(32) not_null unique_key
[...snip...]

// Call
$group = new Object_Group;
$group->find();
while($group->fetch()) {
echo $group->getName();
}

Expected result:
----------------
The group names found would be displayed.

Actual result:
--------------
__find

CONNECT NEW CONNECTION

CONNECT mysql://[username]@localhost/[database] fc355c051919887a98657ea6e6602730

sql QUERYSELECT * FROM group

SENT SELECT * FROM group

ERROR DB Error: syntax error

__find CHECK autofetchd

__find DONE

ERROR fetch: No Data Available

STATIC GET - TRY CACHE Object_User 1

STATIC GET - NOT IN CACHE Object_User 1

[2003-10-22 15:20 UTC] jon at jellybob dot co dot uk

I'm not sure why it's out of scope, don't you just need to
quote the table name whenever you use it, since just
wrapping it in `s will fix the problem.

[2003-11-25 02:36 UTC] brian at OpenSourceConcepts dot com

Just thought I'd add my two cents here - I would definitely recommend quoting the table names. If you take all the keywords for all the databases supported, there are a lot of keywords (Postgres alone has a ton.)

With the strict naming conventions of large and/or integrated apps (where the PHP developer might not own the data model) it seems a lot more robust to assume the worst and quote table names.