PageRenderTime 45ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/rdfapi-php/api/util/adodb/drivers/adodb-ado_mssql.inc.php

https://github.com/EOL/eol_php_code
PHP | 154 lines | 111 code | 23 blank | 20 comment | 11 complexity | 0d0c7d1584cb9e6dd3232054698a66c0 MD5 | raw file
  1. <?php
  2. /*
  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.
  8. Latest version is available at http://adodb.sourceforge.net
  9. Microsoft SQL Server ADO data driver. Requires ADO and MSSQL client.
  10. Works only on MS Windows.
  11. Warning: Some versions of PHP (esp PHP4) leak memory when ADO/COM is used.
  12. Please check http://bugs.php.net/ for more info.
  13. */
  14. // security - hide paths
  15. if (!defined('ADODB_DIR')) die();
  16. if (!defined('_ADODB_ADO_LAYER')) {
  17. if (PHP_VERSION >= 5) include(ADODB_DIR."/drivers/adodb-ado5.inc.php");
  18. else include(ADODB_DIR."/drivers/adodb-ado.inc.php");
  19. }
  20. class ADODB_ado_mssql extends ADODB_ado {
  21. var $databaseType = 'ado_mssql';
  22. var $hasTop = 'top';
  23. var $hasInsertID = true;
  24. var $sysDate = 'convert(datetime,convert(char,GetDate(),102),102)';
  25. var $sysTimeStamp = 'GetDate()';
  26. var $leftOuter = '*=';
  27. var $rightOuter = '=*';
  28. var $ansiOuter = true; // for mssql7 or later
  29. var $substr = "substring";
  30. var $length = 'len';
  31. var $_dropSeqSQL = "drop table %s";
  32. //var $_inTransaction = 1; // always open recordsets, so no transaction problems.
  33. function ADODB_ado_mssql()
  34. {
  35. $this->ADODB_ado();
  36. }
  37. function _insertid()
  38. {
  39. return $this->GetOne('select @@identity');
  40. }
  41. function _affectedrows()
  42. {
  43. return $this->GetOne('select @@rowcount');
  44. }
  45. function SetTransactionMode( $transaction_mode )
  46. {
  47. $this->_transmode = $transaction_mode;
  48. if (empty($transaction_mode)) {
  49. $this->Execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED');
  50. return;
  51. }
  52. if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
  53. $this->Execute("SET TRANSACTION ".$transaction_mode);
  54. }
  55. function qstr($s,$magic_quotes=false)
  56. {
  57. $s = ADOConnection::qstr($s, $magic_quotes);
  58. return str_replace("\0", "\\\\000", $s);
  59. }
  60. function MetaColumns($table)
  61. {
  62. $table = strtoupper($table);
  63. $arr= array();
  64. $dbc = $this->_connectionID;
  65. $osoptions = array();
  66. $osoptions[0] = null;
  67. $osoptions[1] = null;
  68. $osoptions[2] = $table;
  69. $osoptions[3] = null;
  70. $adors=@$dbc->OpenSchema(4, $osoptions);//tables
  71. if ($adors){
  72. while (!$adors->EOF){
  73. $fld = new ADOFieldObject();
  74. $c = $adors->Fields(3);
  75. $fld->name = $c->Value;
  76. $fld->type = 'CHAR'; // cannot discover type in ADO!
  77. $fld->max_length = -1;
  78. $arr[strtoupper($fld->name)]=$fld;
  79. $adors->MoveNext();
  80. }
  81. $adors->Close();
  82. }
  83. $false = false;
  84. return empty($arr) ? $false : $arr;
  85. }
  86. function CreateSequence($seq='adodbseq',$start=1)
  87. {
  88. $this->Execute('BEGIN TRANSACTION adodbseq');
  89. $start -= 1;
  90. $this->Execute("create table $seq (id float(53))");
  91. $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)");
  92. if (!$ok) {
  93. $this->Execute('ROLLBACK TRANSACTION adodbseq');
  94. return false;
  95. }
  96. $this->Execute('COMMIT TRANSACTION adodbseq');
  97. return true;
  98. }
  99. function GenID($seq='adodbseq',$start=1)
  100. {
  101. //$this->debug=1;
  102. $this->Execute('BEGIN TRANSACTION adodbseq');
  103. $ok = $this->Execute("update $seq with (tablock,holdlock) set id = id + 1");
  104. if (!$ok) {
  105. $this->Execute("create table $seq (id float(53))");
  106. $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)");
  107. if (!$ok) {
  108. $this->Execute('ROLLBACK TRANSACTION adodbseq');
  109. return false;
  110. }
  111. $this->Execute('COMMIT TRANSACTION adodbseq');
  112. return $start;
  113. }
  114. $num = $this->GetOne("select id from $seq");
  115. $this->Execute('COMMIT TRANSACTION adodbseq');
  116. return $num;
  117. // in old implementation, pre 1.90, we returned GUID...
  118. //return $this->GetOne("SELECT CONVERT(varchar(255), NEWID()) AS 'Char'");
  119. }
  120. } // end class
  121. class ADORecordSet_ado_mssql extends ADORecordSet_ado {
  122. var $databaseType = 'ado_mssql';
  123. function ADORecordSet_ado_mssql($id,$mode=false)
  124. {
  125. return $this->ADORecordSet_ado($id,$mode);
  126. }
  127. }
  128. ?>