PgSQLPreparedStatement.php

Go to the documentation of this file.
00001 <?php 00002 /* 00003 * $Id: PgSQLPreparedStatement.php,v 1.1 2004/04/28 17:49:35 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/PreparedStatement.php'; 00023 require_once 'creole/common/PreparedStatementCommon.php'; 00024 00033 class PgSQLPreparedStatement extends PreparedStatementCommon 00034 { 00041 function escape($str) 00042 { 00043 return pg_escape_string($str); 00044 } 00045 00052 function arrayToStr($arr) 00053 { 00054 $parts = array(); 00055 foreach((array)$arr as $el) { 00056 if (is_array($el)) { 00057 $parts[] = $this->arrayToStr($el); 00058 } else { 00059 if (is_string($el)) { 00060 $parts[] = '"' . pg_escape_string($el) . '"'; 00061 } else { 00062 $parts[] = $el; 00063 } 00064 } 00065 } 00066 return '{' . implode(',', $parts) . '}'; 00067 } 00068 00078 function setArray($paramIndex, $value) 00079 { 00080 if( $paramIndex > $this->positionsCount || $paramIndex < 1) { 00081 return new SQLException(CREOLE_ERROR_INVALID, 'Cannot bind to invalid param index: '.$paramIndex); 00082 } 00083 00084 if ($value === null) 00085 $this->setNull($paramIndex); 00086 else 00087 $this->boundInVars[$paramIndex] = "'" . $this->arrayToStr($value) . "'"; 00088 00089 return true; 00090 } 00091 00098 function setBoolean($paramIndex, $value) 00099 { 00100 if( $paramIndex > $this->positionsCount || $paramIndex < 1) { 00101 return new SQLException(CREOLE_ERROR_INVALID, 'Cannot bind to invalid param index: '.$paramIndex); 00102 } 00103 00104 if ($value === null) 00105 $this->setNull($paramIndex); 00106 else 00107 $this->boundInVars[$paramIndex] = ($value ? "'t'" : "'f'"); 00108 00109 return true; 00110 } 00111 00118 function setBlob($paramIndex, $blob) 00119 { 00120 if ($blob === null) { 00121 $this->setNull($paramIndex); 00122 } else { 00123 // they took magic __toString() out of PHP5.0.0; this sucks 00124 if (is_object($blob)) { 00125 $blob =& $blob->__toString(); 00126 } 00127 $data = unpack("H*hex", $blob); 00128 $this->boundInVars[$paramIndex] = "'" . pg_escape_bytea( $blob ) . "'"; 00129 } 00130 00131 return true; 00132 } 00133 }

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


Copyright © 2004 Hans Lellelid  
Creole[php4] CVS