+ 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<br>\n", $bdb->last_error());
+ fail($msg);
+ break;
+ }
+ succ($msg);
+ }
+ printf("<br>\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<br>\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<br>\n", $ip_obj->ip, $v));
+ }
+ }
+ printf("<br>\n");
+
+ if (($ip_pg = $bdb->query(sprintf("SELECT * FROM test_ip ORDER BY code;"))) == FALSE) {
+ printf("%s<br>\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<br>\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");
+