#!perl -w # vim: ft=perl use Test::More; use DBI; use DBI::Const::GetInfoType; use lib 't', '.'; require 'lib.pl'; use strict; $|= 1; use vars qw($table $test_dsn $test_user $test_password); my $dbh; eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password, { RaiseError => 1, PrintError => 1, AutoCommit => 1 });}; if ($@) { plan skip_all => "ERROR: $DBI::errstr. Can't continue test"; } plan tests => 17; ok(defined $dbh, "Connected to database"); ok($dbh->do("DROP TABLE IF EXISTS $table"), "making slate clean"); ok($dbh->do("CREATE TABLE $table (id INT(4), name VARCHAR(64))"), "creating table"); ok($dbh->do("INSERT INTO $table VALUES(1, 'Alligator Descartes')"), "loading data"); ok($dbh->do("INSERT INTO $table VALUES(2, 'test value 2')"), "loading data2"); { ok (my $sth= $dbh->prepare("SELECT * FROM $table WHERE id = 1")); ok($sth->execute()); my $arrayref = $sth->fetchrow_arrayref; is_deeply $arrayref, [1, 'Alligator Descartes']; } { ok (my $sth = $dbh->prepare("update $table set name = 'Nobuo Danjou' where id = 1")); ok ($sth->execute()); my $hash = $dbh->selectall_hashref("select * from $table", 'id'); is_deeply $hash, { 1 => { id => 1, name => 'Nobuo Danjou', }, 2 => { id => 2, name => 'test value 2', } }; } ok($dbh->do("DELETE FROM $table WHERE id = 1"), "deleting from table $table"); ok (my $sth= $dbh->prepare("SELECT * FROM $table WHERE id = 1")); ok($sth->execute()); ok(not $sth->fetchrow_arrayref()); ok($sth->finish()); ok($dbh->do("DROP TABLE $table"),"Dropping table"); $dbh->disconnect();