Translation update done using Pootle.
[phpmyadmin/dkf.git] / libraries / sqlvalidator.class.php
blob3b6847ccbf6621e6f6d1a8fe53e6e2645af2d11f
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 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
20 * This code that also used to depend on the PHP overload module, but that has been
21 * removed now.
23 * @access public
26 * @version $Id$
27 * @package phpMyAdmin
29 if (! defined('PHPMYADMIN')) {
30 exit;
33 /**
34 * Load SOAP client.
36 @include_once 'SOAP/Client.php';
38 if (!function_exists('class_exists') || !class_exists('SOAP_Client')) {
39 $GLOBALS['sqlvalidator_error'] = TRUE;
40 } else {
41 // Ok, we have SOAP Support, so let's use it!
43 /**
44 * @package phpMyAdmin
46 class PMA_SQLValidator {
48 var $url;
49 var $service_name;
50 var $wsdl;
51 var $output_type;
53 var $username;
54 var $password;
55 var $calling_program;
56 var $calling_program_version;
57 var $target_dbms;
58 var $target_dbms_version;
59 var $connectionTechnology;
60 var $connection_technology_version;
61 var $interactive;
63 var $service_link = null;
64 var $session_data = null;
67 /**
68 * Private functions - You don't need to mess with these
71 /**
72 * Service opening
74 * @param string URL of Mimer SQL Validator WSDL file
76 * @return object Object to use
78 * @access private
80 function _openService($url)
82 $obj = new SOAP_Client($url, TRUE);
83 return $obj;
84 } // end of the "openService()" function
87 /**
88 * Service initializer to connect to server
90 * @param object Service object
91 * @param string Username
92 * @param string Password
93 * @param string Name of calling program
94 * @param string Version of calling program
95 * @param string Target DBMS
96 * @param string Version of target DBMS
97 * @param string Connection Technology
98 * @param string version of Connection Technology
99 * @param integer boolean of 1/0 to specify if we are an interactive system
101 * @return object stdClass return object with data
103 * @access private
105 function _openSession($obj, $username, $password,
106 $calling_program, $calling_program_version,
107 $target_dbms, $target_dbms_version,
108 $connection_technology, $connection_technology_version,
109 $interactive)
111 $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);
112 $ret = $obj->call("openSession", $use_array);
114 // This is the old version that needed the overload extension
115 /* $ret = $obj->openSession($username, $password,
116 $calling_program, $calling_program_version,
117 $target_dbms, $target_dbms_version,
118 $connection_technology, $connection_technology_version,
119 $interactive); */
121 return $ret;
122 } // end of the "_openSession()" function
126 * Validator sytem call
128 * @param object Service object
129 * @param object Session object
130 * @param string SQL Query to validate
131 * @param string Data return type
133 * @return object stClass return with data
135 * @access private
137 function _validateSQL($obj, $session, $sql, $method)
139 $use_array = array("a_sessionId" => $session->sessionId, "a_sessionKey" => $session->sessionKey, "a_SQL" => $sql, "a_resultType" => $this->output_type);
140 $res = $obj->call("validateSQL", $use_array);
142 // This is the old version that needed the overload extension
143 // $res = $obj->validateSQL($session->sessionId, $session->sessionKey, $sql, $this->output_type);
144 return $res;
145 } // end of the "validateSQL()" function
149 * Validator sytem call
151 * @param string SQL Query to validate
153 * @return object stdClass return with data
155 * @access private
157 * @see validateSQL()
159 function _validate($sql)
161 $ret = $this->_validateSQL($this->service_link, $this->session_data,
162 $sql, $this->output_type);
163 return $ret;
164 } // end of the "validate()" function
168 * Public functions
172 * Constructor
174 * @access public
176 function __construct()
178 $this->url = 'http://sqlvalidator.mimer.com/v1/services';
179 $this->service_name = 'SQL99Validator';
180 $this->wsdl = '?wsdl';
182 $this->output_type = 'html';
184 $this->username = 'anonymous';
185 $this->password = '';
186 $this->calling_program = 'PHP_SQLValidator';
187 $this->calling_program_version = '$Revision$';
188 $this->target_dbms = 'N/A';
189 $this->target_dbms_version = 'N/A';
190 $this->connection_technology = 'PHP';
191 $this->connection_technology_version = phpversion();
192 $this->interactive = 1;
194 $this->service_link = null;
195 $this->session_data = null;
196 } // end of the "PMA_SQLValidator()" function
200 * Sets credentials
202 * @param string the username
203 * @param string the password
205 * @access public
207 function setCredentials($username, $password)
209 $this->username = $username;
210 $this->password = $password;
211 } // end of the "setCredentials()" function
215 * Sets the calling program
217 * @param string the calling program name
218 * @param string the calling program revision
220 * @access public
222 function setCallingProgram($calling_program, $calling_program_version)
224 $this->calling_program = $calling_program;
225 $this->calling_program_version = $calling_program_version;
226 } // end of the "setCallingProgram()" function
230 * Appends the calling program
232 * @param string the calling program name
233 * @param string the calling program revision
235 * @access public
237 function appendCallingProgram($calling_program, $calling_program_version)
239 $this->calling_program .= ' - ' . $calling_program;
240 $this->calling_program_version .= ' - ' . $calling_program_version;
241 } // end of the "appendCallingProgram()" function
245 * Sets the target DBMS
247 * @param string the target DBMS name
248 * @param string the target DBMS revision
250 * @access public
252 function setTargetDbms($target_dbms, $target_dbms_version)
254 $this->target_dbms = $target_dbms;
255 $this->target_dbms_version = $target_dbms_version;
256 } // end of the "setTargetDbms()" function
260 * Appends the target DBMS
262 * @param string the target DBMS name
263 * @param string the target DBMS revision
265 * @access public
267 function appendTargetDbms($target_dbms, $target_dbms_version)
269 $this->target_dbms .= ' - ' . $target_dbms;
270 $this->target_dbms_version .= ' - ' . $target_dbms_version;
271 } // end of the "appendTargetDbms()" function
275 * Sets the connection technology used
277 * @param string the connection technology name
278 * @param string the connection technology revision
280 * @access public
282 function setConnectionTechnology($connection_technology, $connection_technology_version)
284 $this->connection_technology = $connection_technology;
285 $this->connection_technology_version = $connection_technology_version;
286 } // end of the "setConnectionTechnology()" function
290 * Appends the connection technology used
292 * @param string the connection technology name
293 * @param string the connection technology revision
295 * @access public
297 function appendConnectionTechnology($connection_technology, $connection_technology_version)
299 $this->connection_technology .= ' - ' . $connection_technology;
300 $this->connection_technology_version .= ' - ' . $connection_technology_version;
301 } // end of the "appendConnectionTechnology()" function
305 * Sets whether interactive mode should be used or not
307 * @param integer whether interactive mode should be used or not
309 * @access public
311 function setInteractive($interactive)
313 $this->interactive = $interactive;
314 } // end of the "setInteractive()" function
318 * Sets the output type to use
320 * @param string the output type to use
322 * @access public
324 function setOutputType($output_type)
326 $this->output_type = $output_type;
327 } // end of the "setOutputType()" function
331 * Starts service
333 * @access public
335 function startService()
338 $this->service_link = $this->_openService($this->url . '/' . $this->service_name . $this->wsdl);
340 } // end of the "startService()" function
344 * Starts session
346 * @access public
348 function startSession()
350 $this->session_data = $this->_openSession($this->service_link, $this->username, $this->password,
351 $this->calling_program, $this->calling_program_version,
352 $this->target_dbms, $this->target_dbms_version,
353 $this->connection_technology, $this->connection_technology_version,
354 $this->interactive);
356 if (isset($this->session_data) && ($this->session_data != null)
357 && ($this->session_data->target != $this->url)) {
358 // Reopens the service on the new URL that was provided
359 $url = $this->session_data->target;
360 $this->startService();
362 } // end of the "startSession()" function
366 * Do start service and session
368 * @access public
370 function start()
372 $this->startService();
373 $this->startSession();
374 } // end of the "start()" function
378 * Call to determine just if a query is valid or not.
380 * @param string SQL statement to validate
382 * @return string Validator string from Mimer
384 * @see _validate
386 function isValid($sql)
388 $res = $this->_validate($sql);
389 return $res->standard;
390 } // end of the "isValid()" function
394 * Call for complete validator response
396 * @param string SQL statement to validate
398 * @return string Validator string from Mimer
400 * @see _validate
402 function validationString($sql)
404 $res = $this->_validate($sql);
405 return $res->data;
407 } // end of the "validationString()" function
408 } // end class PMA_SQLValidator
410 //add an extra check to ensure that the class was defined without errors
411 if (!class_exists('PMA_SQLValidator')) {
412 $GLOBALS['sqlvalidator_error'] = TRUE;
415 } // end else