phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] phpgwapi/inc class.db.inc.php


From: Dave Hall
Subject: [Phpgroupware-cvs] phpgwapi/inc class.db.inc.php
Date: Mon, 17 Apr 2006 11:50:54 +0000

CVSROOT:        /cvsroot/phpgwapi
Module name:    phpgwapi
Branch:         
Changes by:     Dave Hall <address@hidden>      06/04/17 11:50:54

Modified files:
        inc            : class.db.inc.php 

Log message:
        cleanup and some changes discussed with sigurd

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/phpgwapi/phpgwapi/inc/class.db.inc.php.diff?tr1=1.23&tr2=1.24&r1=text&r2=text

Patches:
Index: phpgwapi/inc/class.db.inc.php
diff -u phpgwapi/inc/class.db.inc.php:1.23 phpgwapi/inc/class.db.inc.php:1.24
--- phpgwapi/inc/class.db.inc.php:1.23  Sat Apr 15 12:12:59 2006
+++ phpgwapi/inc/class.db.inc.php       Mon Apr 17 11:50:54 2006
@@ -9,7 +9,7 @@
        * @link http://www.sanisoft.com/phplib/manual/DB_sql.php
        * @package phpgwapi
        * @subpackage database
-       * @version $Id: class.db.inc.php,v 1.23 2006/04/15 12:12:59 sigurdne 
Exp $
+       * @version $Id: class.db.inc.php,v 1.24 2006/04/17 11:50:54 skwashd Exp 
$
        */
 
        if (empty($GLOBALS['phpgw_info']['server']['db_type']))
@@ -40,6 +40,16 @@
                * @var string $Host database hostname
                */
                var $Host;
+               
+               /**
+                * @var string $join the sql syntax to use for JOIN
+                */
+                var $join = ' INNER JOIN ';
+                
+               /**
+                * @var string $like the sql syntax to use for a case 
insensitive LIKE
+                */
+                var $like = 'LIKE';
 
                /**
                * @var string $Type RDBMS server ??
@@ -77,40 +87,28 @@
                var $auto_stripslashes = false;
                
                /**
-               * @var string JOIN-statement dependent on dbms
-               */
-               var $join;
-
-               /**
-               * @var string case insensitive LIKE-statement dependent on dbms
-               */
-               var $like;
-
-               /**
                * Constructor
                * @param string $query query to be executed (optional)
                */
                function db($query = '')
                {
+                       // We do it this way to allow it to be easily extended 
in the future
+                       switch ( $GLOBALS['phpgw_info']['server']['db_type'] )
+                       {
+                               case 'pgsql':
+                                       $this->join = " JOIN ";
+                                       $this->like = "ILIKE";
+                                       break;
+                               default:
+                                       //do nothing for now
+                       }
+
                        $this->adodb = 
NewADOConnection($GLOBALS['phpgw_info']['server']['db_type']);
                        $this->adodb->SetFetchMode(3);
                        if($query != '')
                        {
-                               echo "wtf: db";
                                $this->query($query);
                        }
-                       //$this->debug = $debug; // commented to stop undefined 
var error
-                       
-                       if 
($GLOBALS['phpgw_info']['server']['db_type']=='pgsql')
-                       {
-                               $this->join = "JOIN";
-                               $this->like = "ILIKE";
-                       }
-                       else
-                       {
-                               $this->join = "INNER JOIN";
-                               $this->like = "LIKE";
-                       }
                }
 
                /**
@@ -119,7 +117,6 @@
                */
                function link_id()
                {
-                       //echo "link_id: depricated";
                        if(!$this->adodb->isConnected())
                        {
                                $this->connect();
@@ -133,8 +130,6 @@
                */
                function query_id()
                {
-                       echo "query_id: depricated";
-                       die('you really need this method?');
                        return $this->Query_ID;
                }
 
@@ -148,11 +143,6 @@
                */
                function connect($Database = '', $Host = '', $User = '', 
$Password = '')
                {
-                       if($this->debug)
-                       {
-                               // $GLOBALS['phpgw']->log
-                               echo 'depricated: connect';
-                       }
                        $this->Database = $Database != '' ? $Database : 
$this->Database;
                        $this->Host = $Host != '' ? $Host : $this->Host;
                        $this->User = $User != '' ? $User : $this->User;
@@ -168,7 +158,7 @@
                        if($this->debug)
                        {
                                // $GLOBALS['phpgw']->log
-                               echo 'disconnect: depricated';
+                               //echo 'disconnect: depricated';
                        }
                        $this->adodb->close();
                }
@@ -184,7 +174,7 @@
                        if($this->debug)
                        {
                                // $GLOBALS['phpgw']->log
-                               echo 'to_timestanp: db_addsl';
+                               //echo 'to_timestanp: db_addsl';
                        }
                        if(!$this->adodb)  //workaround
                        {
@@ -204,7 +194,7 @@
                        if($this->debug)
                        {
                                // $GLOBALS['phpgw']->log
-                               echo 'to_timestanp: depricated';
+                               //echo 'to_timestanp: depricated';
                        }
                        return substr($this->adodb->DBTimeStamp($epoch), 1, -1);
                }
@@ -220,7 +210,7 @@
                        if($this->debug)
                        {
                                //$GLOBALS['phpgw']->log
-                               echo 'from_timestanp: depricated';
+                               //echo 'from_timestanp: depricated';
                        }
                        return $this->adodb->UnixTimeStamp($timestamp);
                }
@@ -236,7 +226,7 @@
                        if($this->debug)
                        {
                                //$GLOBALS['phpgw']->log
-                               echo 'depricated: limit';
+                               //echo 'depricated: limit';
                        }
                        die('where is the sql string?');
                }
@@ -246,7 +236,7 @@
                */
                function free()
                {
-                       if($this->debug) /* $GLOBALS['phpgw']->log */ echo 
"depricated: limit";
+                       //if($this->debug) /* $GLOBALS['phpgw']->log */ //echo 
"depricated: limit";
                        unset($this->resultSet);
                        return true;
                }
@@ -261,7 +251,7 @@
                */
                function query($Query_String, $line = '', $file = '')
                {
-                       if($this->debug) /* $GLOBALS['phpgw']->log */ echo 
"query: depricated: $Query_String <br>";
+                       //if($this->debug) /* $GLOBALS['phpgw']->log */ //echo 
"query: depricated: $Query_String <br>";
                        if(!$this->adodb->isConnected())
                        {
                                $this->connect();
@@ -306,7 +296,7 @@
                        $this->resultSet = 
$this->adodb->SelectLimit($Query_String, $num_rows, $offset);
                        if(!$this->resultSet && $this->Halt_On_Error == 'yes')
                        {
-                               echo "$Query_String<br>";
+                               //echo "$Query_String<br>";
                                print $this->adodb->ErrorMsg();
                                _debug_array(debug_backtrace());
                                die();
@@ -325,7 +315,7 @@
                */
                function next_record()
                {
-                       if($this->debug) /* $GLOBALS['phpgw']->log */ echo 
"depricated: next_record<br>";
+                       //if($this->debug) /* $GLOBALS['phpgw']->log */ //echo 
"depricated: next_record<br>";
                        if($this->resultSet && $this->resultSet->RecordCount())
                        {
                                if($this->delayPointer)
@@ -336,7 +326,9 @@
        
                                if(!$this->resultSet->EOF)
                                {
-                                       return $this->resultSet->MoveNext();
+                                       $row = $this->resultSet->MoveNext();
+                                       $this->Record =& 
$this->resultSet->fields;
+                                       return !!$row;
                                }
                        }
                        return false;
@@ -350,7 +342,7 @@
                */
                function seek($pos = 0)
                {
-                       if($this->debug) /* $GLOBALS['phpgw']->log */ echo 
"depricated: seek";
+                       //if($this->debug) /* $GLOBALS['phpgw']->log */ //echo 
"depricated: seek";
                        if($this->resultSet)
                        {
                                return $this->resultSet->Move($pos);
@@ -365,8 +357,7 @@
                */
                function transaction_begin()
                {
-                       if($this->debug) /* $GLOBALS['phpgw']->log */ echo 
'depricated';
-                       return $this->adodb->BeginTrans();
+                       return $this->adodb->StartTrans();
                }
                
                /**
@@ -376,8 +367,7 @@
                */ 
                function transaction_commit()
                {
-                       if($this->debug) /* $GLOBALS['phpgw']->log */ echo 
"depricated: transaction_commit";
-                       return $this->adodb->CommitTrans();
+                       return $this->adodb->CompleteTrans();
                }
                
                /**
@@ -387,8 +377,8 @@
                */
                function transaction_abort()
                {
-                       echo "depricated: transaction_abort";
-                       return True;
+                       $this->adodb->FailTrans();
+                       return $this->adodb->HasFailedTrans();
                }
 
                /**
@@ -400,7 +390,6 @@
                */
                function get_last_insert_id($table, $field)
                {
-                       //echo "depricated: get_last_insert_id";
                        return $this->adodb->Insert_ID($table, $field);
                }
 
@@ -428,6 +417,76 @@
                        //echo "depricated: unlock";
                        //$this->adodb->CommitTrans();
                }
+               
+               /**
+                * Prepare the VALUES component of an INSERT sql statement
+                * 
+                * @param array $value_set array of values to insert into the 
database
+                * @return string the prepared sql, empty string for invalid 
input
+                */
+               function validate_insert($values)
+               {
+                       if ( !is_array($values) || !count($values) )
+                       {
+                               return '';
+                       }
+                       
+                       $insert_value = array();
+                       foreach ( $values as $value )
+                       {
+                               if($value || $value === 0)
+                               {
+                                       if ( is_numeric($value) )
+                                       {
+                                               $insert_value[] = "$value";
+                                       }
+                                       else
+                                       {
+                                               $insert_value[] = "'$value'";
+                                       }
+                               }
+                               else
+                               {
+                                       $insert_value[] = 'NULL';
+                               }
+                       }
+                       return implode(",", $insert_value);
+               }
+
+               /**
+                * Prepare the SET component of an UPDATE sql statement
+                * 
+                * @param array $value_set associative array of values to 
update the database with
+                * @return string the prepared sql, empty string for invalid 
input
+                */
+               function validate_update($value_set)
+               {
+                       if ( !is_array($value_set) || !count($value_set) )
+                       {
+                               return '';
+                       }
+                       
+                       $value_entry = array();
+                       foreach ( $value_set as $field => $value )
+                       {
+                               if($value || $value === 0)
+                               {
+                                       if ( is_numeric($value) )
+                                       {
+                                               $value_entry[]= 
"{$field}={$value}";
+                                       }
+                                       else
+                                       {
+                                               $value_entry[]= 
"{$field}='{$value}'";
+                                       }
+                               }
+                               else
+                               {
+                                       $value_entry[]= "{$field}=NULL";
+                               }
+                       }
+                       return implode(',', $value_entry);
+               }
 
                /**
                * Get the number of rows affected by last update
@@ -436,7 +495,6 @@
                */
                function affected_rows()
                {
-                       //echo "depricated: affected_rows";
                        return $this->adodb->Affected_Rows();
                }
                
@@ -447,7 +505,6 @@
                */
                function num_rows()
                {
-                       //echo "depricated: num_rows";
                        if($this->resultSet)
                        {
                                return $this->resultSet->RecordCount();
@@ -460,10 +517,13 @@
                *
                * @return integer number of fields
                */
-               
                function num_fields()
                {
-                       echo "depricated: num_fields";
+                       if($this->resultSet)
+                       {
+                               return $this->resultSet->fieldCount();
+                       }
+                       return 0;
                }
 
                /**
@@ -473,7 +533,7 @@
                */
                function nf()
                {
-                       echo "depricated: nf";
+                       //echo "depricated: nf";
                        return $this->num_rows();
                }
 
@@ -482,7 +542,7 @@
                */
                function np()
                {
-                       echo "depricated: np";
+                       //echo "depricated: np";
                        print $this->num_rows();
                }
 
@@ -517,7 +577,7 @@
                */
                function p($Name, $strip_slashes = True)
                {
-                       echo "depi: p";
+                       //echo "depi: p";
                        print $this->f($Name, $strip_slashes);
                }
 
@@ -529,7 +589,7 @@
                */
                function nextid($seq_name)
                {
-                       echo "depi: nextid";
+                       //echo "depi: nextid";
                }
 
                /**
@@ -543,7 +603,7 @@
                {
                        if($this->debug)
                        {
-                               echo "depi: metadata";
+                               //echo "depi: metadata";
                        }
                        
                        if(!$this->adodb->IsConnected())
@@ -592,10 +652,7 @@
                */
                function halt($msg, $line = '', $file = '')
                {
-                       if($this->debug)
-                       {
-                               echo "depricated: halt";
-                       }
+                       $this->adodb->RollbackTrans();
                }
                
                /**
@@ -607,7 +664,7 @@
                {
                        if($this->debug)
                        {
-                               echo "depricated: table_names";
+                               //echo "depricated: table_names";
                        }
                        
                        if(!$this->adodb->IsConnected())
@@ -628,7 +685,7 @@
                */
                function index_names()
                {
-                       echo "depi: index_names";
+                       //echo "depi: index_names";
                        return array();
                }
                
@@ -683,7 +740,7 @@
                */
                function prepare_sql_statement($query)
                {
-                       echo "depi";
+                       //echo "depi";
                        if (($query == '') || (!$this->connect()))
                        {
                                return false;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]