Esempio n. 1
0
 protected function create($table)
 {
     $cache = \Gaia\Souk\Storage::cacher();
     $key = 'souk/storage/__create/' . md5($this->dsn . '/' . get_class($this) . '/' . $table);
     if ($cache->get($key)) {
         return;
     }
     if (!$cache->add($key, 1, 60)) {
         return;
     }
     $rs = $rs = $this->execute("SELECT `name` FROM `sqlite_master` WHERE `type` = 'table' and `name` = %s", $table);
     $row = $rs->fetch();
     $rs->free();
     if (!$row) {
         Transaction::onRollback(array($cache, 'delete'), array($key));
         $rs = $this->execute("CREATE TABLE IF NOT EXISTS {$table} (\n              `row_id` INTEGER PRIMARY KEY AUTOINCREMENT,\n              `seller` BIGINT NOT NULL,\n              `buyer` BIGINT NOT NULL DEFAULT '0',\n              `item_id` INTEGER NOT NULL DEFAULT '0',\n              `quantity` BIGINT NOT NULL DEFAULT '0',\n              `price` BIGINT default '0',\n              `pricesort` BIGINT default '0',\n              `step` BIGINT default '0',\n              `bid` BIGINT default '0',\n              `proxybid` BIGINT default '0',\n              `bidcount` INTEGER default '0',\n              `bidder` BIGINT default '0',\n              `reserve` BIGINT default NULL,\n              `closed` INTEGER NOT NULL DEFAULT '0',\n              `created` INTEGER,\n              `expires` INTEGER,\n              `touch` INTEGER\n            )");
         foreach (array('closed', 'created', 'expires', 'pricesort', 'item_id', 'step', 'seller', 'bidder', 'buyer') as $idx) {
             $idx_name = $table . '_idx_' . $idx;
             $this->execute("CREATE INDEX IF NOT EXISTS `{$idx_name}` ON `{$table}` (`{$idx}`)");
         }
     }
     $table_attr = $table . '_attr';
     $rs = $this->execute("SELECT `name` FROM `sqlite_master` WHERE `type` = 'table' and `name` = %s", $table_attr);
     $row = $rs->fetch();
     $rs->free();
     if (!$row) {
         Transaction::onRollback(array($cache, 'delete'), array($key));
         $this->execute("CREATE TABLE IF NOT EXISTS {$table_attr} (\n              `row_id` INTEGER NOT NULL,\n              `attributes` TEXT,\n              PRIMARY KEY  (`row_id`)\n            )");
     }
 }
Esempio n. 2
0
 protected function create($table)
 {
     $cache = \Gaia\Souk\Storage::cacher();
     $key = 'souk/storage/__create/' . md5($this->dsn . '/' . get_class($this) . '/' . $table);
     if ($cache->get($key)) {
         return;
     }
     if (!$cache->add($key, 1, 60)) {
         return;
     }
     $rs = $this->execute('SHOW TABLES LIKE %s', $table);
     $row = $rs->fetch();
     $rs->free();
     if (!$row) {
         $this->execute("CREATE TABLE IF NOT EXISTS {$table} (\n              `row_id` int unsigned NOT NULL auto_increment,\n              `seller` bigint unsigned NOT NULL,\n              `buyer` bigint unsigned NOT NULL DEFAULT '0',\n              `item_id` int unsigned NOT NULL DEFAULT '0',\n              `quantity` bigint unsigned NOT NULL DEFAULT '0',\n              `price` bigint unsigned default '0',\n              `pricesort` bigint unsigned default '0',\n              `step` bigint unsigned default '0',\n              `bid` bigint unsigned default '0',\n              `proxybid` bigint unsigned default '0',\n              `bidcount` int unsigned default '0',\n              `bidder` bigint unsigned default '0',\n              `reserve` bigint unsigned default NULL,\n              `closed` tinyint unsigned NOT NULL DEFAULT '0',\n              `created` int unsigned,\n              `expires` int unsigned,\n              `touch` int(10) unsigned,\n              PRIMARY KEY  (`row_id`),\n              KEY `closed` (`closed`),\n              KEY `created` (`created`),\n              KEY `expires` (`expires`),\n              KEY `pricesort` (`pricesort`),\n              KEY `item` (`item_id`),\n              KEY `price` (`price`),\n              KEY `step` (`step`),\n              KEY `seller` (`seller`),\n              KEY `bidder` (`bidder`),\n              KEY `buyer` (`buyer`)\n            ) ENGINE=InnoDB");
     }
     $table_attr = $table . '_attr';
     $rs = $this->execute('SHOW TABLES LIKE %s', $table_attr);
     $row = $rs->fetch();
     $rs->free();
     if (!$row) {
         $this->execute("CREATE TABLE IF NOT EXISTS {$table_attr} (\n              `row_id` int unsigned NOT NULL,\n              `attributes` varchar(5000) character set utf8,\n              PRIMARY KEY  (`row_id`)\n            ) ENGINE=InnoDB");
     }
 }