Esempio n. 1
0
 /**
  * @REST\Get("/query/analyze")
  */
 public function analyzeQueryTest(Request $request)
 {
     $query = $request->query->get('query');
     $parser = new \PHPSQLParser\PHPSQLParser();
     $result = $parser->parse($query);
     if (false) {
         return new Response(print_r($result, true), 200);
         ob_start();
         var_dump($result);
         $dump = ob_get_clean();
         return new Response($dump, 200);
     } else {
         $parser = new \PHPSQLParser\PHPSQLParser();
         $creator = new \PHPSQLParser\PHPSQLCreator();
         $tree = $parser->parse($query);
         $column = 'foo';
         $direction = 'asc';
         $tree['ORDER'] = array(array('expr_type' => 'colref', 'base_expr' => $column, 'no_quotes' => array('delim' => false, 'parts' => array($column)), 'sub_tree' => false, 'direction' => strtoupper($direction)));
         return array('query' => $creator->create($tree));
     }
 }
Esempio n. 2
0
 /**
  * Will add an alias to every column that is a function. This is to workaround
  * a bug in the Zend framework that does not allow columns to have names that
  * look like functions. Will turn things like 'count(x)' or 'func(x, y)' into
  * '_count_x' and '_func_x_y'. The changes are written to a copy of the two 
  * input arrays.
  * @param array $multiLines multiline SQL 
  * @param array $multiLineParseTrees multiline SQL parse trees
  * @param array $outMultiLineSQL output array with one multiline SQL string in each element
  * @param array $outMultiLineParseTrees output multiline SQL parse trees
  * @return void
  */
 function escapeFunctions(&$multiLines, &$multiLineParseTrees, &$outMultiLineSQL, &$outMultiLineParseTrees)
 {
     foreach ($multiLineParseTrees as $key => $currTree) {
         $outMultiLineParseTrees[$key] = $currTree;
         $this->escapeFunctionsRec($currTree, $outMultiLineParseTrees[$key]);
         $sqlCreator = new \PHPSQLParser\PHPSQLCreator();
         try {
             $outMultiLineSQL[$key] = $sqlCreator->create($outMultiLineParseTrees[$key]);
         } catch (UnsupportedFeatureException $e) {
             $outMultiLineSQL[$key] = $multiLines[$key];
         } catch (UnableToCreateSQLException $e) {
             $outMultiLineSQL[$key] = $multiLines[$key];
         }
     }
 }