3 V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
4 Released under both BSD license and Lesser GPL library license.
5 Whenever there is any discrepancy between the two licenses,
6 the BSD license will take precedence.
7 Set tabs to 4 for best viewing.
9 Latest version is available at http://adodb.sourceforge.net
11 Microsoft SQL Server ADO data driver. Requires ADO and MSSQL client.
12 Works only on MS Windows.
14 Warning: Some versions of PHP (esp PHP4) leak memory when ADO/COM is used.
15 Please check http://bugs.php.net/ for more info.
18 // security - hide paths
19 if (!defined('ADODB_DIR')) die();
21 if (!defined('_ADODB_ADO_LAYER')) {
22 if (PHP_VERSION
>= 5) include(ADODB_DIR
."/drivers/adodb-ado5.inc.php");
23 else include(ADODB_DIR
."/drivers/adodb-ado.inc.php");
27 class ADODB_ado_mssql
extends ADODB_ado
{
28 var $databaseType = 'ado_mssql';
30 var $hasInsertID = true;
31 var $sysDate = 'convert(datetime,convert(char,GetDate(),102),102)';
32 var $sysTimeStamp = 'GetDate()';
33 var $leftOuter = '*=';
34 var $rightOuter = '=*';
35 var $ansiOuter = true; // for mssql7 or later
36 var $substr = "substring";
38 var $_dropSeqSQL = "drop table %s";
40 //var $_inTransaction = 1; // always open recordsets, so no transaction problems.
42 function ADODB_ado_mssql()
49 return $this->GetOne('select @@identity');
52 function _affectedrows()
54 return $this->GetOne('select @@rowcount');
57 function SetTransactionMode( $transaction_mode )
59 $this->_transmode
= $transaction_mode;
60 if (empty($transaction_mode)) {
61 $this->Execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED');
64 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
65 $this->Execute("SET TRANSACTION ".$transaction_mode);
68 function qstr($s,$magic_quotes=false)
70 $s = ADOConnection
::qstr($s, $magic_quotes);
71 return str_replace("\0", "\\\\000", $s);
74 function MetaColumns($table)
76 $table = strtoupper($table);
78 $dbc = $this->_connectionID
;
83 $osoptions[2] = $table;
86 $adors=@$dbc->OpenSchema(4, $osoptions);//tables
90 $fld = new ADOFieldObject();
91 $c = $adors->Fields(3);
92 $fld->name
= $c->Value
;
93 $fld->type
= 'CHAR'; // cannot discover type in ADO!
94 $fld->max_length
= -1;
95 $arr[strtoupper($fld->name
)]=$fld;
102 return empty($arr) ?
$false : $arr;
105 function CreateSequence($seq='adodbseq',$start=1)
108 $this->Execute('BEGIN TRANSACTION adodbseq');
110 $this->Execute("create table $seq (id float(53))");
111 $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)");
113 $this->Execute('ROLLBACK TRANSACTION adodbseq');
116 $this->Execute('COMMIT TRANSACTION adodbseq');
120 function GenID($seq='adodbseq',$start=1)
123 $this->Execute('BEGIN TRANSACTION adodbseq');
124 $ok = $this->Execute("update $seq with (tablock,holdlock) set id = id + 1");
126 $this->Execute("create table $seq (id float(53))");
127 $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)");
129 $this->Execute('ROLLBACK TRANSACTION adodbseq');
132 $this->Execute('COMMIT TRANSACTION adodbseq');
135 $num = $this->GetOne("select id from $seq");
136 $this->Execute('COMMIT TRANSACTION adodbseq');
139 // in old implementation, pre 1.90, we returned GUID...
140 //return $this->GetOne("SELECT CONVERT(varchar(255), NEWID()) AS 'Char'");
145 class ADORecordSet_ado_mssql
extends ADORecordSet_ado
{
147 var $databaseType = 'ado_mssql';
149 function ADORecordSet_ado_mssql($id,$mode=false)
151 return $this->ADORecordSet_ado($id,$mode);