1
# Hej, Emacs, give us -*- perl -*- mode here!
3
# $Id: CSV.dbtest,v 1.1.1.1 1999/06/13 12:59:35 joe Exp $
5
# database specific definitions for a 'CSV' database
8
# This function generates a mapping of ANSI type names to
9
# database specific type names; it is called by TableDefinition().
11
sub AnsiTypeToDb ($;$) {
12
my ($type, $size) = @_;
15
if ((lc $type) eq 'char' || (lc $type) eq 'varchar') {
17
return (uc $type) . " ($size)";
18
} elsif ((lc $type) eq 'blob' || (lc $type) eq 'real' ||
19
(lc $type) eq 'integer') {
21
} elsif ((lc $type) eq 'int') {
24
warn "Unknown type $type\n";
32
# This function generates a table definition based on an
33
# input list. The input list consists of references, each
34
# reference referring to a single column. The column
35
# reference consists of column name, type, size and a bitmask of
36
# certain flags, namely
38
# $COL_NULLABLE - true, if this column may contain NULL's
39
# $COL_KEY - true, if this column is part of the table's
42
# Hopefully there's no big need for you to modify this function,
43
# if your database conforms to ANSI specifications.
46
sub TableDefinition ($@) {
47
my($tablename, @cols) = @_;
51
# Should be acceptable for most ANSI conformant databases;
53
# msql 1 uses a non-ANSI definition of the primary key: A
54
# column definition has the attribute "PRIMARY KEY". On
55
# the other hand, msql 2 uses the ANSI fashion ...
57
my($col, @keys, @colDefs, $keyDef);
60
# Count number of keys
63
foreach $col (@cols) {
64
if ($$col[2] & $::COL_KEY) {
65
push(@keys, $$col[0]);
69
foreach $col (@cols) {
70
my $colDef = $$col[0] . " " . AnsiTypeToDb($$col[1], $$col[2]);
71
if (!($$col[3] & $::COL_NULLABLE)) {
72
$colDef .= " NOT NULL";
74
push(@colDefs, $colDef);
77
$keyDef = ", PRIMARY KEY (" . join(", ", @keys) . ")";
81
$def = sprintf("CREATE TABLE %s (%s%s)", $tablename,
82
join(", ", @colDefs), $keyDef);
87
# This function generates a list of tables associated to a
94
@tables = $dbh->func('list_tables');
96
die "Cannot create table list: " . $dbh->errstr;
103
# This function is called by DBD::pNET; given a hostname and a
104
# dsn without hostname, return a dsn for connecting to dsn at
107
my($hostname, $dsn) = @_;
113
# Return a string for checking, whether a given column is NULL.
123
# Return TRUE, if database supports transactions
125
sub HaveTransactions () {
131
mkdir "output", 0755;