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", "201.102.123.111", "5.9.11.13" );
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) {
80 $msg = sprintf(" INSERT INTO test_ip [%s] val: [%d (%x)]", $i, $v, $v);
81 if ($bdb->query(sprintf("INSERT INTO test_ip (ip, atime) VALUES (%d, '1999-01-08 04:05:06');", $v)) == FALSE) {
82 printf("%s<br>\n", $bdb->last_error());
89 if (($ip_pg = $bdb->query(sprintf("SELECT * FROM test_ip ORDER BY code;"))) == FALSE) {
90 printf("%s<br>\n", $bdb->last_error());
91 fail("SELECT * FROM test_ip");
94 succ("SELECT * FROM test_ip");
96 for ($r = 0 ; $r < pg_numrows($ip_pg) ; $r++) {
97 $ip_obj = pg_fetch_object($ip_pg, $r);
99 $v = int2ip($ip_obj->ip);
101 if ($arr_ip[$r] != $v) {
102 fail(sprintf(" Expected: %s, retrieved: %s", $arr_ip[$r], $v));
105 succ(sprintf(" Expected: %s", $arr_ip[$r]));
107 // printf("RET IP: %d IP: %s<br>\n", $ip_obj->ip, $v));
111 if ($bdb->query("DROP TABLE IF EXISTS test_ip;") == FALSE) {
112 fail("DROP TABLE test_ip");
115 succ("DROP TABLE test_ip");
118 if ($bdb->transaction("BEgIN") != FALSE) {
119 fail("BEgIN missed fail");
122 succ("BEgIN missed fail");