CodeIgniter Forums
postgresql INSERT ... RETURNING and db->query() - 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: postgresql INSERT ... RETURNING and db->query() (/showthread.php?tid=10919)



postgresql INSERT ... RETURNING and db->query() - El Forum - 08-18-2008

[eluser]Unknown[/eluser]
postgresql 8.2+ allows INSERT ... RETURNING ... queries, but db->query() does not return the results (only TRUE). query() should return the results just as SELECT does.

Temporarily I changed this line in DB_driver.php:
Code:
if ( ! preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql))
to this
Code:
if ( ! preg_match('/^\s*"?(SET|UPDATE|DELETE|REPLACE|CREATE|DROP|LOAD DATA|COPY|ALTER|GRANT|REVOKE|LOCK|UNLOCK)\s+/i', $sql))
but I don't think this is right answer.

Dwayne


postgresql INSERT ... RETURNING and db->query() - El Forum - 06-28-2013

[eluser]Unknown[/eluser]
My general solution was to update the DB_driver.php from

Code:
public function is_write_type($sql)
{
  return (bool) (preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX)\s+/i', $sql);
}

to:

Code:
public function is_write_type($sql)
{
  return (bool) (preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX)\s+/i', $sql) && !preg_match('/ RETURNING /i', $sql));
}