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 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; }
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]); }
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); }
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(); } }
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; }
function execute() { $sql = $this->toSQL(); return \Radical\DB::Q($sql); }
function exists() { $sql = 'show tables like ' . \Radical\DB::E($this->getTable()); $res = \Radical\DB::Q($sql); if ($res->Fetch()) { return true; } return false; }