示例#1
0
 function table($table = null, $tablePrefix = null)
 {
     if ($table === null) {
         return $this->table;
     } else {
         if ($tablePrefix === null) {
             if (is_array($table)) {
                 if (Arr::is_assoc($table)) {
                     foreach ($table as $k => $t) {
                         $this->table($t, $k);
                     }
                 } else {
                     foreach ($table as $t) {
                         $this->table($t);
                     }
                 }
                 return;
             }
             $tablePrefix = $table;
         } elseif ($tablePrefix) {
             $table = new Alias\TableAlias($table, $tablePrefix);
         }
         if (isset($this->table[$tablePrefix])) {
             throw new \Exception('Table Alias "' . $tablePrefix . '" already exists in this query.');
         }
         $this->tables[$tablePrefix] = $table;
     }
     return $this;
 }
示例#2
0
 function _Set($k, $v)
 {
     if ($k === null || Number::is($k)) {
         if ($v instanceof IToSQL) {
             //Add(WhereAnd | WhereOr) -> Append
             //Add(Statement) -> WhereAnd -> Append
             $this->data[] = $v;
         } elseif (is_string($v)) {
             //Add(string) -> Statement -> Add
             $this->data[] = new WhereAND($v);
         } elseif (is_array($v)) {
             if (!$v) {
                 return;
                 //Empty array
             }
             if (Arr::is_assoc($v)) {
                 //Add(array(array('field'=>'value'))) -> Statement -> Add
                 foreach ($v as $k => $vv) {
                     $this->_Set($k, $vv);
                 }
             } elseif (isset($v[0]) && is_array($v[0])) {
                 foreach ($v as $vv) {
                     $this->_Set(null, $vv);
                 }
             } else {
                 //Add(array(expr1,comparison,expr2)) -> Statement -> Add
                 $op = null;
                 if (count($v) == 2) {
                     $op = '=';
                 }
                 if (count($v) == 3) {
                     $op = $v[1];
                     $v = array($v[0], $v[1]);
                 }
                 if ($op === null) {
                     throw new \Exception('Invalid array format');
                 }
                 $this->data[] = new Comparison($v[0], $v[1], $op, static::AUTO_NULL);
             }
         } else {
             throw new \Exception('Unknown format for add');
         }
     } else {
         //Assosiative simple syntax
         $op = '=';
         if ($v instanceof IComparison) {
             $op = '';
         }
         $this->data[] = WhereAND::fromAssign($k, $v, $op, static::AUTO_NULL);
     }
 }
示例#3
0
 function _Set($k, $v)
 {
     if ($k === null || \Radical\Basic\String\Number::is($k)) {
         if (is_array($v)) {
             if (Arr::is_assoc($v)) {
                 foreach ($v as $k => $vv) {
                     $this->_Add($k, $vv);
                 }
             } else {
                 foreach ($v as $k => $vv) {
                     $this->_Add(null, $vv);
                 }
             }
         } elseif ($v !== null) {
             //Add(expr)
             $this->data[] = $v;
         }
     } else {
         //Add(table,field) -> TableExpression
         $this->data[] = new TableExpression($v, $k);
     }
 }
示例#4
0
 function _Set($k, $order_by)
 {
     if ($k === null || \Radical\Basic\String\Number::is($k)) {
         if (is_string($order_by)) {
             $this->data[] = $order_by;
         } elseif ($order_by instanceof OrderBy) {
             //Add(OrderByPart)
             $this->data = $order_by;
         } elseif (is_array($order_by)) {
             if (Arr::is_assoc($order_by)) {
                 foreach ($order_by as $key => $order) {
                     $this->_Set($key, $order);
                 }
             } else {
                 foreach ($order_by as $o) {
                     if (is_array($o)) {
                         //Add(array(array(expr1,order1 = ASC),array(expr1,order2 = ASC)))
                         if (count($o) == 2) {
                             $this->_Set($o[0], $o[1]);
                         } else {
                             throw new \Exception('Unknown array format');
                         }
                     } else {
                         //Add(array(expr1,expr2))
                         $this->_Add(null, $o);
                     }
                 }
             }
         } else {
             throw new \Exception('Invalid order by call');
         }
     } else {
         //Add(expr,order)
         $this->data[] = new OrderByPart($k, $order_by);
     }
 }
 /**
  * Return true if the array is associative.
  * 
  * @return boolean
  */
 function isAssoc()
 {
     return Arr::is_assoc($this->data);
 }