2 /* vim: set expandtab sw=4 ts=4 sts=4: */
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 the PEAR SOAP Module
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 * If you got this file from somewhere other than phpMyAdmin
17 * please be aware that the latest copy will always be in the
18 * phpMyAdmin subversion tree as
19 * $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyAdmin/libraries/sqlvalidator.class.php $
21 * This code that also used to depend on the PHP overload module, but that has been
26 * @author Robin Johnson <robbat2@users.sourceforge.net>
31 @include_once
'SOAP/Client.php';
33 if (!function_exists('class_exists') ||
!class_exists('SOAP_Client')) {
34 $GLOBALS['sqlvalidator_error'] = TRUE;
36 // Ok, we have SOAP Support, so let's use it!
38 class PMA_SQLValidator
{
48 var $calling_program_version;
50 var $target_dbms_version;
51 var $connectionTechnology;
52 var $connection_technology_version;
55 var $service_link = null;
56 var $session_data = null;
60 * Private functions - You don't need to mess with these
66 * @param string URL of Mimer SQL Validator WSDL file
68 * @return object Object to use
72 function _openService($url)
74 $obj = new SOAP_Client($url, TRUE);
76 } // end of the "openService()" function
80 * Service initializer to connect to server
82 * @param object Service object
83 * @param string Username
84 * @param string Password
85 * @param string Name of calling program
86 * @param string Version of calling program
87 * @param string Target DBMS
88 * @param string Version of target DBMS
89 * @param string Connection Technology
90 * @param string version of Connection Technology
91 * @param integer boolean of 1/0 to specify if we are an interactive system
93 * @return object stdClass return object with data
97 function _openSession($obj, $username, $password,
98 $calling_program, $calling_program_version,
99 $target_dbms, $target_dbms_version,
100 $connection_technology, $connection_technology_version,
103 $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);
104 $ret = $obj->call("openSession", $use_array);
106 // This is the old version that needed the overload extension
107 /* $ret = $obj->openSession($username, $password,
108 $calling_program, $calling_program_version,
109 $target_dbms, $target_dbms_version,
110 $connection_technology, $connection_technology_version,
114 } // end of the "_openSession()" function
118 * Validator sytem call
120 * @param object Service object
121 * @param object Session object
122 * @param string SQL Query to validate
123 * @param string Data return type
125 * @return object stClass return with data
129 function _validateSQL($obj, $session, $sql, $method)
131 $use_array = array("a_sessionId" => $session->sessionId
, "a_sessionKey" => $session->sessionKey
, "a_SQL" => $sql, "a_resultType" => $this->output_type
);
132 $res = $obj->call("validateSQL", $use_array);
134 // This is the old version that needed the overload extension
135 // $res = $obj->validateSQL($session->sessionId, $session->sessionKey, $sql, $this->output_type);
137 } // end of the "validateSQL()" function
141 * Validator sytem call
143 * @param string SQL Query to validate
145 * @return object stdClass return with data
151 function _validate($sql)
153 $ret = $this->_validateSQL($this->service_link
, $this->session_data
,
154 $sql, $this->output_type
);
156 } // end of the "validate()" function
168 function PMA_SQLValidator()
170 $this->url
= 'http://sqlvalidator.mimer.com/v1/services';
171 $this->service_name
= 'SQL99Validator';
172 $this->wsdl
= '?wsdl';
174 $this->output_type
= 'html';
176 $this->username
= 'anonymous';
177 $this->password
= '';
178 $this->calling_program
= 'PHP_SQLValidator';
179 $this->calling_program_version
= '$Revision$';
180 $this->target_dbms
= 'N/A';
181 $this->target_dbms_version
= 'N/A';
182 $this->connection_technology
= 'PHP';
183 $this->connection_technology_version
= phpversion();
184 $this->interactive
= 1;
186 $this->service_link
= null;
187 $this->session_data
= null;
188 } // end of the "PMA_SQLValidator()" function
194 * @param string the username
195 * @param string the password
199 function setCredentials($username, $password)
201 $this->username
= $username;
202 $this->password
= $password;
203 } // end of the "setCredentials()" function
207 * Sets the calling program
209 * @param string the calling program name
210 * @param string the calling program revision
214 function setCallingProgram($calling_program, $calling_program_version)
216 $this->calling_program
= $calling_program;
217 $this->calling_program_version
= $calling_program_version;
218 } // end of the "setCallingProgram()" function
222 * Appends the calling program
224 * @param string the calling program name
225 * @param string the calling program revision
229 function appendCallingProgram($calling_program, $calling_program_version)
231 $this->calling_program
.= ' - ' . $calling_program;
232 $this->calling_program_version
.= ' - ' . $calling_program_version;
233 } // end of the "appendCallingProgram()" function
237 * Sets the target DBMS
239 * @param string the target DBMS name
240 * @param string the target DBMS revision
244 function setTargetDbms($target_dbms, $target_dbms_version)
246 $this->target_dbms
= $target_dbms;
247 $this->target_dbms_version
= $target_dbms_version;
248 } // end of the "setTargetDbms()" function
252 * Appends the target DBMS
254 * @param string the target DBMS name
255 * @param string the target DBMS revision
259 function appendTargetDbms($target_dbms, $target_dbms_version)
261 $this->target_dbms
.= ' - ' . $target_dbms;
262 $this->target_dbms_version
.= ' - ' . $target_dbms_version;
263 } // end of the "appendTargetDbms()" function
267 * Sets the connection technology used
269 * @param string the connection technology name
270 * @param string the connection technology revision
274 function setConnectionTechnology($connection_technology, $connection_technology_version)
276 $this->connection_technology
= $connection_technology;
277 $this->connection_technology_version
= $connection_technology_version;
278 } // end of the "setConnectionTechnology()" function
282 * Appends the connection technology used
284 * @param string the connection technology name
285 * @param string the connection technology revision
289 function appendConnectionTechnology($connection_technology, $connection_technology_version)
291 $this->connection_technology
.= ' - ' . $connection_technology;
292 $this->connection_technology_version
.= ' - ' . $connection_technology_version;
293 } // end of the "appendConnectionTechnology()" function
297 * Sets whether interactive mode should be used or not
299 * @param integer whether interactive mode should be used or not
303 function setInteractive($interactive)
305 $this->interactive
= $interactive;
306 } // end of the "setInteractive()" function
310 * Sets the output type to use
312 * @param string the output type to use
316 function setOutputType($output_type)
318 $this->output_type
= $output_type;
319 } // end of the "setOutputType()" function
327 function startService()
330 $this->service_link
= $this->_openService($this->url
. '/' . $this->service_name
. $this->wsdl
);
332 } // end of the "startService()" function
340 function startSession()
342 $this->session_data
= $this->_openSession($this->service_link
, $this->username
, $this->password
,
343 $this->calling_program
, $this->calling_program_version
,
344 $this->target_dbms
, $this->target_dbms_version
,
345 $this->connection_technology
, $this->connection_technology_version
,
348 if (isset($this->session_data
) && ($this->session_data
!= null)
349 && ($this->session_data
->target
!= $this->url
)) {
350 // Reopens the service on the new URL that was provided
351 $url = $this->session_data
->target
;
352 $this->startService();
354 } // end of the "startSession()" function
358 * Do start service and session
364 $this->startService();
365 $this->startSession();
366 } // end of the "start()" function
370 * Call to determine just if a query is valid or not.
372 * @param string SQL statement to validate
374 * @return string Validator string from Mimer
378 function isValid($sql)
380 $res = $this->_validate($sql);
381 return $res->standard
;
382 } // end of the "isValid()" function
386 * Call for complete validator response
388 * @param string SQL statement to validate
390 * @return string Validator string from Mimer
394 function validationString($sql)
396 $res = $this->_validate($sql);
399 } // end of the "validationString()" function
400 } // end class PMA_SQLValidator
402 //add an extra check to ensure that the class was defined without errors
403 if (!class_exists('PMA_SQLValidator')) {
404 $GLOBALS['sqlvalidator_error'] = TRUE;