Re: Problems creating records Cake 1.2 on postgres

2008-02-24 Thread b logica

You guys thought of everything. That's pretty sweet.

On Sun, Feb 24, 2008 at 5:36 PM, nate <[EMAIL PROTECTED]> wrote:
>
>  Some older versions of Postgres won't tell you the sequence name for a
>  column (I think the earliest version I've tested on is 8.1 or so).  In
>  those cases, you need to do as Chris says, and provide the sequence
>  name in the model class using var $sequence.
>
>
>  On Feb 23, 12:12 pm, "b logica" <[EMAIL PROTECTED]> wrote:
>  > What is the model name you're dealing with here? The 'public' part of
>  > the query refers to the public schema and is used in creating the
>  > sequence name (from which the last value is to be gotten). It looks
>  > like something in your table name is causing Cake to come up with an
>  > incomplete sequence name:
>  >
>  > function lastInsertId($source, $field = 'id') {
>  > foreach ($this->__descriptions[$source] as $name => $sourceinfo) {
>  > if (strcasecmp($name, $field) == 0) {
>  > break;
>  > }
>  > }
>  >
>  > if (isset($this->_sequenceMap[$source])) {
>  > $seq = $this->_sequenceMap[$source];
>  > } elseif (preg_match('/^nextval\(\'(\w+)\'/', 
> $sourceinfo['default'],
>  > $matches)) {
>  > $seq = $matches[1];
>  > } else {
>  > $seq = "{$source}_{$field}_seq";
>  > }
>  >
>  > $res = $this->rawQuery("SELECT last_value AS max FROM \"{$seq}\"");
>  > $data = $this->fetchRow($res);
>  > return $data[0]['max'];
>  >
>  > }
>  >
>  > If you can, log into psql and type:
>  >
>  > \ds
>  >
>  > to see your sequence names. Maybe something's screwy there. Otherwise,
>  > it might be something you've set in your Cake app.
>  >
>
>
> > On Sat, Feb 23, 2008 at 1:27 AM, Bruce <[EMAIL PROTECTED]> wrote:
>  >
>  > >  I am working in Cake 1.2 with PHP5 and a postgres backend DB. When I
>  > >  try to create records in any app I have tried, I get a warning then an
>  > >  SQL error. The record seems to be created in the db, but with my
>  > >  limited knowledge, it looks to me like cake is constructing an
>  > >  incomplete SQL statement when trying to retrieve the ID of the record
>  > >  just written.
>  >
>  > >  Output is like:
>  >
>  > >  Warning (2): pg_query() [function.pg-query]: Query failed: ERROR:
>  > >  relation "public" does not exist [CORE/cake/libs/model/datasources/dbo/
>  > >  dbo_postgres.php, line 122]
>  >
>  > >  Code | Context
>  > >  $sql=   "SELECT last_value AS max FROM "public""
>  > >   */
>  > > function _execute($sql) {
>  > > return pg_query($this->connection, $sql);
>  >
>  > >  pg_query - CORE/cake/libs/model/datasources/dbo/dbo_postgres.php, line
>  > >  122
>  > >  DboPostgres::_execute() - CORE/cake/libs/model/datasources/dbo/
>  > >  dbo_postgres.php, line 122
>  > >  DboPostgres::execute() - CORE/cake/libs/model/datasources/
>  > >  dbo_source.php, line 155
>  > >  DboPostgres::fetchRow() - CORE/cake/libs/model/datasources/
>  > >  dbo_source.php, line 269
>  > >  DboPostgres::lastInsertId() - CORE/cake/libs/model/datasources/dbo/
>  > >  dbo_postgres.php, line 355
>  > >  DboPostgres::create() - CORE/cake/libs/model/datasources/
>  > >  dbo_source.php, line 500
>  > >  JobHistory::save() - CORE/cake/libs/model/model.php, line 1234
>  > >  JobHistoriesController::add() - APP/controllers/
>  > >  job_histories_controller.php, line 23
>  > >  Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 265
>  > >  Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 237
>  > >  [main] - APP/webroot/index.php, line 84
>  > >  Query: SELECT last_value AS max FROM "public"
>  >
>  > >  Any suggestions?
>  >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Problems creating records Cake 1.2 on postgres

2008-02-24 Thread nate

Some older versions of Postgres won't tell you the sequence name for a
column (I think the earliest version I've tested on is 8.1 or so).  In
those cases, you need to do as Chris says, and provide the sequence
name in the model class using var $sequence.

On Feb 23, 12:12 pm, "b logica" <[EMAIL PROTECTED]> wrote:
> What is the model name you're dealing with here? The 'public' part of
> the query refers to the public schema and is used in creating the
> sequence name (from which the last value is to be gotten). It looks
> like something in your table name is causing Cake to come up with an
> incomplete sequence name:
>
> function lastInsertId($source, $field = 'id') {
>         foreach ($this->__descriptions[$source] as $name => $sourceinfo) {
>                 if (strcasecmp($name, $field) == 0) {
>                         break;
>                 }
>         }
>
>         if (isset($this->_sequenceMap[$source])) {
>                 $seq = $this->_sequenceMap[$source];
>         } elseif (preg_match('/^nextval\(\'(\w+)\'/', $sourceinfo['default'],
> $matches)) {
>                 $seq = $matches[1];
>         } else {
>                 $seq = "{$source}_{$field}_seq";
>         }
>
>         $res = $this->rawQuery("SELECT last_value AS max FROM \"{$seq}\"");
>         $data = $this->fetchRow($res);
>         return $data[0]['max'];
>
> }
>
> If you can, log into psql and type:
>
> \ds
>
> to see your sequence names. Maybe something's screwy there. Otherwise,
> it might be something you've set in your Cake app.
>
> On Sat, Feb 23, 2008 at 1:27 AM, Bruce <[EMAIL PROTECTED]> wrote:
>
> >  I am working in Cake 1.2 with PHP5 and a postgres backend DB. When I
> >  try to create records in any app I have tried, I get a warning then an
> >  SQL error. The record seems to be created in the db, but with my
> >  limited knowledge, it looks to me like cake is constructing an
> >  incomplete SQL statement when trying to retrieve the ID of the record
> >  just written.
>
> >  Output is like:
>
> >  Warning (2): pg_query() [function.pg-query]: Query failed: ERROR:
> >  relation "public" does not exist [CORE/cake/libs/model/datasources/dbo/
> >  dbo_postgres.php, line 122]
>
> >  Code | Context
> >  $sql    =       "SELECT last_value AS max FROM "public""
> >   */
> >     function _execute($sql) {
> >         return pg_query($this->connection, $sql);
>
> >  pg_query - CORE/cake/libs/model/datasources/dbo/dbo_postgres.php, line
> >  122
> >  DboPostgres::_execute() - CORE/cake/libs/model/datasources/dbo/
> >  dbo_postgres.php, line 122
> >  DboPostgres::execute() - CORE/cake/libs/model/datasources/
> >  dbo_source.php, line 155
> >  DboPostgres::fetchRow() - CORE/cake/libs/model/datasources/
> >  dbo_source.php, line 269
> >  DboPostgres::lastInsertId() - CORE/cake/libs/model/datasources/dbo/
> >  dbo_postgres.php, line 355
> >  DboPostgres::create() - CORE/cake/libs/model/datasources/
> >  dbo_source.php, line 500
> >  JobHistory::save() - CORE/cake/libs/model/model.php, line 1234
> >  JobHistoriesController::add() - APP/controllers/
> >  job_histories_controller.php, line 23
> >  Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 265
> >  Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 237
> >  [main] - APP/webroot/index.php, line 84
> >  Query: SELECT last_value AS max FROM "public"
>
> >  Any suggestions?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Problems creating records Cake 1.2 on postgres

2008-02-24 Thread Chris Hartjes

On Sat, Feb 23, 2008 at 10:34 PM, Bruce <[EMAIL PROTECTED]> wrote:
>
>  As you say, it looks like it is not reading the names of the sequence
>  correctly somewhere along the line.

I ran into this using postgres as well.  Just make sure to define the
sequence in the model itself

var $sequence = 'name of sequence';


-- 
Chris Hartjes
Internet Loudmouth
Motto for 2008: "Moving from herding elephants to handling snakes..."
@TheKeyBoard: http://www.littlehart.net/atthekeyboard

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Problems creating records Cake 1.2 on postgres

2008-02-24 Thread b logica

I have to wonder if 'action' is acting like a keyword to disrupt things.

On Sat, Feb 23, 2008 at 10:34 PM, Bruce <[EMAIL PROTECTED]> wrote:
>
>  Since the last message, I have created a new table, model, controller
>  and views from scratch with new names and the same structure - the
>  problem still exists.
>
>  Table name is job_actions, with a serial field called 'id' (was called
>  'job_histories' last time).
>  Sequence name (created by postgres) is 'job_actions_id_seq'.
>  Model is just the bare bones and is called 'job_action.php'.
>  Controller and views were built with bake. Controller name is
>  'job_actions.php'.
>
>  All DB ownership seems to be in order with the user defined in cake
>  owning the table and the sequence.
>
>  As you say, it looks like it is not reading the names of the sequence
>  correctly somewhere along the line.
>
>
>
>  >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Problems creating records Cake 1.2 on postgres

2008-02-23 Thread Bruce

Since the last message, I have created a new table, model, controller
and views from scratch with new names and the same structure - the
problem still exists.

Table name is job_actions, with a serial field called 'id' (was called
'job_histories' last time).
Sequence name (created by postgres) is 'job_actions_id_seq'.
Model is just the bare bones and is called 'job_action.php'.
Controller and views were built with bake. Controller name is
'job_actions.php'.

All DB ownership seems to be in order with the user defined in cake
owning the table and the sequence.

As you say, it looks like it is not reading the names of the sequence
correctly somewhere along the line.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Problems creating records Cake 1.2 on postgres

2008-02-23 Thread b logica

What is the model name you're dealing with here? The 'public' part of
the query refers to the public schema and is used in creating the
sequence name (from which the last value is to be gotten). It looks
like something in your table name is causing Cake to come up with an
incomplete sequence name:

function lastInsertId($source, $field = 'id') {
foreach ($this->__descriptions[$source] as $name => $sourceinfo) {
if (strcasecmp($name, $field) == 0) {
break;
}
}

if (isset($this->_sequenceMap[$source])) {
$seq = $this->_sequenceMap[$source];
} elseif (preg_match('/^nextval\(\'(\w+)\'/', $sourceinfo['default'],
$matches)) {
$seq = $matches[1];
} else {
$seq = "{$source}_{$field}_seq";
}

$res = $this->rawQuery("SELECT last_value AS max FROM \"{$seq}\"");
$data = $this->fetchRow($res);
return $data[0]['max'];
}


If you can, log into psql and type:

\ds

to see your sequence names. Maybe something's screwy there. Otherwise,
it might be something you've set in your Cake app.

On Sat, Feb 23, 2008 at 1:27 AM, Bruce <[EMAIL PROTECTED]> wrote:
>
>  I am working in Cake 1.2 with PHP5 and a postgres backend DB. When I
>  try to create records in any app I have tried, I get a warning then an
>  SQL error. The record seems to be created in the db, but with my
>  limited knowledge, it looks to me like cake is constructing an
>  incomplete SQL statement when trying to retrieve the ID of the record
>  just written.
>
>  Output is like:
>
>  Warning (2): pg_query() [function.pg-query]: Query failed: ERROR:
>  relation "public" does not exist [CORE/cake/libs/model/datasources/dbo/
>  dbo_postgres.php, line 122]
>
>  Code | Context
>  $sql=   "SELECT last_value AS max FROM "public""
>   */
> function _execute($sql) {
> return pg_query($this->connection, $sql);
>
>  pg_query - CORE/cake/libs/model/datasources/dbo/dbo_postgres.php, line
>  122
>  DboPostgres::_execute() - CORE/cake/libs/model/datasources/dbo/
>  dbo_postgres.php, line 122
>  DboPostgres::execute() - CORE/cake/libs/model/datasources/
>  dbo_source.php, line 155
>  DboPostgres::fetchRow() - CORE/cake/libs/model/datasources/
>  dbo_source.php, line 269
>  DboPostgres::lastInsertId() - CORE/cake/libs/model/datasources/dbo/
>  dbo_postgres.php, line 355
>  DboPostgres::create() - CORE/cake/libs/model/datasources/
>  dbo_source.php, line 500
>  JobHistory::save() - CORE/cake/libs/model/model.php, line 1234
>  JobHistoriesController::add() - APP/controllers/
>  job_histories_controller.php, line 23
>  Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 265
>  Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 237
>  [main] - APP/webroot/index.php, line 84
>  Query: SELECT last_value AS max FROM "public"
>
>  Any suggestions?
>
>
>  >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Problems creating records Cake 1.2 on postgres

2008-02-23 Thread Bruce

I am working in Cake 1.2 with PHP5 and a postgres backend DB. When I
try to create records in any app I have tried, I get a warning then an
SQL error. The record seems to be created in the db, but with my
limited knowledge, it looks to me like cake is constructing an
incomplete SQL statement when trying to retrieve the ID of the record
just written.

Output is like:

Warning (2): pg_query() [function.pg-query]: Query failed: ERROR:
relation "public" does not exist [CORE/cake/libs/model/datasources/dbo/
dbo_postgres.php, line 122]

Code | Context
$sql=   "SELECT last_value AS max FROM "public""
 */
function _execute($sql) {
return pg_query($this->connection, $sql);

pg_query - CORE/cake/libs/model/datasources/dbo/dbo_postgres.php, line
122
DboPostgres::_execute() - CORE/cake/libs/model/datasources/dbo/
dbo_postgres.php, line 122
DboPostgres::execute() - CORE/cake/libs/model/datasources/
dbo_source.php, line 155
DboPostgres::fetchRow() - CORE/cake/libs/model/datasources/
dbo_source.php, line 269
DboPostgres::lastInsertId() - CORE/cake/libs/model/datasources/dbo/
dbo_postgres.php, line 355
DboPostgres::create() - CORE/cake/libs/model/datasources/
dbo_source.php, line 500
JobHistory::save() - CORE/cake/libs/model/model.php, line 1234
JobHistoriesController::add() - APP/controllers/
job_histories_controller.php, line 23
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 265
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 237
[main] - APP/webroot/index.php, line 84
Query: SELECT last_value AS max FROM "public"

Any suggestions?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---