protected function execute($query) { if (!Transaction::atStart()) { Transaction::add($this->db); } $args = func_get_args(); array_shift($args); $rs = $this->db->execute($qs = $this->db->prep_args($query, $args)); if (!$rs) { throw new Exception('database error', array('db' => $this->db, 'query' => $qs, 'error' => $this->db->error())); } return $rs; }
protected function execute($query) { if (!Transaction::atStart()) { Transaction::add($this->db); } $args = func_get_args(); array_shift($args); $rs = $this->db->execute($qs = $this->db->prep_args($query, $args)); //print "# " . $qs ."\n"; if (!$rs) { throw new Exception('database error', $this->dbInfo($qs)); } return $rs; }
public function identifiers(array $affiliations) { if (!$affiliations) { return array(); } $result = array_fill_keys($affiliations, array()); $db = $this->db(); $table = $this->table(); if (!DB\Transaction::atStart()) { DB\Transaction::add($db); } $rs = $db->execute("SELECT `affiliation`, `identifier` FROM `{$table}` WHERE `affiliation` IN ( %i )", $affiliations); $result = array(); while ($row = $rs->fetch()) { $result[$row['affiliation']][] = $row['identifier']; } $rs->free(); return $result; }
/** * pass in two accounts, always. */ public function __construct(Iface $core, Iface $other) { parent::__construct($core); if (Transaction::atStart()) { throw $this->handle(new Exception('need transaction to transfer')); } if ($core->app() == $other->app() && $core->user() == $other->user()) { throw $this->handle(new Exception('need two different parties to trade')); } if ($core->coreType() == $this->coreType()) { throw $this->handle(new Exception('core must not be a transfer')); } if ($other->coreType() == $this->coreType()) { throw $this->handle(new Exception('other must not be a transfer')); } if ($core->coreType() != $other->coreType() && $core->coreType() != 'serial-tally' && $other->coreType() != 'serial-tally') { throw $this->handle(new Exception('both must be of same coretype in a transfer')); } $this->other = $other; }
protected function db() { if ($this->db instanceof \Closure) { $mapper = $this->db; $db = $mapper($this->table()); } elseif (is_scalar($this->db)) { $db = DB\Connection::instance($this->db); } else { $db = $this->db; } if (!$db instanceof DB\Iface) { throw new Exception('invalid db'); } if (!$db->isa('mysql')) { throw new Exception('invalid db'); } if (!$db->isa('gaia\\db\\extendediface')) { throw new Exception('invalid db'); } if (!$db->isa('Gaia\\DB\\Except')) { $db = new DB\Except($db); } if (!Transaction::atStart()) { Transaction::add($db); } return $db; }
public function close($listing) { // grab the shard and row id. list($shard, $row_id) = Souk\Util::parseId($listing->id); // update the listing. $table = $this->table($shard); if (\Gaia\Souk\Storage::isAutoSchemaEnabled()) { $this->create($table); } if (!Transaction::atStart()) { Transaction::add($this->db); } $sql = "UPDATE {$table} SET buyer = %i, touch = %i, closed = 1, pricesort = NULL WHERE row_id = %i"; $rs = $this->execute($sql, $listing->buyer, $listing->touch, $row_id); // should have affected a row. if it didn't toss an exception. if ($rs->affected() < 1) { throw new Exception('failed', $this->db); } }
public function delete(array $identifiers) { $db = $this->db(); $table = $this->table(); if (!DB\Transaction::atStart()) { DB\Transaction::add($db); } $hashes = array(); foreach ($identifiers as $identifier) { $hashes[] = sha1($identifier, true); } $db->execute("DELETE FROM `{$table}` WHERE `hash` IN ( %s )", $hashes); }
public static function inTran() { return Transaction::atStart() ? FALSE : TRUE; }
/** * write the record into the cache. */ protected function writeToCache(Listing $listing) { $cache = $this->cache(); $timeout = $this->cacheTimeout(); $cache->set($listing->id, $listing, 0, $timeout); if (!Transaction::atStart()) { Transaction::onRollback(array($cache, 'delete'), array($listing->id)); } $this->updateListingSearchVectors($listing); return $listing; }