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
Switch to threaded view of this topic Create a new topic Submit Reply
pg_last_oid() and postgresql-8.1 [message #36923] Tue, 17 April 2007 17:34 Go to next message
buck is currently offline  buck   Switzerland
Messages: 1
Registered: April 2007
Karma: 0
Junior Member
Hi,
Quote:

OID field became an optional field from PostgreSQL 7.2 and will not be present by default in PostgreSQL 8.1

http://de3.php.net/manual/en/function.pg-last-oid.php

Therefore, f.e. index.php fails because of an error in the sql-query: "SELECT id FROM fud26_ses WHERE id=";

Possible solution: Use PostgreSQL function LASTVAL() as described in the manual linked above. LASTVAL() is available since PostgreSQL 8.1... good luck.

regards,
Patrik

[Updated on: Tue, 17 April 2007 17:36]

Report message to a moderator

Re: pg_last_oid() and postgresql-8.1 [message #36927 is a reply to message #36923] Tue, 17 April 2007 23:13 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
I recommend enabling OID support in your PostgreSQL install

FUDforum Core Developer
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 next message
lawrencec is currently offline  lawrencec   United States
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 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 Go to previous message
jacpad is currently offline  jacpad   Germany
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 :
Quote:

An error is reported if nextval has never been called for this sequence in this session
(http://www.postgresql.org/docs/8.0/static/functions-sequence.htm)

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
  Switch to threaded view of this topic Create a new topic Submit Reply
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: Sat Nov 30 16:31:49 GMT 2024

Total time taken to generate the page: 0.02633 seconds