View Issue Details

IDProjectCategoryView StatusLast Update
0000302WackoWikidatabasepublic2019-02-14 12:04
Reporteradministrator Assigned ToTann San  
PriorityurgentSeverityfeatureReproducibilityN/A
Status feedbackResolutionopen 
Product Version4.2 
Target Version6.1.x 
Summary0000302: add function lastInsertId for last_insert_id()
DescriptionGets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.

db normalization requires a function for last_insert_id()
Additional Information1. PDO: PDO->lastInsertId() http://de.php.net/manual/en/pdo.lastinsertid.php
2. msql / mysqli -> LAST_INSERT_ID() - http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id
TagsNo tags attached.

Relationships

child of 0000300 resolvedadministrator Normalize database 

Activities

administrator

2009-06-18 13:35

administrator   ~0000658

Last edited: 2009-06-18 13:39

Rev. 481 - Added Experimental last_insert_id($dblink) database functionality. Requires testing.

TanSan:
last_insert_id($dblink)

to the three database drivers we support. It should work fine for
MySQL and MySQLi but I'm not sure about the PDO versions, specifically
the PostgreSQL one. I think it will work fine since we don't use
sequences in our PDO implemention but without testing I can't be
sure.

administrator

2009-09-12 14:50

administrator   ~0000677

Rev. 587 - expanded function GetPageId to get new page_id via page tag, intermediate solution till the function 'lastInsertId' is ready to replace it

Tann San

2009-10-13 12:05

manager   ~0000698

I've just tested both the mysql and mysqli drivers and they both work for me. I'm using

$id = last_insert_id($this->dblink);

You have to grab the ID inside the SavePage function straight after the INSERT query otherwise it will be changed when the ACLs are set/inserted.

My actual test that come straight after the INSERT is this:

$last_id = last_insert_id($this->dblink);
print("Last ID: ".$last_id);
exit(0);

What that does is that after saving a NEW page it will do the insert and then exit giving you a plain screen with just the new ID on it.

I was thinking of switching us over to ADOdb (http://adodb.sourceforge.net/) which says it has support for this built in. The downside is that the documentation for it is somewhat sparse. I can't find anything about retrieving the last ID. The only thing I've seen is a random post somewhere about how they do it like PostgreSQL where you actually create the ID prior to doing the INSERT. Then you use your generated ID in the actual INSERT.

The latest version is PHP5 only but there is another version that supports both PHP4 and PHP5 at the same time. Later on when we remove PHP4 support we can switch to the latest PHP5 only version.

I think it will take me a day or two to port us over to it but then it will obviously take several days longer to test it all out. I think this would be a great move as it means we can get rid of alot of our seperate database code such as in the installer.

Freeman

2009-10-28 09:34

developer   ~0000723

last_insert_id() is not transaction safe. It would work only for databases that lock the table during insert. Because PostgreSQL uses serialization and redo functionality for transaction isolation, "last id" is defined only for this transaction and always undefined globally. Instead of "last id" feature PostgreSQL uses RETURNING clause for insert statement to return autogenerated values: http://www.postgresql.org/docs/current/static/sql-insert.html

Freeman

2010-02-27 15:04

developer   ~0000746

I found it: http://php.net/manual/en/pdo.lastinsertid.php#86591

Issue History

Date Modified Username Field Change
2009-06-18 13:33 administrator New Issue
2009-06-18 13:33 administrator Status new => assigned
2009-06-18 13:33 administrator Assigned To => Tann San
2009-06-18 13:34 administrator Relationship added child of 0000300
2009-06-18 13:35 administrator Note Added: 0000658
2009-06-18 13:39 administrator Note Edited: 0000658
2009-07-15 10:43 administrator Priority high => urgent
2009-09-10 18:56 administrator Description Updated
2009-09-12 14:50 administrator Note Added: 0000677
2009-10-13 12:05 Tann San Note Added: 0000698
2009-10-13 12:12 Tann San Status assigned => feedback
2009-10-28 09:34 Freeman Note Added: 0000723
2010-02-27 15:04 Freeman Note Added: 0000746
2010-03-08 10:11 administrator Category Database => database
2012-04-22 17:04 administrator Target Version 5.0.0 => 5.4.0
2014-03-21 14:57 administrator Target Version 5.4.0 => 5.5.0
2015-02-19 19:29 administrator Target Version 5.5.0 => 6.1.x
2018-08-06 14:37 administrator Target Version 6.1.x => 5.5.7
2019-01-14 14:21 administrator Target Version 5.5.7 => 5.5.8
2019-02-14 12:04 administrator Target Version 5.5.8 => 6.1.x