Merge branch 'master' of git://github.com/openemr/openemr
[openemr.git] / library / adodb / drivers / adodb-csv.inc.php
bloba444d9e0f93b26eeea153b87db9dd1e1e2e475a0
1 <?php
2 /*
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.
7 Set tabs to 4.
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.
12 */
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'";
25 var $_affectedrows=0;
26 var $_insertid=0;
27 var $_url;
28 var $replaceQuote = "''"; // string to use to replace quotes
29 var $hasTransactions = false;
30 var $_errorNo = false;
32 function ADODB_csv()
36 function _insertid()
38 return $this->_insertid;
41 function _affectedrows()
43 return $this->_affectedrows;
46 function &MetaDatabases()
48 return false;
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;
57 return true;
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;
65 return true;
68 function &MetaColumns($table)
70 return false;
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).
81 "&offset=$offset";
82 $err = false;
83 $rs = csv2rs($url,$err,false);
85 if ($this->debug) print "$url<br><i>$err</i><br>";
87 $at = strpos($err,'::::');
88 if ($at === false) {
89 $this->_errorMsg = $err;
90 $this->_errorNo = (integer)$err;
91 } else {
92 $this->_errorMsg = substr($err,$at+4,1024);
93 $this->_errorNo = -9999;
95 if ($this->_errorNo)
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;
106 return $rs;
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);
116 $sql = '';
117 $i = 0;
118 foreach($inputarr as $v) {
120 $sql .= $sqlarr[$i];
121 if (gettype($v) == 'string')
122 $sql .= $this->qstr($v);
123 else if ($v === null)
124 $sql .= 'NULL';
125 else
126 $sql .= $v;
127 $i += 1;
130 $sql .= $sqlarr[$i];
131 if ($i+1 != sizeof($sqlarr))
132 print "Input Array does not match ?: ".htmlspecialchars($sql);
133 $inputarr = false;
136 $url = $this->_url.'?sql='.urlencode($sql)."&fetch=".
137 (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE);
138 $err = false;
141 $rs = csv2rs($url,$err,false);
142 if ($this->debug) print urldecode($url)."<br><i>$err</i><br>";
143 $at = strpos($err,'::::');
144 if ($at === false) {
145 $this->_errorMsg = $err;
146 $this->_errorNo = (integer)$err;
147 } else {
148 $this->_errorMsg = substr($err,$at+4,1024);
149 $this->_errorNo = -9999;
152 if ($this->_errorNo)
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;
164 return $rs;
167 /* Returns: the last error message from previous database operation */
168 function ErrorMsg()
170 return $this->_errorMsg;
173 /* Returns: the last error number from previous database operation */
174 function ErrorNo()
176 return $this->_errorNo;
179 // returns true or false
180 function _close()
182 return true;
184 } // class
186 class ADORecordset_csv extends ADORecordset {
187 function ADORecordset_csv($id,$mode=false)
189 $this->ADORecordset($id,$mode);
192 function _close()
194 return true;
198 } // define