List Info

Thread: Re: Problems creating records Cake 1.2 on postgres




Re: Problems creating records Cake 1.2 on postgres
user name
2008-02-23 11:12:30
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 <bruceward51gmail.com> 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-phpgooglegroups.com
To unsubscribe from this group, send email to
cake-php-unsubscribegooglegroups.com
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
user name
2008-02-23 21:34:50
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-phpgooglegroups.com
To unsubscribe from this group, send email to
cake-php-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )