DataObject postgresql problems
| From: | Jeroen Houben | Date: | Mon, 23 Jun 2003 13:56:31 +0000 |
| Subject: | DataObject postgresql problems | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-17645@lists.php.net to get a copy of this message | ||
Hi,
My table definition looks like this:
CREATE TABLE "users" (
"user_id" SMALLINT DEFAULT nextval('users_id_seq::text') NOT NULL, // I should get rid of ::text, but it was created automatically migrating from MySql
"fullname" CHAR(60) DEFAULT '' NOT NULL,
"username" VARCHAR(10) DEFAULT '' NOT NULL,
"pwd" VARCHAR(40) DEFAULT '' NOT NULL,
"email" VARCHAR(150),
PRIMARY KEY("user_id"),
UNIQUE("username")
) WITH OIDS;
CREATE INDEX "idx_pwd_users_index" ON "users"
USING btree ("pwd");
Problem is that it tries to to skip the username column on inserts. Possibly because it thinks it's a primary auto incrementing key or something. This is the query that gets send to PG:
INSERT INTO users (user_id , fullname , pwd , email ) VALUES ( 4 , 'dsasd' , 'fdsasdasddsa' , 'dsa@dsadas.nl' )
[nativecode=ERROR: Cannot insert a duplicate key into unique index users_username_key ]
Another problem is that it takes a wrong number for the sequence. It should be 120. It creates it's own sequence and uses values from that:
CREATE SEQUENCE "users_seq"
INCREMENT 1 MINVALUE 1
MAXVALUE 9223372036854775807 CACHE 1;
But it should be using the sequence I created:
CREATE SEQUENCE "users_id_seq"
INCREMENT 1 MINVALUE 1
MAXVALUE 9223372036854775807 CACHE 1;
I'm using 0.19 and here's my generated table class, just to be complete:
Help is much appreciated!
jeroen
<?php
/**
* Table Definition for users
*/
require_once 'DB/DataObject.php';
class DataObjects_Users extends DB_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
var $__table = 'users'; // table name var $user_id; // int2(2) not_null default_nextval(users_id_seq::text) unique primary var $fullname; // bpchar(-1) not_null default_ var $username; // varchar(-1) not_null default_ unique var $pwd; // varchar(-1) not_null default_ var $email; // varchar(-1)/* ZE2 compatibility trick*/ function __clone() { return $this;} /* Static get */ function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('DataObjects_Users',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE } ?>