Loading...
 
Skip to main content

last_insert_id() is mysql-specific - need to replace with ADODB equivalent

Status
Closed
Subject
last_insert_id() is mysql-specific - need to replace with ADODB equivalent
Version
1.9.x
2.x
Category
  • Error
Feature
Database MySQL (MyISAM)
Trackers
i18n (Multilingual, l10n, Babelfish)
Resolution status
Fixed or Solved
Submitted by
Michael Davey
Volunteered to solve
Michael Davey
Lastmod by
Michael Davey, lindon
Rating
(0)
Description

last_insert_id() is used in SQL in a couple of places in TikiWIki. This is a mysql-specific function that breaks functionality when other databases are used.

For TikiWiki CVS HEAD (1.10):

lib/articles/artlib.php:152: $query = "select `subId` from `tiki_submissions` where `subId`=last_insert_id()";

lib/multilingual/multilinguallib.php:28: $query = "insert into `tiki_translated_objects` (`type`,`objId`,`traId`,`lang`) values (?,?,last_insert_id(),?)";

Also present in TikiWiki 1.9.x

Reported by Thrain - thanks.

Solution

$adodb->genID() ?

mo0co0 says:
The proposed solution adodb.genID() is unpratical to use because it emulates
sequences in MySQL by using a dedicated table with one row and one column for
each sequence. This would have to be done throughout the codebase. Instead I
used the the quick and dirty approach taken in other places by simply querying
for the just inserted tuple.

fix by mo0co0:
diff -u -d -r1.40.2.10 -r1.40.2.11


artlib.php 5 May 2005 08:55:15 -0000 1.40.2.10 +++ artlib.php 2 Oct 2005 19:14:09 -0000 1.40.2.11

@@ -149,8 +149,9 @@
$result = $this->query($query,array($title,$authorName,(int) $topicId,$useImage,$imgname,(int) $imgsize,$imgtype,
$imgdata,(int) $publishDate,(int) $expireDate, (int) $now,$heading,$body,$hash,$user,0,0,0,(int) $size,$topicName,(int) $image_x,
(int) $image_y,$type,(float) $rating,$isfloat,$topline, $subtitle, $linkto, $image_caption, $lang));
- $query = "select `subId` from `tiki_submissions` where `subId`=last_insert_id()";
- $id = $this->getOne($query);

+ // Fixed query. -edgar + $query = "select max(`subId`) from `tiki_submissions` where `created` = ? and `title`=? and `hash`=?"; + $id = $this->getOne($query, array( (int) $now, $title, $hash ) );

}

$emails = $notificationlib->get_mail_events('article_submitted', '*');

--
Fixed in 1.9.2-pre; awaiting merge for CVS head (1.10)

Importance
5
Priority
25
Demonstrate Bug on Tiki 19+
Demonstrate Bug (older Tiki versions)
Ticket ID
349
Created
Sunday 02 October, 2005 15:27:02 UTC
by Unknown
LastModif
Sunday 18 June, 2017 22:53:40 UTC


Show PHP error messages