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
#!usr/bin/perl
use warnings;
use strict;
use DBI;
my $datenbankname = "datenbank.db";
#-----------------DATENBANK-VERBINDUNG------------------#
my $database = DBI::->connect("dbi:SQLite:dbname=$datenbankname","","")
or die "Fehler bei Datenbankverbindung!";
#----------------DATENBANK-VERBINDUNG-ENDE--------------#
#---------------UEBERPRUEFUNG-EXIST-------------#
my $exist = $database->selectall_arrayref( "SELECT * from schueler" );
if ( defined $exist ) #
{
#----------------LOESCHT-TABELLE--------------#
my $sql = 'DROP TABLE schueler';
$database->do($sql)
or die $database->errstr;
#----------------LOESCHT-TABELLE-ENDE-------------#
}
else
{
print "Es konnte auf keine existierende Datei zugegriffen werden";
print "\n";
print "Bitte laden Sie er die Schueler in die Datenbank";
print "\n";
exit;
}
#------------UEBERPRUEFUNG-EXIST-ENDE------------#
#---------------DATENBANK-VERBINDUNG-DISCONNECT-------------#
$database->disconnect
or $database->errstr;
#------------DATENBANK-VERBINDUNG-DISCONNECT-ENDE------------#
SELECT name FROM sqlite_master WHERE name='table_name';
DROP TABLE IF EXISTS table_name;
Quotekomme auch mit
SELECT name FROM sqlite_master WHERE name='schueler'
leider nicht weiter...
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
#! /usr/bin/perl use strict; use warnings; use DBI; my $dbname = 'schueler.db'; my $dbh = DBI->connect( "dbi:SQLite:dbname=$dbname", "", # empty user "", # empty password { RaiseError => 1, }, ) or die $DBI::errstr, "\n"; # see http://search.cpan.org/perldoc?DBI#selectrow_array # no "or die..." here, because empty list may be returned # which would trigger the "or die"... Remember, that # RaiseError is enabled above! my @row = $dbh->selectrow_array( q~SELECT name FROM sqlite_master WHERE name='schueler'~, ); if ( ! @row ) { # Table 'schueler' does not exist } __END__