3 V4.22 15 Apr 2004 (c) 2000-2004 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.
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.
14 if (! defined("_ADODB_CSV_LAYER")) {
15 define("_ADODB_CSV_LAYER", 1 );
17 include_once(ADODB_DIR.'/adodb-csvlib.inc.php');
19 class ADODB_csv extends ADOConnection {
20 var $databaseType = 'csv';
21 var $databaseProvider = 'csv';
22 var $hasInsertID = true;
23 var $hasAffectedRows = true;
24 var $fmtTimeStamp = "'Y-m-d H:i:s'";
28 var $replaceQuote = "''"; // string to use to replace quotes
29 var $hasTransactions = false;
30 var $_errorNo = false;
38 return $this->_insertid;
41 function _affectedrows()
43 return $this->_affectedrows;
46 function &MetaDatabases()
51 // returns true or false
52 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
54 if (strtolower(substr($argHostname,0,7)) !== 'http://') return false;
55 $this->_url = $argHostname;
59 // returns true or false
60 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
62 if (strtolower(substr($argHostname,0,7)) !== 'http://') return false;
63 $this->_url = $argHostname;
67 function &MetaColumns($table)
72 // parameters use PostgreSQL convention, not MySQL
73 function &SelectLimit($sql,$nrows=-1,$offset=-1)
75 global $ADODB_FETCH_MODE;
77 $url = $this->_url.'?sql='.urlencode($sql)."&nrows=$nrows&fetch=".
78 (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE).
81 $rs = csv2rs($url,$err,false);
83 if ($this->debug) print "$url<br><i>$err</i><br>";
85 $at = strpos($err,'::::');
87 $this->_errorMsg = $err;
88 $this->_errorNo = (integer)$err;
90 $this->_errorMsg = substr($err,$at+4,1024);
91 $this->_errorNo = -9999;
94 if ($fn = $this->raiseErrorFn) {
95 $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,'');
100 $rs->databaseType='csv';
101 $rs->fetchMode = ($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE;
102 $rs->connection = &$this;
107 // returns queryID or false
108 function &_Execute($sql,$inputarr=false)
110 global $ADODB_FETCH_MODE;
112 if (!$this->_bindInputArray && $inputarr) {
113 $sqlarr = explode('?',$sql);
116 foreach($inputarr as $v) {
119 if (gettype($v) == 'string')
120 $sql .= $this->qstr($v);
121 else if ($v === null)
129 if ($i+1 != sizeof($sqlarr))
130 print "Input Array does not match ?: ".htmlspecialchars($sql);
134 $url = $this->_url.'?sql='.urlencode($sql)."&fetch=".
135 (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE);
138 $rs = csv2rs($url,$err,false);
139 if ($this->debug) print urldecode($url)."<br><i>$err</i><br>";
140 $at = strpos($err,'::::');
142 $this->_errorMsg = $err;
143 $this->_errorNo = (integer)$err;
145 $this->_errorMsg = substr($err,$at+4,1024);
146 $this->_errorNo = -9999;
150 if ($fn = $this->raiseErrorFn) {
151 $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr);
153 if (is_object($rs)) {
154 $rs->fetchMode = ($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE;
156 $this->_affectedrows = $rs->affectedrows;
157 $this->_insertid = $rs->insertid;
158 $rs->databaseType='csv';
159 $rs->connection = &$this;
164 /* Returns: the last error message from previous database operation */
167 return $this->_errorMsg;
170 /* Returns: the last error number from previous database operation */
173 return $this->_errorNo;
176 // returns true or false
183 class ADORecordset_csv extends ADORecordset {
184 function ADORecordset_csv($id,$mode=false)
186 $this->ADORecordset($id,$mode);