Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]
1 <?php 2 /* 3 @version v5.21.0 2021-02-27 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 10 Latest version is available at https://adodb.org/ 11 12 Interbase data driver. Requires interbase client. Works on Windows and Unix. 13 14 3 Jan 2002 -- suggestions by Hans-Peter Oeri <kampfcaspar75@oeri.ch> 15 changed transaction handling and added experimental blob stuff 16 17 Docs to interbase at the website 18 http://www.synectics.co.za/php3/tutorial/IB_PHP3_API.html 19 20 To use gen_id(), see 21 http://www.volny.cz/iprenosil/interbase/ip_ib_code.htm#_code_creategen 22 23 $rs = $conn->Execute('select gen_id(adodb,1) from rdb$database'); 24 $id = $rs->fields[0]; 25 $conn->Execute("insert into table (id, col1,...) values ($id, $val1,...)"); 26 */ 27 28 // security - hide paths 29 if (!defined('ADODB_DIR')) die(); 30 31 class ADODB_ibase extends ADOConnection { 32 var $databaseType = "ibase"; 33 var $dataProvider = "ibase"; 34 var $replaceQuote = "''"; // string to use to replace quotes 35 var $ibase_datefmt = '%Y-%m-%d'; // For hours,mins,secs change to '%Y-%m-%d %H:%M:%S'; 36 var $fmtDate = "'Y-m-d'"; 37 var $ibase_timestampfmt = "%Y-%m-%d %H:%M:%S"; 38 var $ibase_timefmt = "%H:%M:%S"; 39 var $fmtTimeStamp = "'Y-m-d, H:i:s'"; 40 var $concat_operator='||'; 41 var $_transactionID; 42 var $metaTablesSQL = "select rdb\$relation_name from rdb\$relations where rdb\$relation_name not like 'RDB\$%'"; 43 //OPN STUFF start 44 var $metaColumnsSQL = "select a.rdb\$field_name, a.rdb\$null_flag, a.rdb\$default_source, b.rdb\$field_length, b.rdb\$field_scale, b.rdb\$field_sub_type, b.rdb\$field_precision, b.rdb\$field_type from rdb\$relation_fields a, rdb\$fields b where a.rdb\$field_source = b.rdb\$field_name and a.rdb\$relation_name = '%s' order by a.rdb\$field_position asc"; 45 //OPN STUFF end 46 var $ibasetrans; 47 var $hasGenID = true; 48 var $_bindInputArray = true; 49 var $buffers = 0; 50 var $dialect = 1; 51 var $sysDate = "cast('TODAY' as timestamp)"; 52 var $sysTimeStamp = "CURRENT_TIMESTAMP"; //"cast('NOW' as timestamp)"; 53 var $ansiOuter = true; 54 var $hasAffectedRows = false; 55 var $poorAffectedRows = true; 56 var $blobEncodeType = 'C'; 57 var $role = false; 58 59 function __construct() 60 { 61 if (defined('IBASE_DEFAULT')) $this->ibasetrans = IBASE_DEFAULT; 62 } 63 64 65 // returns true or false 66 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename,$persist=false) 67 { 68 if (!function_exists('ibase_pconnect')) return null; 69 if ($argDatabasename) $argHostname .= ':'.$argDatabasename; 70 $fn = ($persist) ? 'ibase_pconnect':'ibase_connect'; 71 if ($this->role) 72 $this->_connectionID = $fn($argHostname,$argUsername,$argPassword, 73 $this->charSet,$this->buffers,$this->dialect,$this->role); 74 else 75 $this->_connectionID = $fn($argHostname,$argUsername,$argPassword, 76 $this->charSet,$this->buffers,$this->dialect); 77 78 if ($this->dialect != 1) { // http://www.ibphoenix.com/ibp_60_del_id_ds.html 79 $this->replaceQuote = "''"; 80 } 81 if ($this->_connectionID === false) { 82 $this->_handleerror(); 83 return false; 84 } 85 86 // PHP5 change. 87 if (function_exists('ibase_timefmt')) { 88 ibase_timefmt($this->ibase_datefmt,IBASE_DATE ); 89 if ($this->dialect == 1) { 90 ibase_timefmt($this->ibase_datefmt,IBASE_TIMESTAMP ); 91 } 92 else { 93 ibase_timefmt($this->ibase_timestampfmt,IBASE_TIMESTAMP ); 94 } 95 ibase_timefmt($this->ibase_timefmt,IBASE_TIME ); 96 97 } else { 98 ini_set("ibase.timestampformat", $this->ibase_timestampfmt); 99 ini_set("ibase.dateformat", $this->ibase_datefmt); 100 ini_set("ibase.timeformat", $this->ibase_timefmt); 101 } 102 return true; 103 } 104 105 // returns true or false 106 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) 107 { 108 return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename,true); 109 } 110 111 112 function MetaPrimaryKeys($table,$owner_notused=false,$internalKey=false) 113 { 114 if ($internalKey) { 115 return array('RDB$DB_KEY'); 116 } 117 118 $table = strtoupper($table); 119 120 $sql = 'SELECT S.RDB$FIELD_NAME AFIELDNAME 121 FROM RDB$INDICES I JOIN RDB$INDEX_SEGMENTS S ON I.RDB$INDEX_NAME=S.RDB$INDEX_NAME 122 WHERE I.RDB$RELATION_NAME=\''.$table.'\' and I.RDB$INDEX_NAME like \'RDB$PRIMARY%\' 123 ORDER BY I.RDB$INDEX_NAME,S.RDB$FIELD_POSITION'; 124 125 $a = $this->GetCol($sql,false,true); 126 if ($a && sizeof($a)>0) return $a; 127 return false; 128 } 129 130 function ServerInfo() 131 { 132 $arr['dialect'] = $this->dialect; 133 switch($arr['dialect']) { 134 case '': 135 case '1': $s = 'Interbase 5.5 or earlier'; break; 136 case '2': $s = 'Interbase 5.6'; break; 137 default: 138 case '3': $s = 'Interbase 6.0'; break; 139 } 140 $arr['version'] = ADOConnection::_findvers($s); 141 $arr['description'] = $s; 142 return $arr; 143 } 144 145 function BeginTrans() 146 { 147 if ($this->transOff) return true; 148 $this->transCnt += 1; 149 $this->autoCommit = false; 150 $this->_transactionID = $this->_connectionID;//ibase_trans($this->ibasetrans, $this->_connectionID); 151 return $this->_transactionID; 152 } 153 154 function CommitTrans($ok=true) 155 { 156 if (!$ok) { 157 return $this->RollbackTrans(); 158 } 159 if ($this->transOff) { 160 return true; 161 } 162 if ($this->transCnt) { 163 $this->transCnt -= 1; 164 } 165 $ret = false; 166 $this->autoCommit = true; 167 if ($this->_transactionID) { 168 //print ' commit '; 169 $ret = ibase_commit($this->_transactionID); 170 } 171 $this->_transactionID = false; 172 return $ret; 173 } 174 175 // there are some compat problems with ADODB_COUNTRECS=false and $this->_logsql currently. 176 // it appears that ibase extension cannot support multiple concurrent queryid's 177 function _Execute($sql,$inputarr=false) 178 { 179 global $ADODB_COUNTRECS; 180 181 if ($this->_logsql) { 182 $savecrecs = $ADODB_COUNTRECS; 183 $ADODB_COUNTRECS = true; // force countrecs 184 $ret = ADOConnection::_Execute($sql,$inputarr); 185 $ADODB_COUNTRECS = $savecrecs; 186 } else { 187 $ret = ADOConnection::_Execute($sql,$inputarr); 188 } 189 return $ret; 190 } 191 192 function RollbackTrans() 193 { 194 if ($this->transOff) return true; 195 if ($this->transCnt) $this->transCnt -= 1; 196 $ret = false; 197 $this->autoCommit = true; 198 if ($this->_transactionID) { 199 $ret = ibase_rollback($this->_transactionID); 200 } 201 $this->_transactionID = false; 202 203 return $ret; 204 } 205 206 function MetaIndexes ($table, $primary = FALSE, $owner=false) 207 { 208 // save old fetch mode 209 global $ADODB_FETCH_MODE; 210 $false = false; 211 $save = $ADODB_FETCH_MODE; 212 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 213 if ($this->fetchMode !== FALSE) { 214 $savem = $this->SetFetchMode(FALSE); 215 } 216 $table = strtoupper($table); 217 $sql = "SELECT * FROM RDB\$INDICES WHERE RDB\$RELATION_NAME = '".$table."'"; 218 if (!$primary) { 219 $sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$%'"; 220 } else { 221 $sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$FOREIGN%'"; 222 } 223 // get index details 224 $rs = $this->Execute($sql); 225 if (!is_object($rs)) { 226 // restore fetchmode 227 if (isset($savem)) { 228 $this->SetFetchMode($savem); 229 } 230 $ADODB_FETCH_MODE = $save; 231 return $false; 232 } 233 234 $indexes = array(); 235 while ($row = $rs->FetchRow()) { 236 $index = $row[0]; 237 if (!isset($indexes[$index])) { 238 if (is_null($row[3])) { 239 $row[3] = 0; 240 } 241 $indexes[$index] = array( 242 'unique' => ($row[3] == 1), 243 'columns' => array() 244 ); 245 } 246 $sql = "SELECT * FROM RDB\$INDEX_SEGMENTS WHERE RDB\$INDEX_NAME = '".$index."' ORDER BY RDB\$FIELD_POSITION ASC"; 247 $rs1 = $this->Execute($sql); 248 while ($row1 = $rs1->FetchRow()) { 249 $indexes[$index]['columns'][$row1[2]] = $row1[1]; 250 } 251 } 252 // restore fetchmode 253 if (isset($savem)) { 254 $this->SetFetchMode($savem); 255 } 256 $ADODB_FETCH_MODE = $save; 257 258 return $indexes; 259 } 260 261 262 // See http://community.borland.com/article/0,1410,25844,00.html 263 function RowLock($tables,$where,$col=false) 264 { 265 if ($this->autoCommit) { 266 $this->BeginTrans(); 267 } 268 $this->Execute("UPDATE $table SET $col=$col WHERE $where "); // is this correct - jlim? 269 return 1; 270 } 271 272 273 function CreateSequence($seqname = 'adodbseq', $startID = 1) 274 { 275 $ok = $this->Execute(("INSERT INTO RDB\$GENERATORS (RDB\$GENERATOR_NAME) VALUES (UPPER('$seqname'))" )); 276 if (!$ok) return false; 277 return $this->Execute("SET GENERATOR $seqname TO ".($startID-1).';'); 278 } 279 280 function DropSequence($seqname = 'adodbseq') 281 { 282 $seqname = strtoupper($seqname); 283 $this->Execute("delete from RDB\$GENERATORS where RDB\$GENERATOR_NAME='$seqname'"); 284 } 285 286 function GenID($seqname='adodbseq',$startID=1) 287 { 288 $getnext = ("SELECT Gen_ID($seqname,1) FROM RDB\$DATABASE"); 289 $rs = @$this->Execute($getnext); 290 if (!$rs) { 291 $this->Execute(("INSERT INTO RDB\$GENERATORS (RDB\$GENERATOR_NAME) VALUES (UPPER('$seqname'))" )); 292 $this->Execute("SET GENERATOR $seqname TO ".($startID-1).';'); 293 $rs = $this->Execute($getnext); 294 } 295 if ($rs && !$rs->EOF) { 296 $this->genID = (integer) reset($rs->fields); 297 } 298 else { 299 $this->genID = 0; // false 300 } 301 302 if ($rs) { 303 $rs->Close(); 304 } 305 306 return $this->genID; 307 } 308 309 function SelectDB($dbName) 310 { 311 return false; 312 } 313 314 function _handleerror() 315 { 316 $this->_errorMsg = ibase_errmsg(); 317 } 318 319 function ErrorNo() 320 { 321 if (preg_match('/error code = ([\-0-9]*)/i', $this->_errorMsg,$arr)) return (integer) $arr[1]; 322 else return 0; 323 } 324 325 function ErrorMsg() 326 { 327 return $this->_errorMsg; 328 } 329 330 function Prepare($sql) 331 { 332 $stmt = ibase_prepare($this->_connectionID,$sql); 333 if (!$stmt) return false; 334 return array($sql,$stmt); 335 } 336 337 // returns query ID if successful, otherwise false 338 // there have been reports of problems with nested queries - the code is probably not re-entrant? 339 function _query($sql,$iarr=false) 340 { 341 342 if (!$this->autoCommit && $this->_transactionID) { 343 $conn = $this->_transactionID; 344 $docommit = false; 345 } else { 346 $conn = $this->_connectionID; 347 $docommit = true; 348 } 349 if (is_array($sql)) { 350 $fn = 'ibase_execute'; 351 $sql = $sql[1]; 352 if (is_array($iarr)) { 353 if ( !isset($iarr[0]) ) 354 $iarr[0] = ''; // PHP5 compat hack 355 $fnarr = array_merge( array($sql) , $iarr); 356 $ret = call_user_func_array($fn,$fnarr); 357 } 358 else { 359 $ret = $fn($sql); 360 } 361 } else { 362 $fn = 'ibase_query'; 363 364 if (is_array($iarr)) { 365 if (sizeof($iarr) == 0) 366 $iarr[0] = ''; // PHP5 compat hack 367 $fnarr = array_merge( array($conn,$sql) , $iarr); 368 $ret = call_user_func_array($fn,$fnarr); 369 } 370 else { 371 $ret = $fn($conn, $sql); 372 } 373 } 374 if ($docommit && $ret === true) { 375 ibase_commit($this->_connectionID); 376 } 377 378 $this->_handleerror(); 379 return $ret; 380 } 381 382 // returns true or false 383 function _close() 384 { 385 if (!$this->autoCommit) { 386 @ibase_rollback($this->_connectionID); 387 } 388 return @ibase_close($this->_connectionID); 389 } 390 391 //OPN STUFF start 392 function _ConvertFieldType(&$fld, $ftype, $flen, $fscale, $fsubtype, $fprecision, $dialect3) 393 { 394 $fscale = abs($fscale); 395 $fld->max_length = $flen; 396 $fld->scale = null; 397 switch($ftype){ 398 case 7: 399 case 8: 400 if ($dialect3) { 401 switch($fsubtype){ 402 case 0: 403 $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); 404 break; 405 case 1: 406 $fld->type = 'numeric'; 407 $fld->max_length = $fprecision; 408 $fld->scale = $fscale; 409 break; 410 case 2: 411 $fld->type = 'decimal'; 412 $fld->max_length = $fprecision; 413 $fld->scale = $fscale; 414 break; 415 } // switch 416 } else { 417 if ($fscale !=0) { 418 $fld->type = 'decimal'; 419 $fld->scale = $fscale; 420 $fld->max_length = ($ftype == 7 ? 4 : 9); 421 } else { 422 $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); 423 } 424 } 425 break; 426 case 16: 427 if ($dialect3) { 428 switch($fsubtype){ 429 case 0: 430 $fld->type = 'decimal'; 431 $fld->max_length = 18; 432 $fld->scale = 0; 433 break; 434 case 1: 435 $fld->type = 'numeric'; 436 $fld->max_length = $fprecision; 437 $fld->scale = $fscale; 438 break; 439 case 2: 440 $fld->type = 'decimal'; 441 $fld->max_length = $fprecision; 442 $fld->scale = $fscale; 443 break; 444 } // switch 445 } 446 break; 447 case 10: 448 $fld->type = 'float'; 449 break; 450 case 14: 451 $fld->type = 'char'; 452 break; 453 case 27: 454 if ($fscale !=0) { 455 $fld->type = 'decimal'; 456 $fld->max_length = 15; 457 $fld->scale = 5; 458 } else { 459 $fld->type = 'double'; 460 } 461 break; 462 case 35: 463 if ($dialect3) { 464 $fld->type = 'timestamp'; 465 } else { 466 $fld->type = 'date'; 467 } 468 break; 469 case 12: 470 $fld->type = 'date'; 471 break; 472 case 13: 473 $fld->type = 'time'; 474 break; 475 case 37: 476 $fld->type = 'varchar'; 477 break; 478 case 40: 479 $fld->type = 'cstring'; 480 break; 481 case 261: 482 $fld->type = 'blob'; 483 $fld->max_length = -1; 484 break; 485 } // switch 486 } 487 //OPN STUFF end 488 489 // returns array of ADOFieldObjects for current table 490 function MetaColumns($table, $normalize=true) 491 { 492 global $ADODB_FETCH_MODE; 493 494 $save = $ADODB_FETCH_MODE; 495 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 496 497 $rs = $this->Execute(sprintf($this->metaColumnsSQL,strtoupper($table))); 498 499 $ADODB_FETCH_MODE = $save; 500 $false = false; 501 if ($rs === false) { 502 return $false; 503 } 504 505 $retarr = array(); 506 //OPN STUFF start 507 $dialect3 = ($this->dialect==3 ? true : false); 508 //OPN STUFF end 509 while (!$rs->EOF) { //print_r($rs->fields); 510 $fld = new ADOFieldObject(); 511 $fld->name = trim($rs->fields[0]); 512 //OPN STUFF start 513 $this->_ConvertFieldType($fld, $rs->fields[7], $rs->fields[3], $rs->fields[4], $rs->fields[5], $rs->fields[6], $dialect3); 514 if (isset($rs->fields[1]) && $rs->fields[1]) { 515 $fld->not_null = true; 516 } 517 if (isset($rs->fields[2])) { 518 519 $fld->has_default = true; 520 $d = substr($rs->fields[2],strlen('default ')); 521 switch ($fld->type) 522 { 523 case 'smallint': 524 case 'integer': $fld->default_value = (int) $d; break; 525 case 'char': 526 case 'blob': 527 case 'text': 528 case 'varchar': $fld->default_value = (string) substr($d,1,strlen($d)-2); break; 529 case 'double': 530 case 'float': $fld->default_value = (float) $d; break; 531 default: $fld->default_value = $d; break; 532 } 533 // case 35:$tt = 'TIMESTAMP'; break; 534 } 535 if ((isset($rs->fields[5])) && ($fld->type == 'blob')) { 536 $fld->sub_type = $rs->fields[5]; 537 } else { 538 $fld->sub_type = null; 539 } 540 //OPN STUFF end 541 if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; 542 else $retarr[strtoupper($fld->name)] = $fld; 543 544 $rs->MoveNext(); 545 } 546 $rs->Close(); 547 if ( empty($retarr)) return $false; 548 else return $retarr; 549 } 550 551 function BlobEncode( $blob ) 552 { 553 $blobid = ibase_blob_create( $this->_connectionID); 554 ibase_blob_add( $blobid, $blob ); 555 return ibase_blob_close( $blobid ); 556 } 557 558 // since we auto-decode all blob's since 2.42, 559 // BlobDecode should not do any transforms 560 function BlobDecode($blob) 561 { 562 return $blob; 563 } 564 565 566 567 568 // old blobdecode function 569 // still used to auto-decode all blob's 570 function _BlobDecode_old( $blob ) 571 { 572 $blobid = ibase_blob_open($this->_connectionID, $blob ); 573 $realblob = ibase_blob_get( $blobid,$this->maxblobsize); // 2nd param is max size of blob -- Kevin Boillet <kevinboillet@yahoo.fr> 574 while($string = ibase_blob_get($blobid, 8192)){ 575 $realblob .= $string; 576 } 577 ibase_blob_close( $blobid ); 578 579 return( $realblob ); 580 } 581 582 function _BlobDecode( $blob ) 583 { 584 $blob_data = ibase_blob_info($this->_connectionID, $blob ); 585 $blobid = ibase_blob_open($this->_connectionID, $blob ); 586 587 if( $blob_data[0] > $this->maxblobsize ) { 588 589 $realblob = ibase_blob_get($blobid, $this->maxblobsize); 590 591 while($string = ibase_blob_get($blobid, 8192)){ 592 $realblob .= $string; 593 } 594 } else { 595 $realblob = ibase_blob_get($blobid, $blob_data[0]); 596 } 597 598 ibase_blob_close( $blobid ); 599 return( $realblob ); 600 } 601 602 function UpdateBlobFile($table,$column,$path,$where,$blobtype='BLOB') 603 { 604 $fd = fopen($path,'rb'); 605 if ($fd === false) return false; 606 $blob_id = ibase_blob_create($this->_connectionID); 607 608 /* fill with data */ 609 610 while ($val = fread($fd,32768)){ 611 ibase_blob_add($blob_id, $val); 612 } 613 614 /* close and get $blob_id_str for inserting into table */ 615 $blob_id_str = ibase_blob_close($blob_id); 616 617 fclose($fd); 618 return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; 619 } 620 621 /* 622 Insert a null into the blob field of the table first. 623 Then use UpdateBlob to store the blob. 624 625 Usage: 626 627 $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); 628 $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); 629 */ 630 function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB') 631 { 632 $blob_id = ibase_blob_create($this->_connectionID); 633 634 // ibase_blob_add($blob_id, $val); 635 636 // replacement that solves the problem by which only the first modulus 64K / 637 // of $val are stored at the blob field //////////////////////////////////// 638 // Thx Abel Berenstein aberenstein#afip.gov.ar 639 $len = strlen($val); 640 $chunk_size = 32768; 641 $tail_size = $len % $chunk_size; 642 $n_chunks = ($len - $tail_size) / $chunk_size; 643 644 for ($n = 0; $n < $n_chunks; $n++) { 645 $start = $n * $chunk_size; 646 $data = substr($val, $start, $chunk_size); 647 ibase_blob_add($blob_id, $data); 648 } 649 650 if ($tail_size) { 651 $start = $n_chunks * $chunk_size; 652 $data = substr($val, $start, $tail_size); 653 ibase_blob_add($blob_id, $data); 654 } 655 // end replacement ///////////////////////////////////////////////////////// 656 657 $blob_id_str = ibase_blob_close($blob_id); 658 659 return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; 660 661 } 662 663 664 function OldUpdateBlob($table,$column,$val,$where,$blobtype='BLOB') 665 { 666 $blob_id = ibase_blob_create($this->_connectionID); 667 ibase_blob_add($blob_id, $val); 668 $blob_id_str = ibase_blob_close($blob_id); 669 return $this->Execute("UPDATE $table SET $column=(?) WHERE $where",array($blob_id_str)) != false; 670 } 671 672 // Format date column in sql string given an input format that understands Y M D 673 // Only since Interbase 6.0 - uses EXTRACT 674 // problem - does not zero-fill the day and month yet 675 function SQLDate($fmt, $col=false) 676 { 677 if (!$col) $col = $this->sysDate; 678 $s = ''; 679 680 $len = strlen($fmt); 681 for ($i=0; $i < $len; $i++) { 682 if ($s) $s .= '||'; 683 $ch = $fmt[$i]; 684 switch($ch) { 685 case 'Y': 686 case 'y': 687 $s .= "extract(year from $col)"; 688 break; 689 case 'M': 690 case 'm': 691 $s .= "extract(month from $col)"; 692 break; 693 case 'Q': 694 case 'q': 695 $s .= "cast(((extract(month from $col)+2) / 3) as integer)"; 696 break; 697 case 'D': 698 case 'd': 699 $s .= "(extract(day from $col))"; 700 break; 701 case 'H': 702 case 'h': 703 $s .= "(extract(hour from $col))"; 704 break; 705 case 'I': 706 case 'i': 707 $s .= "(extract(minute from $col))"; 708 break; 709 case 'S': 710 case 's': 711 $s .= "CAST((extract(second from $col)) AS INTEGER)"; 712 break; 713 714 default: 715 if ($ch == '\\') { 716 $i++; 717 $ch = substr($fmt,$i,1); 718 } 719 $s .= $this->qstr($ch); 720 break; 721 } 722 } 723 return $s; 724 } 725 } 726 727 /*-------------------------------------------------------------------------------------- 728 Class Name: Recordset 729 --------------------------------------------------------------------------------------*/ 730 731 class ADORecordset_ibase extends ADORecordSet 732 { 733 734 var $databaseType = "ibase"; 735 var $bind=false; 736 var $_cacheType; 737 738 function __construct($id,$mode=false) 739 { 740 global $ADODB_FETCH_MODE; 741 742 $this->fetchMode = ($mode === false) ? $ADODB_FETCH_MODE : $mode; 743 parent::__construct($id); 744 } 745 746 /* Returns: an object containing field information. 747 Get column information in the Recordset object. fetchField() can be used in order to obtain information about 748 fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by 749 fetchField() is retrieved. */ 750 751 function FetchField($fieldOffset = -1) 752 { 753 $fld = new ADOFieldObject; 754 $ibf = ibase_field_info($this->_queryID,$fieldOffset); 755 756 $name = empty($ibf['alias']) ? $ibf['name'] : $ibf['alias']; 757 758 switch (ADODB_ASSOC_CASE) { 759 case ADODB_ASSOC_CASE_UPPER: 760 $fld->name = strtoupper($name); 761 break; 762 case ADODB_ASSOC_CASE_LOWER: 763 $fld->name = strtolower($name); 764 break; 765 case ADODB_ASSOC_CASE_NATIVE: 766 default: 767 $fld->name = $name; 768 break; 769 } 770 771 $fld->type = $ibf['type']; 772 $fld->max_length = $ibf['length']; 773 774 /* This needs to be populated from the metadata */ 775 $fld->not_null = false; 776 $fld->has_default = false; 777 $fld->default_value = 'null'; 778 return $fld; 779 } 780 781 function _initrs() 782 { 783 $this->_numOfRows = -1; 784 $this->_numOfFields = @ibase_num_fields($this->_queryID); 785 786 // cache types for blob decode check 787 for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { 788 $f1 = $this->FetchField($i); 789 $this->_cacheType[] = $f1->type; 790 } 791 } 792 793 function _seek($row) 794 { 795 return false; 796 } 797 798 function _fetch() 799 { 800 $f = @ibase_fetch_row($this->_queryID); 801 if ($f === false) { 802 $this->fields = false; 803 return false; 804 } 805 // OPN stuff start - optimized 806 // fix missing nulls and decode blobs automatically 807 808 global $ADODB_ANSI_PADDING_OFF; 809 //$ADODB_ANSI_PADDING_OFF=1; 810 $rtrim = !empty($ADODB_ANSI_PADDING_OFF); 811 812 for ($i=0, $max = $this->_numOfFields; $i < $max; $i++) { 813 if ($this->_cacheType[$i]=="BLOB") { 814 if (isset($f[$i])) { 815 $f[$i] = $this->connection->_BlobDecode($f[$i]); 816 } else { 817 $f[$i] = null; 818 } 819 } else { 820 if (!isset($f[$i])) { 821 $f[$i] = null; 822 } else if ($rtrim && is_string($f[$i])) { 823 $f[$i] = rtrim($f[$i]); 824 } 825 } 826 } 827 // OPN stuff end 828 829 $this->fields = $f; 830 if ($this->fetchMode == ADODB_FETCH_ASSOC) { 831 $this->fields = $this->GetRowAssoc(); 832 } else if ($this->fetchMode == ADODB_FETCH_BOTH) { 833 $this->fields = array_merge($this->fields,$this->GetRowAssoc()); 834 } 835 return true; 836 } 837 838 /* Use associative array to get fields array */ 839 function Fields($colname) 840 { 841 if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; 842 if (!$this->bind) { 843 $this->bind = array(); 844 for ($i=0; $i < $this->_numOfFields; $i++) { 845 $o = $this->FetchField($i); 846 $this->bind[strtoupper($o->name)] = $i; 847 } 848 } 849 850 return $this->fields[$this->bind[strtoupper($colname)]]; 851 852 } 853 854 855 function _close() 856 { 857 return @ibase_free_result($this->_queryID); 858 } 859 860 function MetaType($t,$len=-1,$fieldobj=false) 861 { 862 if (is_object($t)) { 863 $fieldobj = $t; 864 $t = $fieldobj->type; 865 $len = $fieldobj->max_length; 866 } 867 switch (strtoupper($t)) { 868 case 'CHAR': 869 return 'C'; 870 871 case 'TEXT': 872 case 'VARCHAR': 873 case 'VARYING': 874 if ($len <= $this->blobSize) return 'C'; 875 return 'X'; 876 case 'BLOB': 877 return 'B'; 878 879 case 'TIMESTAMP': 880 case 'DATE': return 'D'; 881 case 'TIME': return 'T'; 882 //case 'T': return 'T'; 883 884 //case 'L': return 'L'; 885 case 'INT': 886 case 'SHORT': 887 case 'INTEGER': return 'I'; 888 default: return ADODB_DEFAULT_METATYPE; 889 } 890 } 891 892 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body