|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00004 00006 // // 00007 // NOTICE OF COPYRIGHT // 00008 // // 00009 // ADOdb - Database Abstraction Library for PHP // 00010 // http://adodb.sourceforge.net/ // 00011 // // 00012 // Copyright (c) 2000-2011 John Lim (jlim\@natsoft.com.my) // 00013 // All rights reserved. // 00014 // Released under both BSD license and LGPL library license. // 00015 // Whenever there is any discrepancy between the two licenses, // 00016 // the BSD license will take precedence // 00017 // // 00018 // Moodle - Modular Object-Oriented Dynamic Learning Environment // 00019 // http://moodle.com // 00020 // // 00021 // Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com // 00022 // (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com // 00023 // // 00024 // This program is free software; you can redistribute it and/or modify // 00025 // it under the terms of the GNU General Public License as published by // 00026 // the Free Software Foundation; either version 2 of the License, or // 00027 // (at your option) any later version. // 00028 // // 00029 // This program is distributed in the hope that it will be useful, // 00030 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 00031 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 00032 // GNU General Public License for more details: // 00033 // // 00034 // http://www.gnu.org/copyleft/gpl.html // 00035 // // 00037 00045 // security - hide paths 00046 if (!defined('ADODB_DIR')) die(); 00047 00048 // one useful constant 00049 if (!defined('SINGLEQUOTE')) define('SINGLEQUOTE', "'"); 00050 00051 include_once(ADODB_DIR.'/drivers/adodb-mssql.inc.php'); 00052 00053 class ADODB_mssql_n extends ADODB_mssql { 00054 var $databaseType = "mssql_n"; 00055 00056 function ADODB_mssqlpo() 00057 { 00058 ADODB_mssql::ADODB_mssql(); 00059 } 00060 00061 function _query($sql,$inputarr=false) 00062 { 00063 $sql = $this->_appendN($sql); 00064 return ADODB_mssql::_query($sql,$inputarr); 00065 } 00066 00076 function _appendN($sql) { 00077 00078 $result = $sql; 00079 00081 if (strpos($sql, SINGLEQUOTE) === false) { 00082 return $sql; 00083 } 00084 00087 if ((substr_count($sql, SINGLEQUOTE) & 1)) { 00088 if ($this->debug) { 00089 ADOConnection::outp("{$this->databaseType} internal transformation: not converted. Wrong number of quotes (odd)"); 00090 } 00091 return $sql; 00092 } 00093 00096 $regexp = '/(\\\\' . SINGLEQUOTE . '[^' . SINGLEQUOTE . '])/'; 00097 if (preg_match($regexp, $sql)) { 00098 if ($this->debug) { 00099 ADOConnection::outp("{$this->databaseType} internal transformation: not converted. Found bad use of backslash + single quote"); 00100 } 00101 return $sql; 00102 } 00103 00105 $pairs = array(); 00106 $regexp = '/(' . SINGLEQUOTE . SINGLEQUOTE . ')/'; 00107 preg_match_all($regexp, $result, $list_of_pairs); 00108 if ($list_of_pairs) { 00109 foreach (array_unique($list_of_pairs[0]) as $key=>$value) { 00110 $pairs['<@#@#@PAIR-'.$key.'@#@#@>'] = $value; 00111 } 00112 if (!empty($pairs)) { 00113 $result = str_replace($pairs, array_keys($pairs), $result); 00114 } 00115 } 00116 00118 $literals = array(); 00119 $regexp = '/(N?' . SINGLEQUOTE . '.*?' . SINGLEQUOTE . ')/is'; 00120 preg_match_all($regexp, $result, $list_of_literals); 00121 if ($list_of_literals) { 00122 foreach (array_unique($list_of_literals[0]) as $key=>$value) { 00123 $literals['<#@#@#LITERAL-'.$key.'#@#@#>'] = $value; 00124 } 00125 if (!empty($literals)) { 00126 $result = str_replace($literals, array_keys($literals), $result); 00127 } 00128 } 00129 00130 00132 if (!empty($literals)) { 00133 foreach ($literals as $key=>$value) { 00134 if (!is_numeric(trim($value, SINGLEQUOTE))) { 00136 $literals[$key] = 'N' . trim($value, 'N'); //Trimming potentially existing previous "N" 00137 } 00138 } 00139 } 00140 00142 if (!empty($literals)) { 00143 $result = str_replace(array_keys($literals), $literals, $result); 00144 } 00145 00148 $result = preg_replace("/((<@#@#@PAIR-(\d+)@#@#@>)+)N'/", "N'$1", $result); 00149 00151 if (!empty($pairs)) { 00152 $result = str_replace(array_keys($pairs), $pairs, $result); 00153 } 00154 00156 if ($result != $sql && $this->debug) { 00157 ADOConnection::outp("{$this->databaseType} internal transformation:<br>{$sql}<br>to<br>{$result}"); 00158 } 00159 00160 return $result; 00161 } 00162 } 00163 00164 class ADORecordset_mssql_n extends ADORecordset_mssql { 00165 var $databaseType = "mssql_n"; 00166 function ADORecordset_mssql_n($id,$mode=false) 00167 { 00168 $this->ADORecordset_mssql($id,$mode); 00169 } 00170 } 00171 ?>