bug #1233349 db search in MySQL 5.0.x on fields without a charset
[phpmyadmin/crack.git] / libraries / sqlvalidator.class.php
blobe6aab9cda29e0c1d2195530a6952fe8855ebb0f9
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 /**
6 * PHP interface to MimerSQL Validator
8 * Copyright 2002, 2003 Robin Johnson <robbat2@users.sourceforge.net>
9 * http://www.orbis-terrarum.net/?l=people.robbat2
11 * All data is transported over HTTP-SOAP
12 * And uses the PEAR SOAP Module
14 * Install instructions for PEAR SOAP
15 * Make sure you have a really recent PHP with PEAR support
16 * run this: "pear install Mail_Mime Net_DIME SOAP"
18 * If you got this file from somewhere other than phpMyAdmin
19 * please be aware that the latest copy will always be in the
20 * phpMyAdmin CVS tree as
21 * $Source$
23 * This code that also used to depend on the PHP overload module, but that has been
24 * removed now.
26 * @access public
28 * @author Robin Johnson <robbat2@users.sourceforge.net>
30 * @version $Id$
33 @include_once('SOAP/Client.php');
35 if (!function_exists('class_exists') || !class_exists('SOAP_Client')) {
36 $GLOBALS['sqlvalidator_error'] = TRUE;
37 } else {
38 // Ok, we have SOAP Support, so let's use it!
40 class PMA_SQLValidator {
42 var $url;
43 var $service_name;
44 var $wsdl;
45 var $output_type;
47 var $username;
48 var $password;
49 var $calling_program;
50 var $calling_program_version;
51 var $target_dbms;
52 var $target_dbms_version;
53 var $connectionTechnology;
54 var $connection_technology_version;
55 var $interactive;
57 var $service_link = NULL;
58 var $session_data = NULL;
61 /**
62 * Private functions - You don't need to mess with these
65 /**
66 * Service opening
68 * @param string URL of Mimer SQL Validator WSDL file
70 * @return object Object to use
72 * @access private
74 function _openService($url)
76 $obj = new SOAP_Client($url, TRUE);
77 return $obj;
78 } // end of the "openService()" function
81 /**
82 * Service initializer to connect to server
84 * @param object Service object
85 * @param string Username
86 * @param string Password
87 * @param string Name of calling program
88 * @param string Version of calling program
89 * @param string Target DBMS
90 * @param string Version of target DBMS
91 * @param string Connection Technology
92 * @param string version of Connection Technology
93 * @param integer boolean of 1/0 to specify if we are an interactive system
95 * @return object stdClass return object with data
97 * @access private
99 function _openSession($obj, $username, $password,
100 $calling_program, $calling_program_version,
101 $target_dbms, $target_dbms_version,
102 $connection_technology, $connection_technology_version,
103 $interactive)
105 $use_array = array( "a_userName" => $username, "a_password" => $password, "a_callingProgram" => $calling_program, "a_callingProgramVersion" => $calling_program_version, "a_targetDbms" => $target_dbms, "a_targetDbmsVersion" => $target_dbms_version, "a_connectionTechnology" => $connection_technology, "a_connectionTechnologyVersion" => $connection_technology_version, "a_interactive" => $interactive);
106 $ret = $obj->call("openSession",$use_array);
108 // This is the old version that needed the overload extension
109 /* $ret = $obj->openSession($username, $password,
110 $calling_program, $calling_program_version,
111 $target_dbms, $target_dbms_version,
112 $connection_technology, $connection_technology_version,
113 $interactive); */
115 return $ret;
116 } // end of the "_openSession()" function
120 * Validator sytem call
122 * @param object Service object
123 * @param object Session object
124 * @param string SQL Query to validate
125 * @param string Data return type
127 * @return object stClass return with data
129 * @access private
131 function _validateSQL($obj, $session, $sql, $method)
133 $use_array = array("a_sessionId" => $session->sessionId, "a_sessionKey" => $session->sessionKey, "a_SQL" => $sql, "a_resultType" => $this->output_type);
134 $res = $obj->call("validateSQL",$use_array);
136 // This is the old version that needed the overload extension
137 // $res = $obj->validateSQL($session->sessionId, $session->sessionKey, $sql, $this->output_type);
138 return $res;
139 } // end of the "validateSQL()" function
143 * Validator sytem call
145 * @param string SQL Query to validate
147 * @return object stdClass return with data
149 * @access private
151 * @see validateSQL()
153 function _validate($sql)
155 $ret = $this->_validateSQL($this->service_link, $this->session_data,
156 $sql, $this->output_type);
157 return $ret;
158 } // end of the "validate()" function
162 * Public functions
166 * Constructor
168 * @access public
170 function PMA_SQLValidator()
172 $this->url = 'http://sqlvalidator.mimer.com/v1/services';
173 $this->service_name = 'SQL99Validator';
174 $this->wsdl = '?wsdl';
176 $this->output_type = 'html';
178 $this->username = 'anonymous';
179 $this->password = '';
180 $this->calling_program = 'PHP_SQLValidator';
181 $this->calling_program_version = '$Revision$';
182 $this->target_dbms = 'N/A';
183 $this->target_dbms_version = 'N/A';
184 $this->connection_technology = 'PHP';
185 $this->connection_technology_version = phpversion();
186 $this->interactive = 1;
188 $this->service_link = NULL;
189 $this->session_data = NULL;
190 } // end of the "PMA_SQLValidator()" function
194 * Sets credentials
196 * @param string the username
197 * @param string the password
199 * @access public
201 function setCredentials($username, $password)
203 $this->username = $username;
204 $this->password = $password;
205 } // end of the "setCredentials()" function
209 * Sets the calling program
211 * @param string the calling program name
212 * @param string the calling program revision
214 * @access public
216 function setCallingProgram($calling_program, $calling_program_version)
218 $this->calling_program = $calling_program;
219 $this->calling_program_version = $calling_program_version;
220 } // end of the "setCallingProgram()" function
224 * Appends the calling program
226 * @param string the calling program name
227 * @param string the calling program revision
229 * @access public
231 function appendCallingProgram($calling_program, $calling_program_version)
233 $this->calling_program .= ' - ' . $calling_program;
234 $this->calling_program_version .= ' - ' . $calling_program_version;
235 } // end of the "appendCallingProgram()" function
239 * Sets the target DBMS
241 * @param string the target DBMS name
242 * @param string the target DBMS revision
244 * @access public
246 function setTargetDbms($target_dbms, $target_dbms_version)
248 $this->target_dbms = $target_dbms;
249 $this->target_dbms_version = $target_dbms_version;
250 } // end of the "setTargetDbms()" function
254 * Appends the target DBMS
256 * @param string the target DBMS name
257 * @param string the target DBMS revision
259 * @access public
261 function appendTargetDbms($target_dbms, $target_dbms_version)
263 $this->target_dbms .= ' - ' . $target_dbms;
264 $this->target_dbms_version .= ' - ' . $target_dbms_version;
265 } // end of the "appendTargetDbms()" function
269 * Sets the connection technology used
271 * @param string the connection technology name
272 * @param string the connection technology revision
274 * @access public
276 function setConnectionTechnology($connection_technology, $connection_technology_version)
278 $this->connection_technology = $connection_technology;
279 $this->connection_technology_version = $connection_technology_version;
280 } // end of the "setConnectionTechnology()" function
284 * Appends the connection technology used
286 * @param string the connection technology name
287 * @param string the connection technology revision
289 * @access public
291 function appendConnectionTechnology($connection_technology, $connection_technology_version)
293 $this->connection_technology .= ' - ' . $connection_technology;
294 $this->connection_technology_version .= ' - ' . $connection_technology_version;
295 } // end of the "appendConnectionTechnology()" function
299 * Sets whether interactive mode should be used or not
301 * @param integer whether interactive mode should be used or not
303 * @access public
305 function setInteractive($interactive)
307 $this->interactive = $interactive;
308 } // end of the "setInteractive()" function
312 * Sets the output type to use
314 * @param string the output type to use
316 * @access public
318 function setOutputType($output_type)
320 $this->output_type = $output_type;
321 } // end of the "setOutputType()" function
325 * Starts service
327 * @access public
329 function startService()
332 $this->service_link = $this->_openService($this->url . '/' . $this->service_name . $this->wsdl);
334 } // end of the "startService()" function
338 * Starts session
340 * @access public
342 function startSession()
344 $this->session_data = $this->_openSession($this->service_link, $this->username, $this->password,
345 $this->calling_program, $this->calling_program_version,
346 $this->target_dbms, $this->target_dbms_version,
347 $this->connection_technology, $this->connection_technology_version,
348 $this->interactive);
350 if (isset($this->session_data) && ($this->session_data != NULL)
351 && ($this->session_data->target != $this->url)) {
352 // Reopens the service on the new URL that was provided
353 $url = $this->session_data->target;
354 $this->startService();
356 } // end of the "startSession()" function
360 * Do start service and session
362 * @access public
364 function start()
366 $this->startService();
367 $this->startSession();
368 } // end of the "start()" function
372 * Call to determine just if a query is valid or not.
374 * @param string SQL statement to validate
376 * @return string Validator string from Mimer
378 * @see _validate
380 function isValid($sql)
382 $res = $this->_validate($sql);
383 return $res->standard;
384 } // end of the "isValid()" function
388 * Call for complete validator response
390 * @param string SQL statement to validate
392 * @return string Validator string from Mimer
394 * @see _validate
396 function validationString($sql)
398 $res = $this->_validate($sql);
399 return $res->data;
401 } // end of the "validationString()" function
402 } // end class PMA_SQLValidator
404 //add an extra check to ensure that the class was defined without errors
405 if (!class_exists('PMA_SQLValidator')) {
406 $GLOBALS['sqlvalidator_error'] = TRUE;
409 } // end else