TYPO3 CMS  TYPO3_6-2
adodb-csv.inc.php
Go to the documentation of this file.
1 <?php
2 /*
3 V5.19 23-Apr-2014 (c) 2000-2014 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.
7  Set tabs to 4.
8 
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 
13  Limitation of url length. For IIS, see MaxClientRequestBuffer registry value.
14 
15  http://support.microsoft.com/default.aspx?scid=kb;en-us;260694
16 */
17 
18 // security - hide paths
19 if (!defined('ADODB_DIR')) die();
20 
21 if (! defined("_ADODB_CSV_LAYER")) {
22  define("_ADODB_CSV_LAYER", 1 );
23 
24 include_once(ADODB_DIR.'/adodb-csvlib.inc.php');
25 
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'";
32  var $_affectedrows=0;
33  var $_insertid=0;
34  var $_url;
35  var $replaceQuote = "''"; // string to use to replace quotes
36  var $hasTransactions = false;
37  var $_errorNo = false;
38 
39  function ADODB_csv()
40  {
41  }
42 
43  function _insertid()
44  {
45  return $this->_insertid;
46  }
47 
48  function _affectedrows()
49  {
50  return $this->_affectedrows;
51  }
52 
53  function MetaDatabases()
54  {
55  return false;
56  }
57 
58 
59  // returns true or false
60  function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
61  {
62  if (strtolower(substr($argHostname,0,7)) !== 'http://') return false;
63  $this->_url = $argHostname;
64  return true;
65  }
66 
67  // returns true or false
68  function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
69  {
70  if (strtolower(substr($argHostname,0,7)) !== 'http://') return false;
71  $this->_url = $argHostname;
72  return true;
73  }
74 
75  function MetaColumns($table, $normalize=true)
76  {
77  return false;
78  }
79 
80 
81  // parameters use PostgreSQL convention, not MySQL
82  function SelectLimit($sql,$nrows=-1,$offset=-1)
83  {
84  global $ADODB_FETCH_MODE;
85 
86  $url = $this->_url.'?sql='.urlencode($sql)."&nrows=$nrows&fetch=".
87  (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE).
88  "&offset=$offset";
89  $err = false;
90  $rs = csv2rs($url,$err,false);
91 
92  if ($this->debug) print "$url<br><i>$err</i><br>";
93 
94  $at = strpos($err,'::::');
95  if ($at === false) {
96  $this->_errorMsg = $err;
97  $this->_errorNo = (integer)$err;
98  } else {
99  $this->_errorMsg = substr($err,$at+4,1024);
100  $this->_errorNo = -9999;
101  }
102  if ($this->_errorNo)
103  if ($fn = $this->raiseErrorFn) {
104  $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,'');
105  }
106 
107  if (is_object($rs)) {
108 
109  $rs->databaseType='csv';
110  $rs->fetchMode = ($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE;
111  $rs->connection = $this;
112  }
113  return $rs;
114  }
115 
116  // returns queryID or false
117  function _Execute($sql,$inputarr=false)
118  {
119  global $ADODB_FETCH_MODE;
120 
121  if (!$this->_bindInputArray && $inputarr) {
122  $sqlarr = explode('?',$sql);
123  $sql = '';
124  $i = 0;
125  foreach($inputarr as $v) {
126 
127  $sql .= $sqlarr[$i];
128  if (gettype($v) == 'string')
129  $sql .= $this->qstr($v);
130  else if ($v === null)
131  $sql .= 'NULL';
132  else
133  $sql .= $v;
134  $i += 1;
135 
136  }
137  $sql .= $sqlarr[$i];
138  if ($i+1 != sizeof($sqlarr))
139  print "Input Array does not match ?: ".htmlspecialchars($sql);
140  $inputarr = false;
141  }
142 
143  $url = $this->_url.'?sql='.urlencode($sql)."&fetch=".
144  (($this->fetchMode !== false)?$this->fetchMode : $ADODB_FETCH_MODE);
145  $err = false;
146 
147 
148  $rs = csv2rs($url,$err,false);
149  if ($this->debug) print urldecode($url)."<br><i>$err</i><br>";
150  $at = strpos($err,'::::');
151  if ($at === false) {
152  $this->_errorMsg = $err;
153  $this->_errorNo = (integer)$err;
154  } else {
155  $this->_errorMsg = substr($err,$at+4,1024);
156  $this->_errorNo = -9999;
157  }
158 
159  if ($this->_errorNo)
160  if ($fn = $this->raiseErrorFn) {
161  $fn($this->databaseType,'EXECUTE',$this->ErrorNo(),$this->ErrorMsg(),$sql,$inputarr);
162  }
163  if (is_object($rs)) {
164  $rs->fetchMode = ($this->fetchMode !== false) ? $this->fetchMode : $ADODB_FETCH_MODE;
165 
166  $this->_affectedrows = $rs->affectedrows;
167  $this->_insertid = $rs->insertid;
168  $rs->databaseType='csv';
169  $rs->connection = $this;
170  }
171  return $rs;
172  }
173 
174  /* Returns: the last error message from previous database operation */
175  function ErrorMsg()
176  {
177  return $this->_errorMsg;
178  }
179 
180  /* Returns: the last error number from previous database operation */
181  function ErrorNo()
182  {
183  return $this->_errorNo;
184  }
185 
186  // returns true or false
187  function _close()
188  {
189  return true;
190  }
191 } // class
192 
193 class ADORecordset_csv extends ADORecordset {
194  function ADORecordset_csv($id,$mode=false)
195  {
196  $this->ADORecordset($id,$mode);
197  }
198 
199  function _close()
200  {
201  return true;
202  }
203 }
204 
205 } // define
$sql
Definition: server.php:82
if(isset($_REQUEST['nrows'])) else $rs
Definition: server.php:92
die
Definition: index.php:6
csv2rs($url, &$err, $timeout=0, $rsclass='ADORecordSet_array')
debug($variable='', $name=' *variable *', $line=' *line *', $file=' *file *', $recursiveDepth=3, $debugLevel=E_DEBUG)