[Vtigercrm-developers] [PATCH] some new $adb (PearDatabase) methods
Enrico Weigelt
weigelt at metux.de
Thu May 10 18:13:10 PDT 2007
Hi folks,
this patch adds two new functions to the PearDatabase ($adb)
class:
* sql_concat(array):
generates an sql expression for field concatenations, based
on selected RDBMS.
* run_query_field(string):
executes an given SQL query and returns only the first field
of the first record.
cu
--
---------------------------------------------------------------------
Enrico Weigelt == metux IT service
phone: +49 36207 519931 www: http://www.metux.de/
fax: +49 36207 519932 email: contact at metux.de
cellphone: +49 174 7066481
---------------------------------------------------------------------
-- DSL ab 0 Euro. -- statische IP -- UUCP -- Hosting -- Webshops --
---------------------------------------------------------------------
-------------- next part --------------
diff -ruN htdocs.orig/include/database/PearDatabase.php htdocs/include/database/PearDatabase.php
--- htdocs.orig/include/database/PearDatabase.php 2007-05-11 02:17:06.000000000 +0200
+++ htdocs/include/database/PearDatabase.php 2007-05-11 02:55:29.000000000 +0200
@@ -434,6 +434,31 @@
return $this->change_key_case($result->FetchRow());
}
+ function sql_concat($list)
+ {
+ switch ($this->dbType)
+ {
+ case 'mysql':
+ return 'concat('.implode(',',$list).')';
+ case 'pgsql':
+ return '('.implode('||',$list).')';
+ default:
+ throw new Exception("unsupported dbtype \"".$this->dbType."\"");
+ }
+ }
+
+ function run_query_field($sql)
+ {
+ $this->checkConnection();
+ $result = $this->database->Execute($sql);
+
+ if (!is_object($result))
+ throw new Exception("query failed: $sql");
+
+ $row = $result->FetchRow();
+ return array_shift($row);
+ }
+
/* ADODB newly added. replacement for mysql_result() */
function query_result(&$result, $row, $col=0)
{
More information about the vtigercrm-developers
mailing list