3 V4.20 22 Feb 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()
52 // returns true or false
53 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
55 if (strtolower(substr($argHostname,0,7)) !== 'http://') return false;
56 $this->_url
= $argHostname;
60 // returns true or false
61 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
63 if (strtolower(substr($argHostname,0,7)) !== 'http://') return false;
64 $this->_url
= $argHostname;
68 function &MetaColumns($table)
74 // parameters use PostgreSQL convention, not MySQL
75 function &SelectLimit($sql,$nrows=-1,$offset=-1)
77 global $ADODB_FETCH_MODE;
79 $url = $this->_url
.'?sql='.urlencode($sql)."&nrows=$nrows&fetch=".
80 (($this->fetchMode
!== false)?
$this->fetchMode
: $ADODB_FETCH_MODE).
83 $rs = csv2rs($url,$err,false);
85 if ($this->debug
) print "$url<br><i>$err</i><br>";
87 $at = strpos($err,'::::');
89 $this->_errorMsg
= $err;
90 $this->_errorNo
= (integer)$err;
92 $this->_errorMsg
= substr($err,$at+
4,1024);
93 $this->_errorNo
= -9999;
96 if ($fn = $this->raiseErrorFn
) {
97 $fn($this->databaseType
,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,'');
100 if (is_object($rs)) {
102 $rs->databaseType
='csv';
103 $rs->fetchMode
= ($this->fetchMode
!== false) ?
$this->fetchMode
: $ADODB_FETCH_MODE;
104 $rs->connection
= &$this;
109 // returns queryID or false
110 function &_Execute($sql,$inputarr=false)
112 global $ADODB_FETCH_MODE;
114 if (!$this->_bindInputArray
&& $inputarr) {
115 $sqlarr = explode('?',$sql);
118 foreach($inputarr as $v) {
121 if (gettype($v) == 'string')
122 $sql .= $this->qstr($v);
123 else if ($v === null)
131 if ($i+
1 != sizeof($sqlarr))
132 print "Input Array does not match ?: ".htmlspecialchars($sql);
136 $url = $this->_url
.'?sql='.urlencode($sql)."&fetch=".
137 (($this->fetchMode
!== false)?
$this->fetchMode
: $ADODB_FETCH_MODE);
141 $rs = csv2rs($url,$err,false);
142 if ($this->debug
) print urldecode($url)."<br><i>$err</i><br>";
143 $at = strpos($err,'::::');
145 $this->_errorMsg
= $err;
146 $this->_errorNo
= (integer)$err;
148 $this->_errorMsg
= substr($err,$at+
4,1024);
149 $this->_errorNo
= -9999;
153 if ($fn = $this->raiseErrorFn
) {
154 $fn($this->databaseType
,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr);
156 if (is_object($rs)) {
157 $rs->fetchMode
= ($this->fetchMode
!== false) ?
$this->fetchMode
: $ADODB_FETCH_MODE;
159 $this->_affectedrows
= $rs->affectedrows
;
160 $this->_insertid
= $rs->insertid
;
161 $rs->databaseType
='csv';
162 $rs->connection
= &$this;
167 /* Returns: the last error message from previous database operation */
170 return $this->_errorMsg
;
173 /* Returns: the last error number from previous database operation */
176 return $this->_errorNo
;
179 // returns true or false
186 class ADORecordset_csv
extends ADORecordset
{
187 function ADORecordset_csv($id,$mode=false)
189 $this->ADORecordset($id,$mode);