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