00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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;
00036 var $substr = "substring";
00037 var $length = 'len';
00038
00039
00040
00041 function ADODB_ado_mssql()
00042 {
00043 $this->ADODB_ado();
00044 }
00045
00046 function _insertid()
00047 {
00048 return $this->GetOne('select @@identity');
00049 }
00050
00051 function _affectedrows()
00052 {
00053 return $this->GetOne('select @@rowcount');
00054 }
00055
00056 function SetTransactionMode( $transaction_mode )
00057 {
00058 $this->_transmode = $transaction_mode;
00059 if (empty($transaction_mode)) {
00060 $this->Execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED');
00061 return;
00062 }
00063 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
00064 $this->Execute("SET TRANSACTION ".$transaction_mode);
00065 }
00066
00067 function MetaColumns($table)
00068 {
00069 $table = strtoupper($table);
00070 $arr= array();
00071 $dbc = $this->_connectionID;
00072
00073 $osoptions = array();
00074 $osoptions[0] = null;
00075 $osoptions[1] = null;
00076 $osoptions[2] = $table;
00077 $osoptions[3] = null;
00078
00079 $adors=@$dbc->OpenSchema(4, $osoptions);
00080
00081 if ($adors){
00082 while (!$adors->EOF){
00083 $fld = new ADOFieldObject();
00084 $c = $adors->Fields(3);
00085 $fld->name = $c->Value;
00086 $fld->type = 'CHAR';
00087 $fld->max_length = -1;
00088 $arr[strtoupper($fld->name)]=$fld;
00089
00090 $adors->MoveNext();
00091 }
00092 $adors->Close();
00093 }
00094 $false = false;
00095 return empty($arr) ? $false : $arr;
00096 }
00097
00098 function CreateSequence($seq='adodbseq',$start=1)
00099 {
00100
00101 $this->Execute('BEGIN TRANSACTION adodbseq');
00102 $start -= 1;
00103 $this->Execute("create table $seq (id float(53))");
00104 $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)");
00105 if (!$ok) {
00106 $this->Execute('ROLLBACK TRANSACTION adodbseq');
00107 return false;
00108 }
00109 $this->Execute('COMMIT TRANSACTION adodbseq');
00110 return true;
00111 }
00112
00113 function GenID($seq='adodbseq',$start=1)
00114 {
00115
00116 $this->Execute('BEGIN TRANSACTION adodbseq');
00117 $ok = $this->Execute("update $seq with (tablock,holdlock) set id = id + 1");
00118 if (!$ok) {
00119 $this->Execute("create table $seq (id float(53))");
00120 $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)");
00121 if (!$ok) {
00122 $this->Execute('ROLLBACK TRANSACTION adodbseq');
00123 return false;
00124 }
00125 $this->Execute('COMMIT TRANSACTION adodbseq');
00126 return $start;
00127 }
00128 $num = $this->GetOne("select id from $seq");
00129 $this->Execute('COMMIT TRANSACTION adodbseq');
00130 return $num;
00131
00132
00133
00134 }
00135
00136 }
00137
00138 class ADORecordSet_ado_mssql extends ADORecordSet_ado {
00139
00140 var $databaseType = 'ado_mssql';
00141
00142 function ADORecordSet_ado_mssql($id,$mode=false)
00143 {
00144 return $this->ADORecordSet_ado($id,$mode);
00145 }
00146 }
00147 ?>