SQLiteResultSet.php

Go to the documentation of this file.
00001 <?php 00002 /* 00003 * $Id: SQLiteResultSet.php,v 1.8 2004/03/20 04:16:50 hlellelid 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/ResultSet.php'; 00023 require_once 'creole/common/ResultSetCommon.php'; 00024 00036 class SQLiteResultSet extends ResultSetCommon implements ResultSet { 00037 00042 public function getIterator() 00043 { 00044 require_once 'creole/drivers/sqlite/SQLiteResultSetIterator.php'; 00045 return new SQLiteResultSetIterator($this); 00046 } 00047 00051 public function seek($rownum) 00052 { 00053 // MySQL rows start w/ 0, but this works, because we are 00054 // looking to move the position _before_ the next desired position 00055 if (!@sqlite_seek($this->result, $rownum)) { 00056 return false; 00057 } 00058 $this->cursorPos = $rownum; 00059 return true; 00060 } 00061 00065 function next() 00066 { 00067 $this->fields = sqlite_fetch_array($this->result, $this->fetchmode); // (ResultSet::FETCHMODE_NUM = SQLITE_NUM, etc.) 00068 if (!$this->fields) { 00069 $errno = sqlite_last_error($this->conn->getResource()); 00070 if (!$errno) { 00071 // We've advanced beyond end of recordset. 00072 $this->afterLast(); 00073 return false; 00074 } else { 00075 throw new SQLException("Error fetching result", sqlite_error_string($errno)); 00076 } 00077 } 00078 00079 // Advance cursor position 00080 $this->cursorPos++; 00081 return true; 00082 } 00083 00087 public function getRecordCount() 00088 { 00089 $rows = @sqlite_num_rows($this->result); 00090 if ($rows === null) { 00091 throw new SQLException("Error fetching num rows", sqlite_error_string(sqlite_last_error($this->conn->connection))); 00092 } 00093 return (int) $rows; 00094 } 00095 00100 public function getBlob($column) 00101 { 00102 $idx = (is_int($column) ? $column - 1 : $column); 00103 if (!array_key_exists($idx, $this->fields)) { throw new SQLException("Invalid resultset column: " . $column); } 00104 if ($this->fields[$idx] === null) { return null; } 00105 require_once 'creole/util/Blob.php'; 00106 $b = new Blob(); 00107 $b->setContents(sqlite_udf_decode_binary($this->fields[$idx])); 00108 return $b; 00109 } 00110 00115 public function close() 00116 { 00117 $this->fields = array(); 00118 } 00119 }

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


Copyright © 2004 Hans Lellelid  
Creole[php5] CVS