phpLens
 home  products examples manual  faq support forum  contact news  login store

Forums: phplens   adodb
Forums:   ADOdb Help & Dev:   Replies 
New ReplySearch
Topic: ActiveRecord: save() throws error with SERIAL types on postgres 8.4
author: Peter Thomas   created: 20-03-2012 01:12:49 PM
There appears to be an issue when saving new active records into tables whose PKs are SERIAL types.

Calling save() on a new ADOdb_Active_Record results in this error:


PHP Fatal error: Uncaught exception 'ADODB_Exception' with
message 'postgres7 error: [-1: ERROR: null value in column
"id" violates not-null constraint] in EXECUTE("INSERT INTO
persons(id,name_first,name_last,favorite_color) VALUES
($1,$2,$3,$4)")


Has anyone else run into this problem? I'm using ADOdb 5.15, PHP 5.3.2 and PostgreSQL 8.4.

Here is the code that produces the error (adapted from the example in the ADOdb Active Record docs):


<?php

require_once('./adodb5/adodb-exceptions.inc.php');
require_once('./adodb5/adodb.inc.php');
require_once('./adodb5/adodb-active-record.inc.php');

$db = NewADOConnection("postgres://$user:$password@$host/$dbname");
ADOdb_Active_Record::SetDatabaseAdapter($db);

$db->Execute("CREATE TEMPORARY TABLE persons (
id SERIAL,
name_first varchar(100) NOT NULL default '',
name_last varchar(100) NOT NULL default '',
favorite_color varchar(100) NOT NULL default '',
PRIMARY KEY (id)
)
");

class person extends ADOdb_Active_Record{}
$person = new person();

$person = new person();
$person->name_first = 'Andi';
$person->name_last = 'Gutmans';
$person->favorite_color = 'blue';
$person->save();

?>
Topic: Re:ActiveRecord: save() throws error with SERIAL types on postgres 8.4
author: John Lim   created: 26-03-2012 01:49:57 AM
Could because the serial data type is not properly recognised. This is fixed in 5.16.
Topic: Re:ActiveRecord: save() throws error with SERIAL types on postgres 8.4
author: Josh Tanski   created: 13-03-2013 03:28:18 PM
I appear to be having the same issue with adodb 5.18:


(postgres9): INSERT INTO newsitems(id,title,posting_date,author,contents) VALUES ($1,$2,$3,$4,$5) [ (0=>null) (1=>'test') (2=>'03/12/2013') (3=>'jdt') (4=>'three') ] Warning: pg_query_params(): Query failed: ERROR: null value in column "id" violates not-null constraint in /var/www/lib/adodb-5.18/drivers/adodb-postgres7.inc.php on line 217 -1: ERROR: null value in column "id" violates not-null constraint

ADOConnection._Execute(INSERT INTO newsitems(id,title,posting_date,author,contents) VALUES ($1,$2,$3,$4,$5), Array[5]) % line 1045, file: adodb.inc.php
ADOConnection.Execute(INSERT INTO newsitems(id,title,posting_date,author,contents) VALUES ($1,$2,$3,$4,$5), Array[5]) % line 771, file: adodb-active-record.inc.php
ADODB_Active_Record.Insert() % line 735, file: adodb-active-record.inc.php
ADODB_Active_Record.Save() % line 39, file: add.php
Topic: Re:ActiveRecord: save() throws error with SERIAL types on postgres 8.4
author: Josh Tanski   created: 14-03-2013 10:41:59 AM
I've found that version 5.07 is the newest version that works correctly.
Topic: Re:ActiveRecord: save() throws error with SERIAL types on postgres 8.4
author: Jun Ota   created: 10-04-2013 05:47:40 AM
I found same issue on 5.18.

It could fix it to change adodb-active-record.inc.php:754.

if(!is_array($val) || !is_null($val) || !array_key_exists($name, $table->keys))

to

if(!(is_array($val) || is_null($val)) || !array_key_exists($name, $table->keys))

It had always returned true.
Page 1
New ReplySearch

View Source

email: contact#phplens.com (change # to @)     telephone (malaysia): 60-3-7947 2888     fax (malaysia): 60-3-7947 2800