PEAR is archived and read-only

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

Home » Database » MDB_QueryTool » Bug #7757

_makeIndexed return NULL value when db col type is NOT NULL

Details

Submitted2006-05-30 12:46 UTC
Fromsima at igldesign dot cz
Assignedquipo
StatusBogus
PackageMDB_QueryTool
PHP VersionIrrelevant
Roadmaps(Not assigned)

Comments

[2006-05-30 12:46 UTC] sima at igldesign dot cz

Description:
------------
There is simply mysql table:
id, int, primary
s1, varchar 255, not null
s2, varchar 255, not null

I add one record and fill only id (s1,s2 no filled)
Now get this data.
Function get return array with index s1 and s2 which have NULL values.
Now fill s1 value with some string and update.
Now is something wrong.

Result query is UPDATE mytable SET id='', s1=NULL...
It is wrong because column s1,s2 have definition NOT NULL

[2006-06-02 13:38 UTC] sima at igldesign dot cz

require_once('MDB/QueryTool.php');

class CObject extends MDB_QueryTool {

var $table = "test";
var $sequenceName = "test";

var $data = array();

function __construct( &$db ) {
parent::__construct();
$this->setDbInstance( $db );
}
function CObject( &$db ) {
$this->__construct( $db );
}

function Load( $id ) {
$this->data = parent::get( $id );
}

function Save() {
/* my patch */
foreach($this->data as $k=>$v) {
if (gettype($v) == 'NULL') {
unset($this->data[$k]);
}
}
return parent::save( $this->data );
}

function Delete() {
$this->data['invalid'] = 1;
return $this->Save();
}

function Set( $attribute, $value ) {
$this->data[$attribute] = $value;
}

function Get( $attribute, &$value ) {
$value = $this->data[$attribute];
}

function Dump() {
echo '<pre>';
print_r( $this->data );
echo '</pre>';
}
}

$db =& MDB2::connect( 'mysql://test:test@localhost/test' );

$test = new CObject( &$db );
$test->Set('test1', 'lorem ipsum');
$id = $test->Save();

$test = new CObject( &$db );
$test->Load( $id );
$test->Set('test1', 'lorem ipsum changed');
$test->Save();

MySQL TABLE
CREATE TABLE `test` (
id int(11) NOT NULL auto_increment,
test1 varchar(255) collate utf8_czech_ci NOT NULL default '',
test2 varchar(255) collate utf8_czech_ci NOT NULL default '',
invalid tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;