| 1 |
efrain |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Microsoft ADO driver (PHP5 compat version).
|
|
|
4 |
*
|
|
|
5 |
* Requires ADO. Works only on MS Windows.
|
|
|
6 |
*
|
|
|
7 |
* This file is part of ADOdb, a Database Abstraction Layer library for PHP.
|
|
|
8 |
*
|
|
|
9 |
* @package ADOdb
|
|
|
10 |
* @link https://adodb.org Project's web site and documentation
|
|
|
11 |
* @link https://github.com/ADOdb/ADOdb Source code and issue tracker
|
|
|
12 |
*
|
|
|
13 |
* The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
|
|
|
14 |
* and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
|
|
|
15 |
* any later version. This means you can use it in proprietary products.
|
|
|
16 |
* See the LICENSE.md file distributed with this source code for details.
|
|
|
17 |
* @license BSD-3-Clause
|
|
|
18 |
* @license LGPL-2.1-or-later
|
|
|
19 |
*
|
|
|
20 |
* @copyright 2000-2013 John Lim
|
|
|
21 |
* @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
// security - hide paths
|
|
|
25 |
if (!defined('ADODB_DIR')) die();
|
|
|
26 |
|
|
|
27 |
define("_ADODB_ADO_LAYER", 1 );
|
|
|
28 |
/*--------------------------------------------------------------------------------------
|
|
|
29 |
--------------------------------------------------------------------------------------*/
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
class ADODB_ado extends ADOConnection {
|
|
|
33 |
var $databaseType = "ado";
|
|
|
34 |
var $_bindInputArray = false;
|
|
|
35 |
var $fmtDate = "'Y-m-d'";
|
|
|
36 |
var $fmtTimeStamp = "'Y-m-d, h:i:sA'";
|
|
|
37 |
var $replaceQuote = "''"; // string to use to replace quotes
|
|
|
38 |
var $dataProvider = "ado";
|
|
|
39 |
var $hasAffectedRows = true;
|
|
|
40 |
var $adoParameterType = 201; // 201 = long varchar, 203=long wide varchar, 205 = long varbinary
|
|
|
41 |
var $_affectedRows = false;
|
|
|
42 |
var $_thisTransactions;
|
|
|
43 |
var $_cursor_type = 3; // 3=adOpenStatic,0=adOpenForwardOnly,1=adOpenKeyset,2=adOpenDynamic
|
|
|
44 |
var $_cursor_location = 3; // 2=adUseServer, 3 = adUseClient;
|
|
|
45 |
var $_lock_type = -1;
|
|
|
46 |
var $_execute_option = -1;
|
|
|
47 |
var $poorAffectedRows = true;
|
|
|
48 |
var $charPage;
|
|
|
49 |
|
|
|
50 |
function __construct()
|
|
|
51 |
{
|
|
|
52 |
$this->_affectedRows = new VARIANT;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
function ServerInfo()
|
|
|
56 |
{
|
|
|
57 |
if (!empty($this->_connectionID)) $desc = $this->_connectionID->provider;
|
|
|
58 |
return array('description' => $desc, 'version' => '');
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
function _affectedrows()
|
|
|
62 |
{
|
|
|
63 |
return $this->_affectedRows;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
// you can also pass a connection string like this:
|
|
|
67 |
//
|
|
|
68 |
// $DB->Connect('USER ID=sa;PASSWORD=pwd;SERVER=mangrove;DATABASE=ai',false,false,'SQLOLEDB');
|
|
|
69 |
function _connect($argHostname, $argUsername, $argPassword,$argDBorProvider, $argProvider= '')
|
|
|
70 |
{
|
|
|
71 |
// two modes
|
|
|
72 |
// - if $argProvider is empty, we assume that $argDBorProvider holds provider -- this is for backward compat
|
|
|
73 |
// - if $argProvider is not empty, then $argDBorProvider holds db
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
if ($argProvider) {
|
|
|
77 |
$argDatabasename = $argDBorProvider;
|
|
|
78 |
} else {
|
|
|
79 |
$argDatabasename = '';
|
|
|
80 |
if ($argDBorProvider) $argProvider = $argDBorProvider;
|
|
|
81 |
else if (stripos($argHostname,'PROVIDER') === false) /* full conn string is not in $argHostname */
|
|
|
82 |
$argProvider = 'MSDASQL';
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
try {
|
|
|
87 |
$u = 'UID';
|
|
|
88 |
$p = 'PWD';
|
|
|
89 |
|
|
|
90 |
if (!empty($this->charPage))
|
|
|
91 |
$dbc = new COM('ADODB.Connection',null,$this->charPage);
|
|
|
92 |
else
|
|
|
93 |
$dbc = new COM('ADODB.Connection');
|
|
|
94 |
|
|
|
95 |
if (! $dbc) return false;
|
|
|
96 |
|
|
|
97 |
/* special support if provider is mssql or access */
|
|
|
98 |
if ($argProvider=='mssql') {
|
|
|
99 |
$u = 'User Id'; //User parameter name for OLEDB
|
|
|
100 |
$p = 'Password';
|
|
|
101 |
$argProvider = "SQLOLEDB"; // SQL Server Provider
|
|
|
102 |
|
|
|
103 |
// not yet
|
|
|
104 |
//if ($argDatabasename) $argHostname .= ";Initial Catalog=$argDatabasename";
|
|
|
105 |
|
|
|
106 |
//use trusted connection for SQL if username not specified
|
|
|
107 |
if (!$argUsername) $argHostname .= ";Trusted_Connection=Yes";
|
|
|
108 |
} else if ($argProvider=='access')
|
|
|
109 |
$argProvider = "Microsoft.Jet.OLEDB.4.0"; // Microsoft Jet Provider
|
|
|
110 |
|
|
|
111 |
if ($argProvider) $dbc->Provider = $argProvider;
|
|
|
112 |
|
|
|
113 |
if ($argProvider) $argHostname = "PROVIDER=$argProvider;DRIVER={SQL Server};SERVER=$argHostname";
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
if ($argDatabasename) $argHostname .= ";DATABASE=$argDatabasename";
|
|
|
117 |
if ($argUsername) $argHostname .= ";$u=$argUsername";
|
|
|
118 |
if ($argPassword)$argHostname .= ";$p=$argPassword";
|
|
|
119 |
|
|
|
120 |
if ($this->debug) ADOConnection::outp( "Host=".$argHostname."<BR>\n version=$dbc->version");
|
|
|
121 |
// @ added below for php 4.0.1 and earlier
|
|
|
122 |
@$dbc->Open((string) $argHostname);
|
|
|
123 |
|
|
|
124 |
$this->_connectionID = $dbc;
|
|
|
125 |
|
|
|
126 |
$dbc->CursorLocation = $this->_cursor_location;
|
|
|
127 |
return $dbc->State > 0;
|
|
|
128 |
} catch (exception $e) {
|
|
|
129 |
if ($this->debug) echo "<pre>",$argHostname,"\n",$e,"</pre>\n";
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
return false;
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
// returns true or false
|
|
|
136 |
function _pconnect($argHostname, $argUsername, $argPassword, $argProvider='MSDASQL')
|
|
|
137 |
{
|
|
|
138 |
return $this->_connect($argHostname,$argUsername,$argPassword,$argProvider);
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
/*
|
|
|
142 |
adSchemaCatalogs = 1,
|
|
|
143 |
adSchemaCharacterSets = 2,
|
|
|
144 |
adSchemaCollations = 3,
|
|
|
145 |
adSchemaColumns = 4,
|
|
|
146 |
adSchemaCheckConstraints = 5,
|
|
|
147 |
adSchemaConstraintColumnUsage = 6,
|
|
|
148 |
adSchemaConstraintTableUsage = 7,
|
|
|
149 |
adSchemaKeyColumnUsage = 8,
|
|
|
150 |
adSchemaReferentialContraints = 9,
|
|
|
151 |
adSchemaTableConstraints = 10,
|
|
|
152 |
adSchemaColumnsDomainUsage = 11,
|
|
|
153 |
adSchemaIndexes = 12,
|
|
|
154 |
adSchemaColumnPrivileges = 13,
|
|
|
155 |
adSchemaTablePrivileges = 14,
|
|
|
156 |
adSchemaUsagePrivileges = 15,
|
|
|
157 |
adSchemaProcedures = 16,
|
|
|
158 |
adSchemaSchemata = 17,
|
|
|
159 |
adSchemaSQLLanguages = 18,
|
|
|
160 |
adSchemaStatistics = 19,
|
|
|
161 |
adSchemaTables = 20,
|
|
|
162 |
adSchemaTranslations = 21,
|
|
|
163 |
adSchemaProviderTypes = 22,
|
|
|
164 |
adSchemaViews = 23,
|
|
|
165 |
adSchemaViewColumnUsage = 24,
|
|
|
166 |
adSchemaViewTableUsage = 25,
|
|
|
167 |
adSchemaProcedureParameters = 26,
|
|
|
168 |
adSchemaForeignKeys = 27,
|
|
|
169 |
adSchemaPrimaryKeys = 28,
|
|
|
170 |
adSchemaProcedureColumns = 29,
|
|
|
171 |
adSchemaDBInfoKeywords = 30,
|
|
|
172 |
adSchemaDBInfoLiterals = 31,
|
|
|
173 |
adSchemaCubes = 32,
|
|
|
174 |
adSchemaDimensions = 33,
|
|
|
175 |
adSchemaHierarchies = 34,
|
|
|
176 |
adSchemaLevels = 35,
|
|
|
177 |
adSchemaMeasures = 36,
|
|
|
178 |
adSchemaProperties = 37,
|
|
|
179 |
adSchemaMembers = 38
|
|
|
180 |
|
|
|
181 |
*/
|
|
|
182 |
|
|
|
183 |
function MetaTables($ttype = false, $showSchema = false, $mask = false)
|
|
|
184 |
{
|
|
|
185 |
$arr= array();
|
|
|
186 |
$dbc = $this->_connectionID;
|
|
|
187 |
|
|
|
188 |
$adors=@$dbc->OpenSchema(20);//tables
|
|
|
189 |
if ($adors){
|
|
|
190 |
$f = $adors->Fields(2);//table/view name
|
|
|
191 |
$t = $adors->Fields(3);//table type
|
|
|
192 |
while (!$adors->EOF){
|
|
|
193 |
$tt=substr($t->value,0,6);
|
|
|
194 |
if ($tt!='SYSTEM' && $tt !='ACCESS')
|
|
|
195 |
$arr[]=$f->value;
|
|
|
196 |
//print $f->value . ' ' . $t->value.'<br>';
|
|
|
197 |
$adors->MoveNext();
|
|
|
198 |
}
|
|
|
199 |
$adors->Close();
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
return $arr;
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
function MetaColumns($table, $normalize=true)
|
|
|
206 |
{
|
|
|
207 |
$table = strtoupper($table);
|
|
|
208 |
$arr= array();
|
|
|
209 |
$dbc = $this->_connectionID;
|
|
|
210 |
|
|
|
211 |
$adors=@$dbc->OpenSchema(4);//tables
|
|
|
212 |
|
|
|
213 |
if ($adors){
|
|
|
214 |
$t = $adors->Fields(2);//table/view name
|
|
|
215 |
while (!$adors->EOF){
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
if (strtoupper($t->Value) == $table) {
|
|
|
219 |
|
|
|
220 |
$fld = new ADOFieldObject();
|
|
|
221 |
$c = $adors->Fields(3);
|
|
|
222 |
$fld->name = $c->Value;
|
|
|
223 |
$fld->type = 'CHAR'; // cannot discover type in ADO!
|
|
|
224 |
$fld->max_length = -1;
|
|
|
225 |
$arr[strtoupper($fld->name)]=$fld;
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
$adors->MoveNext();
|
|
|
229 |
}
|
|
|
230 |
$adors->Close();
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
return $arr;
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
function _query($sql,$inputarr=false)
|
|
|
237 |
{
|
|
|
238 |
try { // In PHP5, all COM errors are exceptions, so to maintain old behaviour...
|
|
|
239 |
|
|
|
240 |
$dbc = $this->_connectionID;
|
|
|
241 |
|
|
|
242 |
// return rs
|
|
|
243 |
|
|
|
244 |
$false = false;
|
|
|
245 |
|
|
|
246 |
if ($inputarr) {
|
|
|
247 |
|
|
|
248 |
if (!empty($this->charPage))
|
|
|
249 |
$oCmd = new COM('ADODB.Command',null,$this->charPage);
|
|
|
250 |
else
|
|
|
251 |
$oCmd = new COM('ADODB.Command');
|
|
|
252 |
$oCmd->ActiveConnection = $dbc;
|
|
|
253 |
$oCmd->CommandText = $sql;
|
|
|
254 |
$oCmd->CommandType = 1;
|
|
|
255 |
|
|
|
256 |
foreach ($inputarr as $val) {
|
|
|
257 |
$type = gettype($val);
|
|
|
258 |
$len=strlen($val);
|
|
|
259 |
if ($type == 'boolean')
|
|
|
260 |
$this->adoParameterType = 11;
|
|
|
261 |
else if ($type == 'integer')
|
|
|
262 |
$this->adoParameterType = 3;
|
|
|
263 |
else if ($type == 'double')
|
|
|
264 |
$this->adoParameterType = 5;
|
|
|
265 |
elseif ($type == 'string')
|
|
|
266 |
$this->adoParameterType = 202;
|
|
|
267 |
else if (($val === null) || (!defined($val)))
|
|
|
268 |
$len=1;
|
|
|
269 |
else
|
|
|
270 |
$this->adoParameterType = 130;
|
|
|
271 |
|
|
|
272 |
// name, type, direction 1 = input, len,
|
|
|
273 |
$p = $oCmd->CreateParameter('name',$this->adoParameterType,1,$len,$val);
|
|
|
274 |
|
|
|
275 |
$oCmd->Parameters->Append($p);
|
|
|
276 |
}
|
|
|
277 |
|
|
|
278 |
$p = false;
|
|
|
279 |
$rs = $oCmd->Execute();
|
|
|
280 |
$e = $dbc->Errors;
|
|
|
281 |
if ($dbc->Errors->Count > 0) return $false;
|
|
|
282 |
return $rs;
|
|
|
283 |
}
|
|
|
284 |
|
|
|
285 |
$rs = @$dbc->Execute($sql,$this->_affectedRows, $this->_execute_option);
|
|
|
286 |
|
|
|
287 |
if ($dbc->Errors->Count > 0) return $false;
|
|
|
288 |
if (! $rs) return $false;
|
|
|
289 |
|
|
|
290 |
if ($rs->State == 0) {
|
|
|
291 |
$true = true;
|
|
|
292 |
return $true; // 0 = adStateClosed means no records returned
|
|
|
293 |
}
|
|
|
294 |
return $rs;
|
|
|
295 |
|
|
|
296 |
} catch (exception $e) {
|
|
|
297 |
|
|
|
298 |
}
|
|
|
299 |
return $false;
|
|
|
300 |
}
|
|
|
301 |
|
|
|
302 |
|
|
|
303 |
function BeginTrans()
|
|
|
304 |
{
|
|
|
305 |
if ($this->transOff) return true;
|
|
|
306 |
|
|
|
307 |
if (isset($this->_thisTransactions))
|
|
|
308 |
if (!$this->_thisTransactions) return false;
|
|
|
309 |
else {
|
|
|
310 |
$o = $this->_connectionID->Properties("Transaction DDL");
|
|
|
311 |
$this->_thisTransactions = $o ? true : false;
|
|
|
312 |
if (!$o) return false;
|
|
|
313 |
}
|
|
|
314 |
@$this->_connectionID->BeginTrans();
|
|
|
315 |
$this->transCnt += 1;
|
|
|
316 |
return true;
|
|
|
317 |
}
|
|
|
318 |
function CommitTrans($ok=true)
|
|
|
319 |
{
|
|
|
320 |
if (!$ok) return $this->RollbackTrans();
|
|
|
321 |
if ($this->transOff) return true;
|
|
|
322 |
|
|
|
323 |
@$this->_connectionID->CommitTrans();
|
|
|
324 |
if ($this->transCnt) @$this->transCnt -= 1;
|
|
|
325 |
return true;
|
|
|
326 |
}
|
|
|
327 |
function RollbackTrans() {
|
|
|
328 |
if ($this->transOff) return true;
|
|
|
329 |
@$this->_connectionID->RollbackTrans();
|
|
|
330 |
if ($this->transCnt) @$this->transCnt -= 1;
|
|
|
331 |
return true;
|
|
|
332 |
}
|
|
|
333 |
|
|
|
334 |
/* Returns: the last error message from previous database operation */
|
|
|
335 |
|
|
|
336 |
function ErrorMsg()
|
|
|
337 |
{
|
|
|
338 |
if (!$this->_connectionID) return "No connection established";
|
|
|
339 |
$errmsg = '';
|
|
|
340 |
|
|
|
341 |
try {
|
|
|
342 |
$errc = $this->_connectionID->Errors;
|
|
|
343 |
if (!$errc) return "No Errors object found";
|
|
|
344 |
if ($errc->Count == 0) return '';
|
|
|
345 |
$err = $errc->Item($errc->Count-1);
|
|
|
346 |
$errmsg = $err->Description;
|
|
|
347 |
}catch(exception $e) {
|
|
|
348 |
}
|
|
|
349 |
return $errmsg;
|
|
|
350 |
}
|
|
|
351 |
|
|
|
352 |
function ErrorNo()
|
|
|
353 |
{
|
|
|
354 |
$errc = $this->_connectionID->Errors;
|
|
|
355 |
if ($errc->Count == 0) return 0;
|
|
|
356 |
$err = $errc->Item($errc->Count-1);
|
|
|
357 |
return $err->NativeError;
|
|
|
358 |
}
|
|
|
359 |
|
|
|
360 |
// returns true or false
|
|
|
361 |
function _close()
|
|
|
362 |
{
|
|
|
363 |
if ($this->_connectionID) $this->_connectionID->Close();
|
|
|
364 |
$this->_connectionID = false;
|
|
|
365 |
return true;
|
|
|
366 |
}
|
|
|
367 |
|
|
|
368 |
|
|
|
369 |
}
|
|
|
370 |
|
|
|
371 |
/*--------------------------------------------------------------------------------------
|
|
|
372 |
Class Name: Recordset
|
|
|
373 |
--------------------------------------------------------------------------------------*/
|
|
|
374 |
|
|
|
375 |
class ADORecordSet_ado extends ADORecordSet {
|
|
|
376 |
|
|
|
377 |
var $bind = false;
|
|
|
378 |
var $databaseType = "ado";
|
|
|
379 |
var $dataProvider = "ado";
|
|
|
380 |
var $_tarr = false; // caches the types
|
|
|
381 |
var $_flds; // and field objects
|
|
|
382 |
var $canSeek = true;
|
|
|
383 |
var $hideErrors = true;
|
|
|
384 |
|
|
|
385 |
function __construct($id,$mode=false)
|
|
|
386 |
{
|
|
|
387 |
if ($mode === false) {
|
|
|
388 |
global $ADODB_FETCH_MODE;
|
|
|
389 |
$mode = $ADODB_FETCH_MODE;
|
|
|
390 |
}
|
|
|
391 |
$this->fetchMode = $mode;
|
|
|
392 |
parent::__construct($id);
|
|
|
393 |
}
|
|
|
394 |
|
|
|
395 |
|
|
|
396 |
// returns the field object
|
|
|
397 |
function FetchField($fieldOffset = -1) {
|
|
|
398 |
$off=$fieldOffset+1; // offsets begin at 1
|
|
|
399 |
|
|
|
400 |
$o= new ADOFieldObject();
|
|
|
401 |
$rs = $this->_queryID;
|
|
|
402 |
if (!$rs) return false;
|
|
|
403 |
|
|
|
404 |
$f = $rs->Fields($fieldOffset);
|
|
|
405 |
$o->name = $f->Name;
|
|
|
406 |
$t = $f->Type;
|
|
|
407 |
$o->type = $this->MetaType($t);
|
|
|
408 |
$o->max_length = $f->DefinedSize;
|
|
|
409 |
$o->ado_type = $t;
|
|
|
410 |
|
|
|
411 |
|
|
|
412 |
//print "off=$off name=$o->name type=$o->type len=$o->max_length<br>";
|
|
|
413 |
return $o;
|
|
|
414 |
}
|
|
|
415 |
|
|
|
416 |
/* Use associative array to get fields array */
|
|
|
417 |
function Fields($colname)
|
|
|
418 |
{
|
|
|
419 |
if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname];
|
|
|
420 |
if (!$this->bind) {
|
|
|
421 |
$this->bind = array();
|
|
|
422 |
for ($i=0; $i < $this->_numOfFields; $i++) {
|
|
|
423 |
$o = $this->FetchField($i);
|
|
|
424 |
$this->bind[strtoupper($o->name)] = $i;
|
|
|
425 |
}
|
|
|
426 |
}
|
|
|
427 |
|
|
|
428 |
return $this->fields[$this->bind[strtoupper($colname)]];
|
|
|
429 |
}
|
|
|
430 |
|
|
|
431 |
|
|
|
432 |
function _initrs()
|
|
|
433 |
{
|
|
|
434 |
$rs = $this->_queryID;
|
|
|
435 |
|
|
|
436 |
try {
|
|
|
437 |
$this->_numOfRows = $rs->RecordCount;
|
|
|
438 |
} catch (Exception $e) {
|
|
|
439 |
$this->_numOfRows = -1;
|
|
|
440 |
}
|
|
|
441 |
$f = $rs->Fields;
|
|
|
442 |
$this->_numOfFields = $f->Count;
|
|
|
443 |
}
|
|
|
444 |
|
|
|
445 |
|
|
|
446 |
// should only be used to move forward as we normally use forward-only cursors
|
|
|
447 |
function _seek($row)
|
|
|
448 |
{
|
|
|
449 |
$rs = $this->_queryID;
|
|
|
450 |
// absoluteposition doesn't work -- my maths is wrong ?
|
|
|
451 |
// $rs->AbsolutePosition->$row-2;
|
|
|
452 |
// return true;
|
|
|
453 |
if ($this->_currentRow > $row) return false;
|
|
|
454 |
@$rs->Move((integer)$row - $this->_currentRow-1); //adBookmarkFirst
|
|
|
455 |
return true;
|
|
|
456 |
}
|
|
|
457 |
|
|
|
458 |
/*
|
|
|
459 |
OLEDB types
|
|
|
460 |
|
|
|
461 |
enum DBTYPEENUM
|
|
|
462 |
{ DBTYPE_EMPTY = 0,
|
|
|
463 |
DBTYPE_NULL = 1,
|
|
|
464 |
DBTYPE_I2 = 2,
|
|
|
465 |
DBTYPE_I4 = 3,
|
|
|
466 |
DBTYPE_R4 = 4,
|
|
|
467 |
DBTYPE_R8 = 5,
|
|
|
468 |
DBTYPE_CY = 6,
|
|
|
469 |
DBTYPE_DATE = 7,
|
|
|
470 |
DBTYPE_BSTR = 8,
|
|
|
471 |
DBTYPE_IDISPATCH = 9,
|
|
|
472 |
DBTYPE_ERROR = 10,
|
|
|
473 |
DBTYPE_BOOL = 11,
|
|
|
474 |
DBTYPE_VARIANT = 12,
|
|
|
475 |
DBTYPE_IUNKNOWN = 13,
|
|
|
476 |
DBTYPE_DECIMAL = 14,
|
|
|
477 |
DBTYPE_UI1 = 17,
|
|
|
478 |
DBTYPE_ARRAY = 0x2000,
|
|
|
479 |
DBTYPE_BYREF = 0x4000,
|
|
|
480 |
DBTYPE_I1 = 16,
|
|
|
481 |
DBTYPE_UI2 = 18,
|
|
|
482 |
DBTYPE_UI4 = 19,
|
|
|
483 |
DBTYPE_I8 = 20,
|
|
|
484 |
DBTYPE_UI8 = 21,
|
|
|
485 |
DBTYPE_GUID = 72,
|
|
|
486 |
DBTYPE_VECTOR = 0x1000,
|
|
|
487 |
DBTYPE_RESERVED = 0x8000,
|
|
|
488 |
DBTYPE_BYTES = 128,
|
|
|
489 |
DBTYPE_STR = 129,
|
|
|
490 |
DBTYPE_WSTR = 130,
|
|
|
491 |
DBTYPE_NUMERIC = 131,
|
|
|
492 |
DBTYPE_UDT = 132,
|
|
|
493 |
DBTYPE_DBDATE = 133,
|
|
|
494 |
DBTYPE_DBTIME = 134,
|
|
|
495 |
DBTYPE_DBTIMESTAMP = 135
|
|
|
496 |
|
|
|
497 |
ADO Types
|
|
|
498 |
|
|
|
499 |
adEmpty = 0,
|
|
|
500 |
adTinyInt = 16,
|
|
|
501 |
adSmallInt = 2,
|
|
|
502 |
adInteger = 3,
|
|
|
503 |
adBigInt = 20,
|
|
|
504 |
adUnsignedTinyInt = 17,
|
|
|
505 |
adUnsignedSmallInt = 18,
|
|
|
506 |
adUnsignedInt = 19,
|
|
|
507 |
adUnsignedBigInt = 21,
|
|
|
508 |
adSingle = 4,
|
|
|
509 |
adDouble = 5,
|
|
|
510 |
adCurrency = 6,
|
|
|
511 |
adDecimal = 14,
|
|
|
512 |
adNumeric = 131,
|
|
|
513 |
adBoolean = 11,
|
|
|
514 |
adError = 10,
|
|
|
515 |
adUserDefined = 132,
|
|
|
516 |
adVariant = 12,
|
|
|
517 |
adIDispatch = 9,
|
|
|
518 |
adIUnknown = 13,
|
|
|
519 |
adGUID = 72,
|
|
|
520 |
adDate = 7,
|
|
|
521 |
adDBDate = 133,
|
|
|
522 |
adDBTime = 134,
|
|
|
523 |
adDBTimeStamp = 135,
|
|
|
524 |
adBSTR = 8,
|
|
|
525 |
adChar = 129,
|
|
|
526 |
adVarChar = 200,
|
|
|
527 |
adLongVarChar = 201,
|
|
|
528 |
adWChar = 130,
|
|
|
529 |
adVarWChar = 202,
|
|
|
530 |
adLongVarWChar = 203,
|
|
|
531 |
adBinary = 128,
|
|
|
532 |
adVarBinary = 204,
|
|
|
533 |
adLongVarBinary = 205,
|
|
|
534 |
adChapter = 136,
|
|
|
535 |
adFileTime = 64,
|
|
|
536 |
adDBFileTime = 137,
|
|
|
537 |
adPropVariant = 138,
|
|
|
538 |
adVarNumeric = 139
|
|
|
539 |
*/
|
|
|
540 |
function MetaType($t,$len=-1,$fieldobj=false)
|
|
|
541 |
{
|
|
|
542 |
if (is_object($t)) {
|
|
|
543 |
$fieldobj = $t;
|
|
|
544 |
$t = $fieldobj->type;
|
|
|
545 |
$len = $fieldobj->max_length;
|
|
|
546 |
}
|
|
|
547 |
|
|
|
548 |
$t = strtoupper($t);
|
|
|
549 |
|
|
|
550 |
if (array_key_exists($t,$this->connection->customActualTypes))
|
|
|
551 |
return $this->connection->customActualTypes[$t];
|
|
|
552 |
|
|
|
553 |
if (!is_numeric($t))
|
|
|
554 |
return $t;
|
|
|
555 |
|
|
|
556 |
switch ($t) {
|
|
|
557 |
case 0:
|
|
|
558 |
case 12: // variant
|
|
|
559 |
case 8: // bstr
|
|
|
560 |
case 129: //char
|
|
|
561 |
case 130: //wc
|
|
|
562 |
case 200: // varc
|
|
|
563 |
case 202:// varWC
|
|
|
564 |
case 128: // bin
|
|
|
565 |
case 204: // varBin
|
|
|
566 |
case 72: // guid
|
|
|
567 |
if ($len <= $this->blobSize) return 'C';
|
|
|
568 |
|
|
|
569 |
case 201:
|
|
|
570 |
case 203:
|
|
|
571 |
return 'X';
|
|
|
572 |
case 128:
|
|
|
573 |
case 204:
|
|
|
574 |
case 205:
|
|
|
575 |
return 'B';
|
|
|
576 |
case 7:
|
|
|
577 |
case 133: return 'D';
|
|
|
578 |
|
|
|
579 |
case 134:
|
|
|
580 |
case 135: return 'T';
|
|
|
581 |
|
|
|
582 |
case 11: return 'L';
|
|
|
583 |
|
|
|
584 |
case 16:// adTinyInt = 16,
|
|
|
585 |
case 2://adSmallInt = 2,
|
|
|
586 |
case 3://adInteger = 3,
|
|
|
587 |
case 4://adBigInt = 20,
|
|
|
588 |
case 17://adUnsignedTinyInt = 17,
|
|
|
589 |
case 18://adUnsignedSmallInt = 18,
|
|
|
590 |
case 19://adUnsignedInt = 19,
|
|
|
591 |
case 20://adUnsignedBigInt = 21,
|
|
|
592 |
return 'I';
|
|
|
593 |
default: return ADODB_DEFAULT_METATYPE;
|
|
|
594 |
}
|
|
|
595 |
}
|
|
|
596 |
|
|
|
597 |
// time stamp not supported yet
|
|
|
598 |
function _fetch()
|
|
|
599 |
{
|
|
|
600 |
$rs = $this->_queryID;
|
|
|
601 |
if (!$rs or $rs->EOF) {
|
|
|
602 |
$this->fields = false;
|
|
|
603 |
return false;
|
|
|
604 |
}
|
|
|
605 |
$this->fields = array();
|
|
|
606 |
|
|
|
607 |
if (!$this->_tarr) {
|
|
|
608 |
$tarr = array();
|
|
|
609 |
$flds = array();
|
|
|
610 |
for ($i=0,$max = $this->_numOfFields; $i < $max; $i++) {
|
|
|
611 |
$f = $rs->Fields($i);
|
|
|
612 |
$flds[] = $f;
|
|
|
613 |
$tarr[] = $f->Type;
|
|
|
614 |
}
|
|
|
615 |
// bind types and flds only once
|
|
|
616 |
$this->_tarr = $tarr;
|
|
|
617 |
$this->_flds = $flds;
|
|
|
618 |
}
|
|
|
619 |
$t = reset($this->_tarr);
|
|
|
620 |
$f = reset($this->_flds);
|
|
|
621 |
|
|
|
622 |
if ($this->hideErrors) $olde = error_reporting(E_ERROR|E_CORE_ERROR);// sometimes $f->value be null
|
|
|
623 |
for ($i=0,$max = $this->_numOfFields; $i < $max; $i++) {
|
|
|
624 |
//echo "<p>",$t,' ';var_dump($f->value); echo '</p>';
|
|
|
625 |
switch($t) {
|
|
|
626 |
case 135: // timestamp
|
|
|
627 |
if (!strlen((string)$f->value)) $this->fields[] = false;
|
|
|
628 |
else {
|
|
|
629 |
if (!is_numeric($f->value)) # $val = variant_date_to_timestamp($f->value);
|
|
|
630 |
// VT_DATE stores dates as (float) fractional days since 1899/12/30 00:00:00
|
|
|
631 |
$val= (float) variant_cast($f->value,VT_R8)*3600*24-2209161600;
|
|
|
632 |
else
|
|
|
633 |
$val = $f->value;
|
|
|
634 |
$this->fields[] = adodb_date('Y-m-d H:i:s',$val);
|
|
|
635 |
}
|
|
|
636 |
break;
|
|
|
637 |
case 133:// A date value (yyyymmdd)
|
|
|
638 |
if ($val = $f->value) {
|
|
|
639 |
$this->fields[] = substr($val,0,4).'-'.substr($val,4,2).'-'.substr($val,6,2);
|
|
|
640 |
} else
|
|
|
641 |
$this->fields[] = false;
|
|
|
642 |
break;
|
|
|
643 |
case 7: // adDate
|
|
|
644 |
if (!strlen((string)$f->value)) $this->fields[] = false;
|
|
|
645 |
else {
|
|
|
646 |
if (!is_numeric($f->value)) $val = variant_date_to_timestamp($f->value);
|
|
|
647 |
else $val = $f->value;
|
|
|
648 |
|
|
|
649 |
if (($val % 86400) == 0) $this->fields[] = adodb_date('Y-m-d',$val);
|
|
|
650 |
else $this->fields[] = adodb_date('Y-m-d H:i:s',$val);
|
|
|
651 |
}
|
|
|
652 |
break;
|
|
|
653 |
case 1: // null
|
|
|
654 |
$this->fields[] = false;
|
|
|
655 |
break;
|
|
|
656 |
case 20:
|
|
|
657 |
case 21: // bigint (64 bit)
|
|
|
658 |
$this->fields[] = (float) $f->value; // if 64 bit PHP, could use (int)
|
|
|
659 |
break;
|
|
|
660 |
case 6: // currency is not supported properly;
|
|
|
661 |
ADOConnection::outp( '<b>'.$f->Name.': currency type not supported by PHP</b>');
|
|
|
662 |
$this->fields[] = (float) $f->value;
|
|
|
663 |
break;
|
|
|
664 |
case 11: //BIT;
|
|
|
665 |
$val = "";
|
|
|
666 |
if(is_bool($f->value)) {
|
|
|
667 |
if($f->value==true) $val = 1;
|
|
|
668 |
else $val = 0;
|
|
|
669 |
}
|
|
|
670 |
if(is_null($f->value)) $val = null;
|
|
|
671 |
|
|
|
672 |
$this->fields[] = $val;
|
|
|
673 |
break;
|
|
|
674 |
default:
|
|
|
675 |
$this->fields[] = $f->value;
|
|
|
676 |
break;
|
|
|
677 |
}
|
|
|
678 |
//print " $f->value $t, ";
|
|
|
679 |
$f = next($this->_flds);
|
|
|
680 |
$t = next($this->_tarr);
|
|
|
681 |
} // for
|
|
|
682 |
if ($this->hideErrors) error_reporting($olde);
|
|
|
683 |
@$rs->MoveNext(); // @ needed for some versions of PHP!
|
|
|
684 |
|
|
|
685 |
if ($this->fetchMode & ADODB_FETCH_ASSOC) {
|
|
|
686 |
$this->fields = $this->GetRowAssoc();
|
|
|
687 |
}
|
|
|
688 |
return true;
|
|
|
689 |
}
|
|
|
690 |
|
|
|
691 |
function NextRecordSet()
|
|
|
692 |
{
|
|
|
693 |
$rs = $this->_queryID;
|
|
|
694 |
$this->_queryID = $rs->NextRecordSet();
|
|
|
695 |
//$this->_queryID = $this->_QueryId->NextRecordSet();
|
|
|
696 |
if ($this->_queryID == null) return false;
|
|
|
697 |
|
|
|
698 |
$this->_currentRow = -1;
|
|
|
699 |
$this->_currentPage = -1;
|
|
|
700 |
$this->bind = false;
|
|
|
701 |
$this->fields = false;
|
|
|
702 |
$this->_flds = false;
|
|
|
703 |
$this->_tarr = false;
|
|
|
704 |
|
|
|
705 |
$this->_inited = false;
|
|
|
706 |
$this->Init();
|
|
|
707 |
return true;
|
|
|
708 |
}
|
|
|
709 |
|
|
|
710 |
function _close() {
|
|
|
711 |
$this->_flds = false;
|
|
|
712 |
try {
|
|
|
713 |
@$this->_queryID->Close();// by Pete Dishman (peterd@telephonetics.co.uk)
|
|
|
714 |
} catch (Exception $e) {
|
|
|
715 |
}
|
|
|
716 |
$this->_queryID = false;
|
|
|
717 |
}
|
|
|
718 |
|
|
|
719 |
}
|