Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
/**
3
 * ADOdb driver for ADS.
4
 *
5
 * NOTE: This driver requires the Advantage PHP client libraries, which
6
 * can be downloaded for free via:
7
 * @link http://devzone.advantagedatabase.com/dz/content.aspx?key=20
8
 *
9
 * This file is part of ADOdb, a Database Abstraction Layer library for PHP.
10
 *
11
 * @package ADOdb
12
 * @link https://adodb.org Project's web site and documentation
13
 * @link https://github.com/ADOdb/ADOdb Source code and issue tracker
14
 *
15
 * The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
16
 * and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
17
 * any later version. This means you can use it in proprietary products.
18
 * See the LICENSE.md file distributed with this source code for details.
19
 * @license BSD-3-Clause
20
 * @license LGPL-2.1-or-later
21
 *
22
 * @copyright 2000-2013 John Lim
23
 * @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
24
 */
25
 
26
/*
27
DELPHI FOR PHP USERS:
28
      The following steps can be taken to utilize this driver from the
29
      CodeGear Delphi for PHP product:
30
        1 - See note above, download and install the Advantage PHP client.
31
        2 - Copy the following files to the Delphi for PHP\X.X\php\ext directory:
32
              ace32.dll
33
              axcws32.dll
34
              adsloc32.dll
35
              php_advantage.dll (rename the existing php_advantage.dll.5.x.x file)
36
        3 - Add the following line to the Delphi for PHP\X.X\php\php.ini.template file:
37
              extension=php_advantage.dll
38
        4 - To use: enter "ads" as the DriverName on a connection component, and set
39
            a Host property similar to "DataDirectory=c:\". See the Advantage PHP
40
            help file topic for ads_connect for details on connection path options
41
            and formatting.
42
        5 - (optional) - Modify the Delphi for PHP\X.X\vcl\packages\database.packages.php
43
            file and add ads to the list of strings returned when registering the
44
            Database object's DriverName property.
45
 
46
*/
47
 
48
// security - hide paths
49
if (!defined('ADODB_DIR')) {
50
	die();
51
}
52
 
53
define("_ADODB_ADS_LAYER", 2);
54
 
55
/*--------------------------------------------------------------------------------------
56
--------------------------------------------------------------------------------------*/
57
 
58
 
59
class ADODB_ads extends ADOConnection
60
{
61
	var $databaseType = "ads";
62
	var $fmt = "'m-d-Y'";
63
	var $fmtTimeStamp = "'Y-m-d H:i:s'";
64
	var $concat_operator = '';
65
	var $replaceQuote = "''"; // string to use to replace quotes
66
	var $dataProvider = "ads";
67
	var $hasAffectedRows = true;
68
	var $binmode = ODBC_BINMODE_RETURN;
69
	var $useFetchArray = false; // setting this to true will make array elements in FETCH_ASSOC mode case-sensitive
70
	// breaking backward-compat
71
	//var $longreadlen = 8000; // default number of chars to return for a Blob/Long field
72
	var $_bindInputArray = false;
73
	var $curmode = SQL_CUR_USE_DRIVER; // See sqlext.h, SQL_CUR_DEFAULT == SQL_CUR_USE_DRIVER == 2L
74
	var $_genSeqSQL = "create table %s (id integer)";
75
	var $_autocommit = true;
76
	var $_lastAffectedRows = 0;
77
	var $uCaseTables = true; // for meta* functions, uppercase table names
78
 
79
	function __construct()
80
	{
81
	}
82
 
83
	// returns true or false
84
	function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
85
	{
86
		if (!function_exists('ads_connect')) {
87
			return null;
88
		}
89
 
90
		if ($this->debug && $argDatabasename && $this->databaseType != 'vfp') {
91
			ADOConnection::outp("For Advantage Connect(), $argDatabasename is not used. Place dsn in 1st parameter.");
92
		}
93
		$last_php_error = $this->resetLastError();
94
		if ($this->curmode === false) {
95
			$this->_connectionID = ads_connect($argDSN, $argUsername, $argPassword);
96
		} else {
97
			$this->_connectionID = ads_connect($argDSN, $argUsername, $argPassword, $this->curmode);
98
		}
99
		$this->_errorMsg = $this->getChangedErrorMsg($last_php_error);
100
		if ($this->connectStmt) {
101
			$this->Execute($this->connectStmt);
102
		}
103
 
104
		return $this->_connectionID != false;
105
	}
106
 
107
	// returns true or false
108
	function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
109
	{
110
		if (!function_exists('ads_connect')) {
111
			return null;
112
		}
113
 
114
		$last_php_error = $this->resetLastError();
115
		$this->_errorMsg = '';
116
		if ($this->debug && $argDatabasename) {
117
			ADOConnection::outp("For PConnect(), $argDatabasename is not used. Place dsn in 1st parameter.");
118
		}
119
		//  print "dsn=$argDSN u=$argUsername p=$argPassword<br>"; flush();
120
		if ($this->curmode === false) {
121
			$this->_connectionID = ads_connect($argDSN, $argUsername, $argPassword);
122
		} else {
123
			$this->_connectionID = ads_pconnect($argDSN, $argUsername, $argPassword, $this->curmode);
124
		}
125
 
126
		$this->_errorMsg = $this->getChangedErrorMsg($last_php_error);
127
		if ($this->_connectionID && $this->autoRollback) {
128
			@ads_rollback($this->_connectionID);
129
		}
130
		if ($this->connectStmt) {
131
			$this->Execute($this->connectStmt);
132
		}
133
 
134
		return $this->_connectionID != false;
135
	}
136
 
137
	// returns the Server version and Description
138
	function ServerInfo()
139
	{
140
 
141
		if (!empty($this->host)) {
142
			$stmt = $this->Prepare('EXECUTE PROCEDURE sp_mgGetInstallInfo()');
143
			$res = $this->Execute($stmt);
144
			if (!$res) {
145
				print $this->ErrorMsg();
146
			} else {
147
				$ret["version"] = $res->fields[3];
148
				$ret["description"] = "Advantage Database Server";
149
				return $ret;
150
			}
151
		} else {
152
			return ADOConnection::ServerInfo();
153
		}
154
	}
155
 
156
 
157
	// returns true or false
158
	function CreateSequence($seqname = 'adodbseq', $start = 1)
159
	{
160
		$res = $this->Execute("CREATE TABLE $seqname ( ID autoinc( 1 ) ) IN DATABASE");
161
		if (!$res) {
162
			print $this->ErrorMsg();
163
			return false;
164
		} else {
165
			return true;
166
		}
167
 
168
	}
169
 
170
	// returns true or false
171
	function DropSequence($seqname = 'adodbseq')
172
	{
173
		$res = $this->Execute("DROP TABLE $seqname");
174
		if (!$res) {
175
			print $this->ErrorMsg();
176
			return false;
177
		} else {
178
			return true;
179
		}
180
	}
181
 
182
 
183
	// returns the generated ID or false
184
	// checks if the table already exists, else creates the table and inserts a record into the table
185
	// and gets the ID number of the last inserted record.
186
	function GenID($seqname = 'adodbseq', $start = 1)
187
	{
188
		$go = $this->Execute("select * from $seqname");
189
		if (!$go) {
190
			$res = $this->Execute("CREATE TABLE $seqname ( ID autoinc( 1 ) ) IN DATABASE");
191
			if (!$res) {
192
				print $this->ErrorMsg();
193
				return false;
194
			}
195
		}
196
		$res = $this->Execute("INSERT INTO $seqname VALUES( DEFAULT )");
197
		if (!$res) {
198
			print $this->ErrorMsg();
199
			return false;
200
		} else {
201
			$gen = $this->Execute("SELECT LastAutoInc( STATEMENT ) FROM system.iota");
202
			$ret = $gen->fields[0];
203
			return $ret;
204
		}
205
 
206
	}
207
 
208
 
209
	function ErrorMsg()
210
	{
211
		if ($this->_errorMsg !== false) {
212
			return $this->_errorMsg;
213
		}
214
		if (empty($this->_connectionID)) {
215
			return @ads_errormsg();
216
		}
217
		return @ads_errormsg($this->_connectionID);
218
	}
219
 
220
 
221
	function ErrorNo()
222
	{
223
		if ($this->_errorCode !== false) {
224
			// bug in 4.0.6, error number can be corrupted string (should be 6 digits)
225
			return (strlen($this->_errorCode) <= 2) ? 0 : $this->_errorCode;
226
		}
227
 
228
		if (empty($this->_connectionID)) {
229
			$e = @ads_error();
230
		} else {
231
			$e = @ads_error($this->_connectionID);
232
		}
233
 
234
		// bug in 4.0.6, error number can be corrupted string (should be 6 digits)
235
		// so we check and patch
236
		if (strlen($e) <= 2) {
237
			return 0;
238
		}
239
		return $e;
240
	}
241
 
242
 
243
	function BeginTrans()
244
	{
245
		if (!$this->hasTransactions) {
246
			return false;
247
		}
248
		if ($this->transOff) {
249
			return true;
250
		}
251
		$this->transCnt += 1;
252
		$this->_autocommit = false;
253
		return ads_autocommit($this->_connectionID, false);
254
	}
255
 
256
	function CommitTrans($ok = true)
257
	{
258
		if ($this->transOff) {
259
			return true;
260
		}
261
		if (!$ok) {
262
			return $this->RollbackTrans();
263
		}
264
		if ($this->transCnt) {
265
			$this->transCnt -= 1;
266
		}
267
		$this->_autocommit = true;
268
		$ret = ads_commit($this->_connectionID);
269
		ads_autocommit($this->_connectionID, true);
270
		return $ret;
271
	}
272
 
273
	function RollbackTrans()
274
	{
275
		if ($this->transOff) {
276
			return true;
277
		}
278
		if ($this->transCnt) {
279
			$this->transCnt -= 1;
280
		}
281
		$this->_autocommit = true;
282
		$ret = ads_rollback($this->_connectionID);
283
		ads_autocommit($this->_connectionID, true);
284
		return $ret;
285
	}
286
 
287
 
288
	// Returns tables,Views or both on successful execution. Returns
289
	// tables by default on successful execution.
290
	function &MetaTables($ttype = false, $showSchema = false, $mask = false)
291
	{
292
		$recordSet1 = $this->Execute("select * from system.tables");
293
		if (!$recordSet1) {
294
			print $this->ErrorMsg();
295
			return false;
296
		}
297
		$recordSet2 = $this->Execute("select * from system.views");
298
		if (!$recordSet2) {
299
			print $this->ErrorMsg();
300
			return false;
301
		}
302
		$i = 0;
303
		while (!$recordSet1->EOF) {
304
			$arr["$i"] = $recordSet1->fields[0];
305
			$recordSet1->MoveNext();
306
			$i = $i + 1;
307
		}
308
		if ($ttype == 'FALSE') {
309
			while (!$recordSet2->EOF) {
310
				$arr["$i"] = $recordSet2->fields[0];
311
				$recordSet2->MoveNext();
312
				$i = $i + 1;
313
			}
314
			return $arr;
315
		} elseif ($ttype == 'VIEWS') {
316
			while (!$recordSet2->EOF) {
317
				$arrV["$i"] = $recordSet2->fields[0];
318
				$recordSet2->MoveNext();
319
				$i = $i + 1;
320
			}
321
			return $arrV;
322
		} else {
323
			return $arr;
324
		}
325
 
326
	}
327
 
328
	function &MetaPrimaryKeys($table, $owner = false)
329
	{
330
		$recordSet = $this->Execute("select table_primary_key from system.tables where name='$table'");
331
		if (!$recordSet) {
332
			print $this->ErrorMsg();
333
			return false;
334
		}
335
		$i = 0;
336
		while (!$recordSet->EOF) {
337
			$arr["$i"] = $recordSet->fields[0];
338
			$recordSet->MoveNext();
339
			$i = $i + 1;
340
		}
341
		return $arr;
342
	}
343
 
344
	/*
345
	See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcdatetime_data_type_changes.asp
346
	/ SQL data type codes /
347
	#define SQL_UNKNOWN_TYPE  0
348
	#define SQL_CHAR      1
349
	#define SQL_NUMERIC    2
350
	#define SQL_DECIMAL    3
351
	#define SQL_INTEGER    4
352
	#define SQL_SMALLINT    5
353
	#define SQL_FLOAT      6
354
	#define SQL_REAL      7
355
	#define SQL_DOUBLE      8
356
	#if (ODBCVER >= 0x0300)
357
	#define SQL_DATETIME    9
358
	#endif
359
	#define SQL_VARCHAR   12
360
 
361
 
362
	/ One-parameter shortcuts for date/time data types /
363
	#if (ODBCVER >= 0x0300)
364
	#define SQL_TYPE_DATE   91
365
	#define SQL_TYPE_TIME   92
366
	#define SQL_TYPE_TIMESTAMP 93
367
 
368
	#define SQL_UNICODE                             (-95)
369
	#define SQL_UNICODE_VARCHAR                     (-96)
370
	#define SQL_UNICODE_LONGVARCHAR                 (-97)
371
	*/
372
	function ODBCTypes($t)
373
	{
374
		switch ((integer)$t) {
375
			case 1:
376
			case 12:
377
			case 0:
378
			case -95:
379
			case -96:
380
				return 'C';
381
			case -97:
382
			case -1: //text
383
				return 'X';
384
			case -4: //image
385
				return 'B';
386
 
387
			case 9:
388
			case 91:
389
				return 'D';
390
 
391
			case 10:
392
			case 11:
393
			case 92:
394
			case 93:
395
				return 'T';
396
 
397
			case 4:
398
			case 5:
399
			case -6:
400
				return 'I';
401
 
402
			case -11: // uniqidentifier
403
				return 'R';
404
			case -7: //bit
405
				return 'L';
406
 
407
			default:
408
				return 'N';
409
		}
410
	}
411
 
412
	function &MetaColumns($table, $normalize = true)
413
	{
414
		global $ADODB_FETCH_MODE;
415
 
416
		$false = false;
417
		if ($this->uCaseTables) {
418
			$table = strtoupper($table);
419
		}
420
		$schema = '';
421
		$this->_findschema($table, $schema);
422
 
423
		$savem = $ADODB_FETCH_MODE;
424
		$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
425
 
426
		/*if (false) { // after testing, confirmed that the following does not work because of a bug
427
		  $qid2 = ads_tables($this->_connectionID);
428
		  $rs = new ADORecordSet_ads($qid2);
429
		  $ADODB_FETCH_MODE = $savem;
430
		  if (!$rs) return false;
431
		  $rs->_fetch();
432
 
433
		  while (!$rs->EOF) {
434
			if ($table == strtoupper($rs->fields[2])) {
435
			  $q = $rs->fields[0];
436
			  $o = $rs->fields[1];
437
			  break;
438
			}
439
			$rs->MoveNext();
440
		  }
441
		  $rs->Close();
442
 
443
		  $qid = ads_columns($this->_connectionID,$q,$o,strtoupper($table),'%');
444
		} */
445
 
446
		switch ($this->databaseType) {
447
			case 'access':
448
			case 'vfp':
449
				$qid = ads_columns($this->_connectionID);#,'%','',strtoupper($table),'%');
450
				break;
451
 
452
 
453
			case 'db2':
454
				$colname = "%";
455
				$qid = ads_columns($this->_connectionID, "", $schema, $table, $colname);
456
				break;
457
 
458
			default:
459
				$qid = @ads_columns($this->_connectionID, '%', '%', strtoupper($table), '%');
460
				if (empty($qid)) {
461
					$qid = ads_columns($this->_connectionID);
462
				}
463
				break;
464
		}
465
		if (empty($qid)) {
466
			return $false;
467
		}
468
 
469
		$rs = new ADORecordSet_ads($qid);
470
		$ADODB_FETCH_MODE = $savem;
471
 
472
		if (!$rs) {
473
			return $false;
474
		}
475
		$rs->_fetch();
476
 
477
		$retarr = array();
478
 
479
		/*
480
		$rs->fields indices
481
 
482
		1 TABLE_SCHEM
483
		2 TABLE_NAME
484
		3 COLUMN_NAME
485
		4 DATA_TYPE
486
		5 TYPE_NAME
487
		6 PRECISION
488
		7 LENGTH
489
		8 SCALE
490
		9 RADIX
491
		10 NULLABLE
492
		11 REMARKS
493
		*/
494
		while (!$rs->EOF) {
495
			//  adodb_pr($rs->fields);
496
			if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) {
497
				$fld = new ADOFieldObject();
498
				$fld->name = $rs->fields[3];
499
				$fld->type = $this->ODBCTypes($rs->fields[4]);
500
 
501
				// ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp
502
				// access uses precision to store length for char/varchar
503
				if ($fld->type == 'C' or $fld->type == 'X') {
504
					if ($this->databaseType == 'access') {
505
						$fld->max_length = $rs->fields[6];
506
					} else {
507
						if ($rs->fields[4] <= -95) // UNICODE
508
						{
509
							$fld->max_length = $rs->fields[7] / 2;
510
						} else {
511
							$fld->max_length = $rs->fields[7];
512
						}
513
					}
514
				} else {
515
					$fld->max_length = $rs->fields[7];
516
				}
517
				$fld->not_null = !empty($rs->fields[10]);
518
				$fld->scale = $rs->fields[8];
519
				$retarr[strtoupper($fld->name)] = $fld;
520
			} else {
521
				if (sizeof($retarr) > 0) {
522
					break;
523
				}
524
			}
525
			$rs->MoveNext();
526
		}
527
		$rs->Close(); //-- crashes 4.03pl1 -- why?
528
 
529
		if (empty($retarr)) {
530
			$retarr = false;
531
		}
532
		return $retarr;
533
	}
534
 
535
	// Returns an array of columns names for a given table
536
	function &MetaColumnNames($table, $numIndexes = false, $useattnum = false)
537
	{
538
		$recordSet = $this->Execute("select name from system.columns where parent='$table'");
539
		if (!$recordSet) {
540
			print $this->ErrorMsg();
541
			return false;
542
		} else {
543
			$i = 0;
544
			while (!$recordSet->EOF) {
545
				$arr["FIELD$i"] = $recordSet->fields[0];
546
				$recordSet->MoveNext();
547
				$i = $i + 1;
548
			}
549
			return $arr;
550
		}
551
	}
552
 
553
 
554
	function Prepare($sql)
555
	{
556
		if (!$this->_bindInputArray) {
557
			return $sql;
558
		} // no binding
559
		$stmt = ads_prepare($this->_connectionID, $sql);
560
		if (!$stmt) {
561
			// we don't know whether odbc driver is parsing prepared stmts, so just return sql
562
			return $sql;
563
		}
564
		return array($sql, $stmt, false);
565
	}
566
 
567
	function _query($sql, $inputarr = false)
568
	{
569
		$last_php_error = $this->resetLastError();
570
		$this->_errorMsg = '';
571
 
572
		if ($inputarr) {
573
			if (is_array($sql)) {
574
				$stmtid = $sql[1];
575
			} else {
576
				$stmtid = ads_prepare($this->_connectionID, $sql);
577
 
578
				if ($stmtid == false) {
579
					$this->_errorMsg = $this->getChangedErrorMsg($last_php_error);
580
					return false;
581
				}
582
			}
583
 
584
			if (!ads_execute($stmtid, $inputarr)) {
585
				//@ads_free_result($stmtid);
586
				$this->_errorMsg = ads_errormsg();
587
				$this->_errorCode = ads_error();
588
				return false;
589
			}
590
 
591
		} else {
592
			if (is_array($sql)) {
593
				$stmtid = $sql[1];
594
				if (!ads_execute($stmtid)) {
595
					//@ads_free_result($stmtid);
596
					$this->_errorMsg = ads_errormsg();
597
					$this->_errorCode = ads_error();
598
					return false;
599
				}
600
			} else {
601
 
602
				$stmtid = ads_exec($this->_connectionID, $sql);
603
 
604
			}
605
		}
606
 
607
		$this->_lastAffectedRows = 0;
608
 
609
		if ($stmtid) {
610
 
611
			if (@ads_num_fields($stmtid) == 0) {
612
				$this->_lastAffectedRows = ads_num_rows($stmtid);
613
				$stmtid = true;
614
 
615
			} else {
616
 
617
				$this->_lastAffectedRows = 0;
618
				ads_binmode($stmtid, $this->binmode);
619
				ads_longreadlen($stmtid, $this->maxblobsize);
620
 
621
			}
622
 
623
			$this->_errorMsg = '';
624
			$this->_errorCode = 0;
625
		} else {
626
			$this->_errorMsg = ads_errormsg();
627
			$this->_errorCode = ads_error();
628
		}
629
 
630
		return $stmtid;
631
 
632
	}
633
 
634
	/*
635
	  Insert a null into the blob field of the table first.
636
	  Then use UpdateBlob to store the blob.
637
 
638
	  Usage:
639
 
640
	  $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
641
	  $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');
642
	 */
643
	function UpdateBlob($table, $column, $val, $where, $blobtype = 'BLOB')
644
	{
645
		$last_php_error = $this->resetLastError();
646
		$sql = "UPDATE $table SET $column=? WHERE $where";
647
		$stmtid = ads_prepare($this->_connectionID, $sql);
648
		if ($stmtid == false) {
649
			$this->_errorMsg = $this->getChangedErrorMsg($last_php_error);
650
			return false;
651
		}
652
		if (!ads_execute($stmtid, array($val), array(SQL_BINARY))) {
653
			$this->_errorMsg = ads_errormsg();
654
			$this->_errorCode = ads_error();
655
			return false;
656
		}
657
		return true;
658
	}
659
 
660
	// returns true or false
661
	function _close()
662
	{
663
		$ret = @ads_close($this->_connectionID);
664
		$this->_connectionID = false;
665
		return $ret;
666
	}
667
 
668
	function _affectedrows()
669
	{
670
		return $this->_lastAffectedRows;
671
	}
672
 
673
}
674
 
675
/*--------------------------------------------------------------------------------------
676
   Class Name: Recordset
677
--------------------------------------------------------------------------------------*/
678
 
679
class ADORecordSet_ads extends ADORecordSet
680
{
681
 
682
	var $bind = false;
683
	var $databaseType = "ads";
684
	var $dataProvider = "ads";
685
	var $useFetchArray;
686
 
687
	function __construct($id, $mode = false)
688
	{
689
		if ($mode === false) {
690
			global $ADODB_FETCH_MODE;
691
			$mode = $ADODB_FETCH_MODE;
692
		}
693
		$this->fetchMode = $mode;
694
 
695
		$this->_queryID = $id;
696
 
697
		// the following is required for mysql odbc driver in 4.3.1 -- why?
698
		$this->EOF = false;
699
		$this->_currentRow = -1;
700
		//parent::__construct($id);
701
	}
702
 
703
 
704
	// returns the field object
705
	function &FetchField($fieldOffset = -1)
706
	{
707
 
708
		$off = $fieldOffset + 1; // offsets begin at 1
709
 
710
		$o = new ADOFieldObject();
711
		$o->name = @ads_field_name($this->_queryID, $off);
712
		$o->type = @ads_field_type($this->_queryID, $off);
713
		$o->max_length = @ads_field_len($this->_queryID, $off);
714
		if (ADODB_ASSOC_CASE == 0) {
715
			$o->name = strtolower($o->name);
716
		} else {
717
			if (ADODB_ASSOC_CASE == 1) {
718
				$o->name = strtoupper($o->name);
719
			}
720
		}
721
		return $o;
722
	}
723
 
724
	/* Use associative array to get fields array */
725
	function Fields($colname)
726
	{
727
		if ($this->fetchMode & ADODB_FETCH_ASSOC) {
728
			return $this->fields[$colname];
729
		}
730
		if (!$this->bind) {
731
			$this->bind = array();
732
			for ($i = 0; $i < $this->_numOfFields; $i++) {
733
				$o = $this->FetchField($i);
734
				$this->bind[strtoupper($o->name)] = $i;
735
			}
736
		}
737
 
738
		return $this->fields[$this->bind[strtoupper($colname)]];
739
	}
740
 
741
 
742
	function _initrs()
743
	{
744
		global $ADODB_COUNTRECS;
745
		$this->_numOfRows = ($ADODB_COUNTRECS) ? @ads_num_rows($this->_queryID) : -1;
746
		$this->_numOfFields = @ads_num_fields($this->_queryID);
747
		// some silly drivers such as db2 as/400 and intersystems cache return _numOfRows = 0
748
		if ($this->_numOfRows == 0) {
749
			$this->_numOfRows = -1;
750
		}
751
		//$this->useFetchArray = $this->connection->useFetchArray;
752
	}
753
 
754
	function _seek($row)
755
	{
756
		return false;
757
	}
758
 
759
	// speed up SelectLimit() by switching to ADODB_FETCH_NUM as ADODB_FETCH_ASSOC is emulated
760
	function &GetArrayLimit($nrows, $offset = -1)
761
	{
762
		if ($offset <= 0) {
763
			$rs =& $this->GetArray($nrows);
764
			return $rs;
765
		}
766
		$savem = $this->fetchMode;
767
		$this->fetchMode = ADODB_FETCH_NUM;
768
		$this->Move($offset);
769
		$this->fetchMode = $savem;
770
 
771
		if ($this->fetchMode & ADODB_FETCH_ASSOC) {
772
			$this->fields =& $this->GetRowAssoc();
773
		}
774
 
775
		$results = array();
776
		$cnt = 0;
777
		while (!$this->EOF && $nrows != $cnt) {
778
			$results[$cnt++] = $this->fields;
779
			$this->MoveNext();
780
		}
781
 
782
		return $results;
783
	}
784
 
785
 
786
	function MoveNext()
787
	{
788
		if ($this->_numOfRows != 0 && !$this->EOF) {
789
			$this->_currentRow++;
790
			if ($this->_fetch()) {
791
				return true;
792
			}
793
		}
794
		$this->fields = false;
795
		$this->EOF = true;
796
		return false;
797
	}
798
 
799
	function _fetch()
800
	{
801
		$this->fields = false;
802
		$rez = @ads_fetch_into($this->_queryID, $this->fields);
803
		if ($rez) {
804
			if ($this->fetchMode & ADODB_FETCH_ASSOC) {
805
				$this->fields =& $this->GetRowAssoc();
806
			}
807
			return true;
808
		}
809
		return false;
810
	}
811
 
812
	function _close()
813
	{
814
		return @ads_free_result($this->_queryID);
815
	}
816
 
817
}