|
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. 00007 Set tabs to 4 for best viewing. 00008 00009 Latest version is available at http://adodb.sourceforge.net 00010 00011 Microsoft SQL Server ADO data driver. Requires ADO and MSSQL client. 00012 Works only on MS Windows. 00013 00014 Warning: Some versions of PHP (esp PHP4) leak memory when ADO/COM is used. 00015 Please check http://bugs.php.net/ for more info. 00016 */ 00017 00018 // security - hide paths 00019 if (!defined('ADODB_DIR')) die(); 00020 00021 if (!defined('_ADODB_ADO_LAYER')) { 00022 if (PHP_VERSION >= 5) include(ADODB_DIR."/drivers/adodb-ado5.inc.php"); 00023 else include(ADODB_DIR."/drivers/adodb-ado.inc.php"); 00024 } 00025 00026 00027 class ADODB_ado_mssql extends ADODB_ado { 00028 var $databaseType = 'ado_mssql'; 00029 var $hasTop = 'top'; 00030 var $hasInsertID = true; 00031 var $sysDate = 'convert(datetime,convert(char,GetDate(),102),102)'; 00032 var $sysTimeStamp = 'GetDate()'; 00033 var $leftOuter = '*='; 00034 var $rightOuter = '=*'; 00035 var $ansiOuter = true; // for mssql7 or later 00036 var $substr = "substring"; 00037 var $length = 'len'; 00038 var $_dropSeqSQL = "drop table %s"; 00039 00040 //var $_inTransaction = 1; // always open recordsets, so no transaction problems. 00041 00042 function ADODB_ado_mssql() 00043 { 00044 $this->ADODB_ado(); 00045 } 00046 00047 function _insertid() 00048 { 00049 return $this->GetOne('select SCOPE_IDENTITY()'); 00050 } 00051 00052 function _affectedrows() 00053 { 00054 return $this->GetOne('select @@rowcount'); 00055 } 00056 00057 function SetTransactionMode( $transaction_mode ) 00058 { 00059 $this->_transmode = $transaction_mode; 00060 if (empty($transaction_mode)) { 00061 $this->Execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED'); 00062 return; 00063 } 00064 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode; 00065 $this->Execute("SET TRANSACTION ".$transaction_mode); 00066 } 00067 00068 function qstr($s,$magic_quotes=false) 00069 { 00070 $s = ADOConnection::qstr($s, $magic_quotes); 00071 return str_replace("\0", "\\\\000", $s); 00072 } 00073 00074 function MetaColumns($table, $normalize=true) 00075 { 00076 $table = strtoupper($table); 00077 $arr= array(); 00078 $dbc = $this->_connectionID; 00079 00080 $osoptions = array(); 00081 $osoptions[0] = null; 00082 $osoptions[1] = null; 00083 $osoptions[2] = $table; 00084 $osoptions[3] = null; 00085 00086 $adors=@$dbc->OpenSchema(4, $osoptions);//tables 00087 00088 if ($adors){ 00089 while (!$adors->EOF){ 00090 $fld = new ADOFieldObject(); 00091 $c = $adors->Fields(3); 00092 $fld->name = $c->Value; 00093 $fld->type = 'CHAR'; // cannot discover type in ADO! 00094 $fld->max_length = -1; 00095 $arr[strtoupper($fld->name)]=$fld; 00096 00097 $adors->MoveNext(); 00098 } 00099 $adors->Close(); 00100 } 00101 $false = false; 00102 return empty($arr) ? $false : $arr; 00103 } 00104 00105 function CreateSequence($seq='adodbseq',$start=1) 00106 { 00107 00108 $this->Execute('BEGIN TRANSACTION adodbseq'); 00109 $start -= 1; 00110 $this->Execute("create table $seq (id float(53))"); 00111 $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)"); 00112 if (!$ok) { 00113 $this->Execute('ROLLBACK TRANSACTION adodbseq'); 00114 return false; 00115 } 00116 $this->Execute('COMMIT TRANSACTION adodbseq'); 00117 return true; 00118 } 00119 00120 function GenID($seq='adodbseq',$start=1) 00121 { 00122 //$this->debug=1; 00123 $this->Execute('BEGIN TRANSACTION adodbseq'); 00124 $ok = $this->Execute("update $seq with (tablock,holdlock) set id = id + 1"); 00125 if (!$ok) { 00126 $this->Execute("create table $seq (id float(53))"); 00127 $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)"); 00128 if (!$ok) { 00129 $this->Execute('ROLLBACK TRANSACTION adodbseq'); 00130 return false; 00131 } 00132 $this->Execute('COMMIT TRANSACTION adodbseq'); 00133 return $start; 00134 } 00135 $num = $this->GetOne("select id from $seq"); 00136 $this->Execute('COMMIT TRANSACTION adodbseq'); 00137 return $num; 00138 00139 // in old implementation, pre 1.90, we returned GUID... 00140 //return $this->GetOne("SELECT CONVERT(varchar(255), NEWID()) AS 'Char'"); 00141 } 00142 00143 } // end class 00144 00145 class ADORecordSet_ado_mssql extends ADORecordSet_ado { 00146 00147 var $databaseType = 'ado_mssql'; 00148 00149 function ADORecordSet_ado_mssql($id,$mode=false) 00150 { 00151 return $this->ADORecordSet_ado($id,$mode); 00152 } 00153 } 00154 ?>