1<?php 2/* 3V4.65 22 July 2005 (c) 2000-2005 John Lim (jlim@natsoft.com.my). All rights reserved. 4 Released under both BSD license and Lesser GPL library license. 5 Whenever there is any discrepancy between the two licenses, 6 the BSD license will take precedence. 7 Set tabs to 4. 8 9 Currently unsupported: MetaDatabases, MetaTables and MetaColumns, and also inputarr in Execute. 10 Native types have been converted to MetaTypes. 11 Transactions not supported yet. 12*/ 13 14// security - hide paths 15if (!defined('ADODB_DIR')) die(); 16 17if (! defined("_ADODB_CSV_LAYER")) { 18 define("_ADODB_CSV_LAYER", 1 ); 19 20include_once(ADODB_DIR.'/adodb-csvlib.inc.php'); 21 22class ADODB_csv extends ADOConnection { 23 var $databaseType = 'csv'; 24 var $databaseProvider = 'csv'; 25 var $hasInsertID = true; 26 var $hasAffectedRows = true; 27 var $fmtTimeStamp = "'Y-m-d H:i:s'"; 28 var $_affectedrows=0; 29 var $_insertid=0; 30 var $_url; 31 var $replaceQuote = "''"; // string to use to replace quotes 32 var $hasTransactions = false; 33 var $_errorNo = false; 34 35 function ADODB_csv() 36 { 37 } 38 39 function _insertid() 40 { 41 return $this->_insertid; 42 } 43 44 function _affectedrows() 45 { 46 return $this->_affectedrows; 47 } 48 49 function &MetaDatabases() 50 { 51 return false; 52 } 53 54 55 // returns true or false 56 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) 57 { 58 if (strtolower(substr($argHostname,0,7)) !== 'http://') return false; 59 $this->_url = $argHostname; 60 return true; 61 } 62 63 // returns true or false 64 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) 65 { 66 if (strtolower(substr($argHostname,0,7)) !== 'http://') return false; 67 $this->_url = $argHostname; 68 return true; 69 } 70 71 function &MetaColumns($table) 72 { 73 return false; 74 } 75 76 77 // parameters use PostgreSQL convention, not MySQL 78 function &SelectLimit($sql,$nrows=-1,$offset=-1) 79 { 80 global $ADODB_FETCH_MODE; 81 82 $url = $this->_url.'?sql='.urlencode($sql)."&nrows=$nrows&fetch=". 83 (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE). 84 "&offset=$offset"; 85 $err = false; 86 $rs = csv2rs($url,$err,false); 87 88 if ($this->debug) print "$url<br><i>$err</i><br>"; 89 90 $at = strpos($err,'::::'); 91 if ($at === false) { 92 $this->_errorMsg = $err; 93 $this->_errorNo = (integer)$err; 94 } else { 95 $this->_errorMsg = substr($err,$at+4,1024); 96 $this->_errorNo = -9999; 97 } 98 if ($this->_errorNo) 99 if ($fn = $this->raiseErrorFn) { 100 $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,''); 101 } 102 103 if (is_object($rs)) { 104 105 $rs->databaseType='csv'; 106 $rs->fetchMode = ($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE; 107 $rs->connection = &$this; 108 } 109 return $rs; 110 } 111 112 // returns queryID or false 113 function &_Execute($sql,$inputarr=false) 114 { 115 global $ADODB_FETCH_MODE; 116 117 if (!$this->_bindInputArray && $inputarr) { 118 $sqlarr = explode('?',$sql); 119 $sql = ''; 120 $i = 0; 121 foreach($inputarr as $v) { 122 123 $sql .= $sqlarr[$i]; 124 if (gettype($v) == 'string') 125 $sql .= $this->qstr($v); 126 else if ($v === null) 127 $sql .= 'NULL'; 128 else 129 $sql .= $v; 130 $i += 1; 131 132 } 133 $sql .= $sqlarr[$i]; 134 if ($i+1 != sizeof($sqlarr)) 135 print "Input Array does not match ?: ".htmlspecialchars($sql); 136 $inputarr = false; 137 } 138 139 $url = $this->_url.'?sql='.urlencode($sql)."&fetch=". 140 (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE); 141 $err = false; 142 143 144 $rs = csv2rs($url,$err,false); 145 if ($this->debug) print urldecode($url)."<br><i>$err</i><br>"; 146 $at = strpos($err,'::::'); 147 if ($at === false) { 148 $this->_errorMsg = $err; 149 $this->_errorNo = (integer)$err; 150 } else { 151 $this->_errorMsg = substr($err,$at+4,1024); 152 $this->_errorNo = -9999; 153 } 154 155 if ($this->_errorNo) 156 if ($fn = $this->raiseErrorFn) { 157 $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr); 158 } 159 if (is_object($rs)) { 160 $rs->fetchMode = ($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE; 161 162 $this->_affectedrows = $rs->affectedrows; 163 $this->_insertid = $rs->insertid; 164 $rs->databaseType='csv'; 165 $rs->connection = &$this; 166 } 167 return $rs; 168 } 169 170 /* Returns: the last error message from previous database operation */ 171 function ErrorMsg() 172 { 173 return $this->_errorMsg; 174 } 175 176 /* Returns: the last error number from previous database operation */ 177 function ErrorNo() 178 { 179 return $this->_errorNo; 180 } 181 182 // returns true or false 183 function _close() 184 { 185 return true; 186 } 187} // class 188 189class ADORecordset_csv extends ADORecordset { 190 function ADORecordset_csv($id,$mode=false) 191 { 192 $this->ADORecordset($id,$mode); 193 } 194 195 function _close() 196 { 197 return true; 198 } 199} 200 201} // define 202 203?>