diff --git a/classes/query_builder.php b/classes/query_builder.php index 2bf6cb8..480bccc 100644 --- a/classes/query_builder.php +++ b/classes/query_builder.php @@ -19,7 +19,7 @@ * @package Query * @subpackage Query */ -class BadDBDriverException extends UnexpectedValueException {} +class BadDBDriverException extends InvalidArgumentException {} // -------------------------------------------------------------------------- diff --git a/classes/query_parser.php b/classes/query_parser.php new file mode 100644 index 0000000..5bc9e4b --- /dev/null +++ b/classes/query_parser.php @@ -0,0 +1,60 @@ + '`([a-zA-Z0-9_]+\((.*?)\))`', + 'identifier' => '`([a-zA-Z0-9"_-]+\.?)+`', + 'operator' => '`=|AND|&&?|~|\|\|?|\^|/|>=?|<=?|-|%|OR|\+|NOT|\!=?|<>|XOR`' + ); + + /** + * Regex matches + * + * @var array + */ + public $matches = array( + 'functions' => array(), + 'identifiers' => array(), + 'operators' => array(), + ); + + /** + * Constructor/entry point into parser + * + * @param string + */ + public function __construct($sql = '') + { + preg_match_all($this->match_patterns['function'], $sql, $this->matches['functions'], PREG_SET_ORDER); + preg_match_all($this->match_patterns['identifier'], $sql, $this->matches['identifiers'], PREG_SET_ORDER); + preg_match_all($this->match_patterns['operator'], $sql, $this->matches['operators'], PREG_SET_ORDER); + } + +} + +// End of query_parser.php \ No newline at end of file diff --git a/composer.json b/composer.json index 3c61104..186bcd6 100644 --- a/composer.json +++ b/composer.json @@ -5,15 +5,14 @@ "keywords":["database", "query builder"], "homepage":"https://github.com/aviat4ion/Query", "license":"dbad-license", - "authors": [ - { - "name": "Timothy J. Warren", - "email": "tim@timshomepage.net", - "homepage": "https://timshomepage.net", - "role": "Developer" - } - ], + "authors": [{ + "name": "Timothy J. Warren", + "email": "tim@timshomepage.net", + "homepage": "https://timshomepage.net", + "role": "Developer" + }], "require": { "php": ">=5.2.0" - } + }, + } \ No newline at end of file diff --git a/tests/core/db_qp_test.php b/tests/core/db_qp_test.php new file mode 100644 index 0000000..f19578a --- /dev/null +++ b/tests/core/db_qp_test.php @@ -0,0 +1,37 @@ +parser = new Query_Parser(); + } + + public function TestGeneric() + { + $this->parser->__construct('table1.field1=table2.field2'); + + //echo '
'.print_r($this->parser->matches, TRUE).'
'; + } + + public function TestFunction() + { + $this->parser->__construct('table1.field1 > SUM(3+5)'); + + //echo '
'.print_r($this->parser->matches, TRUE).'
'; + } + +} \ No newline at end of file diff --git a/tests/db_files/FB_TEST_DB.FDB b/tests/db_files/FB_TEST_DB.FDB index 6261656..f99f20a 100644 Binary files a/tests/db_files/FB_TEST_DB.FDB and b/tests/db_files/FB_TEST_DB.FDB differ diff --git a/tests/index.php b/tests/index.php index 17a3826..387c74f 100644 --- a/tests/index.php +++ b/tests/index.php @@ -30,6 +30,7 @@ require_once(QBASE_DIR . 'autoload.php'); // Require base testing classes require_once(QTEST_DIR . '/core/core.php'); require_once(QTEST_DIR . '/core/db_test.php'); +require_once(QTEST_DIR . '/core/db_qp_test.php'); require_once(QTEST_DIR . '/core/db_qb_test.php'); // Include db tests