\n", $s); } function fail($s) { printf("%s ... FAILED
\n", $s); } function main() { do { if (($bdb = BriskDB::create()) == FALSE) { fail("DB Creation"); break; } succ("DB Creation"); if ($bdb->transaction("BEGIN") == FALSE) { fail("BEGIN"); break; } succ("BEGIN"); if ($bdb->transaction("COMMIT") == FALSE) { fail("COMMIT"); break; } succ("COMMIT"); $arr_ip = array("1.1.1.1", "127.0.0.1", "255.255.255.255", "255.255.0.0", "201.102.123.111", "5.9.11.13" ); if ($bdb->query("DROP TABLE IF EXISTS test_ip;") == FALSE) { fail("DROP TABLE test_ip"); break; } succ("DROP TABLE test_ip"); if ($bdb->query("CREATE TABLE test_ip ( code integer, -- insertion code ip integer, -- ip v4 address atime timestamp DEFAULT to_timestamp(0) -- access time ); ") == FALSE) { fail("CREATE TABLE test_ip"); break; } succ("CREATE TABLE test_ip"); foreach ($arr_ip as $i) { $v = ip2four($i); $msg = sprintf("  INSERT INTO test_ip [%s] val: [%d (%x)]", $i, $v, $v); if ($bdb->query(sprintf("INSERT INTO test_ip (ip, atime) VALUES (%d, '1999-01-08 04:05:06');", $v)) == FALSE) { printf("%s
\n", $bdb->last_error()); fail($msg); break; } succ($msg); } printf("
\n"); foreach ($arr_ip as $i) { $cmp = int2four(ip2int($i) & 0xffffff00); $msk = int2four(0xffffff00); $cmp_que = sprintf("SELECT * FROM test_ip WHERE (ip & %d = %d);", $msk, $cmp); if (($cmp_pg = $bdb->query($cmp_que)) == FALSE) { printf("%s
\n", $bdb->last_error()); fail("SELECT * FROM test_ip"); break; } succ($cmp_que); for ($r = 0 ; $r < pg_numrows($cmp_pg) ; $r++) { $cmp_obj = pg_fetch_object($cmp_pg, $r); if ($ip_obj->ip & $msk != $cmp) { fail(sprintf("  Expected: %s, retrieved: %s", int2ip($cmp), int2ip($ip_obj->ip & $msk))); } else { succ(sprintf("  Expected: %s (%s)", int2ip($cmp), int2ip($cmp_obj->ip))); } // printf("RET IP: %d IP: %s
\n", $ip_obj->ip, $v)); } } printf("
\n"); if (($ip_pg = $bdb->query(sprintf("SELECT * FROM test_ip ORDER BY code;"))) == FALSE) { printf("%s
\n", $bdb->last_error()); fail("SELECT * FROM test_ip"); break; } succ("SELECT * FROM test_ip"); for ($r = 0 ; $r < pg_numrows($ip_pg) ; $r++) { $ip_obj = pg_fetch_object($ip_pg, $r); $v = int2ip($ip_obj->ip); if ($arr_ip[$r] != $v) { fail(sprintf("  Expected: %s, retrieved: %s", $arr_ip[$r], $v)); } else { succ(sprintf("  Expected: %s", $arr_ip[$r])); } // printf("RET IP: %d IP: %s
\n", $ip_obj->ip, $v)); } if ($bdb->query("DROP TABLE IF EXISTS test_ip;") == FALSE) { fail("DROP TABLE test_ip"); break; } succ("DROP TABLE test_ip"); if ($bdb->transaction("BEgIN") != FALSE) { fail("BEgIN missed fail"); break; } succ("BEgIN missed fail"); } while (FALSE); } main(); ?>