StatementCommon.php

Go to the documentation of this file.
00001 <?php 00002 /* 00003 * $Id: StatementCommon.php,v 1.3 2004/04/27 18:09:16 micha Exp $ 00004 * 00005 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00006 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00007 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00008 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00009 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00010 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00011 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00012 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00013 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00014 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00015 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00016 * 00017 * This software consists of voluntary contributions made by many individuals 00018 * and is licensed under the LGPL. For more information please see 00019 * <http://creole.phpdb.org>. 00020 */ 00021 00022 require_once 'creole/Statement.php'; 00023 00031 class StatementCommon extends Statement 00032 { 00037 var $conn; 00038 00043 var $resultSet; 00044 00049 var $updateCount; 00050 00055 var $warnings = array(); 00056 00061 var $resultClass; 00062 00067 var $stmt; 00068 00073 var $limit = 0; 00074 00080 var $offset = 0; 00081 00087 function StatementCommon(/*Connection*/ &$conn) 00088 { 00089 if (! is_a($conn, 'Connection')) { 00090 trigger_error ( 00091 "StatementCommon::StatementCommon(): parameter 1 not of type 'Connection' !", 00092 E_USER_ERROR 00093 ); 00094 } 00095 00096 $this->conn =& $conn; 00097 } 00098 00106 function setLimit($v) 00107 { 00108 $this->limit = (int) $v; 00109 } 00110 00115 function getLimit() 00116 { 00117 return $this->limit; 00118 } 00119 00128 function setOffset($v) 00129 { 00130 $this->offset = (int) $v; 00131 } 00132 00138 function getOffset() 00139 { 00140 return $this->offset; 00141 } 00142 00150 function close() 00151 { 00152 // do nothing here (subclasses will implement) 00153 } 00154 00166 function & execute($sql, $fetchmode = null) 00167 { 00168 if (! $this->isSelect($sql)) { 00169 return $this->executeUpdate($sql); 00170 } else { 00171 return $this->executeQuery($sql, $fetchmode); 00172 } 00173 } 00174 00182 function & getResultSet() 00183 { 00184 return $this->resultSet; 00185 } 00186 00192 function getUpdateCount() 00193 { 00194 return $this->updateCount; 00195 } 00196 00222 function isSelect($sql) 00223 { 00224 // is first word is SELECT, then return true, unless it's SELECT INTO ... 00225 // this doesn't, however, take comments into account ... 00226 $sql = trim(strtolower($sql)); 00227 return (strpos($sql, 'select') === 0 && strpos($sql, 'select into ') !== 0); 00228 } 00229 00238 function & executeQuery($sql, $fetchmode = null) 00239 { 00240 $this->updateCount = null; 00241 if ($this->limit > 0) { 00242 $this->conn->applyLimit($sql, $this->offset, $this->limit); 00243 } elseif ($this->offset > 0) { 00244 return new SQLException(CREOLE_ERROR, 'Cannot specify an offset without limit.'); 00245 } 00246 $this->resultSet =& $this->conn->executeQuery($sql, $fetchmode); 00247 return $this->resultSet; 00248 } 00249 00257 function executeUpdate($sql) 00258 { 00259 if ($this->resultSet) $this->resultSet->close(); 00260 $this->resultSet = null; 00261 $this->updateCount = $this->conn->executeUpdate($sql); 00262 return $this->updateCount; 00263 } 00264 00278 function getMoreResults() 00279 { 00280 if ($this->resultSet) $this->resultSet->close(); 00281 $this->resultSet = null; 00282 return false; 00283 } 00284 00289 function & getConnection() 00290 { 00291 return $this->conn; 00292 } 00293 }

This file is part of the Creole[php4] library.


Copyright © 2004 Hans Lellelid  
Creole[php4] CVS