Home » Database » DB » Bug #1660
insert does not recognize strings
Details
| Submitted | 2004-06-16 20:08 UTC |
|---|---|
| From | thomas dot haas at fht-esslingen dot de |
| Status | Duplicate |
| Package | DB |
| PHP Version | 5.0.0RC2 (Release Candidate 2) |
| OS | win xp |
| Roadmaps | (Not assigned) |
Comments
[2004-06-16 20:08 UTC] thomas dot haas at fht-esslingen dot de
Description:
------------
I have following table:
CREATE TABLE color(
ColorId integer NOT NULL ,
Name varchar(255) NOT NULL default '',
PRIMARY KEY (ColorId)
);
if i want to insert a string into a field like this:
$color = new Color();
$color->setName("red");
$color->insert();
i get following insert-sql on sqlite:
INSERT INTO color (ColorId , Name) VALUES ( 1 , 0)
on mysql it does work like expected:
INSERT INTO color (ColorId , Name) VALUES ( 1 , 'red')
Expected result:
----------------
Insert should recognize strings on sqlite, not only on mysql
Actual result:
--------------
Insert does not recognize strings on sqlite. On mysql it does work.
[2004-06-17 09:39 UTC] thomas dot haas at fht-esslingen dot de
$db = $color->getDatabaseConnection();
print_r($db->tableInfo('color'));
does shwow the following array:
Array
(
[0] => Array
(
[cid] => 0
[name] => ColorId
[type] => integer
[notnull] => 99
[dflt_value] =>
[pk] => 1
[flags] => primary_key,
[len] =>
)
[1] => Array
(
[cid] => 1
[name] => Name
[type] => varchar(255)
[notnull] => 99
[dflt_value] =>
[pk] => 0
[flags] =>
[len] =>
)
)
[2004-06-17 10:14 UTC] thomas dot haas at fht-esslingen dot de
I've taken the suggested code from http://pear.php.net/bugs/bug.php?id=1317 because there's no code for tableinfo() in the DB CVS that supports it.
If DataObject should work with sqlite in V5 i think tableinfo() should work too!
[2004-06-17 12:03 UTC] thomas dot haas at fht-esslingen dot de
I think, insert does not work with tableinfo(). So the Problem is not tableinfo()!
The values of the SQL command was build in insert() of DataObject like this with an integer:
//if key
$rightq = '';
$rightq .=" {$this->$k} "; //$this->$k is int key
//all other values
$rightq .= ', ';
$rightq .=" {$this->$k} "; //$this->$k is int insert value
With an string the values was build in insert() as following lines show:
//if key
$rightq = '';
$rightq .=" {$this->$k} "; //$this->$k is int key
//all other values
$rightq .= ', ';
$rightq .= ' ' . intval($this->$k) . ' '; //why convert all the values (also strings) to integer???
My suggestion: change the following two lines in DataObject::insert() an it should work:
//old line
//$rightq .= ' ' . intval($this->$k) . ' ';
//new line instead of old line
$rightq .= ' ' . $this->$k . ' ';
[2004-06-17 13:35 UTC] thomas dot haas at fht-esslingen dot de
You're right!
Problem is in tableInfo() of DB sqlite.php and not in DataObject::insert(). With your posted code now it does work fine and database.ini is ok too.
Thanks a lot!!