5 * Copyright (C) 2014 Matteo Nastasi
6 * mailto: nastasi@alternativeoutput.it
7 * matteo.nastasi@milug.org
8 * web: http://www.alternativeoutput.it
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details. You should have received a
19 * copy of the GNU General Public License along with this program; if
20 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21 * Suite 330, Boston, MA 02111-1307, USA.
27 require_once($G_base."Obj/brisk.phh");
28 require_once($G_base."Obj/dbase_${G_dbasetype}.phh");
32 printf("%s ... SUCCESS<br>\n", $s);
37 printf("%s ... FAILED<br>\n", $s);
42 if (($bdb = BriskDB::create()) == FALSE) {
47 if ($bdb->transaction("BEGIN") == FALSE) {
53 if ($bdb->transaction("COMMIT") == FALSE) {
59 $arr_ip = array("1.1.1.1", "127.0.0.1", "255.255.255.255", "255.255.0.0" );
61 if ($bdb->query("DROP TABLE IF EXISTS test_ip;") == FALSE) {
62 fail("DROP TABLE test_ip");
65 succ("DROP TABLE test_ip");
67 if ($bdb->query("CREATE TABLE test_ip (
68 code integer, -- insertion code
69 ip integer, -- ip v4 address
70 atime timestamp DEFAULT to_timestamp(0) -- access time
72 fail("CREATE TABLE test_ip");
75 succ("CREATE TABLE test_ip");
77 foreach ($arr_ip as $i) {
78 $v = $v_or = ip2long($i);
79 if (PHP_INT_SIZE == 8 && $v & 0x80000000)
80 $v = 0xffffffff00000000 | $v_or;
82 if ($bdb->query(sprintf("INSERT INTO test_ip (ip, atime) VALUES (CAST(%d AS integer), '1999-01-08 04:05:06');", $v)) == FALSE) {
83 printf("%s<br>\n", $bdb->last_error());
84 fail("INSERT INTO test_ip ".$i." V: ".$v." V_or: ".$v_or);
87 succ("INSERT INTO test_ip ".$i." V: ".$v." V_or: ".$v_or);
90 if (($ip_pg = $bdb->query(sprintf("SELECT * FROM test_ip ORDER BY code;"))) == FALSE) {
91 printf("%s<br>\n", $bdb->last_error());
92 fail("SELECT * FROM test_ip");
95 succ("SELECT * FROM test_ip");
97 for ($r = 0 ; $r < pg_numrows($ip_pg) ; $r++) {
98 $ip_obj = pg_fetch_object($ip_pg, $r);
100 if (PHP_INT_SIZE == 8)
101 $v = $ip_obj->ip & 0x00000000ffffffff;
105 if ($arr_ip[$r] != long2ip($v)) {
106 fail(sprintf(" Expected: %s, retrieved: %s", $arr_ip[$r], long2ip($v)));
109 succ(sprintf(" Expected: %s", $arr_ip[$r]));
111 // printf("RET IP: %d V: %d IP: %s<br>\n", $ip_obj->ip, $v, long2ip($v));
115 if ($bdb->query("DROP TABLE IF EXISTS test_ip;") == FALSE) {
116 fail("DROP TABLE test_ip");
119 succ("DROP TABLE test_ip");
122 if ($bdb->transaction("BEgIN") != FALSE) {
123 fail("BEgIN missed fail");
126 succ("BEgIN missed fail");