Documentation TYPO3 par Ameos |
00001 <?php 00002 /* 00003 V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved. 00004 Released under both BSD license and Lesser GPL library license. 00005 Whenever there is any discrepancy between the two licenses, 00006 the BSD license will take precedence. 00007 Set tabs to 4. 00008 00009 Currently unsupported: MetaDatabases, MetaTables and MetaColumns, and also inputarr in Execute. 00010 Native types have been converted to MetaTypes. 00011 Transactions not supported yet. 00012 00013 Limitation of url length. For IIS, see MaxClientRequestBuffer registry value. 00014 00015 http://support.microsoft.com/default.aspx?scid=kb;en-us;260694 00016 */ 00017 00018 // security - hide paths 00019 if (!defined('ADODB_DIR')) die(); 00020 00021 if (! defined("_ADODB_CSV_LAYER")) { 00022 define("_ADODB_CSV_LAYER", 1 ); 00023 00024 include_once(ADODB_DIR.'/adodb-csvlib.inc.php'); 00025 00026 class ADODB_csv extends ADOConnection { 00027 var $databaseType = 'csv'; 00028 var $databaseProvider = 'csv'; 00029 var $hasInsertID = true; 00030 var $hasAffectedRows = true; 00031 var $fmtTimeStamp = "'Y-m-d H:i:s'"; 00032 var $_affectedrows=0; 00033 var $_insertid=0; 00034 var $_url; 00035 var $replaceQuote = "''"; // string to use to replace quotes 00036 var $hasTransactions = false; 00037 var $_errorNo = false; 00038 00039 function ADODB_csv() 00040 { 00041 } 00042 00043 function _insertid() 00044 { 00045 return $this->_insertid; 00046 } 00047 00048 function _affectedrows() 00049 { 00050 return $this->_affectedrows; 00051 } 00052 00053 function &MetaDatabases() 00054 { 00055 return false; 00056 } 00057 00058 00059 // returns true or false 00060 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) 00061 { 00062 if (strtolower(substr($argHostname,0,7)) !== 'http://') return false; 00063 $this->_url = $argHostname; 00064 return true; 00065 } 00066 00067 // returns true or false 00068 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) 00069 { 00070 if (strtolower(substr($argHostname,0,7)) !== 'http://') return false; 00071 $this->_url = $argHostname; 00072 return true; 00073 } 00074 00075 function &MetaColumns($table) 00076 { 00077 return false; 00078 } 00079 00080 00081 // parameters use PostgreSQL convention, not MySQL 00082 function &SelectLimit($sql,$nrows=-1,$offset=-1) 00083 { 00084 global $ADODB_FETCH_MODE; 00085 00086 $url = $this->_url.'?sql='.urlencode($sql)."&nrows=$nrows&fetch=". 00087 (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE). 00088 "&offset=$offset"; 00089 $err = false; 00090 $rs = csv2rs($url,$err,false); 00091 00092 if ($this->debug) print "$url<br><i>$err</i><br>"; 00093 00094 $at = strpos($err,'::::'); 00095 if ($at === false) { 00096 $this->_errorMsg = $err; 00097 $this->_errorNo = (integer)$err; 00098 } else { 00099 $this->_errorMsg = substr($err,$at+4,1024); 00100 $this->_errorNo = -9999; 00101 } 00102 if ($this->_errorNo) 00103 if ($fn = $this->raiseErrorFn) { 00104 $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,''); 00105 } 00106 00107 if (is_object($rs)) { 00108 00109 $rs->databaseType='csv'; 00110 $rs->fetchMode = ($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE; 00111 $rs->connection = &$this; 00112 } 00113 return $rs; 00114 } 00115 00116 // returns queryID or false 00117 function &_Execute($sql,$inputarr=false) 00118 { 00119 global $ADODB_FETCH_MODE; 00120 00121 if (!$this->_bindInputArray && $inputarr) { 00122 $sqlarr = explode('?',$sql); 00123 $sql = ''; 00124 $i = 0; 00125 foreach($inputarr as $v) { 00126 00127 $sql .= $sqlarr[$i]; 00128 if (gettype($v) == 'string') 00129 $sql .= $this->qstr($v); 00130 else if ($v === null) 00131 $sql .= 'NULL'; 00132 else 00133 $sql .= $v; 00134 $i += 1; 00135 00136 } 00137 $sql .= $sqlarr[$i]; 00138 if ($i+1 != sizeof($sqlarr)) 00139 print "Input Array does not match ?: ".htmlspecialchars($sql); 00140 $inputarr = false; 00141 } 00142 00143 $url = $this->_url.'?sql='.urlencode($sql)."&fetch=". 00144 (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE); 00145 $err = false; 00146 00147 00148 $rs = csv2rs($url,$err,false); 00149 if ($this->debug) print urldecode($url)."<br><i>$err</i><br>"; 00150 $at = strpos($err,'::::'); 00151 if ($at === false) { 00152 $this->_errorMsg = $err; 00153 $this->_errorNo = (integer)$err; 00154 } else { 00155 $this->_errorMsg = substr($err,$at+4,1024); 00156 $this->_errorNo = -9999; 00157 } 00158 00159 if ($this->_errorNo) 00160 if ($fn = $this->raiseErrorFn) { 00161 $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr); 00162 } 00163 if (is_object($rs)) { 00164 $rs->fetchMode = ($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE; 00165 00166 $this->_affectedrows = $rs->affectedrows; 00167 $this->_insertid = $rs->insertid; 00168 $rs->databaseType='csv'; 00169 $rs->connection = &$this; 00170 } 00171 return $rs; 00172 } 00173 00174 /* Returns: the last error message from previous database operation */ 00175 function ErrorMsg() 00176 { 00177 return $this->_errorMsg; 00178 } 00179 00180 /* Returns: the last error number from previous database operation */ 00181 function ErrorNo() 00182 { 00183 return $this->_errorNo; 00184 } 00185 00186 // returns true or false 00187 function _close() 00188 { 00189 return true; 00190 } 00191 } // class 00192 00193 class ADORecordset_csv extends ADORecordset { 00194 function ADORecordset_csv($id,$mode=false) 00195 { 00196 $this->ADORecordset($id,$mode); 00197 } 00198 00199 function _close() 00200 { 00201 return true; 00202 } 00203 } 00204 00205 } // define 00206 00207 ?>