ChangeLog
[Packages/TYPO3.CMS.git] / typo3 / sysext / adodb / adodb / drivers / adodb-ado_mssql.inc.php
1 <?php
2 /*
3 V4.90 8 June 2006 (c) 2000-2006 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.
8
9 Latest version is available at http://adodb.sourceforge.net
10
11 Microsoft SQL Server ADO data driver. Requires ADO and MSSQL client.
12 Works only on MS Windows.
13
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.
16 */
17
18 // security - hide paths
19 if (!defined('ADODB_DIR')) die();
20
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");
24 }
25
26
27 class ADODB_ado_mssql extends ADODB_ado {
28 var $databaseType = 'ado_mssql';
29 var $hasTop = 'top';
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";
37 var $length = 'len';
38
39 //var $_inTransaction = 1; // always open recordsets, so no transaction problems.
40
41 function ADODB_ado_mssql()
42 {
43 $this->ADODB_ado();
44 }
45
46 function _insertid()
47 {
48 return $this->GetOne('select @@identity');
49 }
50
51 function _affectedrows()
52 {
53 return $this->GetOne('select @@rowcount');
54 }
55
56 function SetTransactionMode( $transaction_mode )
57 {
58 $this->_transmode = $transaction_mode;
59 if (empty($transaction_mode)) {
60 $this->Execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED');
61 return;
62 }
63 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
64 $this->Execute("SET TRANSACTION ".$transaction_mode);
65 }
66
67 function MetaColumns($table)
68 {
69 $table = strtoupper($table);
70 $arr= array();
71 $dbc = $this->_connectionID;
72
73 $osoptions = array();
74 $osoptions[0] = null;
75 $osoptions[1] = null;
76 $osoptions[2] = $table;
77 $osoptions[3] = null;
78
79 $adors=@$dbc->OpenSchema(4, $osoptions);//tables
80
81 if ($adors){
82 while (!$adors->EOF){
83 $fld = new ADOFieldObject();
84 $c = $adors->Fields(3);
85 $fld->name = $c->Value;
86 $fld->type = 'CHAR'; // cannot discover type in ADO!
87 $fld->max_length = -1;
88 $arr[strtoupper($fld->name)]=$fld;
89
90 $adors->MoveNext();
91 }
92 $adors->Close();
93 }
94 $false = false;
95 return empty($arr) ? $false : $arr;
96 }
97
98 function CreateSequence($seq='adodbseq',$start=1)
99 {
100
101 $this->Execute('BEGIN TRANSACTION adodbseq');
102 $start -= 1;
103 $this->Execute("create table $seq (id float(53))");
104 $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)");
105 if (!$ok) {
106 $this->Execute('ROLLBACK TRANSACTION adodbseq');
107 return false;
108 }
109 $this->Execute('COMMIT TRANSACTION adodbseq');
110 return true;
111 }
112
113 function GenID($seq='adodbseq',$start=1)
114 {
115 //$this->debug=1;
116 $this->Execute('BEGIN TRANSACTION adodbseq');
117 $ok = $this->Execute("update $seq with (tablock,holdlock) set id = id + 1");
118 if (!$ok) {
119 $this->Execute("create table $seq (id float(53))");
120 $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)");
121 if (!$ok) {
122 $this->Execute('ROLLBACK TRANSACTION adodbseq');
123 return false;
124 }
125 $this->Execute('COMMIT TRANSACTION adodbseq');
126 return $start;
127 }
128 $num = $this->GetOne("select id from $seq");
129 $this->Execute('COMMIT TRANSACTION adodbseq');
130 return $num;
131
132 // in old implementation, pre 1.90, we returned GUID...
133 //return $this->GetOne("SELECT CONVERT(varchar(255), NEWID()) AS 'Char'");
134 }
135
136 } // end class
137
138 class ADORecordSet_ado_mssql extends ADORecordSet_ado {
139
140 var $databaseType = 'ado_mssql';
141
142 function ADORecordSet_ado_mssql($id,$mode=false)
143 {
144 return $this->ADORecordSet_ado($id,$mode);
145 }
146 }
147 ?>