فهرست منبع

Code refactoring to make the OQL parsing self contained in the "oql" subdirectory.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3803 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 9 سال پیش
والد
کامیت
cda7f3861f
5فایلهای تغییر یافته به همراه66 افزوده شده و 17 حذف شده
  1. 6 6
      core/cmdbobject.class.inc.php
  2. 0 11
      core/dbsearch.class.php
  3. 50 0
      core/oql/check_oql.php
  4. 0 0
      core/oql/expression.class.inc.php
  5. 10 0
      core/oql/oqlquery.class.inc.php

+ 6 - 6
core/cmdbobject.class.inc.php

@@ -46,18 +46,18 @@ require_once('stimulus.class.inc.php');
 require_once('valuesetdef.class.inc.php');
 require_once('MyHelpers.class.inc.php');
 
-require_once('expression.class.inc.php');
-
-require_once('cmdbsource.class.inc.php');
-require_once('sqlquery.class.inc.php');
-require_once('sqlobjectquery.class.inc.php');
-require_once('sqlunionquery.class.inc.php');
+require_once('oql/expression.class.inc.php');
 require_once('oql/oqlquery.class.inc.php');
 require_once('oql/oqlexception.class.inc.php');
 require_once('oql/oql-parser.php');
 require_once('oql/oql-lexer.php');
 require_once('oql/oqlinterpreter.class.inc.php');
 
+require_once('cmdbsource.class.inc.php');
+require_once('sqlquery.class.inc.php');
+require_once('sqlobjectquery.class.inc.php');
+require_once('sqlunionquery.class.inc.php');
+
 require_once('dbobject.class.php');
 require_once('dbsearch.class.php');
 require_once('dbobjectset.class.php');

+ 0 - 11
core/dbsearch.class.php

@@ -20,17 +20,6 @@
 require_once('dbobjectsearch.class.php');
 require_once('dbunionsearch.class.php');
 
-
-define('TREE_OPERATOR_EQUALS', 0);
-define('TREE_OPERATOR_BELOW', 1);
-define('TREE_OPERATOR_BELOW_STRICT', 2);
-define('TREE_OPERATOR_NOT_BELOW', 3);
-define('TREE_OPERATOR_NOT_BELOW_STRICT', 4);
-define('TREE_OPERATOR_ABOVE', 5);
-define('TREE_OPERATOR_ABOVE_STRICT', 6);
-define('TREE_OPERATOR_NOT_ABOVE', 7);
-define('TREE_OPERATOR_NOT_ABOVE_STRICT', 8);
-
 /**
  * An object search
  * 

+ 50 - 0
core/oql/check_oql.php

@@ -0,0 +1,50 @@
+<?php
+/**
+ * Minimal file (with all the needed includes) to check the validity of an OQL by verifying:
+ * - The syntax (of the OQL query string)
+ * - The consistency with a given data model (represented by an instance of ModelReflection)
+ * 
+ * Usage:
+ * 
+ * require_once(APPROOT.'core/oql/check_oql.php');
+ * 
+ * $sOQL = "SELECT Zerver WHERE status = 'production'";
+ * $oModelReflection = new ModelReflectionRuntime();
+ * $aResults = CheckOQL($sOQL, $oModelReflection);
+ * if ($aResults['status'] == 'error')
+ * {
+ *     echo "The query '$sOQL' is not a valid query. Reason: {$aResults['message']}";
+ * }
+ * else
+ * {
+ *     echo "Ok, '$sOQL' is a valid query";
+ * }
+ */
+class CoreException extends Exception
+{
+
+}
+
+require_once(__DIR__.'/expression.class.inc.php');
+require_once(__DIR__.'/oqlquery.class.inc.php');
+require_once(__DIR__.'/oqlexception.class.inc.php');
+require_once(__DIR__.'/oql-parser.php');
+require_once(__DIR__.'/oql-lexer.php');
+require_once(__DIR__.'/oqlinterpreter.class.inc.php');
+
+function CheckOQL($sOQL, ModelReflection $oModelReflection)
+{
+	$aRes = array('status' => 'ok', 'message' => '');
+	try
+	{
+		$oOql = new OqlInterpreter($sOQL);
+		$oOqlQuery = $oOql->ParseQuery(); // Exceptions thrown in case of issue
+		$oOqlQuery->Check($oModelReflection,$sOQL); // Exceptions thrown in case of issue
+	}
+	catch(Exception $e)
+	{
+		$aRes['status'] = 'error';
+		$aRes['message'] = $e->getMessage();
+	}
+	return $aRes;
+}

+ 0 - 0
core/expression.class.inc.php → core/oql/expression.class.inc.php


+ 10 - 0
core/oql/oqlquery.class.inc.php

@@ -24,6 +24,16 @@
  * @license     http://opensource.org/licenses/AGPL-3.0
  */
 
+define('TREE_OPERATOR_EQUALS', 0);
+define('TREE_OPERATOR_BELOW', 1);
+define('TREE_OPERATOR_BELOW_STRICT', 2);
+define('TREE_OPERATOR_NOT_BELOW', 3);
+define('TREE_OPERATOR_NOT_BELOW_STRICT', 4);
+define('TREE_OPERATOR_ABOVE', 5);
+define('TREE_OPERATOR_ABOVE_STRICT', 6);
+define('TREE_OPERATOR_NOT_ABOVE', 7);
+define('TREE_OPERATOR_NOT_ABOVE_STRICT', 8);
+
 // Position a string within an OQL query
 // This is a must if we want to be able to pinpoint an error at any stage of the query interpretation
 // In particular, the normalization phase requires this