|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 /* 00003 V5.14 8 Sept 2011 (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved. 00004 Released under both BSD license and Lesser GPL library license. 00005 Whenever there is any discrepancy between the two licenses, 00006 the BSD license will take precedence. See License.txt. 00007 Set tabs to 4 for best viewing. 00008 Latest version is available at http://adodb.sourceforge.net 00009 */ 00010 // Code contributed by "stefan bogdan" <sbogdan#rsb.ro> 00011 00012 // security - hide paths 00013 if (!defined('ADODB_DIR')) die(); 00014 00015 define("_ADODB_ODBTP_LAYER", 2 ); 00016 00017 class ADODB_odbtp extends ADOConnection{ 00018 var $databaseType = "odbtp"; 00019 var $dataProvider = "odbtp"; 00020 var $fmtDate = "'Y-m-d'"; 00021 var $fmtTimeStamp = "'Y-m-d, h:i:sA'"; 00022 var $replaceQuote = "''"; // string to use to replace quotes 00023 var $odbc_driver = 0; 00024 var $hasAffectedRows = true; 00025 var $hasInsertID = false; 00026 var $hasGenID = true; 00027 var $hasMoveFirst = true; 00028 00029 var $_genSeqSQL = "create table %s (seq_name char(30) not null unique , seq_value integer not null)"; 00030 var $_dropSeqSQL = "delete from adodb_seq where seq_name = '%s'"; 00031 var $_bindInputArray = false; 00032 var $_useUnicodeSQL = false; 00033 var $_canPrepareSP = false; 00034 var $_dontPoolDBC = true; 00035 00036 function ADODB_odbtp() 00037 { 00038 } 00039 00040 function ServerInfo() 00041 { 00042 return array('description' => @odbtp_get_attr( ODB_ATTR_DBMSNAME, $this->_connectionID), 00043 'version' => @odbtp_get_attr( ODB_ATTR_DBMSVER, $this->_connectionID)); 00044 } 00045 00046 function ErrorMsg() 00047 { 00048 if ($this->_errorMsg !== false) return $this->_errorMsg; 00049 if (empty($this->_connectionID)) return @odbtp_last_error(); 00050 return @odbtp_last_error($this->_connectionID); 00051 } 00052 00053 function ErrorNo() 00054 { 00055 if ($this->_errorCode !== false) return $this->_errorCode; 00056 if (empty($this->_connectionID)) return @odbtp_last_error_state(); 00057 return @odbtp_last_error_state($this->_connectionID); 00058 } 00059 /* 00060 function DBDate($d,$isfld=false) 00061 { 00062 if (empty($d) && $d !== 0) return 'null'; 00063 if ($isfld) return "convert(date, $d, 120)"; 00064 00065 if (is_string($d)) $d = ADORecordSet::UnixDate($d); 00066 $d = adodb_date($this->fmtDate,$d); 00067 return "convert(date, $d, 120)"; 00068 } 00069 00070 function DBTimeStamp($d,$isfld=false) 00071 { 00072 if (empty($d) && $d !== 0) return 'null'; 00073 if ($isfld) return "convert(datetime, $d, 120)"; 00074 00075 if (is_string($d)) $d = ADORecordSet::UnixDate($d); 00076 $d = adodb_date($this->fmtDate,$d); 00077 return "convert(datetime, $d, 120)"; 00078 } 00079 */ 00080 00081 function _insertid() 00082 { 00083 // SCOPE_IDENTITY() 00084 // Returns the last IDENTITY value inserted into an IDENTITY column in 00085 // the same scope. A scope is a module -- a stored procedure, trigger, 00086 // function, or batch. Thus, two statements are in the same scope if 00087 // they are in the same stored procedure, function, or batch. 00088 return $this->GetOne($this->identitySQL); 00089 } 00090 00091 function _affectedrows() 00092 { 00093 if ($this->_queryID) { 00094 return @odbtp_affected_rows ($this->_queryID); 00095 } else 00096 return 0; 00097 } 00098 00099 function CreateSequence($seqname='adodbseq',$start=1) 00100 { 00101 //verify existence 00102 $num = $this->GetOne("select seq_value from adodb_seq"); 00103 $seqtab='adodb_seq'; 00104 if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) { 00105 $path = @odbtp_get_attr( ODB_ATTR_DATABASENAME, $this->_connectionID ); 00106 //if using vfp dbc file 00107 if( !strcasecmp(strrchr($path, '.'), '.dbc') ) 00108 $path = substr($path,0,strrpos($path,'\/')); 00109 $seqtab = $path . '/' . $seqtab; 00110 } 00111 if($num == false) { 00112 if (empty($this->_genSeqSQL)) return false; 00113 $ok = $this->Execute(sprintf($this->_genSeqSQL ,$seqtab)); 00114 } 00115 $num = $this->GetOne("select seq_value from adodb_seq where seq_name='$seqname'"); 00116 if ($num) { 00117 return false; 00118 } 00119 $start -= 1; 00120 return $this->Execute("insert into adodb_seq values('$seqname',$start)"); 00121 } 00122 00123 function DropSequence($seqname) 00124 { 00125 if (empty($this->_dropSeqSQL)) return false; 00126 return $this->Execute(sprintf($this->_dropSeqSQL,$seqname)); 00127 } 00128 00129 function GenID($seq='adodbseq',$start=1) 00130 { 00131 $seqtab='adodb_seq'; 00132 if( $this->odbc_driver == ODB_DRIVER_FOXPRO) { 00133 $path = @odbtp_get_attr( ODB_ATTR_DATABASENAME, $this->_connectionID ); 00134 //if using vfp dbc file 00135 if( !strcasecmp(strrchr($path, '.'), '.dbc') ) 00136 $path = substr($path,0,strrpos($path,'\/')); 00137 $seqtab = $path . '/' . $seqtab; 00138 } 00139 $MAXLOOPS = 100; 00140 while (--$MAXLOOPS>=0) { 00141 $num = $this->GetOne("select seq_value from adodb_seq where seq_name='$seq'"); 00142 if ($num === false) { 00143 //verify if abodb_seq table exist 00144 $ok = $this->GetOne("select seq_value from adodb_seq "); 00145 if(!$ok) { 00146 //creating the sequence table adodb_seq 00147 $this->Execute(sprintf($this->_genSeqSQL ,$seqtab)); 00148 } 00149 $start -= 1; 00150 $num = '0'; 00151 $ok = $this->Execute("insert into adodb_seq values('$seq',$start)"); 00152 if (!$ok) return false; 00153 } 00154 $ok = $this->Execute("update adodb_seq set seq_value=seq_value+1 where seq_name='$seq'"); 00155 if($ok) { 00156 $num += 1; 00157 $this->genID = $num; 00158 return $num; 00159 } 00160 } 00161 if ($fn = $this->raiseErrorFn) { 00162 $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num); 00163 } 00164 return false; 00165 } 00166 00167 //example for $UserOrDSN 00168 //for visual fox : DRIVER={Microsoft Visual FoxPro Driver};SOURCETYPE=DBF;SOURCEDB=c:\YourDbfFileDir;EXCLUSIVE=NO; 00169 //for visual fox dbc: DRIVER={Microsoft Visual FoxPro Driver};SOURCETYPE=DBC;SOURCEDB=c:\YourDbcFileDir\mydb.dbc;EXCLUSIVE=NO; 00170 //for access : DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\path_to_access_db\base_test.mdb;UID=root;PWD=; 00171 //for mssql : DRIVER={SQL Server};SERVER=myserver;UID=myuid;PWD=mypwd;DATABASE=OdbtpTest; 00172 //if uid & pwd can be separate 00173 function _connect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='') 00174 { 00175 if ($argPassword && stripos($UserOrDSN,'DRIVER=') !== false) { 00176 $this->_connectionID = odbtp_connect($HostOrInterface,$UserOrDSN.';PWD='.$argPassword); 00177 } else 00178 $this->_connectionID = odbtp_connect($HostOrInterface,$UserOrDSN,$argPassword,$argDatabase); 00179 if ($this->_connectionID === false) { 00180 $this->_errorMsg = $this->ErrorMsg() ; 00181 return false; 00182 } 00183 00184 odbtp_convert_datetime($this->_connectionID,true); 00185 00186 if ($this->_dontPoolDBC) { 00187 if (function_exists('odbtp_dont_pool_dbc')) 00188 @odbtp_dont_pool_dbc($this->_connectionID); 00189 } 00190 else { 00191 $this->_dontPoolDBC = true; 00192 } 00193 $this->odbc_driver = @odbtp_get_attr(ODB_ATTR_DRIVER, $this->_connectionID); 00194 $dbms = strtolower(@odbtp_get_attr(ODB_ATTR_DBMSNAME, $this->_connectionID)); 00195 $this->odbc_name = $dbms; 00196 00197 // Account for inconsistent DBMS names 00198 if( $this->odbc_driver == ODB_DRIVER_ORACLE ) 00199 $dbms = 'oracle'; 00200 else if( $this->odbc_driver == ODB_DRIVER_SYBASE ) 00201 $dbms = 'sybase'; 00202 00203 // Set DBMS specific attributes 00204 switch( $dbms ) { 00205 case 'microsoft sql server': 00206 $this->databaseType = 'odbtp_mssql'; 00207 $this->fmtDate = "'Y-m-d'"; 00208 $this->fmtTimeStamp = "'Y-m-d h:i:sA'"; 00209 $this->sysDate = 'convert(datetime,convert(char,GetDate(),102),102)'; 00210 $this->sysTimeStamp = 'GetDate()'; 00211 $this->ansiOuter = true; 00212 $this->leftOuter = '*='; 00213 $this->rightOuter = '=*'; 00214 $this->hasTop = 'top'; 00215 $this->hasInsertID = true; 00216 $this->hasTransactions = true; 00217 $this->_bindInputArray = true; 00218 $this->_canSelectDb = true; 00219 $this->substr = "substring"; 00220 $this->length = 'len'; 00221 $this->identitySQL = 'select SCOPE_IDENTITY()'; 00222 $this->metaDatabasesSQL = "select name from master..sysdatabases where name <> 'master'"; 00223 $this->_canPrepareSP = true; 00224 break; 00225 case 'access': 00226 $this->databaseType = 'odbtp_access'; 00227 $this->fmtDate = "#Y-m-d#"; 00228 $this->fmtTimeStamp = "#Y-m-d h:i:sA#"; 00229 $this->sysDate = "FORMAT(NOW,'yyyy-mm-dd')"; 00230 $this->sysTimeStamp = 'NOW'; 00231 $this->hasTop = 'top'; 00232 $this->hasTransactions = false; 00233 $this->_canPrepareSP = true; // For MS Access only. 00234 break; 00235 case 'visual foxpro': 00236 $this->databaseType = 'odbtp_vfp'; 00237 $this->fmtDate = "{^Y-m-d}"; 00238 $this->fmtTimeStamp = "{^Y-m-d, h:i:sA}"; 00239 $this->sysDate = 'date()'; 00240 $this->sysTimeStamp = 'datetime()'; 00241 $this->ansiOuter = true; 00242 $this->hasTop = 'top'; 00243 $this->hasTransactions = false; 00244 $this->replaceQuote = "'+chr(39)+'"; 00245 $this->true = '.T.'; 00246 $this->false = '.F.'; 00247 00248 break; 00249 case 'oracle': 00250 $this->databaseType = 'odbtp_oci8'; 00251 $this->fmtDate = "'Y-m-d 00:00:00'"; 00252 $this->fmtTimeStamp = "'Y-m-d h:i:sA'"; 00253 $this->sysDate = 'TRUNC(SYSDATE)'; 00254 $this->sysTimeStamp = 'SYSDATE'; 00255 $this->hasTransactions = true; 00256 $this->_bindInputArray = true; 00257 $this->concat_operator = '||'; 00258 break; 00259 case 'sybase': 00260 $this->databaseType = 'odbtp_sybase'; 00261 $this->fmtDate = "'Y-m-d'"; 00262 $this->fmtTimeStamp = "'Y-m-d H:i:s'"; 00263 $this->sysDate = 'GetDate()'; 00264 $this->sysTimeStamp = 'GetDate()'; 00265 $this->leftOuter = '*='; 00266 $this->rightOuter = '=*'; 00267 $this->hasInsertID = true; 00268 $this->hasTransactions = true; 00269 $this->identitySQL = 'select SCOPE_IDENTITY()'; 00270 break; 00271 default: 00272 $this->databaseType = 'odbtp'; 00273 if( @odbtp_get_attr(ODB_ATTR_TXNCAPABLE, $this->_connectionID) ) 00274 $this->hasTransactions = true; 00275 else 00276 $this->hasTransactions = false; 00277 } 00278 @odbtp_set_attr(ODB_ATTR_FULLCOLINFO, TRUE, $this->_connectionID ); 00279 00280 if ($this->_useUnicodeSQL ) 00281 @odbtp_set_attr(ODB_ATTR_UNICODESQL, TRUE, $this->_connectionID); 00282 00283 return true; 00284 } 00285 00286 function _pconnect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='') 00287 { 00288 $this->_dontPoolDBC = false; 00289 return $this->_connect($HostOrInterface, $UserOrDSN, $argPassword, $argDatabase); 00290 } 00291 00292 function SelectDB($dbName) 00293 { 00294 if (!@odbtp_select_db($dbName, $this->_connectionID)) { 00295 return false; 00296 } 00297 $this->database = $dbName; 00298 $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions 00299 return true; 00300 } 00301 00302 function MetaTables($ttype='',$showSchema=false,$mask=false) 00303 { 00304 global $ADODB_FETCH_MODE; 00305 00306 $savem = $ADODB_FETCH_MODE; 00307 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00308 if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false); 00309 00310 $arr = $this->GetArray("||SQLTables||||$ttype"); 00311 00312 if (isset($savefm)) $this->SetFetchMode($savefm); 00313 $ADODB_FETCH_MODE = $savem; 00314 00315 $arr2 = array(); 00316 for ($i=0; $i < sizeof($arr); $i++) { 00317 if ($arr[$i][3] == 'SYSTEM TABLE' ) continue; 00318 if ($arr[$i][2]) 00319 $arr2[] = $showSchema && $arr[$i][1]? $arr[$i][1].'.'.$arr[$i][2] : $arr[$i][2]; 00320 } 00321 return $arr2; 00322 } 00323 00324 function MetaColumns($table,$upper=true) 00325 { 00326 global $ADODB_FETCH_MODE; 00327 00328 $schema = false; 00329 $this->_findschema($table,$schema); 00330 if ($upper) $table = strtoupper($table); 00331 00332 $savem = $ADODB_FETCH_MODE; 00333 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00334 if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false); 00335 00336 $rs = $this->Execute( "||SQLColumns||$schema|$table" ); 00337 00338 if (isset($savefm)) $this->SetFetchMode($savefm); 00339 $ADODB_FETCH_MODE = $savem; 00340 00341 if (!$rs || $rs->EOF) { 00342 $false = false; 00343 return $false; 00344 } 00345 $retarr = array(); 00346 while (!$rs->EOF) { 00347 //print_r($rs->fields); 00348 if (strtoupper($rs->fields[2]) == $table) { 00349 $fld = new ADOFieldObject(); 00350 $fld->name = $rs->fields[3]; 00351 $fld->type = $rs->fields[5]; 00352 $fld->max_length = $rs->fields[6]; 00353 $fld->not_null = !empty($rs->fields[9]); 00354 $fld->scale = $rs->fields[7]; 00355 if (isset($rs->fields[12])) // vfp does not have field 12 00356 if (!is_null($rs->fields[12])) { 00357 $fld->has_default = true; 00358 $fld->default_value = $rs->fields[12]; 00359 } 00360 $retarr[strtoupper($fld->name)] = $fld; 00361 } else if (!empty($retarr)) 00362 break; 00363 $rs->MoveNext(); 00364 } 00365 $rs->Close(); 00366 00367 return $retarr; 00368 } 00369 00370 function MetaPrimaryKeys($table, $owner='') 00371 { 00372 global $ADODB_FETCH_MODE; 00373 00374 $savem = $ADODB_FETCH_MODE; 00375 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00376 $arr = $this->GetArray("||SQLPrimaryKeys||$owner|$table"); 00377 $ADODB_FETCH_MODE = $savem; 00378 00379 //print_r($arr); 00380 $arr2 = array(); 00381 for ($i=0; $i < sizeof($arr); $i++) { 00382 if ($arr[$i][3]) $arr2[] = $arr[$i][3]; 00383 } 00384 return $arr2; 00385 } 00386 00387 function MetaForeignKeys($table, $owner='', $upper=false) 00388 { 00389 global $ADODB_FETCH_MODE; 00390 00391 $savem = $ADODB_FETCH_MODE; 00392 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00393 $constraints = $this->GetArray("||SQLForeignKeys|||||$owner|$table"); 00394 $ADODB_FETCH_MODE = $savem; 00395 00396 $arr = false; 00397 foreach($constraints as $constr) { 00398 //print_r($constr); 00399 $arr[$constr[11]][$constr[2]][] = $constr[7].'='.$constr[3]; 00400 } 00401 if (!$arr) { 00402 $false = false; 00403 return $false; 00404 } 00405 00406 $arr2 = array(); 00407 00408 foreach($arr as $k => $v) { 00409 foreach($v as $a => $b) { 00410 if ($upper) $a = strtoupper($a); 00411 $arr2[$a] = $b; 00412 } 00413 } 00414 return $arr2; 00415 } 00416 00417 function BeginTrans() 00418 { 00419 if (!$this->hasTransactions) return false; 00420 if ($this->transOff) return true; 00421 $this->transCnt += 1; 00422 $this->autoCommit = false; 00423 if (defined('ODB_TXN_DEFAULT')) 00424 $txn = ODB_TXN_DEFAULT; 00425 else 00426 $txn = ODB_TXN_READUNCOMMITTED; 00427 $rs = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS,$txn,$this->_connectionID); 00428 if(!$rs) return false; 00429 return true; 00430 } 00431 00432 function CommitTrans($ok=true) 00433 { 00434 if ($this->transOff) return true; 00435 if (!$ok) return $this->RollbackTrans(); 00436 if ($this->transCnt) $this->transCnt -= 1; 00437 $this->autoCommit = true; 00438 if( ($ret = @odbtp_commit($this->_connectionID)) ) 00439 $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off 00440 return $ret; 00441 } 00442 00443 function RollbackTrans() 00444 { 00445 if ($this->transOff) return true; 00446 if ($this->transCnt) $this->transCnt -= 1; 00447 $this->autoCommit = true; 00448 if( ($ret = @odbtp_rollback($this->_connectionID)) ) 00449 $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off 00450 return $ret; 00451 } 00452 00453 function SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) 00454 { 00455 // TOP requires ORDER BY for Visual FoxPro 00456 if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) { 00457 if (!preg_match('/ORDER[ \t\r\n]+BY/is',$sql)) $sql .= ' ORDER BY 1'; 00458 } 00459 $ret = ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); 00460 return $ret; 00461 } 00462 00463 function Prepare($sql) 00464 { 00465 if (! $this->_bindInputArray) return $sql; // no binding 00466 00467 $this->_errorMsg = false; 00468 $this->_errorCode = false; 00469 00470 $stmt = @odbtp_prepare($sql,$this->_connectionID); 00471 if (!$stmt) { 00472 // print "Prepare Error for ($sql) ".$this->ErrorMsg()."<br>"; 00473 return $sql; 00474 } 00475 return array($sql,$stmt,false); 00476 } 00477 00478 function PrepareSP($sql) 00479 { 00480 if (!$this->_canPrepareSP) return $sql; // Can't prepare procedures 00481 00482 $this->_errorMsg = false; 00483 $this->_errorCode = false; 00484 00485 $stmt = @odbtp_prepare_proc($sql,$this->_connectionID); 00486 if (!$stmt) return false; 00487 return array($sql,$stmt); 00488 } 00489 00490 /* 00491 Usage: 00492 $stmt = $db->PrepareSP('SP_RUNSOMETHING'); -- takes 2 params, @myid and @group 00493 00494 # note that the parameter does not have @ in front! 00495 $db->Parameter($stmt,$id,'myid'); 00496 $db->Parameter($stmt,$group,'group',false,64); 00497 $db->Parameter($stmt,$group,'photo',false,100000,ODB_BINARY); 00498 $db->Execute($stmt); 00499 00500 @param $stmt Statement returned by Prepare() or PrepareSP(). 00501 @param $var PHP variable to bind to. Can set to null (for isNull support). 00502 @param $name Name of stored procedure variable name to bind to. 00503 @param [$isOutput] Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in odbtp. 00504 @param [$maxLen] Holds an maximum length of the variable. 00505 @param [$type] The data type of $var. Legal values depend on driver. 00506 00507 See odbtp_attach_param documentation at http://odbtp.sourceforge.net. 00508 */ 00509 function Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=0, $type=0) 00510 { 00511 if ( $this->odbc_driver == ODB_DRIVER_JET ) { 00512 $name = '['.$name.']'; 00513 if( !$type && $this->_useUnicodeSQL 00514 && @odbtp_param_bindtype($stmt[1], $name) == ODB_CHAR ) 00515 { 00516 $type = ODB_WCHAR; 00517 } 00518 } 00519 else { 00520 $name = '@'.$name; 00521 } 00522 return @odbtp_attach_param($stmt[1], $name, $var, $type, $maxLen); 00523 } 00524 00525 /* 00526 Insert a null into the blob field of the table first. 00527 Then use UpdateBlob to store the blob. 00528 00529 Usage: 00530 00531 $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); 00532 $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); 00533 */ 00534 00535 function UpdateBlob($table,$column,$val,$where,$blobtype='image') 00536 { 00537 $sql = "UPDATE $table SET $column = ? WHERE $where"; 00538 if( !($stmt = @odbtp_prepare($sql, $this->_connectionID)) ) 00539 return false; 00540 if( !@odbtp_input( $stmt, 1, ODB_BINARY, 1000000, $blobtype ) ) 00541 return false; 00542 if( !@odbtp_set( $stmt, 1, $val ) ) 00543 return false; 00544 return @odbtp_execute( $stmt ) != false; 00545 } 00546 00547 function MetaIndexes($table,$primary=false, $owner=false) 00548 { 00549 switch ( $this->odbc_driver) { 00550 case ODB_DRIVER_MSSQL: 00551 return $this->MetaIndexes_mssql($table, $primary); 00552 default: 00553 return array(); 00554 } 00555 } 00556 00557 function MetaIndexes_mssql($table,$primary=false, $owner = false) 00558 { 00559 $table = strtolower($this->qstr($table)); 00560 00561 $sql = "SELECT i.name AS ind_name, C.name AS col_name, USER_NAME(O.uid) AS Owner, c.colid, k.Keyno, 00562 CASE WHEN I.indid BETWEEN 1 AND 254 AND (I.status & 2048 = 2048 OR I.Status = 16402 AND O.XType = 'V') THEN 1 ELSE 0 END AS IsPK, 00563 CASE WHEN I.status & 2 = 2 THEN 1 ELSE 0 END AS IsUnique 00564 FROM dbo.sysobjects o INNER JOIN dbo.sysindexes I ON o.id = i.id 00565 INNER JOIN dbo.sysindexkeys K ON I.id = K.id AND I.Indid = K.Indid 00566 INNER JOIN dbo.syscolumns c ON K.id = C.id AND K.colid = C.Colid 00567 WHERE LEFT(i.name, 8) <> '_WA_Sys_' AND o.status >= 0 AND lower(O.Name) = $table 00568 ORDER BY O.name, I.Name, K.keyno"; 00569 00570 global $ADODB_FETCH_MODE; 00571 $save = $ADODB_FETCH_MODE; 00572 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00573 if ($this->fetchMode !== FALSE) { 00574 $savem = $this->SetFetchMode(FALSE); 00575 } 00576 00577 $rs = $this->Execute($sql); 00578 if (isset($savem)) { 00579 $this->SetFetchMode($savem); 00580 } 00581 $ADODB_FETCH_MODE = $save; 00582 00583 if (!is_object($rs)) { 00584 return FALSE; 00585 } 00586 00587 $indexes = array(); 00588 while ($row = $rs->FetchRow()) { 00589 if ($primary && !$row[5]) continue; 00590 00591 $indexes[$row[0]]['unique'] = $row[6]; 00592 $indexes[$row[0]]['columns'][] = $row[1]; 00593 } 00594 return $indexes; 00595 } 00596 00597 function IfNull( $field, $ifNull ) 00598 { 00599 switch( $this->odbc_driver ) { 00600 case ODB_DRIVER_MSSQL: 00601 return " ISNULL($field, $ifNull) "; 00602 case ODB_DRIVER_JET: 00603 return " IIF(IsNull($field), $ifNull, $field) "; 00604 } 00605 return " CASE WHEN $field is null THEN $ifNull ELSE $field END "; 00606 } 00607 00608 function _query($sql,$inputarr=false) 00609 { 00610 global $php_errormsg; 00611 00612 $this->_errorMsg = false; 00613 $this->_errorCode = false; 00614 00615 if ($inputarr) { 00616 if (is_array($sql)) { 00617 $stmtid = $sql[1]; 00618 } else { 00619 $stmtid = @odbtp_prepare($sql,$this->_connectionID); 00620 if ($stmtid == false) { 00621 $this->_errorMsg = $php_errormsg; 00622 return false; 00623 } 00624 } 00625 $num_params = @odbtp_num_params( $stmtid ); 00626 /* 00627 for( $param = 1; $param <= $num_params; $param++ ) { 00628 @odbtp_input( $stmtid, $param ); 00629 @odbtp_set( $stmtid, $param, $inputarr[$param-1] ); 00630 }*/ 00631 00632 $param = 1; 00633 foreach($inputarr as $v) { 00634 @odbtp_input( $stmtid, $param ); 00635 @odbtp_set( $stmtid, $param, $v ); 00636 $param += 1; 00637 if ($param > $num_params) break; 00638 } 00639 00640 if (!@odbtp_execute($stmtid) ) { 00641 return false; 00642 } 00643 } else if (is_array($sql)) { 00644 $stmtid = $sql[1]; 00645 if (!@odbtp_execute($stmtid)) { 00646 return false; 00647 } 00648 } else { 00649 $stmtid = odbtp_query($sql,$this->_connectionID); 00650 } 00651 $this->_lastAffectedRows = 0; 00652 if ($stmtid) { 00653 $this->_lastAffectedRows = @odbtp_affected_rows($stmtid); 00654 } 00655 return $stmtid; 00656 } 00657 00658 function _close() 00659 { 00660 $ret = @odbtp_close($this->_connectionID); 00661 $this->_connectionID = false; 00662 return $ret; 00663 } 00664 } 00665 00666 class ADORecordSet_odbtp extends ADORecordSet { 00667 00668 var $databaseType = 'odbtp'; 00669 var $canSeek = true; 00670 00671 function ADORecordSet_odbtp($queryID,$mode=false) 00672 { 00673 if ($mode === false) { 00674 global $ADODB_FETCH_MODE; 00675 $mode = $ADODB_FETCH_MODE; 00676 } 00677 $this->fetchMode = $mode; 00678 $this->ADORecordSet($queryID); 00679 } 00680 00681 function _initrs() 00682 { 00683 $this->_numOfFields = @odbtp_num_fields($this->_queryID); 00684 if (!($this->_numOfRows = @odbtp_num_rows($this->_queryID))) 00685 $this->_numOfRows = -1; 00686 00687 if (!$this->connection->_useUnicodeSQL) return; 00688 00689 if ($this->connection->odbc_driver == ODB_DRIVER_JET) { 00690 if (!@odbtp_get_attr(ODB_ATTR_MAPCHARTOWCHAR, 00691 $this->connection->_connectionID)) 00692 { 00693 for ($f = 0; $f < $this->_numOfFields; $f++) { 00694 if (@odbtp_field_bindtype($this->_queryID, $f) == ODB_CHAR) 00695 @odbtp_bind_field($this->_queryID, $f, ODB_WCHAR); 00696 } 00697 } 00698 } 00699 } 00700 00701 function FetchField($fieldOffset = 0) 00702 { 00703 $off=$fieldOffset; // offsets begin at 0 00704 $o= new ADOFieldObject(); 00705 $o->name = @odbtp_field_name($this->_queryID,$off); 00706 $o->type = @odbtp_field_type($this->_queryID,$off); 00707 $o->max_length = @odbtp_field_length($this->_queryID,$off); 00708 if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name); 00709 else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name); 00710 return $o; 00711 } 00712 00713 function _seek($row) 00714 { 00715 return @odbtp_data_seek($this->_queryID, $row); 00716 } 00717 00718 function fields($colname) 00719 { 00720 if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; 00721 00722 if (!$this->bind) { 00723 $this->bind = array(); 00724 for ($i=0; $i < $this->_numOfFields; $i++) { 00725 $name = @odbtp_field_name( $this->_queryID, $i ); 00726 $this->bind[strtoupper($name)] = $i; 00727 } 00728 } 00729 return $this->fields[$this->bind[strtoupper($colname)]]; 00730 } 00731 00732 function _fetch_odbtp($type=0) 00733 { 00734 switch ($this->fetchMode) { 00735 case ADODB_FETCH_NUM: 00736 $this->fields = @odbtp_fetch_row($this->_queryID, $type); 00737 break; 00738 case ADODB_FETCH_ASSOC: 00739 $this->fields = @odbtp_fetch_assoc($this->_queryID, $type); 00740 break; 00741 default: 00742 $this->fields = @odbtp_fetch_array($this->_queryID, $type); 00743 } 00744 if ($this->databaseType = 'odbtp_vfp') { 00745 if ($this->fields) 00746 foreach($this->fields as $k => $v) { 00747 if (strncmp($v,'1899-12-30',10) == 0) $this->fields[$k] = ''; 00748 } 00749 } 00750 return is_array($this->fields); 00751 } 00752 00753 function _fetch() 00754 { 00755 return $this->_fetch_odbtp(); 00756 } 00757 00758 function MoveFirst() 00759 { 00760 if (!$this->_fetch_odbtp(ODB_FETCH_FIRST)) return false; 00761 $this->EOF = false; 00762 $this->_currentRow = 0; 00763 return true; 00764 } 00765 00766 function MoveLast() 00767 { 00768 if (!$this->_fetch_odbtp(ODB_FETCH_LAST)) return false; 00769 $this->EOF = false; 00770 $this->_currentRow = $this->_numOfRows - 1; 00771 return true; 00772 } 00773 00774 function NextRecordSet() 00775 { 00776 if (!@odbtp_next_result($this->_queryID)) return false; 00777 $this->_inited = false; 00778 $this->bind = false; 00779 $this->_currentRow = -1; 00780 $this->Init(); 00781 return true; 00782 } 00783 00784 function _close() 00785 { 00786 return @odbtp_free_query($this->_queryID); 00787 } 00788 } 00789 00790 class ADORecordSet_odbtp_mssql extends ADORecordSet_odbtp { 00791 00792 var $databaseType = 'odbtp_mssql'; 00793 00794 function ADORecordSet_odbtp_mssql($id,$mode=false) 00795 { 00796 return $this->ADORecordSet_odbtp($id,$mode); 00797 } 00798 } 00799 00800 class ADORecordSet_odbtp_access extends ADORecordSet_odbtp { 00801 00802 var $databaseType = 'odbtp_access'; 00803 00804 function ADORecordSet_odbtp_access($id,$mode=false) 00805 { 00806 return $this->ADORecordSet_odbtp($id,$mode); 00807 } 00808 } 00809 00810 class ADORecordSet_odbtp_vfp extends ADORecordSet_odbtp { 00811 00812 var $databaseType = 'odbtp_vfp'; 00813 00814 function ADORecordSet_odbtp_vfp($id,$mode=false) 00815 { 00816 return $this->ADORecordSet_odbtp($id,$mode); 00817 } 00818 } 00819 00820 class ADORecordSet_odbtp_oci8 extends ADORecordSet_odbtp { 00821 00822 var $databaseType = 'odbtp_oci8'; 00823 00824 function ADORecordSet_odbtp_oci8($id,$mode=false) 00825 { 00826 return $this->ADORecordSet_odbtp($id,$mode); 00827 } 00828 } 00829 00830 class ADORecordSet_odbtp_sybase extends ADORecordSet_odbtp { 00831 00832 var $databaseType = 'odbtp_sybase'; 00833 00834 function ADORecordSet_odbtp_sybase($id,$mode=false) 00835 { 00836 return $this->ADORecordSet_odbtp($id,$mode); 00837 } 00838 } 00839 ?>