Changeset 34 for trunk/phpgwapi/inc/adodb/drivers/adodb-odbtp.inc.php
- Timestamp:
- 06/29/07 15:17:46 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpgwapi/inc/adodb/drivers/adodb-odbtp.inc.php
r2 r34 1 1 <?php 2 2 /* 3 V4.51 29 July 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.3 V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. 4 4 Released under both BSD license and Lesser GPL library license. 5 5 Whenever there is any discrepancy between the two licenses, … … 29 29 var $_genSeqSQL = "create table %s (seq_name char(30) not null unique , seq_value integer not null)"; 30 30 var $_dropSeqSQL = "delete from adodb_seq where seq_name = '%s'"; 31 var $_autocommit = true;32 31 var $_bindInputArray = false; 33 32 var $_useUnicodeSQL = false; 34 33 var $_canPrepareSP = false; 34 var $_dontPoolDBC = true; 35 35 36 36 function ADODB_odbtp() … … 107 107 { 108 108 $seqtab='adodb_seq'; 109 if( $this->odbc_driver == ODB_DRIVER_FOXPRO 109 if( $this->odbc_driver == ODB_DRIVER_FOXPRO) { 110 110 $path = @odbtp_get_attr( ODB_ATTR_DATABASENAME, $this->_connectionID ); 111 111 //if using vfp dbc file … … 150 150 function _connect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='') 151 151 { 152 $this->_connectionID = @odbtp_connect($HostOrInterface,$UserOrDSN,$argPassword,$argDatabase); 153 if ($this->_connectionID === false) 154 { 152 $this->_connectionID = odbtp_connect($HostOrInterface,$UserOrDSN,$argPassword,$argDatabase); 153 if ($this->_connectionID === false) { 155 154 $this->_errorMsg = $this->ErrorMsg() ; 156 155 return false; 157 156 } 157 158 odbtp_convert_datetime($this->_connectionID,true); 159 160 if ($this->_dontPoolDBC) { 161 if (function_exists('odbtp_dont_pool_dbc')) 162 @odbtp_dont_pool_dbc($this->_connectionID); 163 } 164 else { 165 $this->_dontPoolDBC = true; 166 } 158 167 $this->odbc_driver = @odbtp_get_attr(ODB_ATTR_DRIVER, $this->_connectionID); 159 160 // Set driver specific attributes 161 switch( $this->odbc_driver ) { 162 case ODB_DRIVER_MSSQL: 168 $dbms = strtolower(@odbtp_get_attr(ODB_ATTR_DBMSNAME, $this->_connectionID)); 169 $this->odbc_name = $dbms; 170 171 // Account for inconsistent DBMS names 172 if( $this->odbc_driver == ODB_DRIVER_ORACLE ) 173 $dbms = 'oracle'; 174 else if( $this->odbc_driver == ODB_DRIVER_SYBASE ) 175 $dbms = 'sybase'; 176 177 // Set DBMS specific attributes 178 switch( $dbms ) { 179 case 'microsoft sql server': 180 $this->databaseType = 'odbtp_mssql'; 163 181 $this->fmtDate = "'Y-m-d'"; 164 182 $this->fmtTimeStamp = "'Y-m-d h:i:sA'"; … … 177 195 $this->identitySQL = 'select @@IDENTITY'; 178 196 $this->metaDatabasesSQL = "select name from master..sysdatabases where name <> 'master'"; 197 $this->_canPrepareSP = true; 179 198 break; 180 case ODB_DRIVER_JET: 199 case 'access': 200 $this->databaseType = 'odbtp_access'; 181 201 $this->fmtDate = "#Y-m-d#"; 182 202 $this->fmtTimeStamp = "#Y-m-d h:i:sA#"; … … 186 206 $this->hasTransactions = false; 187 207 $this->_canPrepareSP = true; // For MS Access only. 188 189 // Can't rebind ODB_CHAR to ODB_WCHAR if row cache enabled.190 if ($this->_useUnicodeSQL)191 odbtp_use_row_cache($this->_connectionID, FALSE, 0);192 208 break; 193 case ODB_DRIVER_FOXPRO: 209 case 'visual foxpro': 210 $this->databaseType = 'odbtp_vfp'; 194 211 $this->fmtDate = "{^Y-m-d}"; 195 212 $this->fmtTimeStamp = "{^Y-m-d, h:i:sA}"; … … 198 215 $this->ansiOuter = true; 199 216 $this->hasTop = 'top'; 200 $this->hasTransactions = false;217 $this->hasTransactions = false; 201 218 $this->replaceQuote = "'+chr(39)+'"; 202 219 $this->true = '.T.'; 203 220 $this->false = '.F.'; 221 204 222 break; 205 case ODB_DRIVER_ORACLE: 223 case 'oracle': 224 $this->databaseType = 'odbtp_oci8'; 206 225 $this->fmtDate = "'Y-m-d 00:00:00'"; 207 226 $this->fmtTimeStamp = "'Y-m-d h:i:sA'"; … … 212 231 $this->concat_operator = '||'; 213 232 break; 214 case ODB_DRIVER_SYBASE: 233 case 'sybase': 234 $this->databaseType = 'odbtp_sybase'; 215 235 $this->fmtDate = "'Y-m-d'"; 216 236 $this->fmtTimeStamp = "'Y-m-d H:i:s'"; … … 224 244 break; 225 245 default: 246 $this->databaseType = 'odbtp'; 226 247 if( @odbtp_get_attr(ODB_ATTR_TXNCAPABLE, $this->_connectionID) ) 227 $this->hasTransactions = true;248 $this->hasTransactions = true; 228 249 else 229 250 $this->hasTransactions = false; 230 251 } 231 252 @odbtp_set_attr(ODB_ATTR_FULLCOLINFO, TRUE, $this->_connectionID ); 253 232 254 if ($this->_useUnicodeSQL ) 233 255 @odbtp_set_attr(ODB_ATTR_UNICODESQL, TRUE, $this->_connectionID); 256 234 257 return true; 235 258 } 236 259 237 260 function _pconnect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='') 238 261 { 262 $this->_dontPoolDBC = false; 239 263 return $this->_connect($HostOrInterface, $UserOrDSN, $argPassword, $argDatabase); 240 264 } 241 265 242 266 function SelectDB($dbName) 243 267 { … … 245 269 return false; 246 270 } 247 $this->databaseName = $dbName; 271 $this->database = $dbName; 272 $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions 248 273 return true; 249 274 } … … 255 280 $savem = $ADODB_FETCH_MODE; 256 281 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 282 if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false); 283 257 284 $arr =& $this->GetArray("||SQLTables||||$ttype"); 285 286 if (isset($savefm)) $this->SetFetchMode($savefm); 258 287 $ADODB_FETCH_MODE = $savem; 259 288 … … 262 291 if ($arr[$i][3] == 'SYSTEM TABLE' ) continue; 263 292 if ($arr[$i][2]) 264 $arr2[] = $showSchema ? $arr[$i][1].'.'.$arr[$i][2] : $arr[$i][2];293 $arr2[] = $showSchema && $arr[$i][1]? $arr[$i][1].'.'.$arr[$i][2] : $arr[$i][2]; 265 294 } 266 295 return $arr2; … … 277 306 $savem = $ADODB_FETCH_MODE; 278 307 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 308 if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false); 309 279 310 $rs = $this->Execute( "||SQLColumns||$schema|$table" ); 311 312 if (isset($savefm)) $this->SetFetchMode($savefm); 280 313 $ADODB_FETCH_MODE = $savem; 281 314 282 if (!$rs) return false; 283 315 if (!$rs || $rs->EOF) { 316 $false = false; 317 return $false; 318 } 319 $retarr = array(); 284 320 while (!$rs->EOF) { 285 321 //print_r($rs->fields); … … 291 327 $fld->not_null = !empty($rs->fields[9]); 292 328 $fld->scale = $rs->fields[7]; 293 if (!is_null($rs->fields[12])) { 294 $fld->has_default = true; 295 $fld->default_value = $rs->fields[12]; 296 } 329 if (isset($rs->fields[12])) // vfp does not have field 12 330 if (!is_null($rs->fields[12])) { 331 $fld->has_default = true; 332 $fld->default_value = $rs->fields[12]; 333 } 297 334 $retarr[strtoupper($fld->name)] = $fld; 298 } else if ( sizeof($retarr)>0)335 } else if (!empty($retarr)) 299 336 break; 300 337 $rs->MoveNext(); 301 338 } 302 $rs->Close(); 339 $rs->Close(); 303 340 304 341 return $retarr; … … 336 373 $arr[$constr[11]][$constr[2]][] = $constr[7].'='.$constr[3]; 337 374 } 338 if (!$arr) return false; 339 375 if (!$arr) { 376 $false = false; 377 return $false; 378 } 379 340 380 $arr2 = array(); 341 381 … … 354 394 if ($this->transOff) return true; 355 395 $this->transCnt += 1; 356 $this->_autocommit = false; 357 $rs = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS,ODB_TXN_READUNCOMMITTED,$this->_connectionID); 396 $this->autoCommit = false; 397 if (defined('ODB_TXN_DEFAULT')) 398 $txn = ODB_TXN_DEFAULT; 399 else 400 $txn = ODB_TXN_READUNCOMMITTED; 401 $rs = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS,$txn,$this->_connectionID); 358 402 if(!$rs) return false; 359 elsereturn true;403 return true; 360 404 } 361 405 … … 365 409 if (!$ok) return $this->RollbackTrans(); 366 410 if ($this->transCnt) $this->transCnt -= 1; 367 $this-> _autocommit = true;368 if( ($ret = odbtp_commit($this->_connectionID)) )411 $this->autoCommit = true; 412 if( ($ret = @odbtp_commit($this->_connectionID)) ) 369 413 $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off 370 414 return $ret; … … 375 419 if ($this->transOff) return true; 376 420 if ($this->transCnt) $this->transCnt -= 1; 377 $this-> _autocommit = true;378 if( ($ret = odbtp_rollback($this->_connectionID)) )421 $this->autoCommit = true; 422 if( ($ret = @odbtp_rollback($this->_connectionID)) ) 379 423 $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off 380 424 return $ret; … … 387 431 if (!preg_match('/ORDER[ \t\r\n]+BY/is',$sql)) $sql .= ' ORDER BY 1'; 388 432 } 389 return ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); 433 $ret =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); 434 return $ret; 390 435 } 391 436 … … 393 438 { 394 439 if (! $this->_bindInputArray) return $sql; // no binding 395 $stmt = odbtp_prepare($sql,$this->_connectionID);440 $stmt = @odbtp_prepare($sql,$this->_connectionID); 396 441 if (!$stmt) { 397 442 // print "Prepare Error for ($sql) ".$this->ErrorMsg()."<br>"; … … 405 450 if (!$this->_canPrepareSP) return $sql; // Can't prepare procedures 406 451 407 $stmt = odbtp_prepare_proc($sql,$this->_connectionID);452 $stmt = @odbtp_prepare_proc($sql,$this->_connectionID); 408 453 if (!$stmt) return false; 409 454 return array($sql,$stmt); … … 442 487 $name = '@'.$name; 443 488 } 444 return odbtp_attach_param($stmt[1], $name, $var, $type, $maxLen);489 return @odbtp_attach_param($stmt[1], $name, $var, $type, $maxLen); 445 490 } 446 491 … … 458 503 { 459 504 $sql = "UPDATE $table SET $column = ? WHERE $where"; 460 if( !($stmt = odbtp_prepare($sql, $this->_connectionID)) )505 if( !($stmt = @odbtp_prepare($sql, $this->_connectionID)) ) 461 506 return false; 462 if( ! odbtp_input( $stmt, 1, ODB_BINARY, 1000000, $blobtype ) )507 if( !@odbtp_input( $stmt, 1, ODB_BINARY, 1000000, $blobtype ) ) 463 508 return false; 464 if( ! odbtp_set( $stmt, 1, $val ) )509 if( !@odbtp_set( $stmt, 1, $val ) ) 465 510 return false; 466 return odbtp_execute( $stmt ) != false;511 return @odbtp_execute( $stmt ) != false; 467 512 } 468 513 … … 480 525 function _query($sql,$inputarr=false) 481 526 { 527 global $php_errormsg; 528 482 529 if ($inputarr) { 483 530 if (is_array($sql)) { 484 531 $stmtid = $sql[1]; 485 532 } else { 486 $stmtid = odbtp_prepare($sql,$this->_connectionID);533 $stmtid = @odbtp_prepare($sql,$this->_connectionID); 487 534 if ($stmtid == false) { 488 535 $this->_errorMsg = $php_errormsg; … … 490 537 } 491 538 } 492 $num_params = odbtp_num_params( $stmtid );539 $num_params = @odbtp_num_params( $stmtid ); 493 540 for( $param = 1; $param <= $num_params; $param++ ) { 494 541 @odbtp_input( $stmtid, $param ); 495 542 @odbtp_set( $stmtid, $param, $inputarr[$param-1] ); 496 543 } 497 if (! 544 if (!@odbtp_execute($stmtid) ) { 498 545 return false; 499 546 } 500 547 } else if (is_array($sql)) { 501 548 $stmtid = $sql[1]; 502 if (! odbtp_execute($stmtid)) {549 if (!@odbtp_execute($stmtid)) { 503 550 return false; 504 551 } 505 552 } else { 506 $stmtid = @odbtp_query($sql,$this->_connectionID);553 $stmtid = odbtp_query($sql,$this->_connectionID); 507 554 } 508 555 $this->_lastAffectedRows = 0; … … 541 588 if (!($this->_numOfRows = @odbtp_num_rows($this->_queryID))) 542 589 $this->_numOfRows = -1; 590 591 if (!$this->connection->_useUnicodeSQL) return; 592 593 if ($this->connection->odbc_driver == ODB_DRIVER_JET) { 594 if (!@odbtp_get_attr(ODB_ATTR_MAPCHARTOWCHAR, 595 $this->connection->_connectionID)) 596 { 597 for ($f = 0; $f < $this->_numOfFields; $f++) { 598 if (@odbtp_field_bindtype($this->_queryID, $f) == ODB_CHAR) 599 @odbtp_bind_field($this->_queryID, $f, ODB_WCHAR); 600 } 601 } 602 } 543 603 } 544 604 … … 571 631 } 572 632 } 573 633 return $this->fields[$this->bind[strtoupper($colname)]]; 574 634 } 575 635 … … 586 646 $this->fields = @odbtp_fetch_array($this->_queryID, $type); 587 647 } 648 if ($this->databaseType = 'odbtp_vfp') { 649 if ($this->fields) 650 foreach($this->fields as $k => $v) { 651 if (strncmp($v,'1899-12-30',10) == 0) $this->fields[$k] = ''; 652 } 653 } 588 654 return is_array($this->fields); 589 655 } … … 598 664 if (!$this->_fetch_odbtp(ODB_FETCH_FIRST)) return false; 599 665 $this->EOF = false; 600 601 666 $this->_currentRow = 0; 667 return true; 602 668 } 603 669 604 605 670 function MoveLast() 671 { 606 672 if (!$this->_fetch_odbtp(ODB_FETCH_LAST)) return false; 607 673 $this->EOF = false; 608 674 $this->_currentRow = $this->_numOfRows - 1; 609 610 611 675 return true; 676 } 677 612 678 function NextRecordSet() 613 679 { … … 626 692 } 627 693 694 class ADORecordSet_odbtp_mssql extends ADORecordSet_odbtp { 695 696 var $databaseType = 'odbtp_mssql'; 697 698 function ADORecordSet_odbtp_mssql($id,$mode=false) 699 { 700 return $this->ADORecordSet_odbtp($id,$mode); 701 } 702 } 703 704 class ADORecordSet_odbtp_access extends ADORecordSet_odbtp { 705 706 var $databaseType = 'odbtp_access'; 707 708 function ADORecordSet_odbtp_access($id,$mode=false) 709 { 710 return $this->ADORecordSet_odbtp($id,$mode); 711 } 712 } 713 714 class ADORecordSet_odbtp_vfp extends ADORecordSet_odbtp { 715 716 var $databaseType = 'odbtp_vfp'; 717 718 function ADORecordSet_odbtp_vfp($id,$mode=false) 719 { 720 return $this->ADORecordSet_odbtp($id,$mode); 721 } 722 } 723 724 class ADORecordSet_odbtp_oci8 extends ADORecordSet_odbtp { 725 726 var $databaseType = 'odbtp_oci8'; 727 728 function ADORecordSet_odbtp_oci8($id,$mode=false) 729 { 730 return $this->ADORecordSet_odbtp($id,$mode); 731 } 732 } 733 734 class ADORecordSet_odbtp_sybase extends ADORecordSet_odbtp { 735 736 var $databaseType = 'odbtp_sybase'; 737 738 function ADORecordSet_odbtp_sybase($id,$mode=false) 739 { 740 return $this->ADORecordSet_odbtp($id,$mode); 741 } 742 } 628 743 ?>
Note: See TracChangeset
for help on using the changeset viewer.