TYPO3 CMS  TYPO3_6-2
adodb-mssql_n.inc.php
Go to the documentation of this file.
1 <?php
2 
4 
6 // //
7 // NOTICE OF COPYRIGHT //
8 // //
9 // ADOdb - Database Abstraction Library for PHP //
10 // http://adodb.sourceforge.net/ //
11 // //
12 // Copyright (c) 2000-2014 John Lim (jlim\@natsoft.com.my) //
13 // All rights reserved. //
14 // Released under both BSD license and LGPL library license. //
15 // Whenever there is any discrepancy between the two licenses, //
16 // the BSD license will take precedence //
17 // //
18 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
19 // http://moodle.com //
20 // //
21 // Copyright (C) 2001-3001 Martin Dougiamas http://dougiamas.com //
22 // (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com //
23 // //
24 // This program is free software; you can redistribute it and/or modify //
25 // it under the terms of the GNU General Public License as published by //
26 // the Free Software Foundation; either version 2 of the License, or //
27 // (at your option) any later version. //
28 // //
29 // This program is distributed in the hope that it will be useful, //
30 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
31 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
32 // GNU General Public License for more details: //
33 // //
34 // http://www.gnu.org/copyleft/gpl.html //
35 // //
37 
45 // security - hide paths
46 if (!defined('ADODB_DIR')) die();
47 
48 // one useful constant
49 if (!defined('SINGLEQUOTE')) define('SINGLEQUOTE', "'");
50 
51 include_once(ADODB_DIR.'/drivers/adodb-mssql.inc.php');
52 
53 class ADODB_mssql_n extends ADODB_mssql {
54  var $databaseType = "mssql_n";
55 
56  function ADODB_mssqlpo()
57  {
59  }
60 
61  function _query($sql,$inputarr=false)
62  {
63  $sql = $this->_appendN($sql);
64  return ADODB_mssql::_query($sql,$inputarr);
65  }
66 
76  function _appendN($sql) {
77 
78  $result = $sql;
79 
81  if (strpos($sql, SINGLEQUOTE) === false) {
82  return $sql;
83  }
84 
87  if ((substr_count($sql, SINGLEQUOTE) & 1)) {
88  if ($this->debug) {
89  ADOConnection::outp("{$this->databaseType} internal transformation: not converted. Wrong number of quotes (odd)");
90  }
91  return $sql;
92  }
93 
96  $regexp = '/(\\\\' . SINGLEQUOTE . '[^' . SINGLEQUOTE . '])/';
97  if (preg_match($regexp, $sql)) {
98  if ($this->debug) {
99  ADOConnection::outp("{$this->databaseType} internal transformation: not converted. Found bad use of backslash + single quote");
100  }
101  return $sql;
102  }
103 
105  $pairs = array();
106  $regexp = '/(' . SINGLEQUOTE . SINGLEQUOTE . ')/';
107  preg_match_all($regexp, $result, $list_of_pairs);
108  if ($list_of_pairs) {
109  foreach (array_unique($list_of_pairs[0]) as $key=>$value) {
110  $pairs['<@#@#@PAIR-'.$key.'@#@#@>'] = $value;
111  }
112  if (!empty($pairs)) {
113  $result = str_replace($pairs, array_keys($pairs), $result);
114  }
115  }
116 
118  $literals = array();
119  $regexp = '/(N?' . SINGLEQUOTE . '.*?' . SINGLEQUOTE . ')/is';
120  preg_match_all($regexp, $result, $list_of_literals);
121  if ($list_of_literals) {
122  foreach (array_unique($list_of_literals[0]) as $key=>$value) {
123  $literals['<#@#@#LITERAL-'.$key.'#@#@#>'] = $value;
124  }
125  if (!empty($literals)) {
126  $result = str_replace($literals, array_keys($literals), $result);
127  }
128  }
129 
130 
132  if (!empty($literals)) {
133  foreach ($literals as $key=>$value) {
134  if (!is_numeric(trim($value, SINGLEQUOTE))) {
136  $literals[$key] = 'N' . trim($value, 'N'); //Trimming potentially existing previous "N"
137  }
138  }
139  }
140 
142  if (!empty($literals)) {
143  $result = str_replace(array_keys($literals), $literals, $result);
144  }
145 
148  $result = preg_replace("/((<@#@#@PAIR-(\d+)@#@#@>)+)N'/", "N'$1", $result);
149 
151  if (!empty($pairs)) {
152  $result = str_replace(array_keys($pairs), $pairs, $result);
153  }
154 
156  if ($result != $sql && $this->debug) {
157  ADOConnection::outp("{$this->databaseType} internal transformation:<br>{$sql}<br>to<br>{$result}");
158  }
159 
160  return $result;
161  }
162 }
163 
165  var $databaseType = "mssql_n";
166  function ADORecordset_mssql_n($id,$mode=false)
167  {
168  $this->ADORecordset_mssql($id,$mode);
169  }
170 }
$sql
Definition: server.php:82
if(!defined('SINGLEQUOTE')) define('SINGLEQUOTE' drivers adodb mssql inc php t an odd number of single quotes(this can cause problems below *and should be considered one wrong SQL). Exit with debug info. */if((substr_count($sql SINGLEQUOTE $regexp)
if(preg_match($regexp, $sql)) $pairs
Remove pairs of single-quotes.
die
Definition: index.php:6
_query($sql, $inputarr=false)
ADORecordset_mssql_n($id, $mode=false)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
if($list_of_pairs) $literals
Remove the rest of literals present in the query.
debug($variable='', $name=' *variable *', $line=' *line *', $file=' *file *', $recursiveDepth=3, $debugLevel=E_DEBUG)