viewgit/inc/functions.php:22 Function utf8_encode() is deprecated [8192]

make insertID work with postgres, a=chris

Chris Pollett [2014-04-28 06:Apr:th]
make insertID work with postgres, a=chris
Filename
models/datasources/datasource_manager.php
models/datasources/pdo_manager.php
models/group_model.php
diff --git a/models/datasources/datasource_manager.php b/models/datasources/datasource_manager.php
index 9ab111252..aeaeb1cd1 100755
--- a/models/datasources/datasource_manager.php
+++ b/models/datasources/datasource_manager.php
@@ -110,9 +110,10 @@ abstract class DatasourceManager
      * Returns the ID generated by the last insert statement
      * if table has an auto increment key column
      *
+     * @param string name of table of last insert
      * @return string  the ID of the insert
      */
-    abstract function insertID();
+    abstract function insertID($table_name = "");

     /**
      * Returns the next row from the provided result set
diff --git a/models/datasources/pdo_manager.php b/models/datasources/pdo_manager.php
index a948e82f5..e4c0ec081 100644
--- a/models/datasources/pdo_manager.php
+++ b/models/datasources/pdo_manager.php
@@ -66,6 +66,12 @@ class PdoManager extends DatasourceManager
      */
     var $num_affected = 0;

+    /**
+     *  if DBMS is one like postgres which lower cases table names that aren't
+     *  in quotes that this field has the name of the database;
+     *  otherwise, false.
+     * @var mixed
+     */
     var $to_upper_dbms;

     /** {@inheritdoc} */
@@ -76,7 +82,7 @@ class PdoManager extends DatasourceManager
         $this->pdo = new PDO($db_host, $db_user, $db_password);
         $this->to_upper_dbms = false;
         if(stristr($db_host, 'PGSQL')) {
-            $this->to_upper_dbms = true;
+            $this->to_upper_dbms = 'PGSQL';
         }
         return $this->pdo;
     }
@@ -131,8 +137,12 @@ class PdoManager extends DatasourceManager


     /** {@inheritdoc} */
-    function insertID()
+    function insertID($table = "")
     {
+        if($table && $this->to_upper_dbms == "PGSQL") {
+            $table .= "_ID_SEQ";
+            return $this->pdo->lastInsertId($table);
+        }
         return $this->pdo->lastInsertId();
     }

diff --git a/models/group_model.php b/models/group_model.php
index 50abb36f4..d3255d630 100644
--- a/models/group_model.php
+++ b/models/group_model.php
@@ -544,12 +544,12 @@ class GroupModel extends Model
         $db = $this->db;
         $join_date = time();
         $now = time();
-        $sql = "INSERT INTO GROUP_ITEM(PARENT_ID, GROUP_ID, USER_ID, TITLE,
+        $sql = "INSERT INTO GROUP_ITEM (PARENT_ID, GROUP_ID, USER_ID, TITLE,
             DESCRIPTION, PUBDATE) VALUES (?, ?, ?, ?, ?, ? )";
         $db->execute($sql, array($parent_id, $group_id, $user_id, $title,
             $description, $now));
         if($parent_id == 0) {
-            $id = $db->insertID();
+            $id = $db->insertID("GROUP_ITEM");
             $sql = "UPDATE GROUP_ITEM SET PARENT_ID=? WHERE ID=?";
             $db->execute($sql, array($id, $id));
         }
@@ -631,7 +631,7 @@ class GroupModel extends Model
             P.USER_ID = GI.USER_ID";
         if($for_group >= 0) {
             $group_by = " GROUP BY GI.PARENT_ID";
-            $order_by = "";
+            $order_by = " ORDER BY PUBDATE DESC ";
             $select = "SELECT DISTINCT MIN(GI.ID) AS ID,
                 COUNT(GI.ID) AS NUM_POSTS, GI.PARENT_ID AS PARENT_ID,
                 MIN(GI.GROUP_ID) AS GROUP_ID, MIN(GI.TITLE )AS TITLE,
ViewGit