|
|
Re: pg_last_oid() and postgresql-8.1 [message #38985 is a reply to message #36923] |
Wed, 12 September 2007 14:14 |
lawrencec
Messages: 2 Registered: September 2007
Karma: 0
|
Junior Member |
|
|
This should really be fixed in code, not turned back on in the database (which some users may not be able to do anyway).
From the postgres manual ( http://www.postgresql.org/docs/8.1/interactive/runtime-config-compatible.ht ml#GUC-DEFAULT-WITH-OIDS):
Quote: | The use of OIDs in user tables is considered deprecated
|
While some would argue that using lastval() to get the last value of a serial field is error prone and the proper way to set an id is to call nextval() on the sequence *before* doing the insert and including the id in the insert itself, the way FUDforum is written doesn't allow easy modification to work that way.
So, an easy fix is to locate all lines of code that get the last id created by querying the database using the oid from pg_last_oid() and wrapping this bit of code around it:
if (pg_last_oid($r)) {
<<old return statement>>
}
else {
return q_singleval('SELECT lastval()');
}
So, for example, function db_qid() would be changed from this:
function db_qid($q)
{
$r = q($q);
preg_match('!('.$GLOBALS['DBHOST_TBL_PREFIX'].'[A-Za-z0-9_]+)!', $q, $m);
return q_singleval('SELECT id FROM '.$m[1].' WHERE oid='.pg_last_oid($r));
}
to this:
function db_qid($q)
{
$r = q($q);
preg_match('!('.$GLOBALS['DBHOST_TBL_PREFIX'].'[A-Za-z0-9_]+)!', $q, $m);
if (pg_last_oid($r)) {
return q_singleval('SELECT id FROM '.$m[1].' WHERE oid='.pg_last_oid($r));
}
else {
return q_singleval('SELECT lastval()');
}
}
From what I found, there are two functions that need this change -- db_qid() and db_li() -- that are replicated in six files:
<fud_web>/index.php
<fud_web>/pdf.php
<fud_web>/rdf.php
<fud_data>/include/theme/default/db.inc
<fud_data>/sql/pgsql/db.inc
<fud_data>/src/db.inc.t
---Lawrence
|
|
|
Re: pg_last_oid() and postgresql-8.1 [message #38992 is a reply to message #38985] |
Wed, 12 September 2007 18:35 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
Thanks a fix was applied to the CVS.
The reason you are seeing the code duplicated is because you are looking @ the compiled files. Only the db.inc inside the sql/pgsql/ directory matters.
FUDforum Core Developer
|
|
|
Re: pg_last_oid() and postgresql-8.1 [message #39481 is a reply to message #38992] |
Fri, 26 October 2007 15:18 |
jacpad
Messages: 21 Registered: January 2006
Karma: 0
|
Junior Member |
|
|
I had a similar problem with a combination of forum 2.7.7 and postgresql 8.0.
In this version of postgres the function lastval did not exist. So I tried to replace it with the 'currval()' function, but without success as this function has it's special behaviour :
I modified the function that retrive the data and id - it's working now for me. I don't know if this is of interest for other people. So if it is just post it and I send my proposal to solve it.
anyway thx to Ilia for his great work
|
|
|