From 49eb7218b790d48d2c48b8cadb5cd64828216c7c Mon Sep 17 00:00:00 2001
From: Laurent Giovannoni <laurent.giovannoni@maarch.org>
Date: Wed, 22 May 2013 16:13:41 +0000
Subject: [PATCH] fix: pb with transaction

---
 core/trunk/core/class/class_db.php                  | 13 ++++++++-----
 .../core/tests/class/DataAccessService_Database.php |  7 ++++++-
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/core/trunk/core/class/class_db.php b/core/trunk/core/class/class_db.php
index 20c578076b2..4ca127ab956 100644
--- a/core/trunk/core/class/class_db.php
+++ b/core/trunk/core/class/class_db.php
@@ -62,7 +62,7 @@ class dbquery extends functions
     * SQL link identifier
     * Integer
     */
-    private $_sqlLink;          // sql link identifier
+    public $_sqlLink;          // sql link identifier
 
 
     /**
@@ -319,6 +319,9 @@ class dbquery extends functions
     */
     public function query($sqlQuery, $catchError = false, $noFilter = false)
     {
+        if (!$this->_sqlLink) {
+            $this->connect();
+        }
         $canExecute = true;        
         // if filter, we looking for ; or -- in the sql query
         if (!$noFilter) {
@@ -351,7 +354,7 @@ class dbquery extends functions
                 break;
 
             case 'POSTGRESQL' : 
-                $this->query = @pg_query($sqlQuery);
+                $this->query = @pg_query($this->_sqlLink, $sqlQuery);
                 break;
                 
             case 'SQLSERVER' : 
@@ -407,7 +410,7 @@ class dbquery extends functions
         case 'SQLSERVER'    : 
             break;
         case 'POSTGRESQL'   : 
-            @pg_query('BEGIN');
+            @pg_query($this->_sqlLink, 'BEGIN');
             break;
         case 'ORACLE'       : 
             break;
@@ -424,7 +427,7 @@ class dbquery extends functions
         case 'SQLSERVER'    : 
             break;
         case 'POSTGRESQL'   : 
-            @pg_query('ROLLBACK');
+            @pg_query($this->_sqlLink, 'ROLLBACK');
             break;
         case 'ORACLE'       : 
             break;
@@ -441,7 +444,7 @@ class dbquery extends functions
         case 'SQLSERVER'    : 
             break;
         case 'POSTGRESQL'   : 
-            @pg_query('COMMIT');
+            @pg_query($this->_sqlLink, 'COMMIT');
             break;
         case 'ORACLE'       : 
             break;
diff --git a/core/trunk/core/tests/class/DataAccessService_Database.php b/core/trunk/core/tests/class/DataAccessService_Database.php
index 6037345fa9b..6da9d2da790 100644
--- a/core/trunk/core/tests/class/DataAccessService_Database.php
+++ b/core/trunk/core/tests/class/DataAccessService_Database.php
@@ -363,6 +363,7 @@ class DataAccessService_Database
     
     public function updateData($objectElement, $dataObject)
     {
+        global $argv;
         $updateParts = array();
         
         $tableExpression = $this->createFromExpression($objectElement);
@@ -388,7 +389,11 @@ class DataAccessService_Database
         //echo "<pre>UPDATE QUERY = " . $updateQuery . "</pre>";
         
         try {
-            //$this->databaseObject->connect();
+            if (isset($argv) && count($argv) > 0) {
+                //no new database connection, maybe in transaction
+            } else {
+                $this->databaseObject->connect();
+            }
             $result = $this->databaseObject->query(
                 $updateQuery, 
                 $catchErrors=true
-- 
GitLab