/**
  * @param string $query
  */
 private function validate_query($query)
 {
     $query2tree = new dqml2tree($query);
     $sql_tree = $query2tree->make();
     if (array_key_exists('LIMIT', $sql_tree['SQL']['SELECT']) || array_key_exists('OFFSET', $sql_tree['SQL']['SELECT'])) {
         throw new InvalidArgumentException("Query can't contain OFFSET or LIMIT keyword");
     }
 }
예제 #2
0
파일: example.php 프로젝트: CAH4EC84/Diler
<?php

/**
* Author  : NEUMANN-RYSTOW Franзois <*****@*****.**>
* Date    : 23 Oct, 2008
* Purpose : Usage example of dqml2tree class
*/
require 'dqml2tree.php';
// complex query
$sql_query = 'INSERT INTO ALL_PRICES ( INT_EXTKEY, NAME_FORM, MAKER_COUNTRY, PRICE1, PACK1, LIFETIME, QUANTITY, VENDOR, DateRef, NODES_ID, Doc_Type, COSTMAKER, COSTMAKER_NDS, NDS, UPAK, COMMENT_, EAN, COSTREESTR ) SELECT tamda_2.Int_ExtKey, tamda_2.Name_Form, tamda_2.Maker AS Maker_Country, tamda_2.Price1, tamda_2.Pack1, tamda_2.Lifetime, tamda_2.Quantity, tamda_2.Vendor, tamda_2.DateRef, tamda_2.Nodes_ID, tamda_2.Doc_Type, tamda_2.COSTMAKER, tamda_2.COSTMAKERNDS, tamda_2.VAT, tamda_2.[Кол-во в уп], " Кр: " & [Pack1] & " ШК: " & [Comment] AS Выражение1, tamda_2.EAN, tamda_2.COSTREESTR FROM tamda_2;
';
$query2tree = new dqml2tree($sql_query);
$sql_tree = $query2tree->make();
echo "<pre>";
print_r($sql_tree);
echo "</pre>";
예제 #3
0
{
    $where = array();
    if (isset($tree['SQL']['UPDATE']['WHERE']['0|*AND'])) {
        foreach ($tree['SQL']['UPDATE']['WHERE'] as $where_id => $wheres) {
            $name = $wheres['0|!EQ']['FIELD'];
            $value = '';
            if (isset($wheres['1|!EQ']['VAL'])) {
                $value = trim($wheres['1|!EQ']['VAL'], "'");
            }
            if (isset($wheres['1|!EQ']['FIELD'])) {
                $value = trim($wheres['1|!EQ']['FIELD'], "'");
            }
            $where[$name] = $value;
        }
    } else {
        if (isset($tree['SQL']['UPDATE']['WHERE']['1|!EQ']['VAL'])) {
            $where[$tree['SQL']['UPDATE']['WHERE']['0|!EQ']['FIELD']] = trim($tree['SQL']['UPDATE']['WHERE']['1|!EQ']['VAL'], "'");
        } elseif (isset($tree['SQL']['UPDATE']['WHERE']['1|!EQ']['FIELD'])) {
            $where[$tree['SQL']['UPDATE']['WHERE']['0|!EQ']['FIELD']] = trim($tree['SQL']['UPDATE']['WHERE']['1|!EQ']['FIELD'], "'");
        }
    }
    return $where;
}
$sql = "UPDATE mytable SET myfield1=123, myfield2='abc' WHERE myfield3='def' AND myfield4=4;";
echo $sql . "\n";
$dqml = new dqml2tree($sql);
$tree = $dqml->make();
echo "UPDATE SET\n";
print_r(update_set_to_array($tree));
echo "UPDATE WHERE (must exclusively be separated by and)\n";
print_r(update_where_alone_or_exclusively_separated_by_and_to_array($tree));