<?php include __DIR__ . '/../common.php'; use Gaia\Souk; use Gaia\DB; DB\Connection::load(array('test' => function () { return new DB\Driver\PDO('sqlite:/tmp/souk.db'); })); Gaia\Souk\Storage::attach(function (Gaia\Souk\Iface $souk) { return 'test'; }); Gaia\Souk\Storage::enableAutoSchema(); try { $app = 'test1'; $seller_id = mt_rand(1, 1000000000); $buyer_id = mt_rand(1, 1000000000); $souk = new Souk($app, $seller_id); $listing = $souk->auction(array('price' => 10, 'item_id' => 1, 'quantity' => 1, 'bid' => 2, 'step' => 1)); print "\nNew auction:\n"; print_r($listing->export()); $souk = new Souk($app, $buyer_id); $listing = $souk->bid($listing->id, 10); print "\nAfter first bid:\n"; print_r($souk->get($listing->id)->export()); $souk = new Souk($app); $listing = $souk->close($listing->id); print "\nAfter closing:\n"; print_r($listing->export()); $souk = new Souk($app, $seller_id); $listing = $souk->auction(array('item_id' => 1, 'quantity' => 1, 'price' => 10)); print "\nNew buy-only auction:\n";
<?php use Gaia\Test\Tap; use Gaia\DB; use Gaia\DB\Transaction; $original = $db; Tap::plan(51); $db = new DB($db); Tap::is(spl_object_hash($original), $db->hash(), 'the hash function returns the hash of the original db object'); DB\Connection::load(array('test' => function () use($db) { return $db; })); Tap::ok(DB\Connection::instance('test') === $db, 'db instance returns same object we instantiated at first'); Tap::is($db->isa('mysql'), TRUE, 'driver is mysql'); $rs = $db->execute('SELECT %s as foo, %s as bar', 'dummy\'', 'rummy'); Tap::ok($rs, 'query executed successfully'); Tap::is($rs->fetch(), array('foo' => 'dummy\'', 'bar' => 'rummy'), 'sql query preparation works on strings'); $rs = $db->execute('SELECT %i as test', '1112122445543333333333'); Tap::is($rs->fetch(), array('test' => '1112122445543333333333'), 'query execute works injecting big integer in'); $rs = $db->execute('SELECT %i as test', 'dummy'); Tap::is($rs->fetch(), array('test' => '0'), 'query execute sanitizes non integer'); $rs = $db->execute('SELECT %f as test', '1112.122445543333333333'); Tap::is($rs->fetch(), array('test' => '1112.122445543333333333'), 'query execute works injecting big float in'); $rs = $db->execute('SELECT %f as test', 'dummy'); Tap::is($rs->fetch(), array('test' => '0'), 'query execute sanitizes non float'); $query = $db->prep('%s', array('dummy', 'rummy')); Tap::is($query, "'dummy', 'rummy'", 'format query handles arrays of strings'); $query = $db->prep('%i', array(1, 2, 3)); Tap::is($query, '1, 2, 3', 'format query handles arrays of integers'); $query = $db->prep('%f', array(1.545, 2.2, 3)); Tap::is($query, '1.545, 2.2, 3', 'format query handles arrays of floats');
<?php use Gaia\DB; use Gaia\Test\Tap; include __DIR__ . '/../lib/setup.php'; include __DIR__ . '/../../assert/pdo_installed.php'; include __DIR__ . '/../../assert/pdo_sqlite_installed.php'; DB\Connection::load(array('test' => function () { $db = new DB\Driver\PDO('sqlite:/tmp/souk.db'); $cb = array('start' => function () { $i = \Gaia\DB\Transaction::internals(); Tap::debug('TXN: start ' . $i['depth']); }, 'commit' => function () { $i = \Gaia\DB\Transaction::internals(); Tap::debug('TXN: commit ' . $i['depth']); }, 'rollback' => function () { $i = \Gaia\DB\Transaction::internals(); Tap::debug('TXN: rollback ' . $i['depth']); }, 'query' => function ($args) { $query = array_shift($args); $query = \Gaia\DB\Query::format($query, $args); Tap::debug('QUERY: ' . $query); }); //$db = new DB\Observe( $db, $cb); return $db; }));
<?php use Gaia\DB; use Gaia\Test\Tap; include __DIR__ . '/../lib/setup.php'; include __DIR__ . '/../../assert/mysqli_installed.php'; include __DIR__ . '/../../assert/mysql_running.php'; DB\Connection::load(array('test' => function () { $db = new DB\Driver\MySQLi($host = '127.0.0.1', $user = NULL, $pass = NULL, $db = 'test', '3306'); $cb = array('start' => function () { $i = \Gaia\DB\Transaction::internals(); Tap::debug('TXN: start ' . $i['depth']); }, 'commit' => function () { $i = \Gaia\DB\Transaction::internals(); Tap::debug('TXN: commit ' . $i['depth']); }, 'rollback' => function () { $i = \Gaia\DB\Transaction::internals(); Tap::debug('TXN: rollback ' . $i['depth']); }, 'query' => function ($args) { $query = array_shift($args); $query = \Gaia\DB\Query::format($query, $args); Tap::debug('QUERY: ' . $query); }); //$db = new DB\Observe( $db, $cb); return $db; }));
<?php use Gaia\DB; use Gaia\Test\Tap; include __DIR__ . '/../lib/setup.php'; include __DIR__ . '/../../assert/mysqli_installed.php'; include __DIR__ . '/../../assert/mysql_running.php'; DB\Connection::load(array('test' => function () { $db = new DB(new \MySQLi($host = '127.0.0.1', $user = NULL, $pass = NULL, $db = 'test', '3306')); return $db; }));
#!/usr/bin/env php <?php use Gaia\Skein; use Gaia\Container; use Gaia\DB; include __DIR__ . '/../common.php'; $thread = 5184; $cache = new Container(); DB\Connection::load(array('test' => function () { return new DB\Except(new Gaia\DB(new MySQLi('127.0.0.1', NULL, NULL, 'test', '3306'))); })); $callback = function ($table) use($cache) { $db = DB\Connection::instance('test'); if (!$cache->add($table, 1, 60)) { return $db; } $sql = substr($table, -5) == 'index' ? Skein\MySQL::indexSchema($table) : Skein\MySQL::dataSchema($table); $db->execute($sql); return $db; }; $skein = new Skein\MySQL($thread, $callback, $app_prefix = 'test002'); $data = 'the time is ' . date('Y/m/d H:i:s'); $id = $skein->add($data); print "\nID: {$id} \n"; $data = $skein->get($id); print "\nDATA: " . print_r($data, TRUE) . "\n"; $skein->store($id, array('foo' => $data)); $data = $skein->get($id); print "\nDATA: " . print_r($data, TRUE) . "\n"; $data = $skein->get($skein->descending()); print "\nDESCENDING ORDER: " . print_r($data, TRUE) . "\n";
<?php use Gaia\DB; use Gaia\Test\Tap; include __DIR__ . '/../lib/setup.php'; include __DIR__ . '/../../assert/pdo_installed.php'; include __DIR__ . '/../../assert/pdo_sqlite_installed.php'; DB\Connection::load(array('test' => function () { return new DB(new \PDO('sqlite:/tmp/stockpile.db')); }));