Refresh .po files
[phpmyadmin/madhuracj.git] / libraries / sqlvalidator.class.php
blobf7b836a16297e01a6c42dce84ab5740de7befaf6
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * PHP interface to MimerSQL Validator
6 * Copyright 2002, 2003 Robin Johnson <robbat2@users.sourceforge.net>
7 * http://www.orbis-terrarum.net/?l=people.robbat2
9 * All data is transported over HTTP-SOAP
10 * And uses either the PEAR SOAP Module or PHP SOAP extension
12 * Install instructions for PEAR SOAP:
13 * Make sure you have a really recent PHP with PEAR support
14 * run this: "pear install Mail_Mime Net_DIME SOAP"
16 * @access public
18 * @package phpMyAdmin
20 if (! defined('PHPMYADMIN')) {
21 exit;
24 /**
25 * Load SOAP client.
27 if (class_exists('SOAPClient')) {
28 $GLOBALS['sqlvalidator_error'] = false;
29 $GLOBALS['sqlvalidator_soap'] = 'PHP';
30 } else {
31 @include_once 'SOAP/Client.php';
32 if (class_exists('SOAP_Client')) {
33 $GLOBALS['sqlvalidator_soap'] = 'PEAR';
34 $GLOBALS['sqlvalidator_error'] = false;
35 } else {
36 $GLOBALS['sqlvalidator_soap'] = 'NONE';
37 $GLOBALS['sqlvalidator_error'] = true;
38 PMA_warnMissingExtension('soap');
42 if (!$GLOBALS['sqlvalidator_error']) {
43 // Ok, we have SOAP Support, so let's use it!
45 /**
46 * @package phpMyAdmin
48 class PMA_SQLValidator {
50 var $url;
51 var $service_name;
52 var $wsdl;
53 var $output_type;
55 var $username;
56 var $password;
57 var $calling_program;
58 var $calling_program_version;
59 var $target_dbms;
60 var $target_dbms_version;
61 var $connectionTechnology;
62 var $connection_technology_version;
63 var $interactive;
65 var $service_link = null;
66 var $session_data = null;
69 /**
70 * Private functions - You don't need to mess with these
73 /**
74 * Service opening
76 * @param string URL of Mimer SQL Validator WSDL file
78 * @return object Object to use
80 * @access private
82 function _openService($url)
84 if ($GLOBALS['sqlvalidator_soap'] == 'PHP') {
85 $obj = new SOAPClient($url);
86 } else {
87 $obj = new SOAP_Client($url, true);
89 return $obj;
90 } // end of the "openService()" function
93 /**
94 * Service initializer to connect to server
96 * @param object Service object
97 * @param string Username
98 * @param string Password
99 * @param string Name of calling program
100 * @param string Version of calling program
101 * @param string Target DBMS
102 * @param string Version of target DBMS
103 * @param string Connection Technology
104 * @param string version of Connection Technology
105 * @param integer boolean of 1/0 to specify if we are an interactive system
107 * @return object stdClass return object with data
109 * @access private
111 function _openSession($obj, $username, $password,
112 $calling_program, $calling_program_version,
113 $target_dbms, $target_dbms_version,
114 $connection_technology, $connection_technology_version,
115 $interactive)
117 $use_array = array(
118 "a_userName" => $username,
119 "a_password" => $password,
120 "a_callingProgram" => $calling_program,
121 "a_callingProgramVersion" => $calling_program_version,
122 "a_targetDbms" => $target_dbms,
123 "a_targetDbmsVersion" => $target_dbms_version,
124 "a_connectionTechnology" => $connection_technology,
125 "a_connectionTechnologyVersion" => $connection_technology_version,
126 "a_interactive" => $interactive,
129 if ($GLOBALS['sqlvalidator_soap'] == 'PHP') {
130 $ret = $obj->__soapCall("openSession", $use_array);
131 } else {
132 $ret = $obj->call("openSession", $use_array);
135 return $ret;
136 } // end of the "_openSession()" function
140 * Validator sytem call
142 * @param object Service object
143 * @param object Session object
144 * @param string SQL Query to validate
145 * @param string Data return type
147 * @return object stClass return with data
149 * @access private
151 function _validateSQL($obj, $session, $sql, $method)
153 $use_array = array(
154 "a_sessionId" => $session->sessionId,
155 "a_sessionKey" => $session->sessionKey,
156 "a_SQL" => $sql,
157 "a_resultType" => $this->output_type,
160 if ($GLOBALS['sqlvalidator_soap'] == 'PHP') {
161 $res = $obj->__soapCall("validateSQL", $use_array);
162 } else {
163 $res = $obj->call("validateSQL", $use_array);
166 return $res;
167 } // end of the "validateSQL()" function
171 * Validator sytem call
173 * @param string SQL Query to validate
175 * @return object stdClass return with data
177 * @access private
179 * @see validateSQL()
181 function _validate($sql)
183 $ret = $this->_validateSQL($this->service_link, $this->session_data,
184 $sql, $this->output_type);
185 return $ret;
186 } // end of the "validate()" function
190 * Public functions
194 * Constructor
196 * @access public
198 function __construct()
200 $this->url = 'http://sqlvalidator.mimer.com/v1/services';
201 $this->service_name = 'SQL99Validator';
202 $this->wsdl = '?wsdl';
204 $this->output_type = 'html';
206 $this->username = 'anonymous';
207 $this->password = '';
208 $this->calling_program = 'PHP_SQLValidator';
209 $this->calling_program_version = PMA_VERSION;
210 $this->target_dbms = 'N/A';
211 $this->target_dbms_version = 'N/A';
212 $this->connection_technology = 'PHP';
213 $this->connection_technology_version = phpversion();
214 $this->interactive = 1;
216 $this->service_link = null;
217 $this->session_data = null;
218 } // end of the "PMA_SQLValidator()" function
222 * Sets credentials
224 * @param string the username
225 * @param string the password
227 * @access public
229 function setCredentials($username, $password)
231 $this->username = $username;
232 $this->password = $password;
233 } // end of the "setCredentials()" function
237 * Sets the calling program
239 * @param string the calling program name
240 * @param string the calling program revision
242 * @access public
244 function setCallingProgram($calling_program, $calling_program_version)
246 $this->calling_program = $calling_program;
247 $this->calling_program_version = $calling_program_version;
248 } // end of the "setCallingProgram()" function
252 * Appends the calling program
254 * @param string the calling program name
255 * @param string the calling program revision
257 * @access public
259 function appendCallingProgram($calling_program, $calling_program_version)
261 $this->calling_program .= ' - ' . $calling_program;
262 $this->calling_program_version .= ' - ' . $calling_program_version;
263 } // end of the "appendCallingProgram()" function
267 * Sets the target DBMS
269 * @param string the target DBMS name
270 * @param string the target DBMS revision
272 * @access public
274 function setTargetDbms($target_dbms, $target_dbms_version)
276 $this->target_dbms = $target_dbms;
277 $this->target_dbms_version = $target_dbms_version;
278 } // end of the "setTargetDbms()" function
282 * Appends the target DBMS
284 * @param string the target DBMS name
285 * @param string the target DBMS revision
287 * @access public
289 function appendTargetDbms($target_dbms, $target_dbms_version)
291 $this->target_dbms .= ' - ' . $target_dbms;
292 $this->target_dbms_version .= ' - ' . $target_dbms_version;
293 } // end of the "appendTargetDbms()" function
297 * Sets the connection technology used
299 * @param string the connection technology name
300 * @param string the connection technology revision
302 * @access public
304 function setConnectionTechnology($connection_technology, $connection_technology_version)
306 $this->connection_technology = $connection_technology;
307 $this->connection_technology_version = $connection_technology_version;
308 } // end of the "setConnectionTechnology()" function
312 * Appends the connection technology used
314 * @param string the connection technology name
315 * @param string the connection technology revision
317 * @access public
319 function appendConnectionTechnology($connection_technology, $connection_technology_version)
321 $this->connection_technology .= ' - ' . $connection_technology;
322 $this->connection_technology_version .= ' - ' . $connection_technology_version;
323 } // end of the "appendConnectionTechnology()" function
327 * Sets whether interactive mode should be used or not
329 * @param integer whether interactive mode should be used or not
331 * @access public
333 function setInteractive($interactive)
335 $this->interactive = $interactive;
336 } // end of the "setInteractive()" function
340 * Sets the output type to use
342 * @param string the output type to use
344 * @access public
346 function setOutputType($output_type)
348 $this->output_type = $output_type;
349 } // end of the "setOutputType()" function
353 * Starts service
355 * @access public
357 function startService()
360 $this->service_link = $this->_openService($this->url . '/' . $this->service_name . $this->wsdl);
362 } // end of the "startService()" function
366 * Starts session
368 * @access public
370 function startSession()
372 $this->session_data = $this->_openSession($this->service_link, $this->username, $this->password,
373 $this->calling_program, $this->calling_program_version,
374 $this->target_dbms, $this->target_dbms_version,
375 $this->connection_technology, $this->connection_technology_version,
376 $this->interactive);
378 if (isset($this->session_data) && ($this->session_data != null)
379 && ($this->session_data->target != $this->url)) {
380 // Reopens the service on the new URL that was provided
381 $url = $this->session_data->target;
382 $this->startService();
384 } // end of the "startSession()" function
388 * Do start service and session
390 * @access public
392 function start()
394 $this->startService();
395 $this->startSession();
396 } // end of the "start()" function
400 * Call to determine just if a query is valid or not.
402 * @param string SQL statement to validate
404 * @return string Validator string from Mimer
406 * @see _validate
408 function isValid($sql)
410 $res = $this->_validate($sql);
411 return $res->standard;
412 } // end of the "isValid()" function
416 * Call for complete validator response
418 * @param string SQL statement to validate
420 * @return string Validator string from Mimer
422 * @see _validate
424 function validationString($sql)
426 $res = $this->_validate($sql);
427 return $res->data;
429 } // end of the "validationString()" function
430 } // end class PMA_SQLValidator
432 //add an extra check to ensure that the class was defined without errors
433 if (!class_exists('PMA_SQLValidator')) {
434 $GLOBALS['sqlvalidator_error'] = true;
437 } // end else