FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Bug Reports » pg_last_oid() and postgresql-8.1
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: pg_last_oid() and postgresql-8.1 [message #38985 is a reply to message #36923] Wed, 12 September 2007 14:14 Go to previous messageGo to previous message
lawrencec is currently offline  lawrencec   United States
Messages: 2
Registered: September 2007
Karma:
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

[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Bug on upgrading 2.7.6 => 2.7.7
Next Topic: Modifying Moderator Permissions
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Jul 05 08:10:15 GMT 2024

Total time taken to generate the page: 0.05431 seconds