3 V5.18 3 Sep 2012 (c) 2000-2012 John Lim (jlim#natsoft.com). 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.
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.
13 Limitation of url length. For IIS, see MaxClientRequestBuffer registry value.
15 http://support.microsoft.com/default.aspx?scid=kb;en-us;260694
18 // security - hide paths
19 if (!defined('ADODB_DIR')) die();
21 if (! defined("_ADODB_CSV_LAYER")) {
22 define("_ADODB_CSV_LAYER", 1 );
24 include_once(ADODB_DIR.'/adodb-csvlib.inc.php');
26 class ADODB_csv extends ADOConnection {
27 var $databaseType = 'csv';
28 var $databaseProvider = 'csv';
29 var $hasInsertID = true;
30 var $hasAffectedRows = true;
31 var $fmtTimeStamp = "'Y-m-d H:i:s'";
35 var $replaceQuote = "''"; // string to use to replace quotes
36 var $hasTransactions = false;
37 var $_errorNo = false;
45 return $this->_insertid;
48 function _affectedrows()
50 return $this->_affectedrows;
53 function MetaDatabases()
59 // returns true or false
60 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
62 if (strtolower(substr($argHostname,0,7)) !== 'http://') return false;
63 $this->_url = $argHostname;
67 // returns true or false
68 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
70 if (strtolower(substr($argHostname,0,7)) !== 'http://') return false;
71 $this->_url = $argHostname;
75 function MetaColumns($table, $normalize=true)
81 // parameters use PostgreSQL convention, not MySQL
82 function SelectLimit($sql,$nrows=-1,$offset=-1)
84 global $ADODB_FETCH_MODE;
86 $url = $this->_url.'?sql='.urlencode($sql)."&nrows=$nrows&fetch=".
87 (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE).
90 $rs = csv2rs($url,$err,false);
92 if ($this->debug) print "$url<br><i>$err</i><br>";
94 $at = strpos($err,'::::');
96 $this->_errorMsg = $err;
97 $this->_errorNo = (integer)$err;
99 $this->_errorMsg = substr($err,$at+4,1024);
100 $this->_errorNo = -9999;
103 if ($fn = $this->raiseErrorFn) {
104 $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,'');
107 if (is_object($rs)) {
109 $rs->databaseType='csv';
110 $rs->fetchMode = ($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE;
111 $rs->connection = $this;
116 // returns queryID or false
117 function _Execute($sql,$inputarr=false)
119 global $ADODB_FETCH_MODE;
121 if (!$this->_bindInputArray && $inputarr) {
122 $sqlarr = explode('?',$sql);
125 foreach($inputarr as $v) {
128 if (gettype($v) == 'string')
129 $sql .= $this->qstr($v);
130 else if ($v === null)
138 if ($i+1 != sizeof($sqlarr))
139 print "Input Array does not match ?: ".htmlspecialchars($sql);
143 $url = $this->_url.'?sql='.urlencode($sql)."&fetch=".
144 (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE);
148 $rs = csv2rs($url,$err,false);
149 if ($this->debug) print urldecode($url)."<br><i>$err</i><br>";
150 $at = strpos($err,'::::');
152 $this->_errorMsg = $err;
153 $this->_errorNo = (integer)$err;
155 $this->_errorMsg = substr($err,$at+4,1024);
156 $this->_errorNo = -9999;
160 if ($fn = $this->raiseErrorFn) {
161 $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr);
163 if (is_object($rs)) {
164 $rs->fetchMode = ($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE;
166 $this->_affectedrows = $rs->affectedrows;
167 $this->_insertid = $rs->insertid;
168 $rs->databaseType='csv';
169 $rs->connection = $this;
174 /* Returns: the last error message from previous database operation */
177 return $this->_errorMsg;
180 /* Returns: the last error number from previous database operation */
183 return $this->_errorNo;
186 // returns true or false
193 class ADORecordset_csv extends ADORecordset {
194 function ADORecordset_csv($id,$mode=false)
196 $this->ADORecordset($id,$mode);