$query = $db->prep('%f', array(1.545, 2.2, 3)); Tap::is($query, '1.545, 2.2, 3', 'format query handles arrays of floats'); $query = $db->prep('test %%s ?, (?,?)', array(1, 2), 3, 4); Tap::is($query, "test %s '1', '2', ('3','4')", 'format query question mark as string'); $rs = $db->execute('err'); Tap::cmp_ok($rs, '===', FALSE, 'db returns false on query error'); Tap::like($db->error(), '/you have an error in your sql syntax/i', '$db->error() returns error message'); Tap::is($db->errorcode(), 1064, 'returns expected mysql error code'); $db = new DB\Except(DB\Connection::instance('test')); $err = NULL; try { $db->execute('err'); } catch (Exception $e) { $err = (string) $e; } Tap::like($err, '/database error/i', 'When a bad query is run using execute() the except wrapper tosses an exception'); Tap::is($db->isa(get_class($original)), TRUE, 'isa returns true for original object'); Tap::is($db->isa('gaia\\db'), TRUE, 'isa returns true for gaia\\db'); $rs = $db->execute("SELECT 'test' as r1"); Tap::is($rs->affected(), 1, 'selected a row, affected rows is one'); $newconn = function () use($instance) { return new DB($instance()); }; $table = 'test_' . time() . '_' . mt_rand(10000, 99999); $dbmain = $newconn(); $dbmain->execute("create table {$table} (id int unsigned not null primary key) engine=innodb"); $conn1 = $newconn(); $conn2 = $newconn(); Tap::ok($conn1 !== $conn2, 'created two db objects'); $rs = $conn1->execute('SELECT CONNECTION_ID() as id'); $row = $rs->fetch();
Tap::ok($identifier->store($id, $name), 'able to overwrite with the same name'); $oldname = $name; $name = 'name' . microtime(TRUE); Tap::ok($identifier->store($id, $name), 'able to overwrite with the a new name'); Tap::is($identifier->byName($name), $id, 'found the id by new name'); Tap::is($identifier->byName($oldname), NULL, 'oldname doesnt match anything now'); $oldid = $id; $id = strval(mt_rand(1, 100000000)); Tap::ok($identifier->store($id, $name), 'able to overwrite name with the a new id'); Tap::is($identifier->byId($id), $name, 'found the name by new id'); Tap::is($identifier->byID($oldid), NULL, 'oldid doesnt match anything now'); $e = null; try { $identifier->store(strval(mt_rand(1, 100000000)), $name, $strict = TRUE); } catch (Exception $e) { $e = $e->__toString(); } Tap::like($e, '#name-taken#i', 'trying to map name to new id with strict clause thrown in fails'); Tap::ok($identifier->delete($id, $name), 'deleted the pairing'); Tap::is($identifier->byName($name), NULL, 'after deleting, no name lookup'); Tap::is($identifier->byId($id), NULL, 'after deleting, no id lookup'); Transaction::start(); $identifier = $create_identifier(); Tap::ok($identifier->store($id, $name), 'store the name/id pairing with txn'); Tap::is($identifier->byName($name), $id, 'found the id by name'); Tap::is($identifier->byId($id), $name, 'found the name by id'); Transaction::rollback(); Transaction::reset(); $identifier = $create_identifier(); Tap::is($identifier->byName($name), NULL, 'after rollback, no id found by name'); Tap::is($identifier->byId($id), NULL, 'after rollback, no name found by id');