File: 10dsnlist.t

package info (click to toggle)
libdbd-mysql-perl 2.9006-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 524 kB
  • ctags: 326
  • sloc: perl: 3,571; ansic: 1,986; makefile: 55
file content (82 lines) | stat: -rwxr-xr-x 2,020 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/local/bin/perl
#
#   $Id: 10dsnlist.t,v 1.3 2004/09/03 23:09:27 capttofu Exp $
#
#   This test creates a database and drops it. Should be executed
#   after listdsn.
#


#
#   Include lib.pl
#
require DBI;
$mdriver = "";
foreach $file ("lib.pl", "t/lib.pl", "DBD-mysql/t/lib.pl") {
    do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n";
			   exit 10;
		      }
    if ($mdriver ne '') {
	last;
    }
}
if ($mdriver eq 'pNET'  ||  $mdriver eq 'Adabas') {
    print "1..0\n";
    exit 0;
}
print "Driver is $mdriver\n";

sub ServerError() {
    print STDERR ("Cannot connect: ", $DBI::errstr, "\n",
	"\tEither your server is not up and running or you have no\n",
	"\tpermissions for acessing the DSN $test_dsn.\n",
	"\tThis test requires a running server and write permissions.\n",
	"\tPlease make sure your server is running and you have\n",
	"\tpermissions, then retry.\n");
    exit 10;
}

#
#   Main loop; leave this untouched, put tests into the loop
#
while (Testing()) {
    # Check if the server is awake.
    $dbh = undef;
    Test($state or ($dbh = DBI->connect($test_dsn, $test_user,
					$test_password)))
	or ServerError();

    Test($state or (@dsn = DBI->data_sources($mdriver)) >= 0);
    if (!$state) {
	my $d;
	print "List of $mdriver data sources:\n";
	foreach $d (@dsn) {
	    print "    $d\n";
	}
	print "List ends.\n";
    }
    Test($state or $dbh->disconnect());

    #
    #   Try different DSN's
    #
    my(@dsnList);
    if (($mdriver eq 'mysql'  or  $mdriver eq 'mSQL')
	and  $test_dsn eq "DBI:$mdriver:test") {
	@dsnList = ("DBI:$mdriver:test:localhost",
		    "DBI:$mdriver:test;localhost",
		    "DBI:$mdriver:database=test;host=localhost");
    }
    my($dsn);
    foreach $dsn (@dsnList) {
	Test($state or ($dbh = DBI->connect($dsn, $test_user,
					    $test_password)))
	    or print "Cannot connect to DSN $dsn: ${DBI::errstr}\n";
	Test($state or $dbh->disconnect());
    }
}

exit 0;

# Hate -w :-)
$test_dsn = $test_user = $test_password = $DBI::errstr;