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
21 var $databaseType = 'csv';
22 var $databaseProvider = 'csv';
23 var $hasInsertID = true;
24 var $hasAffectedRows = true;
25 var $fmtTimeStamp = "'Y-m-d H:i:s'";
26 var $_affectedrows = 0;
29 var $replaceQuote = "''"; // string to use to replace quotes
30 var $hasTransactions = false;
31 var $_errorNo = false;
39 return $this->_insertid;
42 function _affectedrows()
44 return $this->_affectedrows;
47 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)
73 // parameters use PostgreSQL convention, not MySQL
74 function &SelectLimit($sql, $nrows = -1, $offset = -1)
76 global $ADODB_FETCH_MODE;
78 $url = $this->_url . '?sql=' . urlencode($sql) . "&nrows=$nrows&fetch=" .
79 (($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE) .
82 $rs = csv2rs($url, $err, false);
84 if ($this->debug) print "$url<br><i>$err</i><br>";
86 $at = strpos($err, '::::');
88 $this->_errorMsg = $err;
89 $this->_errorNo = (integer)$err;
91 $this->_errorMsg = substr($err, $at + 4, 1024);
92 $this->_errorNo = -9999;
95 if ($fn = $this->raiseErrorFn) {
96 $fn($this->databaseType, 'EXECUTE', $this->ErrorNo(), $this->ErrorMsg(), $sql, '');
101 $rs->databaseType = 'csv';
102 $rs->fetchMode = ($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE;
103 $rs->connection = &$this;
108 // returns queryID or false
109 function &_Execute($sql, $inputarr = false)
111 global $ADODB_FETCH_MODE;
113 if (!$this->_bindInputArray && $inputarr) {
114 $sqlarr = explode('?', $sql);
117 foreach ($inputarr as $v) {
120 if (gettype($v) == 'string')
121 $sql .= $this->qstr($v);
122 else if ($v === null)
130 if ($i + 1 != sizeof($sqlarr))
131 print "Input Array does not match ?: " . htmlspecialchars($sql);
135 $url = $this->_url . '?sql=' . urlencode($sql) . "&fetch=" .
136 (($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE);
139 $rs = csv2rs($url, $err, false);
140 if ($this->debug) print urldecode($url) . "<br><i>$err</i><br>";
141 $at = strpos($err, '::::');
143 $this->_errorMsg = $err;
144 $this->_errorNo = (integer)$err;
146 $this->_errorMsg = substr($err, $at + 4, 1024);
147 $this->_errorNo = -9999;
151 if ($fn = $this->raiseErrorFn) {
152 $fn($this->databaseType, 'EXECUTE', $this->ErrorNo(), $this->ErrorMsg(), $sql, $inputarr);
154 if (is_object($rs)) {
155 $rs->fetchMode = ($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE;
157 $this->_affectedrows = $rs->affectedrows;
158 $this->_insertid = $rs->insertid;
159 $rs->databaseType = 'csv';
160 $rs->connection = &$this;
165 /* Returns: the last error message from previous database operation */
168 return $this->_errorMsg;
171 /* Returns: the last error number from previous database operation */
174 return $this->_errorNo;
177 // returns true or false
184 class ADORecordset_csv extends ADORecordset
186 function ADORecordset_csv($id, $mode = false)
188 $this->ADORecordset($id, $mode);