#!/usr/bin/perl -w
plan(
'tests'
=> 11);
my
$test
= 0;
my
$o_conf
= Perlbug::Config->new;
my
$o_test
= Perlbug::Test->new(
$o_conf
);
my
$o_db
=
''
;
my
$str
=
'a string with an id (20010817.021) inside'
;
my
$tid
=
'20010817.021'
;
my
$blank
=
''
;
my
$notanid
=
'2001817.021'
;
my
$ok
= 0;
my
$id
=
''
;
$test
++;
my
%DB
=
$o_conf
->get_all(
'database'
);
if
(
$o_db
= Perlbug::Database->new(
%DB
)) {
ok(
$test
);
}
else
{
ok(0);
}
$test
++;
my
$dbh
=
$o_db
->dbh;
if
(
ref
(
$dbh
)) {
ok(
$test
);
}
else
{
ok(0);
output(
"Invalid database handle dbh($dbh)"
);
}
$test
++;
my
$res
= 1;
if
(
$res
== 1) {
ok(
$test
);
}
else
{
ok(0);
output(
"Can't ping($res) the db :-("
);
}
$test
++;
my
$ustr
=
"x ' %"
;
my
$qstr
=
$o_db
->quote(
$ustr
);
if
(
$qstr
=~ /^x\s\\
' %$/o) { # '
ok(
$test
);
}
else
{
ok(0);
output(
"Can't quote($ustr) => quoted($qstr)!"
);
}
$test
++;
my
$table
=
'pb_bug'
;
my
$sth
=
$o_db
->query(
"SELECT COUNT(*) FROM $table"
);
if
(!(
defined
(
$sth
))) {
ok(0);
output(
"Can't get sth($sth)!"
);
}
else
{
ok(
$test
);
my
@data
=
$sth
->fetchrow_array;
if
(
@data
>= 1) {
ok(
$test
);
}
else
{
ok(0);
output(
"Can't get data(@data) from sth($sth)! missing table($table)?"
);
}
}
my
$TABLE
=
"${table}_$$"
;
$test
++;
my
$create
=
qq|CREATE TABLE $TABLE (id INTEGER(3), string VARCHAR(16))|
;
my
$created
=
$o_db
->query(
$create
);
if
(
defined
(
$created
)) {
ok(
$test
);
}
else
{
ok(0);
output(
"Can't create($create)!"
);
}
$test
++;
my
$insert
=
qq|INSERT INTO $TABLE SET id = '21', string = 'some nonsense'|
;
my
$inserted
=
$o_db
->query(
$insert
);
if
(
defined
(
$created
)) {
ok(
$test
);
}
else
{
ok(0);
output(
"Can't create($create) => created($created)!"
);
}
$test
++;
my
$update
=
qq|UPDATE $TABLE SET string = 'more nonsense' WHERE id = '21'|
;
my
$updated
=
$o_db
->query(
$update
);
if
(
defined
(
$created
)) {
ok(
$test
);
}
else
{
ok(0);
output(
"Can't update($update) => updated($updated)!"
);
}
$test
++;
my
$delete
=
qq|DELETE FROM $TABLE WHERE id = '17'|
;
my
$deleted
=
$o_db
->query(
$delete
);
if
(
defined
(
$deleted
)) {
ok(
$test
);
}
else
{
ok(0);
output(
"Can't delete($delete) => deleted($deleted)!"
);
}
$test
++;
my
$drop
=
qq|DROP TABLE $TABLE|
;
my
$dropped
=
$o_db
->query(
$drop
);
if
(
defined
(
$dropped
)) {
ok(
$test
);
}
else
{
ok(0);
output(
"Can't drop($drop) => dropped($dropped)!"
);
}