Commit 92e3527137275636dd33eb412150dfa94caa90de

Authored by Conrad Vermeulen
1 parent 99b3d0d7

KTS-2358

"php5 migration"
Updated. Removed & from &new. Added statics. Also updated db error logging.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7177 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 25 additions and 18 deletions
lib/database/dbutil.inc
... ... @@ -8,7 +8,7 @@
8 8 * License Version 1.1.2 ("License"); You may not use this file except in
9 9 * compliance with the License. You may obtain a copy of the License at
10 10 * http://www.knowledgetree.com/KPL
11   - *
  11 + *
12 12 * Software distributed under the License is distributed on an "AS IS"
13 13 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
14 14 * See the License for the specific language governing rights and
... ... @@ -19,9 +19,9 @@
19 19 * (ii) the KnowledgeTree copyright notice
20 20 * in the same form as they appear in the distribution. See the License for
21 21 * requirements.
22   - *
  22 + *
23 23 * The Original Code is: KnowledgeTree Open Source
24   - *
  24 + *
25 25 * The Initial Developer of the Original Code is The Jam Warehouse Software
26 26 * (Pty) Ltd, trading as KnowledgeTree.
27 27 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
... ... @@ -33,7 +33,7 @@
33 33 require_once ('PEAR.php');
34 34  
35 35 class DBUtil {
36   - function &getDB($db = null) {
  36 + static function &getDB($db = null) {
37 37 global $default;
38 38 if (is_null($db)) {
39 39 $db =& $default->_db;
... ... @@ -47,7 +47,7 @@ class DBUtil {
47 47 return $db;
48 48 }
49 49  
50   - function &runQuery($query, $db = null) {
  50 + static function &runQuery($query, $db = null) {
51 51 global $default;
52 52 $aParams = null;
53 53  
... ... @@ -55,7 +55,7 @@ class DBUtil {
55 55  
56 56 if (is_array($query)) {
57 57 $sQuery = $query[0];
58   - $aParams = $query[1];
  58 + $aParams = (count($query) > 1)?$query[1]:array();
59 59 } else {
60 60 $sQuery = $query;
61 61 }
... ... @@ -63,13 +63,17 @@ class DBUtil {
63 63 if ($default->queryLog) {
64 64 $default->queryLog->debug('Query: ' . DBUtil::lastQuery($db));
65 65 }
  66 + if (PEAR::isError($res))
  67 + {
  68 + DBUtil::logQueryError(DBUtil::lastQuery($db), $res);
  69 + }
66 70 return $res;
67 71 }
68 72  
69   - function getOneResult($query, $db = null) {
  73 + static function getOneResult($query, $db = null) {
70 74 $result = DBUtil::runQuery($query, $db);
71 75 if (PEAR::isError($result)) {
72   - DBUtil::logQueryError($query, $result);
  76 + // logging by runQuery
73 77 return $result;
74 78 }
75 79 $aRow = $result->fetchRow();
... ... @@ -77,18 +81,19 @@ class DBUtil {
77 81 return $aRow;
78 82 }
79 83  
80   - function getOneResultKey($query, $key, $db = null) {
  84 + static function getOneResultKey($query, $key, $db = null) {
81 85 $aRow = DBUtil::getOneResult($query, $db);
82 86 if (PEAR::isError($aRow)) {
  87 + // logging by runQuery
83 88 return $aRow;
84 89 }
85 90 return $aRow[$key];
86 91 }
87 92  
88   - function getResultArray($query, $db = null) {
  93 + static function getResultArray($query, $db = null) {
89 94 $result = DBUtil::runQuery($query, $db);
90 95 if (PEAR::isError($result)) {
91   - DBUtil::logQueryError($query, $result);
  96 + // logging by runQuery
92 97 return $result;
93 98 }
94 99  
... ... @@ -100,10 +105,10 @@ class DBUtil {
100 105 return $aReturn;
101 106 }
102 107  
103   - function getResultArrayKey($query, $key, $db = null) {
  108 + static function getResultArrayKey($query, $key, $db = null) {
104 109 $result = DBUtil::runQuery($query, $db);
105 110 if (PEAR::isError($result)) {
106   - DBUtil::logQueryError($query, $result);
  111 + // logging by runQuery
107 112 return $result;
108 113 }
109 114  
... ... @@ -117,8 +122,8 @@ class DBUtil {
117 122  
118 123 function logQueryError($query, $result) {
119 124 global $default;
120   - $default->log->error($result->toString());
121   - $default->queryLog->error($result->toString());
  125 + $default->log->error('Problem Query: ' . $query);
  126 + $default->log->error('Problem: ' . $result->getMessage());
122 127 }
123 128  
124 129 function nextId($seqname, $ondemand = false, $db = null) {
... ... @@ -161,6 +166,7 @@ class DBUtil {
161 166 return $aFieldValues['id'];
162 167 }
163 168 if (PEAR::isError($res)) {
  169 + DBUtil::logQueryError(DBUtil::lastQuery($db), $res);
164 170 return $res;
165 171 }
166 172 return PEAR::raiseError(_kt('Unknown return value for autoInsert'));
... ... @@ -176,7 +182,8 @@ class DBUtil {
176 182 return $res;
177 183 }
178 184 if (PEAR::isError($res)) {
179   - return $res;
  185 + DBUtil::logQueryError(DBUtil::lastQuery($db), $res);
  186 + return $res;
180 187 }
181 188 return PEAR::raiseError(_kt('Unknown return value for autoUpdate'));
182 189 }
... ... @@ -206,7 +213,7 @@ class DBUtil {
206 213 return PEAR::raiseError(_kt('Unknown return value for whereUpdate'));
207 214 }
208 215  
209   - function &lastQuery($db = null) {
  216 + static function &lastQuery($db = null) {
210 217 $db =& DBUtil::getDB();
211 218 return $db->last_query;
212 219 }
... ... @@ -219,7 +226,7 @@ class DBUtil {
219 226 $aParams = array($iId);
220 227 return DBUtil::runQuery(array($sQuery, $aParams), $db);
221 228 }
222   -
  229 +
223 230 function deReference($sTable, $iId, $db = null) {
224 231 global $default;
225 232 // $default->log->debug('AutoDelete called for table ' . $sTable . ' with id ' . $iId);
... ...