• Main Page
  • Data Structures
  • Files
  • File List

ingresStatement.php

Go to the documentation of this file.
00001 <?php
00002 
00003 include_once 'ingresResultset.php';
00004 
00005 /**
00006  * Ingres 2006 query statement class
00007  *
00008  * @package objSQL
00009  * @version 2.1.0
00010  * @author MT Jordan <mtjo62@gmail.com>
00011  * @link http://objsql.sourceforge.net
00012  * @copyright 2004-2010 openSource Partners
00013  * @license LGPL
00014  * @revision $Id: ingresStatement.php,v 1.6 2008-01-19 23:42:36-05 mt_jordan Exp $
00015  */
00016 
00017 class ingresStatement
00018 {
00019     /**********************************************
00020      * Internal variables
00021      *********************************************/
00022 
00023     /**
00024      * Database connection object
00025      *
00026      * @access private
00027      * @var    mixed
00028      */
00029     private $objConnection;
00030 
00031     /**
00032      * Select query limit value
00033      *
00034      * @access private
00035      * @var    int
00036      */
00037     private $objLimit = false;
00038 
00039     /**
00040      * Select query offset value
00041      *
00042      * @access private
00043      * @var    int
00044      */
00045     private $objOffset = false;
00046 
00047     /**
00048      * Prepared statement binding parameters
00049      *
00050      * @access private
00051      * @var    array
00052      */
00053     private $objParameters = array();
00054 
00055     /**
00056      * Sequence name
00057      *
00058      * @access private
00059      * @var    str
00060      */
00061     private $objSequence = false;
00062 
00063     /**
00064      * Query string
00065      *
00066      * @access private
00067      * @var    str
00068      */
00069     private $objQuery;
00070 
00071     /**********************************************
00072      * Class methods
00073      *********************************************/
00074 
00075     /**
00076      * Constructor
00077      *
00078      * @access public
00079      * @param  str   $query
00080      * @param  mixed $connection
00081      */
00082     function __construct( $query, $connection )
00083     {
00084         $this->objConnection = $connection;
00085         $this->objQuery      = $query;
00086     }
00087 
00088     /**
00089      * Escape query parameters
00090      *
00091      * @access public
00092      * @param  mixed $param
00093      * @param  bool  $no_quotes
00094      */
00095     function bind( $param, $no_quotes=false )
00096     {
00097         //if $param is numeric str, do not add quotes
00098         if ( ( is_string( $param ) && !is_numeric( $param ) ) && !$no_quotes )
00099         {
00100             if ( get_magic_quotes_gpc() )
00101                 $param = stripslashes( $param );
00102 
00103             $param = str_replace( "'", "''", $param );
00104             $param = "'" . $param . "'";
00105         }
00106 
00107         $this->objParameters[] = $param;
00108     }
00109 
00110     /**
00111      * Execute prepared statement and return resultset methods
00112      *
00113      * @access public
00114      * @return mixed
00115      */
00116     function execute()
00117     {
00118         $objResult = ingres_query( $this->objPrepareSQL(), $this->objConnection->connection() )
00119         or trigger_error( ingres_error( $this->objConnection->connection() ), E_USER_WARNING );
00120 
00121         return new ingresResultset( $objResult, $this->objConnection->connection() );
00122     }
00123 
00124     /**
00125      * Set limit int value
00126      *
00127      * @access public
00128      * @param  int $limit
00129      */
00130     public function limit( $limit )
00131     {
00132         //make sure $limit is an unsigned int > 0
00133         $this->objLimit = ( is_numeric( $limit ) && $limit > 0 ) ? ( int )$limit : 1;
00134     }
00135 
00136     /**
00137      * Execute non-prepared query and return resultset methods
00138      *
00139      * @access public
00140      * @return mixed
00141      */
00142     public function objExecuteNonPrepared()
00143     {
00144         $objResult = ingres_query( $this->objQuery, $this->objConnection->connection() )
00145         or trigger_error( ingres_error( $this->objConnection->connection() ), E_USER_WARNING );
00146 
00147         return new ingresResultset( $objResult, $this->objConnection->connection() );
00148     }
00149 
00150     /**
00151      * Prepare query string and bind parameters
00152      *
00153      * @access private
00154      * @return str
00155      */
00156     private function objPrepareSQL()
00157     {
00158         $objSqlParts = explode( '?', $this->objQuery );
00159         $objQuery = $objSqlParts[0];
00160 
00161         for ( $i = 1; $i < count( $objSqlParts ); $i++ )
00162             $objQuery .= $this->objParameters[$i - 1] . $objSqlParts[$i];
00163 
00164         $objQuery = ( $this->objLimit ) ? str_ireplace( ':limit', $this->objLimit, $objQuery ) : $objQuery;
00165         $objQuery = ( $this->objOffset ) ? str_ireplace( ':offset', $this->objOffset, $objQuery ) : $objQuery;
00166         $objQuery = ( $this->objSequence ) ? str_ireplace( ':seq', $this->objSequence, $objQuery ) : $objQuery;
00167 
00168         return $objQuery;
00169     }
00170 
00171     /**
00172      * Set offset int value
00173      *
00174      * @access public
00175      * @param  int $offset
00176      */
00177     public function offset( $offset )
00178     {
00179         //make sure $offset is an unsigned int > 0
00180         $this->objOffset = ( is_numeric( $offset ) && $offset > 0 ) ? ( int )$offset : 1;
00181     }
00182 
00183     /**
00184      * Get property for named sequence
00185      *
00186      * @access public
00187      * @param  str $sequence
00188      */
00189     public function sequence( $sequence )
00190     {
00191         $this->objSequence = $sequence . '.NEXTVAL';
00192     }
00193 }
00194 
00195 ?>

Generated on Sat Jul 10 2010 15:14:38 for objSQL 2.1.0 by  doxygen 1.7.1