CodeIgniter Forums
bug in ->insert_id() using PostgreSQL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: bug in ->insert_id() using PostgreSQL (/showthread.php?tid=11023)



bug in ->insert_id() using PostgreSQL - El Forum - 08-22-2008

[eluser]Unknown[/eluser]
Logic to figure out version number in ->insert_id() under Postgres has a bug in it.

Currently, it tries to glean the version using this:

Code:
$v = $this->_version();
$v = $v['server'];

Where ->_version() only returns the SQL string:

Code:
"SELECT version() AS ver"

Even if it were to return the actual product of this SQL query using ->version() instead, the next line wouldn't work because this is what it would return:

Code:
"PostgreSQL 8.2.4 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.1.1 (Gentoo 4.1.1-r3)"

-----

Here's a diff of my fix to /system/data/base/drivers/postgre/postgre_driver.php:

Code:
109c109,110
<         return "SELECT version() AS ver";
---
>         // Parse version number out of result    
>         return "SELECT trim(substring(version(), 'PostgreSQL (([0-9]{1,}\.)*)' )) as ver";
257,259c258,259
<         $v = $this->_version();
<         $v = $v['server'];
<        
---
>         $v = $this->version();
>