function toSQL()
 {
     if (count($this->data) == 0) {
         return 'FALSE';
     }
     return static::PART_NAME . '(' . \Radical\DB::A($this->data) . ')';
 }
 function __construct()
 {
     $IP = Session::IP();
     \Radical\DB::Q('INSERT INTO session (session_ip,session_time) VALUES(' . \Radical\DB::E($IP) . ',' . time() . ') ON DUPLICATE KEY UPDATE session_time=' . time());
     $this->id = \Radical\DB::insertId();
     parent::__construct();
 }
 function toSQL()
 {
     if ($this->sql) {
         return $this->sql;
     }
     //Build Append Part
     $append = $this->_appendPart();
     //Build Query
     $sql = 'INSERT ' . ($this->ignore === true ? 'IGNORE ' : '');
     if (isset($this->values[0]) && is_array($this->values[0])) {
         $keys = array_keys($this->values[0]);
         $values = $this->values;
     } else {
         $keys = array_keys($this->values);
         $values = array($this->values);
     }
     $sql .= 'INTO `' . $this->table . '` ';
     if (count($keys)) {
         $sql .= '(`' . implode('`,`', $keys) . '`)';
     }
     $sql .= ' VALUES';
     foreach ($values as $k => $v) {
         $sql .= ($k != 0 ? ',' : '') . '(' . \Radical\DB::A($v) . ')';
     }
     if (count($keys)) {
         $sql .= $append;
     }
     $this->sql = $sql;
     return $sql;
 }
Beispiel #4
0
 function toSQL()
 {
     if (count($this->data)) {
         return 'SET ' . \Radical\DB::A(array_map(function ($r) {
             return $r->expr();
         }, $this->data));
         //Ugly hack
     }
 }
Beispiel #5
0
 function search($text, TableReferenceInstance $table)
 {
     $orm = $table->getORM();
     $sql = new SelectStatement($table->getTable(), $orm->id);
     $this->_Filter($text, $sql);
     $res = \Radical\DB::Q($sql);
     $rows = $res->FetchAll();
     return $rows;
 }
 function toSQL()
 {
     $db = \Radical\DB::getInstance();
     //Build Query
     $sql = 'UPDATE `' . $this->table . '` ';
     $sql .= $this->set . ' ';
     $sql .= $this->where;
     return $sql;
 }
 function getData()
 {
     //Execute
     $res = \Radical\DB::Query($this->sql);
     //Table'ify
     $tableClass = $this->tableClass;
     return $res->FetchCallback(function ($obj) use($tableClass) {
         return TableCache::Add($tableClass::fromSQL($obj));
     });
 }
Beispiel #8
0
 static function fromTable($table)
 {
     $query = new ShowCreateTable($table);
     try {
         $res = \Radical\DB::Q($query->toSQL());
         $data = $res->Fetch(DBAL\Fetch::NUM);
     } catch (\Exception $ex) {
         throw new \Exception('Couldnt get Create Table (' . $ex->getMessage() . ') for ' . $table, null, $ex);
     }
     return new static($data[1]);
 }
Beispiel #9
0
 function toSQL()
 {
     $db = \Radical\DB::getInstance();
     $sql = 'MATCH (' . implode(',', $this->fields) . ') ';
     $sql .= 'AGAINST (' . $db->Escape($this->text);
     if ($this->boolean) {
         $sql .= ' IN BOOLEAN MODE';
     }
     $sql .= ')';
     return $sql;
 }
 private function _triggerCreate($myisam, $innodb, $fields)
 {
     $sql = 'create trigger ' . $myisam . ' after insert on ' . $innodb;
     $sql .= ' FOR EACH ROW insert into ' . $myisam . ' VALUES(';
     foreach ($fields as $f) {
         $sql .= 'new.' . $f . ',';
     }
     $sql = substr($sql, 0, -1);
     $sql .= ')';
     \Radical\DB::Q($sql);
 }
Beispiel #11
0
 static function transaction($function, ...$updating)
 {
     foreach ($updating as $k => $v) {
         if ($v instanceof Table) {
             $updating[$k] = $v->refreshTableData(true);
         }
     }
     $instance = \Radical\DB::getInstance();
     return $instance->transaction(function () use($updating, $function) {
         return $function(...$updating);
     });
 }
Beispiel #12
0
 function execute()
 {
     $sql = $this->BuildQuery();
     if (!$this->con->multi_query($sql)) {
         \Radical\DB::reConnect();
         $this->con->multi_query($sql);
     }
     //Reset SQL storage
     $this->sql = array();
     while ($this->con->next_result()) {
     }
     return $this;
 }
Beispiel #13
0
 static function init()
 {
     self::$pool = \Radical\Cache\PooledCache::get('radical_orm', 'Memory');
     global $_SQL;
     $cfile = '/tmp/' . $_SQL->getDb();
     if (file_exists($cfile) && filemtime($cfile) >= time() - 30) {
         self::$key = file_get_contents($cfile);
     } else {
         touch($cfile);
         $sql = 'SELECT MAX(UNIX_TIMESTAMP( CREATE_TIME )) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = "' . $_SQL->getDb() . '"';
         self::$key = \Radical\DB::Q($sql)->Fetch(Fetch::FIRST);
         file_put_contents($cfile, self::$key);
     }
     if (Server::isProduction()) {
         self::$data = self::$pool->get($_SQL->getDb() . '_' . self::$key);
         register_shutdown_function(function () {
             Cache::save();
         });
     }
     if (!is_array(self::$data)) {
         self::$data = array();
     }
 }
Beispiel #14
0
 function toSQL()
 {
     $a = $this->a;
     if (is_string($a) && strpos($a, '(') === false && strpos($a, '`') === false) {
         $at = '';
         foreach (explode('.', $a) as $v) {
             if ($at) {
                 $at .= '.';
             }
             $at .= '`' . $v . '`';
         }
         $a = $at;
     }
     if ($this->b instanceof IComparison && count($this->b)) {
         return $a . ' ' . (string) $this->b;
     }
     $op = $this->operation;
     $b = $this->b;
     if ($this->autoNull && $b === null) {
         if ($op == '=') {
             $op = 'IS';
         } else {
             if ($op == '!=' || $op == '<>') {
                 $op = 'IS NOT';
             } else {
                 $op = trim(strtoupper($op));
                 if ($op != 'IS' && $op != 'IS NOT') {
                     throw new \Exception("Invalid operation with NULL");
                 }
             }
         }
         $this->escaped = true;
         $b = 'NULL';
     }
     return $a . ' ' . $op . ' ' . ($this->escaped ? $b : \Radical\DB::E($b));
 }
Beispiel #15
0
 function toSQL($where = false)
 {
     if (is_string($this->parts)) {
         $sql = '';
         if ($where && count($this->parts)) {
             $sql = 'WHERE ';
         }
         $sql .= $this->parts;
         return $sql;
     }
     //Do for array
     $db = \Radical\DB::getInstance();
     $ret = array();
     foreach ($this->parts as $alias => $p) {
         $rr = '';
         if ($alias) {
             $rr = '`' . $alias . '`.';
         }
         foreach ($p as $k => $v) {
             $rri = $rr . '`' . $k . '`';
             if ($v instanceof IToSQL) {
                 $rri .= $v->toSQL();
             } else {
                 $rri .= '=' . $db->Escape($v);
             }
             $ret[] = $rri;
         }
     }
     //Build SQL
     $sql = '';
     if ($where) {
         $sql = 'WHERE ';
     }
     $sql .= implode(' ' . static::SEPPERATOR . ' ', $ret);
     return $sql;
 }
Beispiel #16
0
 function toSQL()
 {
     return DB::E((string) $this);
 }
 function exists()
 {
     $sql = 'show tables like ' . \Radical\DB::E($this->getTable());
     $res = \Radical\DB::Q($sql);
     if ($res->Fetch()) {
         return true;
     }
     return false;
 }
Beispiel #18
0
 private function query()
 {
     return \Radical\DB::Query($this->sql);
 }
Beispiel #19
0
 function toSQL()
 {
     return DB::E($this->toSQLFormat());
 }
Beispiel #20
0
 function toSQL()
 {
     return DB::e($this->__toString());
 }
 function ensureExists($drop = false)
 {
     //Check if we need to do anything
     if ($this->Exists()) {
         if ($this->ValidateFields()) {
             return true;
         } else {
             if ($drop) {
                 \Radical\DB::Q('DROP TABLE ' . $this->_tableName);
             }
         }
     }
     //Create
     $this->Create();
     return false;
 }
Beispiel #22
0
 function execute()
 {
     $sql = $this->toSQL();
     return \Radical\DB::Q($sql);
 }
Beispiel #23
0
 function toSQL()
 {
     return DB::e($this->value);
 }
Beispiel #24
0
 static function exists()
 {
     return \Radical\DB::tableExists(static::TABLE);
 }
Beispiel #25
0
 function toEscaped()
 {
     return \Radical\DB::E($this->ip);
 }
Beispiel #26
0
 function toSQL()
 {
     $db = \Radical\DB::getInstance();
     return ' BETWEEN ' . $this->E($db, $this->a) . ' AND ' . $this->E($db, $this->b);
 }
Beispiel #27
0
 function getCount()
 {
     //Check for entry
     $count = clone $this;
     $count->fields('COUNT(*)');
     $count->remove_limit();
     //$count->remove_joins();
     $count->remove_order_by();
     $res = \Radical\DB::Query($count);
     return $res->Fetch(DBAL\Fetch::FIRST, new Cast\Integer());
 }