* libraries/sqlvalidator.php3, libraries/sqlvalidator.class.php3:

- Function documentation and cleanup
This commit is contained in:
Robin Johnson
2002-08-03 22:17:48 +00:00
parent c28a9175ec
commit d67eb1ca1d
3 changed files with 124 additions and 19 deletions

View File

@@ -31,6 +31,8 @@ $Source$
* sql.php3, libraries/common.lib.php3: * sql.php3, libraries/common.lib.php3:
- Improved logic of edit, show_as_php, explain and validator - Improved logic of edit, show_as_php, explain and validator
in the SQL query box in the SQL query box
* libraries/sqlvalidator.php3, libraries/sqlvalidator.class.php3:
- Function documentation and cleanup
2002-08-02 Robin Johnson <robbat2@users.sourceforge.net> 2002-08-02 Robin Johnson <robbat2@users.sourceforge.net>
* libraries/defines*: * libraries/defines*:

View File

@@ -16,14 +16,17 @@
* *
* *
* @access public * @access public
* @author Robin Johnson <robbat2@orbis-terrarum.net> * @author Robin Johnson <robbat2@users.sourceforge.net>
* @version $Revision$ * @version $Id$
*/ */
if (!defined('PMA_SQL_VALIDATOR_CLASS_INCLUDED')) { if (!defined('PMA_SQL_VALIDATOR_CLASS_INCLUDED')) {
define('PMA_SQL_VALIDATOR_CLASS_INCLUDED', 1); define('PMA_SQL_VALIDATOR_CLASS_INCLUDED', 1);
include("SOAP/Client.php"); @include("SOAP/Client.php");
if(!class_exists('SOAP_Client') {
$GLOBALS['sqlvalidator_error'] = TRUE;
} else {
// Ok, so we have SOAP Support, so let's use it! // Ok, so we have SOAP Support, so let's use it!
@@ -52,6 +55,7 @@ if (!defined('PMA_SQL_VALIDATOR_CLASS_INCLUDED')) {
$this->url = "http://sqlvalidator.mimer.com/v1/services"; $this->url = "http://sqlvalidator.mimer.com/v1/services";
$this->serviceName = 'SQL99Validator'; $this->serviceName = 'SQL99Validator';
$this->wsdl = '?wsdl'; $this->wsdl = '?wsdl';
$this->outputType = 'html'; $this->outputType = 'html';
$this->username = 'anonymous'; $this->username = 'anonymous';
@@ -120,6 +124,11 @@ if (!defined('PMA_SQL_VALIDATOR_CLASS_INCLUDED')) {
$this->interactive = $interactive; $this->interactive = $interactive;
} }
function setOutputType($outputtype)
{
$this->OutputType = $outputtype;
}
function start() function start()
{ {
$this->startService(); $this->startService();
@@ -145,21 +154,46 @@ if (!defined('PMA_SQL_VALIDATOR_CLASS_INCLUDED')) {
} }
} }
/**
* Call to determine just if a query is valid or not.
*
* @param string SQL statement to validate
*
* @return string Validator string from Mimer
*
* @see _validate
*/
function isValid($sql) function isValid($sql)
{ {
$res = $this->_validate($sql); $res = $this->_validate($sql);
return $res->standard; return $res->standard;
} }
/**
* Call for complete validator response
*
* @param string SQL statement to validate
*
* @return string Validator string from Mimer
*
* @see _validate
*/
function ValidationString($sql) function ValidationString($sql)
{ {
$res = $this->_validate($sql); $res = $this->_validate($sql);
return $res->data; return $res->data;
} }
/* Private functions beyond here /** Private functions beyond here
* You don't need to mess with these
*/
/**
* Service opening
* *
* @param string URL of Mimer SQL Validator WSDL file
*
* @return object Object to use
*/ */
function _openService($url) function _openService($url)
{ {
@@ -167,6 +201,22 @@ if (!defined('PMA_SQL_VALIDATOR_CLASS_INCLUDED')) {
return $obj; return $obj;
} }
/**
* Service initializer to connect to server
*
* @param object Service object
* @param string Username
* @param string Password
* @param string Name of calling program
* @param string Version of calling program
* @param string Target DBMS
* @param string Version of target DBMS
* @param string Connection Technology
* @param string version of Connection Technology
* @param number boolean of 1/0 to specify if we are an interactive system
*
* @return object stdClass return object with data
*/
function _openSession($obj, $username, $password, $callingProgram, $callingProgramVersion, $targetDbms, $targetDbmsVersion, $connectionTechnology, $connectionTechnologyVersion, $interactive) function _openSession($obj, $username, $password, $callingProgram, $callingProgramVersion, $targetDbms, $targetDbmsVersion, $connectionTechnology, $connectionTechnologyVersion, $interactive)
{ {
@@ -176,10 +226,14 @@ if (!defined('PMA_SQL_VALIDATOR_CLASS_INCLUDED')) {
} }
/** /**
* Standard calling method * Validator sytem call
* *
* @param sql SQL statement to validate * @param object Service object
* @return Raw string from Mimer * @param object Session object
* @param string SQL Query to validate
* @param string Data return type
*
* @return object stClass return with data
*/ */
function _validateSQL($obj,$session,$sql,$method) function _validateSQL($obj,$session,$sql,$method)
{ {
@@ -187,6 +241,13 @@ if (!defined('PMA_SQL_VALIDATOR_CLASS_INCLUDED')) {
return $res; return $res;
} }
/**
* Validator sytem call
*
* @param string SQL Query to validate
*
* @return object stClass return with data
*/
function _validate($sql) function _validate($sql)
{ {
$ret = $this->_validateSQL($this->serviceLink, $this->sessionData, $sql, $this->outputType); $ret = $this->_validateSQL($this->serviceLink, $this->sessionData, $sql, $this->outputType);

View File

@@ -9,6 +9,11 @@
* This function uses the Mimer SQL Validator service * This function uses the Mimer SQL Validator service
* <http://developer.mimer.com/validator/index.htm> from phpMyAdmin * <http://developer.mimer.com/validator/index.htm> from phpMyAdmin
* *
* Copyright for Server side validator systems:
* "All SQL statements are stored anonymously for statistical purposes.
* Mimer SQL Validator, Copyright 2002 Upright Database Technology.
* All rights reserved."
*
* All data is transported over HTTP-SOAP * All data is transported over HTTP-SOAP
* And uses the PEAR SOAP Module * And uses the PEAR SOAP Module
* *
@@ -31,29 +36,66 @@ if (!defined('PMA_SQL_VALIDATOR_INCLUDED')) {
// For now we actually use a configuration flag // For now we actually use a configuration flag
if ($cfg['SQLValidator']['use'] == TRUE) { if ($cfg['SQLValidator']['use'] == TRUE) {
include_once('sqlvalidator.class.php3'); include_once('sqlvalidator.class.php3');
} // if ($cfg['SQLValidator']['use'] == TRUE)
/**
* This function utilizes the Mimer SQL Validator service
* to validate an SQL query
*
* <http://developer.mimer.com/validator/index.htm>
*
* @param string SQL query to validate
*
* @return string Validator result string
*/
function validateSQL($sql) function validateSQL($sql)
{ {
global $cfg; global $cfg;
$str = '';
if ($cfg['SQLValidator']['use'] == TRUE) {
// create new class instance
$srv = new SQLValidator(); $srv = new SQLValidator();
// check for username settings
// The class defaults to anonymous with an empty password
// automatically
if($cfg['SQLValidator']['username'] != '') { if($cfg['SQLValidator']['username'] != '') {
$srv->setCredentials($cfg['SQLValidator']['username'], $cfg['SQLValidator']['password']); $srv->setCredentials($cfg['SQLValidator']['username'], $cfg['SQLValidator']['password']);
} }
// Identify ourselves to the server properly
$srv->appendCallingProgram('phpMyAdmin',PMA_VERSION); $srv->appendCallingProgram('phpMyAdmin',PMA_VERSION);
// And specify what database system we are using
$srv->setTargetDbms('MySQL',PMA_MYSQL_STR_VERSION); $srv->setTargetDbms('MySQL',PMA_MYSQL_STR_VERSION);
// Log on to service
$srv->start(); $srv->start();
// Do service validation
$str = $srv->ValidationString($sql); $str = $srv->ValidationString($sql);
// Strip out the copyright if requested
if($cfg['SQLValidator']['DisplayCopyright'] != TRUE) { if($cfg['SQLValidator']['DisplayCopyright'] != TRUE) {
$match = "reserved.<br/>\n<br/>"; $match = "reserved.<br/>\n<br/>";
$pos = strpos($str,$match); $pos = strpos($str,$match);
$pos += strlen($match); $pos += strlen($match);
$str = substr($str,$pos); $str = substr($str,$pos);
} }
} else {
// The service is not available
// So note that properly
$str = $GLOBALS['strValidatorDisabled'];
}
// Give string back to caller
return $str; return $str;
} // function validateSQL($sql) } // function validateSQL($sql)
} // if ($cfg['SQLValidator']['use'] == TRUE)
} //$__PMA_SQL_VALIDATOR__ } //$__PMA_SQL_VALIDATOR__