3
# Copyright (C) 2000-2006 MySQL AB
5
# This library is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU Library General Public
7
# License as published by the Free Software Foundation; version 2
10
# This library is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
# Library General Public License for more details.
15
# You should have received a copy of the GNU Library General Public
16
# License along with this library; if not, write to the Free
17
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20
# The configuration file for the DBI/DBD tests on different databases ....
21
# You will need the DBD module for the database you are running.
22
# Monty made this bench script and I (Luuk de Boer) rewrote it to DBI/DBD.
23
# Monty rewrote this again to use packages.
25
# Each database has a different package that has 3 functions:
26
# new Creates a object with some standard slot
27
# version Version number of the server
28
# create Generates commands to create a table
32
# First some global functions that help use the packages:
37
my ($name,$host,$database,$odbc,$machine,$socket,$connect_options)=@_;
39
if ($name =~ /mysql/i)
40
{ $server=new db_MySQL($host, $database, $machine, $socket,$connect_options); }
41
elsif ($name =~ /pg/i)
42
{ $server= new db_Pg($host,$database); }
43
elsif ($name =~ /msql/i)
44
{ $server= new db_mSQL($host,$database); }
45
elsif ($name =~ /solid/i)
46
{ $server= new db_Solid($host,$database); }
47
elsif ($name =~ /Empress/i)
48
{ $server= new db_Empress($host,$database); }
49
elsif ($name =~ /FrontBase/i)
50
{ $server= new db_FrontBase($host,$database); }
51
elsif ($name =~ /Oracle/i)
52
{ $server= new db_Oracle($host,$database); }
53
elsif ($name =~ /Access/i)
54
{ $server= new db_access($host,$database); }
55
elsif ($name =~ /Informix/i)
56
{ $server= new db_Informix($host,$database); }
57
elsif ($name =~ /ms-sql/i)
58
{ $server= new db_ms_sql($host,$database); }
59
elsif ($name =~ /sybase/i)
60
{ $server= new db_sybase($host,$database); }
61
elsif ($name =~ /Adabas/i) # Adabas has two drivers
63
$server= new db_Adabas($host,$database);
64
if ($name =~ /AdabasD/i)
66
$server->{'data_source'} =~ s/:Adabas:/:AdabasD:/;
69
elsif ($name =~ /DB2/i)
70
{ $server= new db_db2($host,$database); }
71
elsif ($name =~ /Mimer/i)
72
{ $server= new db_Mimer($host,$database); }
73
elsif ($name =~ /Sapdb/i)
74
{ $server= new db_sapdb($host,$database); }
75
elsif ($name =~ /interBase/i)
76
{ $server= new db_interbase($host,$database); }
79
die "Unknown sql server name used: $name\nUse one of: Access, Adabas, AdabasD, Empress, FrontBase, Oracle, Informix, InterBase, DB2, mSQL, Mimer, MS-SQL, MySQL, Pg, Solid, SAPDB or Sybase.\nIf the connection is done trough ODBC the name must end with _ODBC\n";
81
if ($name =~ /_ODBC$/i || defined($odbc) && $odbc)
83
if (! ($server->{'data_source'} =~ /^([^:]*):([^:]+):([^:]*)/ ))
85
die "Can't find databasename in data_source: '" .
86
$server->{'data_source'}. "'\n";
89
$server->{'data_source'} = "$1:ODBC:$3";
91
$server->{'data_source'} = "$1:ODBC:$database";
99
return ["Access", "Adabas", "DB2", "Empress", "FrontBase", "Oracle",
100
"Informix", "InterBase", "Mimer", "mSQL", "MS-SQL", "MySQL", "Pg","SAPDB",
104
#############################################################################
105
# First the configuration for MySQL off course :-)
106
#############################################################################
112
my ($type,$host,$database,$machine,$socket,$connect_options)= @_;
117
$self->{'cmp_name'} = "mysql";
118
$self->{'data_source'} = "DBI:mysql:database=$database;host=$host";
119
$self->{'data_source'} .= ";mysql_socket=$socket" if($socket);
120
$self->{'data_source'} .= ";$connect_options" if($connect_options);
121
$self->{'limits'} = \%limits;
122
$self->{'blob'} = "blob";
123
$self->{'text'} = "text";
124
$self->{'double_quotes'} = 1; # Can handle: 'Walker''s'
125
$self->{'vacuum'} = 1; # When using with --fast
126
$self->{'drop_attr'} = "";
127
$self->{'transactions'} = 0; # Transactions disabled by default
129
$limits{'NEG'} = 1; # Supports -id
130
$limits{'alter_add_multi_col'}= 1; #Have ALTER TABLE t add a int,add b int;
131
$limits{'alter_table'} = 1; # Have ALTER TABLE
132
$limits{'alter_table_dropcol'}= 1; # Have ALTER TABLE DROP column
133
$limits{'column_alias'} = 1; # Alias for fields in select statement.
134
$limits{'func_extra_%'} = 1; # Has % as alias for mod()
135
$limits{'func_extra_if'} = 1; # Have function if.
136
$limits{'func_extra_in_num'} = 1; # Has function in
137
$limits{'func_odbc_floor'} = 1; # Has func_odbc_floor function
138
$limits{'func_odbc_mod'} = 1; # Have function mod.
139
$limits{'functions'} = 1; # Has simple functions (+/-)
140
$limits{'group_by_position'} = 1; # Can use 'GROUP BY 1'
141
$limits{'group_distinct_functions'}= 1; # Have count(distinct)
142
$limits{'group_func_extra_std'} = 1; # Have group function std().
143
$limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings
144
$limits{'group_functions'} = 1; # Have group functions
145
$limits{'having_with_alias'} = 1; # Can use aliases in HAVING
146
$limits{'having_with_group'} = 1; # Can use group functions in HAVING
147
$limits{'insert_multi_value'} = 1; # Have INSERT ... values (1,2),(3,4)
148
$limits{'insert_select'} = 1;
149
$limits{'join_optimizer'} = 1; # Can optimize FROM tables
150
$limits{'left_outer_join'} = 1; # Supports left outer joins
151
$limits{'like_with_column'} = 1; # Can use column1 LIKE column2
152
$limits{'limit'} = 1; # supports the limit attribute
153
$limits{'truncate_table'} = 1;
154
$limits{'load_data_infile'} = 1; # Has load data infile
155
$limits{'lock_tables'} = 1; # Has lock tables
156
$limits{'max_column_name'} = 64; # max table and column name
157
$limits{'max_columns'} = 2000; # Max number of columns in table
158
$limits{'max_conditions'} = 9999; # (Actually not a limit)
159
$limits{'max_index'} = 16; # Max number of keys
160
$limits{'max_index_parts'} = 16; # Max segments/key
161
$limits{'max_tables'} = (($machine || '') =~ "^win") ? 5000 : 65000;
162
$limits{'max_text_size'} = 1000000; # Good enough for tests
163
$limits{'multi_drop'} = 1; # Drop table can take many tables
164
$limits{'order_by_position'} = 1; # Can use 'ORDER BY 1'
165
$limits{'order_by_unused'} = 1;
166
$limits{'query_size'} = 1000000; # Max size with default buffers.
167
$limits{'select_without_from'}= 1; # Can do 'select 1';
168
$limits{'subqueries'} = 0; # Doesn't support sub-queries.
169
$limits{'table_wildcard'} = 1; # Has SELECT table_name.*
170
$limits{'unique_index'} = 1; # Unique index works or not
171
$limits{'working_all_fields'} = 1;
172
$limits{'working_blobs'} = 1; # If big varchar/blobs works
173
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
175
# Some fixes that depends on the environment
176
if (defined($main::opt_create_options) &&
177
$main::opt_create_options =~ /engine=heap/i)
179
$limits{'working_blobs'} = 0; # HEAP tables can't handle BLOB's
181
if (defined($main::opt_create_options) &&
182
$main::opt_create_options =~ /engine=innodb/i)
184
$self->{'transactions'} = 1; # Transactions enabled
186
if (defined($main::opt_create_options) &&
187
$main::opt_create_options =~ /engine=ndb/i)
189
$self->{'transactions'} = 1; # Transactions enabled
190
$limits{'max_columns'} = 90; # Max number of columns in table
191
$limits{'max_tables'} = 32; # No comments
193
if (defined($main::opt_create_options) &&
194
$main::opt_create_options =~ /engine=bdb/i)
196
$self->{'transactions'} = 1; # Transactions enabled
198
if (defined($main::opt_create_options) &&
199
$main::opt_create_options =~ /engine=gemini/i)
201
$limits{'working_blobs'} = 0; # Blobs not implemented yet
202
$limits{'max_tables'} = 500;
203
$self->{'transactions'} = 1; # Transactions enabled
210
# Get the version number of the database
216
my ($dbh,$sth,$version,@row);
218
$dbh=$self->connect();
219
$sth = $dbh->prepare("select VERSION()") or die $DBI::errstr;
220
$version="MySQL 3.20.?";
221
if ($sth->execute && (@row = $sth->fetchrow_array))
223
$row[0] =~ s/-/ /g; # To get better tables with long names
224
$version="MySQL $row[0]";
228
$sth = $dbh->prepare("show status like 'ssl_version'") or die $DBI::errstr;
229
if ($sth->execute && (@row = $sth->fetchrow_array) && $row[1])
231
$version .= "/$row[1]";
235
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
240
# Connection with optional disabling of logging
247
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
248
$main::opt_password,{ PrintError => 0}) ||
249
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
251
$dbh->do("SET OPTION LOG_OFF=1,UPDATE_LOG=0");
256
# Returns a list of statements to create a table
257
# The field types are in ANSI SQL format.
259
# If one uses $main::opt_fast then one is allowed to use
260
# non standard types to get better speed.
265
my($self,$table_name,$fields,$index,$options) = @_;
268
$query="create table $table_name (";
269
foreach $field (@$fields)
271
# $field =~ s/ decimal/ double(10,2)/i;
272
$field =~ s/ big_decimal/ double(10,2)/i;
273
$query.= $field . ',';
275
foreach $index (@$index)
277
$query.= $index . ',';
279
substr($query,-1)=")"; # Remove last ',';
280
$query.=" $options" if (defined($options));
281
$query.=" $main::opt_create_options" if (defined($main::opt_create_options));
282
push(@queries,$query);
287
my ($self,$dbname, $file, $dbh) = @_;
290
$file =~ s|\\|/|g; # Change Win32 names to Unix syntax
291
$command = "load data infile '$file' into table $dbname columns optionally enclosed by '\\'' terminated by ','";
292
# print "$command\n";
293
$sth = $dbh->do($command) or die $DBI::errstr;
294
return $sth; # Contains number of rows
298
# Do any conversions to the ANSI SQL query so that the database can handle it
307
my ($self,$table,$index) = @_;
308
return "DROP INDEX $index ON $table";
312
# Abort if the server has crashed
314
# 1 question should be retried
317
sub abort_if_fatal_error
323
# This should return 1 if we to do disconnect / connect when doing
327
sub small_rollback_segment
333
# reconnect on errors (needed mainly be crash-me)
336
sub reconnect_on_errors
343
my ($self,$cmd) = @_;
348
# Optimize tables for better performance
353
my ($self,$full_vacuum,$dbh_ref,@tables)=@_;
354
my ($loop_time,$end_time,$dbh);
358
$loop_time=new Benchmark;
359
$dbh->do("OPTIMIZE TABLE " . join(',',@tables)) || die "Got error: $DBI::errstr when executing 'OPTIMIZE TABLE'\n";
360
$end_time=new Benchmark;
361
print "Time for book-keeping (1): " .
362
Benchmark::timestr(Benchmark::timediff($end_time, $loop_time),"all") . "\n\n";
366
#############################################################################
367
# Definitions for mSQL
368
#############################################################################
374
my ($type,$host,$database)= @_;
379
$self->{'cmp_name'} = "msql";
380
$self->{'data_source'} = "DBI:mSQL:$database:$host";
381
$self->{'limits'} = \%limits;
382
$self->{'double_quotes'} = 0;
383
$self->{'drop_attr'} = "";
384
$self->{'transactions'} = 0; # No transactions
385
$self->{'blob'} = "text(" . $limits{'max_text_size'} .")";
386
$self->{'text'} = "text(" . $limits{'max_text_size'} .")";
388
$limits{'max_conditions'} = 74;
389
$limits{'max_columns'} = 75;
390
$limits{'max_tables'} = 65000; # Should be big enough
391
$limits{'max_text_size'} = 32000;
392
$limits{'query_size'} = 65535;
393
$limits{'max_index'} = 5;
394
$limits{'max_index_parts'} = 10;
395
$limits{'max_column_name'} = 35;
397
$limits{'join_optimizer'} = 0; # Can't optimize FROM tables
398
$limits{'load_data_infile'} = 0;
399
$limits{'lock_tables'} = 0;
400
$limits{'functions'} = 0;
401
$limits{'group_functions'} = 0;
402
$limits{'group_distinct_functions'}= 0; # Have count(distinct)
403
$limits{'multi_drop'} = 0;
404
$limits{'select_without_from'}= 0;
405
$limits{'subqueries'} = 0;
406
$limits{'left_outer_join'} = 0;
407
$limits{'table_wildcard'} = 0;
408
$limits{'having_with_alias'} = 0;
409
$limits{'having_with_group'} = 0;
410
$limits{'like_with_column'} = 1;
411
$limits{'order_by_position'} = 1;
412
$limits{'group_by_position'} = 1;
413
$limits{'alter_table'} = 0;
414
$limits{'alter_add_multi_col'}= 0;
415
$limits{'alter_table_dropcol'}= 0;
416
$limits{'group_func_extra_std'} = 0;
417
$limits{'limit'} = 1; # supports the limit attribute
418
$limits{'unique_index'} = 1; # Unique index works or not
419
$limits{'insert_select'} = 0;
421
$limits{'func_odbc_mod'} = 0;
422
$limits{'func_extra_%'} = 0;
423
$limits{'func_odbc_floor'} = 0;
424
$limits{'func_extra_if'} = 0;
425
$limits{'column_alias'} = 0;
427
$limits{'func_extra_in_num'} = 0;
428
$limits{'working_blobs'} = 1; # If big varchar/blobs works
429
$limits{'order_by_unused'} = 1;
430
$limits{'working_all_fields'} = 1;
431
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
436
# Get the version number of the database
442
foreach $dir ("/usr/local/Hughes", "/usr/local/mSQL","/my/local/mSQL",
445
if (-x "$dir/bin/msqladmin")
447
$tmp=`$dir/bin/msqladmin version | grep server`;
448
if ($tmp =~ /^\s*(.*\w)\s*$/)
449
{ # Strip pre- and endspace
451
$tmp =~ s/\s+/ /g; # Remove unnecessary spaces
452
$tmp .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
458
return "mSQL version ???";
466
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
467
$main::opt_password,{ PrintError => 0}) ||
468
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
473
# Can't handle many field types, so we map everything to int and real.
478
my($self,$table_name,$fields,$index) = @_;
479
my($query,@queries,$name,$nr);
481
$query="create table $table_name (";
482
foreach $field (@$fields)
484
$field =~ s/varchar/char/i; # mSQL doesn't have VARCHAR()
485
# mSQL can't handle more than the real basic int types
486
$field =~ s/tinyint|smallint|mediumint|integer/int/i;
487
# mSQL can't handle different visual lengths
488
$field =~ s/int\(\d*\)/int/i;
489
# mSQL doesn't have float, change it to real
490
$field =~ s/float(\(\d*,\d*\)){0,1}/real/i;
491
$field =~ s/double(\(\d*,\d*\)){0,1}/real/i;
492
# mSQL doesn't have blob, it has text instead
493
if ($field =~ / blob/i)
495
$name=$self->{'blob'};
496
$field =~ s/ blob/ $name/;
498
$query.= $field . ',';
500
substr($query,-1)=")"; # Remove last ',';
501
push(@queries,$query);
504
# Prepend table_name to index name because the the name may clash with
505
# a field name. (Should be diffent name space, but this is mSQL...)
507
foreach $index (@$index)
509
# Primary key is unique index in mSQL
510
$index =~ s/primary key/unique index primary/i;
511
if ($index =~ /^unique\s*\(([^\(]*)\)$/i)
514
push(@queries,"create unique index ${table_name}_$nr on $table_name ($1)");
518
if (!($index =~ /^(.*index)\s+(\w*)\s+(\(.*\))$/i))
520
die "Can't parse index information in '$index'\n";
522
push(@queries,"create $1 ${table_name}_$2 on $table_name $3");
530
my($self,$dbname, $file) = @_;
531
print "insert an ascii file isn't supported by mSQL\n";
543
my ($self,$table,$index) = @_;
544
return "DROP INDEX $index FROM $table";
547
sub abort_if_fatal_error
552
sub small_rollback_segment
557
sub reconnect_on_errors
564
my ($self,$cmd) = @_;
568
#############################################################################
569
# Definitions for PostgreSQL #
570
#############################################################################
576
my ($type,$host,$database)= @_;
581
$self->{'cmp_name'} = "pg";
582
$self->{'data_source'} = "DBI:Pg:dbname=$database";
583
$self->{'limits'} = \%limits;
584
$self->{'blob'} = "text";
585
$self->{'text'} = "text";
586
$self->{'double_quotes'} = 1;
587
$self->{'drop_attr'} = "";
588
$self->{'transactions'} = 1; # Transactions enabled
589
$self->{"vacuum"} = 1;
590
$limits{'join_optimizer'} = 1; # Can optimize FROM tables
591
$limits{'load_data_infile'} = 0;
594
$limits{'alter_add_multi_col'}= 0; # alter_add_multi_col ?
595
$limits{'alter_table'} = 1;
596
$limits{'alter_table_dropcol'}= 0;
597
$limits{'column_alias'} = 1;
598
$limits{'func_extra_%'} = 1;
599
$limits{'func_extra_if'} = 0;
600
$limits{'func_extra_in_num'} = 1;
601
$limits{'func_odbc_floor'} = 1;
602
$limits{'func_odbc_mod'} = 1; # Has %
603
$limits{'functions'} = 1;
604
$limits{'group_by_position'} = 1;
605
$limits{'group_distinct_functions'}= 1; # Have count(distinct)
606
$limits{'group_func_extra_std'} = 0;
607
$limits{'group_func_sql_min_str'}= 1; # Can execute MIN() and MAX() on strings
608
$limits{'group_functions'} = 1;
609
$limits{'having_with_alias'} = 0;
610
$limits{'having_with_group'} = 1;
611
$limits{'insert_select'} = 1;
612
$limits{'left_outer_join'} = 1;
613
$limits{'like_with_column'} = 1;
614
$limits{'lock_tables'} = 0; # in ATIS gives this a problem
615
$limits{'max_column_name'} = 128;
616
$limits{'max_columns'} = 1000; # 500 crashes pg 6.3
617
$limits{'max_conditions'} = 9999; # This makes Pg real slow
618
$limits{'max_index'} = 64; # Big enough
619
$limits{'max_index_parts'} = 16;
620
$limits{'max_tables'} = 5000; # 10000 crashes pg 7.0.2
621
$limits{'max_text_size'} = 65000; # Good enough for test
622
$limits{'multi_drop'} = 1;
623
$limits{'order_by_position'} = 1;
624
$limits{'order_by_unused'} = 1;
625
$limits{'query_size'} = 16777216;
626
$limits{'select_without_from'}= 1;
627
$limits{'subqueries'} = 1;
628
$limits{'table_wildcard'} = 1;
629
$limits{'truncate_table'} = 1;
630
$limits{'unique_index'} = 1; # Unique index works or not
631
$limits{'working_all_fields'} = 1;
632
$limits{'working_blobs'} = 1; # If big varchar/blobs works
633
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
638
# couldn't find the option to get the version number
643
$version = "PostgreSQL version ???";
644
foreach $dir ($ENV{'PGDATA'},"/usr/local/pgsql/data", "/usr/local/pg/data")
646
if ($dir && -e "$dir/PG_VERSION")
648
$version= `cat $dir/PG_VERSION`;
652
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
653
return "PostgreSQL $version";
657
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
666
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
667
$main::opt_password,{ PrintError => 0}) ||
668
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
675
my($self,$table_name,$fields,$index) = @_;
676
my($query,@queries,$name,$in,$indfield,$table,$nr);
678
$query="create table $table_name (";
679
foreach $field (@$fields)
683
# Allow use of char2, char4, char8 or char16
684
$field =~ s/char(2|4|8|16)/char$1/;
686
# Pg can't handle more than the real basic int types
687
$field =~ s/tinyint|smallint|mediumint|integer/int/;
688
# Pg can't handle different visual lengths
689
$field =~ s/int\(\d*\)/int/;
690
$field =~ s/float\(\d*,\d*\)/float/;
691
$field =~ s/ double/ float/;
692
# $field =~ s/ decimal/ float/i;
693
# $field =~ s/ big_decimal/ float/i;
694
# $field =~ s/ date/ int/i;
695
# Pg doesn't have blob, it has text instead
696
$field =~ s/ blob/ text/;
697
$query.= $field . ',';
699
substr($query,-1)=")"; # Remove last ',';
700
push(@queries,$query);
701
foreach $index (@$index)
703
$index =~ s/primary key/unique index primary_key/i;
704
if ($index =~ /^unique.*\(([^\(]*)\)$/i)
706
# original: $indfield="using btree (" .$1.")";
707
# using btree doesnļæ½t seem to work with Postgres anymore; it creates
708
# the table and adds the index, but it isnļæ½t unique
709
$indfield=" (" .$1.")";
711
$table="index_$nr"; $nr++;
713
elsif ($index =~ /^(.*index)\s+(\w*)\s+(\(.*\))$/i)
715
# original: $indfield="using btree (" .$1.")";
718
$table="index_$nr"; $nr++;
722
die "Can't parse index information in '$index'\n";
724
push(@queries,"create $in ${table_name}_$table on $table_name $indfield");
731
my ($self,$dbname, $file, $dbh) = @_;
735
# copy [binary] <class_name> [with oids]
736
# {to|from} {<filename>|stdin|stdout} [using delimiters <delim>]
737
print "The ascii files aren't correct for postgres ....!!!\n";
738
$command = "copy $dbname from '$file' using delimiters ','";
740
$sth = $dbh->do($command) or die $DBI::errstr;
745
# As postgreSQL wants A % B instead of standard mod(A,B) we have to map
746
# This will not handle all cases, but as the benchmarks doesn't use functions
747
# inside MOD() the following should work
749
# PostgreSQL cant handle count(*) or even count(1), but it can handle
750
# count(1+1) sometimes. ==> this is solved in PostgreSQL 6.3
752
# PostgreSQL 6.5 is supporting MOD.
757
# if you use PostgreSQL 6.x and x is lower as 5 then uncomment the line below.
758
# $sql =~ s/mod\(([^,]*),([^\)]*)\)/\($1 % $2\)/gi;
760
# if you use PostgreSQL 6.1.x uncomment the lines below
761
# if ($sql =~ /select\s+count\(\*\)\s+from/i) {
763
# elsif ($sql =~ /count\(\*\)/i)
765
# if ($sql =~ /select\s+(.*)\s+from/i)
767
# @select = split(/,/,$1);
768
# if ($select[0] =~ /(.*)\s+as\s+\w+$/i)
774
# $change = $select[0];
777
# if (($change =~ /count/i) || ($change eq "")) {
780
# $sql =~ s/count\(\*\)/count($change)/gi;
788
my ($self,$table,$index) = @_;
789
return "DROP INDEX $index";
792
sub abort_if_fatal_error
794
return 1 if ($DBI::errstr =~ /sent to backend, but backend closed/i);
798
sub small_rollback_segment
803
sub reconnect_on_errors
810
my ($self,$cmd) = @_;
816
my ($self,$full_vacuum,$dbh_ref,@tables)=@_;
817
my ($loop_time,$end_time,$dbh,$table);
818
if (defined($full_vacuum))
820
$$dbh_ref->disconnect; $$dbh_ref= $self->connect();
823
$loop_time=new Benchmark;
826
foreach $table (@tables)
828
$dbh->do("vacuum analyze $table") || die "Got error: $DBI::errstr when executing 'vacuum analyze $table'\n";
829
$dbh->do("vacuum $table") || die "Got error: $DBI::errstr when executing 'vacuum'\n";
834
# $dbh->do("vacuum pg_attributes") || die "Got error: $DBI::errstr when executing 'vacuum'\n";
835
# $dbh->do("vacuum pg_index") || die "Got error: $DBI::errstr when executing 'vacuum'\n";
836
$dbh->do("vacuum analyze") || die "Got error: $DBI::errstr when executing 'vacuum analyze'\n";
837
$dbh->do("vacuum") || die "Got error: $DBI::errstr when executing 'vacuum'\n";
839
$end_time=new Benchmark;
840
print "Time for book-keeping (1): " .
841
Benchmark::timestr(Benchmark::timediff($end_time, $loop_time),"all") . "\n\n";
842
$dbh->disconnect; $$dbh_ref= $self->connect();
846
#############################################################################
847
# Definitions for Solid
848
#############################################################################
854
my ($type,$host,$database)= @_;
859
$self->{'cmp_name'} = "solid";
860
$self->{'data_source'} = "DBI:Solid:";
861
$self->{'limits'} = \%limits;
862
$self->{'blob'} = "long varchar";
863
$self->{'text'} = "long varchar";
864
$self->{'double_quotes'} = 1;
865
$self->{'drop_attr'} = "";
866
$self->{'transactions'} = 1; # Transactions enabled
868
$limits{'max_conditions'} = 9999; # Probably big enough
869
$limits{'max_columns'} = 2000; # From crash-me
870
$limits{'max_tables'} = 65000; # Should be big enough
871
$limits{'max_text_size'} = 65492; # According to tests
872
$limits{'query_size'} = 65535; # Probably a limit
873
$limits{'max_index'} = 64; # Probably big enough
874
$limits{'max_index_parts'} = 64;
875
$limits{'max_column_name'} = 80;
877
$limits{'join_optimizer'} = 1;
878
$limits{'load_data_infile'} = 0;
879
$limits{'lock_tables'} = 0;
880
$limits{'functions'} = 1;
881
$limits{'group_functions'} = 1;
882
$limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings
883
$limits{'group_distinct_functions'}= 1; # Have count(distinct)
884
$limits{'select_without_from'}= 0; # Can do 'select 1' ?;
885
$limits{'multi_drop'} = 0;
886
$limits{'subqueries'} = 1;
887
$limits{'left_outer_join'} = 1;
888
$limits{'table_wildcard'} = 1;
889
$limits{'having_with_alias'} = 0;
890
$limits{'having_with_group'} = 1;
891
$limits{'like_with_column'} = 1;
892
$limits{'order_by_position'} = 0; # 2.30.0018 can this
893
$limits{'group_by_position'} = 0;
894
$limits{'alter_table'} = 1;
895
$limits{'alter_add_multi_col'}= 0;
896
$limits{'alter_table_dropcol'}= 0;
898
$limits{'group_func_extra_std'} = 0; # Have group function std().
900
$limits{'func_odbc_mod'} = 1;
901
$limits{'func_extra_%'} = 0;
902
$limits{'func_odbc_floor'} = 1;
903
$limits{'column_alias'} = 1;
905
$limits{'func_extra_in_num'} = 1;
906
$limits{'unique_index'} = 1; # Unique index works or not
907
$limits{'insert_select'} = 1;
908
$limits{'working_blobs'} = 1; # If big varchar/blobs works
909
$limits{'order_by_unused'} = 1;
910
$limits{'working_all_fields'} = 1;
911
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
917
# Get the version number of the database
923
$version="Solid version ??";
924
foreach $dir ($ENV{'SOLIDDIR'},"/usr/local/solid", "/my/local/solid")
926
if ($dir && -e "$dir/bin/solcon")
928
$version=`$dir/bin/solcon -e"ver" $main::opt_user $main::opt_password | grep Server | sed q`;
932
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
937
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
945
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
946
$main::opt_password,{ PrintError => 0}) ||
947
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
952
# Returns a list of statements to create a table
953
# The field types are in ANSI SQL format.
958
my($self,$table_name,$fields,$index) = @_;
959
my($query,@queries,$nr);
961
$query="create table $table_name (";
962
foreach $field (@$fields)
964
$field =~ s/mediumint/integer/i;
965
$field =~ s/ double/ float/i;
966
# Solid doesn't have blob, it has long varchar
967
$field =~ s/ blob/ long varchar/;
968
# $field =~ s/ decimal/ float/i;
969
# $field =~ s/ big_decimal/ float/i;
970
# $field =~ s/ date/ int/i;
971
$query.= $field . ',';
973
substr($query,-1)=")"; # Remove last ',';
974
push(@queries,$query);
976
foreach $index (@$index)
978
if ($index =~ /^primary key/i || $index =~ /^unique/i)
979
{ # Add to create statement
980
substr($queries[0],-1,0)="," . $index;
984
$index =~ /^(.*)\s+(\(.*\))$/;
985
push(@queries,"create ${1}$nr on $table_name $2");
992
# there is no sql statement in solid which can do the load from
993
# an ascii file in the db ... but there is the speedloader program
994
# an external program which can load the ascii file in the db ...
995
# the server must be down before using speedloader !!!!
996
# (in the standalone version)
997
# it works also with a control file ... that one must be made ....
999
my ($self, $dbname, $file) = @_;
1001
$speedcmd = '/usr/local/solid/bin/solload';
1002
print "At this moment not supported - solid server must go down \n";
1006
# solid can't handle an alias in a having statement so
1007
# select test as foo from tmp group by foo having foor > 2
1009
# select test as foo from tmp group by foo having test > 2
1012
my($self,$sql) = @_;
1013
my(@select,$tmp,$newhaving,$key,%change);
1015
if ($sql =~ /having\s+/i)
1017
if ($sql =~ /select (.*) from/i)
1019
(@select) = split(/,\s*/, $1);
1020
foreach $tmp (@select)
1022
if ($tmp =~ /(.*)\s+as\s+(\w+)/)
1028
if ($sql =~ /having\s+(\w+)/i)
1031
foreach $key (sort {$a cmp $b} keys %change)
1033
if ($newhaving eq $key)
1035
$newhaving =~ s/$key/$change{$key}/g;
1039
$sql =~ s/(having)\s+(\w+)/$1 $newhaving/i;
1047
my ($self,$table,$index) = @_;
1048
return "DROP INDEX $index";
1051
sub abort_if_fatal_error
1056
sub small_rollback_segment
1063
my ($self,$cmd) = @_;
1067
sub reconnect_on_errors
1072
#############################################################################
1073
# Definitions for Empress
1075
# at this moment DBI:Empress can only handle 200 prepare statements ...
1076
# so Empress can't be tested with the benchmark test :(
1077
#############################################################################
1083
my ($type,$host,$database)= @_;
1088
$self->{'cmp_name'} = "empress";
1089
$self->{'data_source'} = "DBI:EmpressNet:SERVER=$host;Database=/usr/local/empress/rdbms/bin/$database";
1090
$self->{'limits'} = \%limits;
1091
$self->{'blob'} = "text";
1092
$self->{'text'} = "text";
1093
$self->{'double_quotes'} = 1; # Can handle: 'Walker''s'
1094
$self->{'drop_attr'} = "";
1095
$self->{'transactions'} = 1; # Transactions enabled
1097
$limits{'max_conditions'} = 1258;
1098
$limits{'max_columns'} = 226; # server is disconnecting????
1099
# above this value .... but can handle 2419 columns
1100
# maybe something for crash-me ... but how to check ???
1101
$limits{'max_tables'} = 65000; # Should be big enough
1102
$limits{'max_text_size'} = 4095; # max returned ....
1103
$limits{'query_size'} = 65535; # Not a limit, big enough
1104
$limits{'max_index'} = 64; # Big enough
1105
$limits{'max_index_parts'} = 64; # Big enough
1106
$limits{'max_column_name'} = 31;
1108
$limits{'join_optimizer'} = 1;
1109
$limits{'load_data_infile'} = 0;
1110
$limits{'lock_tables'} = 1;
1111
$limits{'functions'} = 1;
1112
$limits{'group_functions'} = 1;
1113
$limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings
1114
$limits{'group_distinct_functions'}= 1; # Have count(distinct)
1115
$limits{'select_without_from'}= 0;
1116
$limits{'multi_drop'} = 0;
1117
$limits{'subqueries'} = 1;
1118
$limits{'table_wildcard'} = 0;
1119
$limits{'having_with_alias'} = 0; # AS isn't supported in a select
1120
$limits{'having_with_group'} = 1;
1121
$limits{'like_with_column'} = 1;
1122
$limits{'order_by_position'} = 1;
1123
$limits{'group_by_position'} = 0;
1124
$limits{'alter_table'} = 1;
1125
$limits{'alter_add_multi_col'}= 0;
1126
$limits{'alter_table_dropcol'}= 0;
1128
$limits{'group_func_extra_std'}= 0; # Have group function std().
1130
$limits{'func_odbc_mod'} = 0;
1131
$limits{'func_extra_%'} = 1;
1132
$limits{'func_odbc_floor'} = 1;
1133
$limits{'func_extra_if'} = 0;
1134
$limits{'column_alias'} = 0;
1136
$limits{'func_extra_in_num'} = 0;
1137
$limits{'unique_index'} = 1; # Unique index works or not
1138
$limits{'insert_select'} = 1;
1139
$limits{'working_blobs'} = 1; # If big varchar/blobs works
1140
$limits{'order_by_unused'} = 1;
1141
$limits{'working_all_fields'} = 1;
1142
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
1148
# Get the version number of the database
1156
if (-x "/usr/local/empress/rdbms/bin/empvers")
1158
$version=`/usr/local/empress/rdbms/bin/empvers | grep Version`;
1166
$version="Empress version ???";
1169
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
1177
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
1178
$main::opt_password,{ PrintError => 0}) ||
1179
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
1184
my($self,$dbname, $file) = @_;
1186
$command = "insert into $dbname from '$file'";
1187
print "$command\n" if ($opt_debug);
1188
$sth = $dbh->do($command) or die $DBI::errstr;
1194
# Returns a list of statements to create a table
1195
# The field types are in ANSI SQL format.
1200
my($self,$table_name,$fields,$index) = @_;
1201
my($query,@queries,$nr);
1203
$query="create table $table_name (";
1204
foreach $field (@$fields)
1206
$field =~ s/mediumint/int/i;
1207
$field =~ s/tinyint/int/i;
1208
$field =~ s/smallint/int/i;
1209
$field =~ s/longint/int/i;
1210
$field =~ s/integer/int/i;
1211
$field =~ s/ double/ longfloat/i;
1212
# Solid doesn't have blob, it has long varchar
1213
# $field =~ s/ blob/ text(65535,65535,65535,65535)/;
1214
$field =~ s/ blob/ text/;
1215
$field =~ s/ varchar\((\d+)\)/ char($1,3)/;
1216
$field =~ s/ char\((\d+)\)/ char($1,3)/;
1217
# $field =~ s/ decimal/ float/i;
1218
# $field =~ s/ big_decimal/ longfloat/i;
1219
# $field =~ s/ date/ int/i;
1220
$field =~ s/ float(.*)/ float/i;
1221
if ($field =~ / int\((\d+)\)/) {
1223
$field =~ s/ int\(\d+\)/ longinteger/i;
1225
$field =~ s/ int\(\d+\)/ longinteger/i;
1228
$field =~ s/ int/ longinteger/i;
1230
$query.= $field . ',';
1232
substr($query,-1)=")"; # Remove last ',';
1233
push(@queries,$query);
1235
foreach $index (@$index)
1237
# Primary key is unique index in Empress
1238
$index =~ s/primary key/unique index/i;
1239
if ($index =~ /^unique.*\(([^\(]*)\)$/i)
1242
push(@queries,"create unique index ${table_name}_$nr on $table_name ($1)");
1246
if (!($index =~ /^(.*index)\s+(\w*)\s+(\(.*\))$/i))
1248
die "Can't parse index information in '$index'\n";
1250
push(@queries,"create $1 ${table_name}_$2 on $table_name $3");
1256
# empress can't handle an alias and but can handle the number of the
1258
# select test as foo from tmp order by foo
1260
# select test from tmp order by 1
1263
my($self,$sql) = @_;
1264
my(@select,$i,$tmp,$newselect,$neworder,@order,$key,%change);
1265
my($tmp1,$otmp,$tmp2);
1267
if ($sql =~ /\s+as\s+/i)
1269
if ($sql =~ /select\s+(.*)\s+from/i) {
1271
(@select) = split(/,\s*/, $1);
1273
foreach $tmp (@select) {
1274
if ($tmp =~ /\s+as\s+(\w+)/) {
1280
$newselect =~ s/\s+as\s+(\w+)//gi;
1282
if ($sql =~ /order\s+by\s+(.*)$/i) {
1283
(@order) = split(/,\s*/, $1);
1284
foreach $otmp (@order) {
1285
foreach $key (sort {$a cmp $b} keys %change) {
1286
if ($otmp eq $key) {
1287
$neworder .= "$tmp1"."$change{$key}";
1290
} elsif ($otmp =~ /(\w+)\s+(.+)$/) {
1292
$neworder .= "$tmp1"."$change{$key} $2";
1298
$neworder .= "$tmp1"."$otmp";
1304
$sql =~ s/(select)\s+(.*)\s+(from)/$1 $newselect $3/i;
1305
$sql =~ s/(order\s+by)\s+(.*)$/$1 $neworder/i;
1312
my ($self,$cmd) = @_;
1313
$cmd =~ s/\'\'/\' \'/g;
1320
my ($self,$table,$index) = @_;
1321
return "DROP INDEX $index";
1324
# This is a because of the 200 statement problem with DBI-Empress
1326
sub abort_if_fatal_error
1328
if ($DBI::errstr =~ /Overflow of table of prepared statements/i)
1330
print "Overflow of prepared statements ... killing the process\n";
1336
sub small_rollback_segment
1341
sub reconnect_on_errors
1346
#############################################################################
1347
# Definitions for Oracle
1348
#############################################################################
1354
my ($type,$host,$database)= @_;
1359
$self->{'cmp_name'} = "Oracle";
1360
$self->{'data_source'} = "DBI:Oracle:$database";
1361
$self->{'limits'} = \%limits;
1362
$self->{'blob'} = "long";
1363
$self->{'text'} = "long";
1364
$self->{'double_quotes'} = 1; # Can handle: 'Walker''s'
1365
$self->{'drop_attr'} = "";
1366
$self->{'transactions'} = 1; # Transactions enabled
1367
$self->{"vacuum"} = 1;
1369
$limits{'max_conditions'} = 9999; # (Actually not a limit)
1370
$limits{'max_columns'} = 254; # Max number of columns in table
1371
$limits{'max_tables'} = 65000; # Should be big enough
1372
$limits{'max_text_size'} = 2000; # Limit for blob test-connect
1373
$limits{'query_size'} = 65525; # Max size with default buffers.
1374
$limits{'max_index'} = 16; # Max number of keys
1375
$limits{'max_index_parts'} = 16; # Max segments/key
1376
$limits{'max_column_name'} = 32; # max table and column name
1378
$limits{'truncate_table'} = 1;
1379
$limits{'join_optimizer'} = 1; # Can optimize FROM tables
1380
$limits{'load_data_infile'} = 0; # Has load data infile
1381
$limits{'lock_tables'} = 0; # Has lock tables
1382
$limits{'functions'} = 1; # Has simple functions (+/-)
1383
$limits{'group_functions'} = 1; # Have group functions
1384
$limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings
1385
$limits{'group_distinct_functions'}= 1; # Have count(distinct)
1386
$limits{'select_without_from'}= 0;
1387
$limits{'multi_drop'} = 0;
1388
$limits{'subqueries'} = 1;
1389
$limits{'left_outer_join'} = 0; # This may be fixed in the query module
1390
$limits{'table_wildcard'} = 1; # Has SELECT table_name.*
1391
$limits{'having_with_alias'} = 0; # Can use aliases in HAVING
1392
$limits{'having_with_group'} = 1; # Can't use group functions in HAVING
1393
$limits{'like_with_column'} = 1; # Can use column1 LIKE column2
1394
$limits{'order_by_position'} = 1; # Can use 'ORDER BY 1'
1395
$limits{'group_by_position'} = 0;
1396
$limits{'alter_table'} = 1;
1397
$limits{'alter_add_multi_col'}= 0;
1398
$limits{'alter_table_dropcol'}= 0;
1400
$limits{'group_func_extra_std'} = 0; # Have group function std().
1402
$limits{'func_odbc_mod'} = 0; # Oracle has problem with mod()
1403
$limits{'func_extra_%'} = 0; # Has % as alias for mod()
1404
$limits{'func_odbc_floor'} = 1; # Has func_odbc_floor function
1405
$limits{'func_extra_if'} = 0; # Have function if.
1406
$limits{'column_alias'} = 1; # Alias for fields in select statement.
1407
$limits{'NEG'} = 1; # Supports -id
1408
$limits{'func_extra_in_num'} = 1; # Has function in
1409
$limits{'unique_index'} = 1; # Unique index works or not
1410
$limits{'insert_select'} = 1;
1411
$limits{'working_blobs'} = 1; # If big varchar/blobs works
1412
$limits{'order_by_unused'} = 1;
1413
$limits{'working_all_fields'} = 1;
1414
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
1421
# Get the version number of the database
1427
my ($dbh,$sth,$version,@row);
1429
$dbh=$self->connect();
1430
$sth = $dbh->prepare("select VERSION from product_component_version WHERE PRODUCT like 'Oracle%'") or die $DBI::errstr;
1431
$version="Oracle 7.x";
1432
if ($sth->execute && (@row = $sth->fetchrow_array))
1434
$version="Oracle $row[0]";
1438
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
1446
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
1447
$main::opt_password,{ PrintError => 0}) ||
1448
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
1453
# Returns a list of statements to create a table
1454
# The field types are in ANSI SQL format.
1456
# If one uses $main::opt_fast then one is allowed to use
1457
# non standard types to get better speed.
1462
my($self,$table_name,$fields,$index) = @_;
1463
my($query,@queries,$ind,@keys);
1465
$query="create table $table_name (";
1466
foreach $field (@$fields)
1468
$field =~ s/ character\((\d+)\)/ char\($1\)/i;
1469
$field =~ s/ character varying\((\d+)\)/ varchar\($1\)/i;
1470
$field =~ s/ char varying\((\d+)\)/ varchar\($1\)/i;
1471
$field =~ s/ integer/ number\(38\)/i;
1472
$field =~ s/ int/ number\(38\)/i;
1473
$field =~ s/ tinyint/ number\(38\)/i;
1474
$field =~ s/ smallint/ number\(38\)/i;
1475
$field =~ s/ mediumint/ number\(38\)/i;
1476
$field =~ s/ tinynumber\((\d+)\)\((\d+)\)/ number\($1,$2\)/i;
1477
$field =~ s/ smallnumber\((\d+)\)\((\d+)\)/ number\($1,$2\)/i;
1478
$field =~ s/ mediumnumber\((\d+)\)\((\d+)\)/ number\($1,$2\)/i;
1479
$field =~ s/ number\((\d+)\)\((\d+)\)/ number\($1,$2\)/i;
1480
$field =~ s/ numeric\((\d+)\)\((\d+)\)/ number\($1,$2\)/i;
1481
$field =~ s/ decimal\((\d+)\)\((\d+)\)/ number\($1,$2\)/i;
1482
$field =~ s/ dec\((\d+)\)\((\d+)\)/ number\($1,$2\)/i;
1483
$field =~ s/ float/ number/;
1484
$field =~ s/ real/ number/;
1485
$field =~ s/ double precision/ number/;
1486
$field =~ s/ double/ number/;
1487
$field =~ s/ blob/ long/;
1488
$query.= $field . ',';
1491
foreach $ind (@$index)
1494
if ( $ind =~ /\bKEY\b/i ){
1495
push(@keys,"ALTER TABLE $table_name ADD $ind");
1497
my @fields = split(' ',$index);
1498
my $query="CREATE INDEX $fields[1] ON $table_name $fields[2]";
1499
push(@index,$query);
1502
substr($query,-1)=")"; # Remove last ',';
1503
push(@queries,$query,@keys,@index);
1504
#print "query:$query\n";
1510
my($self,$dbname, $file) = @_;
1511
print "insert an ascii file isn't supported by Oracle (?)\n";
1516
# Do any conversions to the ANSI SQL query so that the database can handle it
1520
my($self,$sql) = @_;
1526
my ($self,$cmd) = @_;
1527
$cmd =~ s/\'\'/\' \'/g;
1534
my ($self,$table,$index) = @_;
1535
return "DROP INDEX $index";
1539
# Abort if the server has crashed
1541
# 1 question should be retried
1544
sub abort_if_fatal_error
1549
sub small_rollback_segment
1554
sub reconnect_on_errors
1560
# optimize the tables ....
1564
my ($self,$full_vacuum,$dbh_ref)=@_;
1565
my ($loop_time,$end_time,$sth,$dbh);
1567
if (defined($full_vacuum))
1569
$$dbh_ref->disconnect; $$dbh_ref= $self->connect();
1572
$loop_time=new Benchmark;
1573
# first analyze all tables
1574
$sth = $dbh->prepare("select table_name from user_tables") || die "Got error: $DBI::errstr";
1575
$sth->execute || die "Got error: $DBI::errstr when select user_tables";
1576
while (my @r = $sth->fetchrow_array)
1578
$dbh->do("analyze table $r[0] compute statistics") || die "Got error: $DBI::errstr when executing 'analyze table'\n";
1580
# now analyze all indexes ...
1581
$sth = $dbh->prepare("select index_name from user_indexes") || die "Got error: $DBI::errstr";
1582
$sth->execute || die "Got error: $DBI::errstr when select user_indexes";
1583
while (my @r1 = $sth->fetchrow_array)
1585
$dbh->do("analyze index $r1[0] compute statistics") || die "Got error: $DBI::errstr when executing 'analyze index $r1[0]'\n";
1587
$end_time=new Benchmark;
1588
print "Time for book-keeping (1): " .
1589
Benchmark::timestr(Benchmark::timediff($end_time, $loop_time),"all") . "\n\n";
1590
$dbh->disconnect; $$dbh_ref= $self->connect();
1594
#############################################################################
1595
# Definitions for Informix
1596
#############################################################################
1598
package db_Informix;
1602
my ($type,$host,$database)= @_;
1607
$self->{'cmp_name'} = "Informix";
1608
$self->{'data_source'} = "DBI:Informix:$database";
1609
$self->{'limits'} = \%limits;
1610
$self->{'blob'} = "byte in table";
1611
$self->{'text'} = "byte in table";
1612
$self->{'double_quotes'} = 0; # Can handle: 'Walker''s'
1613
$self->{'drop_attr'} = "";
1614
$self->{'transactions'} = 1; # Transactions enabled
1615
$self->{'host'} = $host;
1617
$limits{'NEG'} = 1; # Supports -id
1618
$limits{'alter_table'} = 1;
1619
$limits{'alter_add_multi_col'}= 0;
1620
$limits{'alter_table_dropcol'}= 1;
1621
$limits{'column_alias'} = 1; # Alias for fields in select statement.
1622
$limits{'func_extra_%'} = 0; # Has % as alias for mod()
1623
$limits{'func_extra_if'} = 0; # Have function if.
1624
$limits{'func_extra_in_num'}= 0; # Has function in
1625
$limits{'func_odbc_floor'} = 0; # Has func_odbc_floor function
1626
$limits{'func_odbc_mod'} = 1; # Have function mod.
1627
$limits{'functions'} = 1; # Has simple functions (+/-)
1628
$limits{'group_by_position'} = 1; # Can use 'GROUP BY 1'
1629
$limits{'group_by_alias'} = 0; # Can use 'select a as ab from x GROUP BY ab'
1630
$limits{'group_func_extra_std'} = 0; # Have group function std().
1631
$limits{'group_functions'} = 1; # Have group functions
1632
$limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings
1633
$limits{'group_distinct_functions'}= 1; # Have count(distinct)
1634
$limits{'having_with_alias'} = 0; # Can use aliases in HAVING
1635
$limits{'having_with_group'}= 1; # Can't use group functions in HAVING
1636
$limits{'join_optimizer'} = 1; # Can optimize FROM tables (always 1 only for msql)
1637
$limits{'left_outer_join'} = 0; # Supports left outer joins (ANSI)
1638
$limits{'like_with_column'} = 1; # Can use column1 LIKE column2
1639
$limits{'load_data_infile'} = 0; # Has load data infile
1640
$limits{'lock_tables'} = 1; # Has lock tables
1641
$limits{'max_conditions'} = 1214; # (Actually not a limit)
1642
$limits{'max_column_name'} = 18; # max table and column name
1643
$limits{'max_columns'} = 994; # Max number of columns in table
1644
$limits{'max_tables'} = 65000; # Should be big enough
1645
$limits{'max_index'} = 64; # Max number of keys
1646
$limits{'max_index_parts'} = 15; # Max segments/key
1647
$limits{'max_text_size'} = 65535; # Max size with default buffers. ??
1648
$limits{'multi_drop'} = 0; # Drop table can take many tables
1649
$limits{'order_by_position'} = 1; # Can use 'ORDER BY 1'
1650
$limits{'query_size'} = 32766; # Max size with default buffers.
1651
$limits{'select_without_from'}= 0; # Can do 'select 1';
1652
$limits{'subqueries'} = 1; # Doesn't support sub-queries.
1653
$limits{'table_wildcard'} = 1; # Has SELECT table_name.*
1654
$limits{'unique_index'} = 1; # Unique index works or not
1655
$limits{'insert_select'} = 1;
1656
$limits{'working_blobs'} = 1; # If big varchar/blobs works
1657
$limits{'order_by_unused'} = 1;
1658
$limits{'working_all_fields'} = 1;
1659
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
1665
# Get the version number of the database
1671
my ($dbh,$sth,$version,@row);
1673
$ENV{'INFORMIXSERVER'} = $self->{'host'};
1674
$dbh=$self->connect();
1675
$sth = $dbh->prepare("SELECT owner FROM systables WHERE tabname = ' VERSION'")
1676
or die $DBI::errstr;
1677
$version='Informix unknown';
1678
if ($sth->execute && (@row = $sth->fetchrow_array))
1680
$version="Informix $row[0]";
1684
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
1692
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
1693
$main::opt_password,{ PrintError => 0}) ||
1694
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
1705
my($self,$table_name,$fields,$index) = @_;
1706
my($query,@queries,$name,$nr);
1708
$query="create table $table_name (";
1709
foreach $field (@$fields)
1711
# $field =~ s/\btransport_description\b/transport_desc/;
1712
# to overcome limit 18 chars
1713
$field =~ s/tinyint/smallint/i;
1714
$field =~ s/tinyint\(\d+\)/smallint/i;
1715
$field =~ s/mediumint/integer/i;
1716
$field =~ s/mediumint\(\d+\)/integer/i;
1717
$field =~ s/smallint\(\d+\)/smallint/i;
1718
$field =~ s/integer\(\d+\)/integer/i;
1719
$field =~ s/int\(\d+\)/integer/i;
1720
# $field =~ s/\b(?:small)?int(?:eger)?\((\d+)\)/decimal($1)/i;
1721
# $field =~ s/float(\(\d*,\d*\)){0,1}/real/i;
1722
$field =~ s/(float|double)(\(.*?\))?/float/i;
1724
if ($field =~ / blob/i)
1726
$name=$self->{'blob'};
1727
$field =~ s/ blob/ $name/;
1729
$query.= $field . ',';
1731
substr($query,-1)=")"; # Remove last ',';
1732
push(@queries,$query);
1735
foreach $index (@$index)
1737
# Primary key is unique index in Informix
1738
$index =~ s/primary key/unique index primary/i;
1739
if ($index =~ /^unique\s*\(([^\(]*)\)$/i)
1742
push(@queries,"create unique index ${table_name}_$nr on $table_name ($1)");
1746
if (!($index =~ /^(.*index)\s+(\w*)\s+(\(.*\))$/i))
1748
die "Can't parse index information in '$index'\n";
1750
### push(@queries,"create $1 ${table_name}_$2 on $table_name $3");
1752
push(@queries,"create $1 ${table_name}_$nr on $table_name $3");
1758
# Some test needed this
1762
my($self,$sql) = @_;
1769
my ($self,$cmd) = @_;
1778
my ($self,$table,$index) = @_;
1779
return "DROP INDEX $index";
1783
# Abort if the server has crashed
1785
# 1 question should be retried
1788
sub abort_if_fatal_error
1793
sub small_rollback_segment
1798
sub reconnect_on_errors
1804
#############################################################################
1805
# Configuration for Access
1806
#############################################################################
1812
my ($type,$host,$database)= @_;
1817
$self->{'cmp_name'} = "access";
1818
$self->{'data_source'} = "DBI:ODBC:$database";
1819
if (defined($host) && $host ne "")
1821
$self->{'data_source'} .= ":$host";
1823
$self->{'limits'} = \%limits;
1824
$self->{'blob'} = "blob";
1825
$self->{'text'} = "blob"; # text ?
1826
$self->{'double_quotes'} = 1; # Can handle: 'Walker''s'
1827
$self->{'drop_attr'} = "";
1828
$self->{'transactions'} = 1; # Transactions enabled
1830
$limits{'max_conditions'} = 97; # We get 'Query is too complex'
1831
$limits{'max_columns'} = 255; # Max number of columns in table
1832
$limits{'max_tables'} = 65000; # Should be big enough
1833
$limits{'max_text_size'} = 255; # Max size with default buffers.
1834
$limits{'query_size'} = 65535; # Not a limit, big enough
1835
$limits{'max_index'} = 32; # Max number of keys
1836
$limits{'max_index_parts'} = 10; # Max segments/key
1837
$limits{'max_column_name'} = 64; # max table and column name
1839
$limits{'join_optimizer'} = 1; # Can optimize FROM tables
1840
$limits{'load_data_infile'} = 0; # Has load data infile
1841
$limits{'lock_tables'} = 0; # Has lock tables
1842
$limits{'functions'} = 1; # Has simple functions (+/-)
1843
$limits{'group_functions'} = 1; # Have group functions
1844
$limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings
1845
$limits{'group_distinct_functions'}= 0; # Have count(distinct)
1846
$limits{'select_without_from'}= 1; # Can do 'select 1';
1847
$limits{'multi_drop'} = 0; # Drop table can take many tables
1848
$limits{'subqueries'} = 1; # Supports sub-queries.
1849
$limits{'left_outer_join'} = 1; # Supports left outer joins
1850
$limits{'table_wildcard'} = 1; # Has SELECT table_name.*
1851
$limits{'having_with_alias'} = 0; # Can use aliases in HAVING
1852
$limits{'having_with_group'} = 1; # Can use group functions in HAVING
1853
$limits{'like_with_column'} = 1; # Can use column1 LIKE column2
1854
$limits{'order_by_position'} = 1; # Can use 'ORDER BY 1'
1855
$limits{'group_by_position'} = 0; # Can use 'GROUP BY 1'
1856
$limits{'alter_table'} = 1;
1857
$limits{'alter_add_multi_col'}= 2; #Have ALTER TABLE t add a int, b int;
1858
$limits{'alter_table_dropcol'}= 1;
1860
$limits{'group_func_extra_std'} = 0; # Have group function std().
1862
$limits{'func_odbc_mod'} = 0; # Have function mod.
1863
$limits{'func_extra_%'} = 0; # Has % as alias for mod()
1864
$limits{'func_odbc_floor'} = 0; # Has func_odbc_floor function
1865
$limits{'func_extra_if'} = 0; # Have function if.
1866
$limits{'column_alias'} = 1; # Alias for fields in select statement.
1867
$limits{'NEG'} = 1; # Supports -id
1868
$limits{'func_extra_in_num'} = 1; # Has function in
1869
$limits{'unique_index'} = 1; # Unique index works or not
1870
$limits{'insert_select'} = 1;
1871
$limits{'working_blobs'} = 1; # If big varchar/blobs works
1872
$limits{'order_by_unused'} = 1;
1873
$limits{'working_all_fields'} = 1;
1874
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
1879
# Get the version number of the database
1885
my $version="Access 2000";
1886
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
1887
return $version; #DBI/ODBC can't return the server version
1894
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
1895
$main::opt_password,{ PrintError => 0}) ||
1896
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
1901
# Returns a list of statements to create a table
1902
# The field types are in ANSI SQL format.
1907
my($self,$table_name,$fields,$index) = @_;
1908
my($query,@queries,$nr);
1910
$query="create table $table_name (";
1911
foreach $field (@$fields)
1913
$field =~ s/mediumint/integer/i;
1914
$field =~ s/tinyint/smallint/i;
1915
$field =~ s/float\(\d+,\d+\)/float/i;
1916
$field =~ s/integer\(\d+\)/integer/i;
1917
$field =~ s/smallint\(\d+\)/smallint/i;
1918
$field =~ s/int\(\d+\)/integer/i;
1919
$field =~ s/blob/text/i;
1920
$query.= $field . ',';
1922
substr($query,-1)=")"; # Remove last ',';
1923
push(@queries,$query);
1925
foreach $index (@$index)
1927
$ext="WITH DISALLOW NULL";
1928
if (($index =~ s/primary key/unique index primary_key/i))
1930
$ext="WITH PRIMARY;"
1932
if ($index =~ /^unique.*\(([^\(]*)\)$/i)
1935
$index="unique index ${table_name}_$nr ($1)";
1937
$index =~ /^(.*)\s+(\(.*\))$/;
1938
push(@queries,"create ${1} on $table_name $2");
1944
# Do any conversions to the ANSI SQL query so that the database can handle it
1948
my($self,$sql) = @_;
1954
my ($self,$table,$index) = @_;
1955
return "DROP INDEX $index ON $table";
1959
# Abort if the server has crashed
1961
# 1 question should be retried
1964
sub abort_if_fatal_error
1966
return 1 if (($DBI::errstr =~ /The database engine couldn\'t lock table/i) ||
1967
($DBI::errstr =~ /niet vergrendelen. De tabel is momenteel in gebruik /i) ||
1968
($DBI::errstr =~ /Den anv.* redan av en annan/i) ||
1969
($DBI::errstr =~ /non-exclusive access/));
1973
sub small_rollback_segment
1978
sub reconnect_on_errors
1985
my ($self,$cmd) = @_;
1989
#############################################################################
1990
# Configuration for Microsoft SQL server
1991
#############################################################################
1997
my ($type,$host,$database)= @_;
2002
$self->{'cmp_name'} = "ms-sql";
2003
$self->{'data_source'} = "DBI:ODBC:$database";
2004
if (defined($host) && $host ne "")
2006
$self->{'data_source'} .= ":$host";
2008
$self->{'limits'} = \%limits;
2009
$self->{'blob'} = "text";
2010
$self->{'text'} = "text";
2011
$self->{'double_quotes'} = 1; # Can handle: 'Walker''s'
2012
$self->{'drop_attr'} = "";
2013
$self->{'transactions'} = 1; # Transactions enabled
2015
$limits{'max_conditions'} = 1030; # We get 'Query is too complex'
2016
$limits{'max_columns'} = 250; # Max number of columns in table
2017
$limits{'max_tables'} = 65000; # Should be big enough
2018
$limits{'max_text_size'} = 9830; # Max size with default buffers.
2019
$limits{'query_size'} = 9830; # Max size with default buffers.
2020
$limits{'max_index'} = 64; # Max number of keys
2021
$limits{'max_index_parts'} = 15; # Max segments/key
2022
$limits{'max_column_name'} = 30; # max table and column name
2024
$limits{'join_optimizer'} = 1; # Can optimize FROM tables
2025
$limits{'load_data_infile'} = 0; # Has load data infile
2026
$limits{'lock_tables'} = 0; # Has lock tables
2027
$limits{'functions'} = 1; # Has simple functions (+/-)
2028
$limits{'group_functions'} = 1; # Have group functions
2029
$limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings
2030
$limits{'group_distinct_functions'}= 1; # Have count(distinct)
2031
$limits{'select_without_from'}= 1; # Can do 'select 1';
2032
$limits{'multi_drop'} = 1; # Drop table can take many tables
2033
$limits{'subqueries'} = 1; # Supports sub-queries.
2034
$limits{'left_outer_join'} = 1; # Supports left outer joins
2035
$limits{'table_wildcard'} = 1; # Has SELECT table_name.*
2036
$limits{'having_with_alias'} = 0; # Can use aliases in HAVING
2037
$limits{'having_with_group'} = 1; # Can't use group functions in HAVING
2038
$limits{'like_with_column'} = 1; # Can use column1 LIKE column2
2039
$limits{'order_by_position'} = 1; # Can use 'ORDER BY 1'
2040
$limits{'group_by_position'} = 0; # Can use 'GROUP BY 1'
2041
$limits{'alter_table'} = 1;
2042
$limits{'alter_add_multi_col'}= 0;
2043
$limits{'alter_table_dropcol'}= 0;
2045
$limits{'group_func_extra_std'} = 0; # Have group function std().
2047
$limits{'func_odbc_mod'} = 0; # Have function mod.
2048
$limits{'func_extra_%'} = 1; # Has % as alias for mod()
2049
$limits{'func_odbc_floor'} = 1; # Has func_odbc_floor function
2050
$limits{'func_extra_if'} = 0; # Have function if.
2051
$limits{'column_alias'} = 1; # Alias for fields in select statement.
2052
$limits{'NEG'} = 1; # Supports -id
2053
$limits{'func_extra_in_num'} = 0; # Has function in
2054
$limits{'unique_index'} = 1; # Unique index works or not
2055
$limits{'insert_select'} = 1;
2056
$limits{'working_blobs'} = 1; # If big varchar/blobs works
2057
$limits{'order_by_unused'} = 1;
2058
$limits{'working_all_fields'} = 1;
2059
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
2064
# Get the version number of the database
2070
my($sth,@row, $version);
2071
$version='MS SQL server ?';
2072
$dbh=$self->connect();
2073
$sth = $dbh->prepare("SELECT \@\@VERSION") or die $DBI::errstr;
2074
$sth->execute or die $DBI::errstr;
2075
@row = $sth->fetchrow_array;
2077
@server = split(/\n/,$row[0]);
2079
$version= "$server[0]";
2082
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
2090
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
2091
$main::opt_password,{ PrintError => 0}) ||
2092
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
2097
# Returns a list of statements to create a table
2098
# The field types are in ANSI SQL format.
2103
my($self,$table_name,$fields,$index) = @_;
2104
my($query,@queries,$nr);
2106
$query="create table $table_name (";
2107
foreach $field (@$fields)
2109
$field =~ s/mediumint/integer/i;
2110
$field =~ s/float\(\d+,\d+\)/float/i;
2111
$field =~ s/double\(\d+,\d+\)/float/i;
2112
$field =~ s/double/float/i;
2113
$field =~ s/integer\(\d+\)/integer/i;
2114
$field =~ s/int\(\d+\)/integer/i;
2115
$field =~ s/smallint\(\d+\)/smallint/i;
2116
$field =~ s/smallinteger/smallint/i;
2117
$field =~ s/tinyint\(\d+\)/tinyint/i;
2118
$field =~ s/tinyinteger/tinyint/i;
2119
$field =~ s/blob/text/i;
2120
$query.= $field . ',';
2122
substr($query,-1)=")"; # Remove last ',';
2123
push(@queries,$query);
2125
foreach $index (@$index)
2127
$ext="WITH DISALLOW NULL";
2128
if (($index =~ s/primary key/unique index primary_key/i))
2130
$ext="WITH PRIMARY;"
2132
if ($index =~ /^unique.*\(([^\(]*)\)$/i)
2135
$index="unique index ${table_name}_$nr ($1)";
2137
$index =~ /^(.*)\s+(\(.*\))$/;
2138
push(@queries,"create ${1} on $table_name $2");
2144
# Do any conversions to the ANSI SQL query so that the database can handle it
2148
my($self,$sql) = @_;
2154
my ($self,$table,$index) = @_;
2155
return "DROP INDEX $table.$index";
2159
# Abort if the server has crashed
2161
# 1 question should be retried
2164
sub abort_if_fatal_error
2169
sub small_rollback_segment
2174
sub reconnect_on_errors
2181
my ($self,$cmd) = @_;
2185
#############################################################################
2186
# Configuration for Sybase
2187
#############################################################################
2192
my ($type,$host,$database)= @_;
2197
$self->{'cmp_name'} = "sybase";
2198
$self->{'data_source'} = "DBI:Sybase:database=$database";
2199
if (defined($host) && $host ne "")
2201
$self->{'data_source'} .= ";hostname=$host";
2203
$self->{'limits'} = \%limits;
2204
$self->{'blob'} = "text";
2205
$self->{'text'} = "text";
2206
$self->{'double_quotes'} = 1; # Can handle: 'Walker''s'
2207
$self->{'drop_attr'} = "";
2208
$self->{'transactions'} = 1; # Transactions enabled
2209
$self->{"vacuum"} = 1;
2211
$limits{'max_conditions'} = 1030; # We get 'Query is too complex'
2212
$limits{'max_columns'} = 250; # Max number of columns in table
2213
$limits{'max_tables'} = 65000; # Should be big enough
2214
$limits{'max_text_size'} = 9830; # Max size with default buffers.
2215
$limits{'query_size'} = 9830; # Max size with default buffers.
2216
$limits{'max_index'} = 64; # Max number of keys
2217
$limits{'max_index_parts'} = 15; # Max segments/key
2218
$limits{'max_column_name'} = 30; # max table and column name
2220
$limits{'join_optimizer'} = 1; # Can optimize FROM tables
2221
$limits{'load_data_infile'} = 0; # Has load data infile
2222
$limits{'lock_tables'} = 0; # Has lock tables
2223
$limits{'functions'} = 1; # Has simple functions (+/-)
2224
$limits{'group_functions'} = 1; # Have group functions
2225
$limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings
2226
$limits{'group_distinct_functions'}= 1; # Have count(distinct)
2227
$limits{'select_without_from'}= 1; # Can do 'select 1';
2228
$limits{'multi_drop'} = 1; # Drop table can take many tables
2229
$limits{'subqueries'} = 1; # Supports sub-queries.
2230
$limits{'left_outer_join'} = 1; # Supports left outer joins
2231
$limits{'table_wildcard'} = 1; # Has SELECT table_name.*
2232
$limits{'having_with_alias'} = 0; # Can use aliases in HAVING
2233
$limits{'having_with_group'} = 1; # Can't use group functions in HAVING
2234
$limits{'like_with_column'} = 1; # Can use column1 LIKE column2
2235
$limits{'order_by_position'} = 1; # Can use 'ORDER BY 1'
2236
$limits{'group_by_position'} = 0; # Can use 'GROUP BY 1'
2237
$limits{'alter_table'} = 1;
2238
$limits{'alter_add_multi_col'}= 0;
2239
$limits{'alter_table_dropcol'}= 0;
2241
$limits{'group_func_extra_std'} = 0; # Have group function std().
2243
$limits{'func_odbc_mod'} = 0; # Have function mod.
2244
$limits{'func_extra_%'} = 1; # Has % as alias for mod()
2245
$limits{'func_odbc_floor'} = 1; # Has func_odbc_floor function
2246
$limits{'func_extra_if'} = 0; # Have function if.
2247
$limits{'column_alias'} = 1; # Alias for fields in select statement.
2248
$limits{'NEG'} = 1; # Supports -id
2249
$limits{'func_extra_in_num'} = 0; # Has function in
2250
$limits{'unique_index'} = 1; # Unique index works or not
2251
$limits{'insert_select'} = 1;
2252
$limits{'working_blobs'} = 1; # If big varchar/blobs works
2253
$limits{'order_by_unused'} = 1;
2254
$limits{'working_all_fields'} = 1;
2255
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
2260
# Get the version number of the database
2266
my ($dbh,$sth,$version,@row);
2268
$dbh=$self->connect();
2269
$sth = $dbh->prepare('SELECT @@version') or die $DBI::errstr;
2270
$version="Sybase (unknown)";
2271
if ($sth->execute && (@row = $sth->fetchrow_array))
2277
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
2285
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
2286
$main::opt_password,{ PrintError => 0 , AutoCommit => 1}) ||
2287
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
2292
# Returns a list of statements to create a table
2293
# The field types are in ANSI SQL format.
2298
my($self,$table_name,$fields,$index) = @_;
2299
my($query,@queries,$nr);
2301
$query="create table $table_name (";
2302
foreach $field (@$fields)
2304
$field =~ s/mediumint/integer/i;
2305
$field =~ s/float\(\d+,\d+\)/float/i;
2306
$field =~ s/int\(\d+\)/int/i;
2307
$field =~ s/double/float/i;
2308
$field =~ s/integer\(\d+\)/integer/i;
2309
$field =~ s/smallint\(\d+\)/smallint/i;
2310
$field =~ s/tinyint\(\d+\)/tinyint/i;
2311
$field =~ s/blob/text/i;
2312
$query.= $field . ',';
2314
substr($query,-1)=")"; # Remove last ',';
2315
push(@queries,$query);
2317
foreach $index (@$index)
2319
# $ext="WITH DISALLOW NULL";
2320
if (($index =~ s/primary key/unique index primary_key/i))
2322
# $ext="WITH PRIMARY;"
2324
if ($index =~ /^unique.*\(([^\(]*)\)$/i)
2327
$index="unique index ${table_name}_$nr ($1)";
2329
$index =~ /^(.*)\s+(\(.*\))$/;
2330
push(@queries,"create ${1} on $table_name $2");
2336
# Do any conversions to the ANSI SQL query so that the database can handle it
2340
my($self,$sql) = @_;
2346
my ($self,$table,$index) = @_;
2347
return "DROP INDEX $table.$index";
2351
# Abort if the server has crashed
2353
# 1 question should be retried
2356
sub abort_if_fatal_error
2361
sub small_rollback_segment
2366
sub reconnect_on_errors
2373
my ($self,$cmd) = @_;
2378
# optimize the tables ....
2379
# WARNING (from walrus)! This sub will work only from DBD:sybase
2380
# driver. Because if we use ODBC we don't know actual database name
2381
# (but DSN name only)
2384
my ($self,$full_vacuum,$dbh_ref)=@_;
2385
my ($loop_time,$end_time,$dbh);
2387
if (defined($full_vacuum))
2389
$$dbh_ref->disconnect; $$dbh_ref= $self->connect();
2392
$loop_time=new Benchmark;
2393
my (@tables,$sth,$current_table,$current_base);
2394
$dbh->do("dump tran $database with truncate_only");
2395
$sth=$dbh->prepare("sp_tables" ) or die "prepere";
2396
$sth->execute() or die "execute";
2397
while (@row = $sth->fetchrow_array()) {
2398
$current_table = $row[2];
2399
$current_base = $row[0];
2400
next if ($current_table =~ /^sys/);
2401
push(@tables,$current_table) if ($database == $current_base);
2406
foreach $table (@tables) {
2407
# print "$table: \n";
2408
$dbh->do("update statistics $table") or print "Oops!";
2411
# $dbh->do("analyze table ?? compute statistics") || die "Got error: $DBI::errstr when executing 'vacuum'\n";
2412
$end_time=new Benchmark;
2413
print "Time for book-keeping (1): " .
2414
Benchmark::timestr(Benchmark::timediff($end_time, $loop_time),"all") . "\n\n";
2415
$dbh->disconnect; $$dbh_ref= $self->connect();
2421
#############################################################################
2422
# Definitions for Adabas
2423
#############################################################################
2429
my ($type,$host,$database)= @_;
2434
$self->{'cmp_name'} = "Adabas";
2435
$self->{'data_source'} = "DBI:Adabas:$database";
2436
$self->{'limits'} = \%limits;
2437
$self->{'blob'} = "long";
2438
$self->{'text'} = "long";
2439
$self->{'double_quotes'} = 1; # Can handle: 'Walker''s'
2440
$self->{'drop_attr'} = "";
2441
$self->{'transactions'} = 1; # Transactions enabled
2443
$limits{'max_conditions'} = 50; # (Actually not a limit)
2444
$limits{'max_columns'} = 254; # Max number of columns in table
2445
$limits{'max_tables'} = 65000; # Should be big enough
2446
$limits{'max_text_size'} = 2000; # Limit for blob test-connect
2447
$limits{'query_size'} = 65525; # Max size with default buffers.
2448
$limits{'max_index'} = 16; # Max number of keys
2449
$limits{'max_index_parts'} = 16; # Max segments/key
2450
$limits{'max_column_name'} = 32; # max table and column name
2452
$limits{'join_optimizer'} = 1; # Can optimize FROM tables
2453
$limits{'load_data_infile'} = 0; # Has load data infile
2454
$limits{'lock_tables'} = 0; # Has lock tables
2455
$limits{'functions'} = 1; # Has simple functions (+/-)
2456
$limits{'group_functions'} = 1; # Have group functions
2457
$limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings
2458
$limits{'group_distinct_functions'}= 1; # Have count(distinct)
2459
$limits{'select_without_from'}= 0;
2460
$limits{'multi_drop'} = 0;
2461
$limits{'subqueries'} = 1;
2462
$limits{'left_outer_join'} = 0; # This may be fixed in the query module
2463
$limits{'table_wildcard'} = 1; # Has SELECT table_name.*
2464
$limits{'having_with_alias'} = 0; # Can use aliases in HAVING
2465
$limits{'having_with_group'} = 1; # Can't use group functions in HAVING
2466
$limits{'like_with_column'} = 1; # Can use column1 LIKE column2
2467
$limits{'order_by_position'} = 1; # Can use 'ORDER BY 1'
2468
$limits{'group_by_position'} = 1;
2469
$limits{'alter_table'} = 1;
2470
$limits{'alter_add_multi_col'}= 2; #Have ALTER TABLE t add a int, b int;
2471
$limits{'alter_table_dropcol'}= 1;
2473
$limits{'group_func_extra_std'} = 0; # Have group function std().
2475
$limits{'func_odbc_mod'} = 0; # Oracle has problem with mod()
2476
$limits{'func_extra_%'} = 0; # Has % as alias for mod()
2477
$limits{'func_odbc_floor'} = 1; # Has func_odbc_floor function
2478
$limits{'func_extra_if'} = 0; # Have function if.
2479
$limits{'column_alias'} = 1; # Alias for fields in select statement.
2480
$limits{'NEG'} = 1; # Supports -id
2481
$limits{'func_extra_in_num'} = 1; # Has function in
2482
$limits{'unique_index'} = 1; # Unique index works or not
2483
$limits{'insert_select'} = 1;
2484
$limits{'working_blobs'} = 1; # If big varchar/blobs works
2485
$limits{'order_by_unused'} = 1;
2486
$limits{'working_all_fields'} = 1;
2487
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
2494
# Get the version number of the database
2500
my ($dbh,$sth,$version,@row);
2502
$dbh=$self->connect();
2503
$sth = $dbh->prepare("SELECT KERNEL FROM VERSIONS") or die $DBI::errstr;
2504
$version="Adabas (unknown)";
2505
if ($sth->execute && (@row = $sth->fetchrow_array)
2506
&& $row[0] =~ /([\d\.]+)/)
2508
$version="Adabas $1";
2512
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
2520
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
2521
$main::opt_password,{ PrintError => 0}) ||
2522
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
2527
# Returns a list of statements to create a table
2528
# The field types are in ANSI SQL format.
2530
# If one uses $main::opt_fast then one is allowed to use
2531
# non standard types to get better speed.
2536
my($self,$table_name,$fields,$index) = @_;
2537
my($query,@queries,$ind,@keys);
2539
$query="create table $table_name (";
2540
foreach $field (@$fields)
2542
$field =~ s/CHARACTER\s+VARYING/VARCHAR/i;
2543
$field =~ s/TINYINT/SMALLINT/i;
2544
$field =~ s/MEDIUMINT/INT/i;
2545
$field =~ s/SMALLINT\s*\(\d+\)/SMALLINT/i;
2546
$field =~ s/INT\s*\(\d+\)/INT/i;
2547
$field =~ s/BLOB/LONG/i;
2548
$field =~ s/INTEGER\s*\(\d+\)/INTEGER/i;
2549
$field =~ s/FLOAT\s*\((\d+),\d+\)/FLOAT\($1\)/i;
2550
$field =~ s/DOUBLE/FLOAT\(38\)/i;
2551
$field =~ s/DOUBLE\s+PRECISION/FLOAT\(38\)/i;
2552
$query.= $field . ',';
2555
foreach $ind (@$index)
2558
if ( $ind =~ /\bKEY\b/i ){
2559
push(@keys,"ALTER TABLE $table_name ADD $ind");
2561
my @fields = split(' ',$index);
2562
my $query="CREATE INDEX $fields[1] ON $table_name $fields[2]";
2563
push(@index,$query);
2566
substr($query,-1)=")"; # Remove last ',';
2567
push(@queries,$query,@keys,@index);
2568
#print "query:$query\n";
2574
my($self,$dbname, $file) = @_;
2575
print "insert an ascii file isn't supported by Oracle (?)\n";
2580
# Do any conversions to the ANSI SQL query so that the database can handle it
2584
my($self,$sql) = @_;
2590
my ($self,$table,$index) = @_;
2591
return "DROP INDEX $index";
2595
# Abort if the server has crashed
2597
# 1 question should be retried
2600
sub abort_if_fatal_error
2605
sub small_rollback_segment
2610
sub reconnect_on_errors
2617
my ($self,$cmd) = @_;
2621
#############################################################################
2622
# Configuration for IBM DB2
2623
#############################################################################
2629
my ($type,$host,$database)= @_;
2634
$self->{'cmp_name'} = "DB2";
2635
$self->{'data_source'} = "DBI:ODBC:$database";
2636
if (defined($host) && $host ne "")
2638
$self->{'data_source'} .= ":$host";
2640
$self->{'limits'} = \%limits;
2641
$self->{'blob'} = "varchar(255)";
2642
$self->{'text'} = "varchar(255)";
2643
$self->{'double_quotes'} = 1; # Can handle: 'Walker''s'
2644
$self->{'drop_attr'} = "";
2645
$self->{'transactions'} = 1; # Transactions enabled
2647
$limits{'max_conditions'} = 418; # We get 'Query is too complex'
2648
$limits{'max_columns'} = 500; # Max number of columns in table
2649
$limits{'max_tables'} = 65000; # Should be big enough
2650
$limits{'max_text_size'} = 254; # Max size with default buffers.
2651
$limits{'query_size'} = 254; # Max size with default buffers.
2652
$limits{'max_index'} = 48; # Max number of keys
2653
$limits{'max_index_parts'} = 15; # Max segments/key
2654
$limits{'max_column_name'} = 18; # max table and column name
2656
$limits{'join_optimizer'} = 1; # Can optimize FROM tables
2657
$limits{'load_data_infile'} = 0; # Has load data infile
2658
$limits{'lock_tables'} = 0; # Has lock tables
2659
$limits{'functions'} = 1; # Has simple functions (+/-)
2660
$limits{'group_functions'} = 1; # Have group functions
2661
$limits{'group_func_sql_min_str'}= 1;
2662
$limits{'group_distinct_functions'}= 1; # Have count(distinct)
2663
$limits{'select_without_from'}= 0; # Can do 'select 1';
2664
$limits{'multi_drop'} = 0; # Drop table can take many tables
2665
$limits{'subqueries'} = 1; # Supports sub-queries.
2666
$limits{'left_outer_join'} = 1; # Supports left outer joins
2667
$limits{'table_wildcard'} = 1; # Has SELECT table_name.*
2668
$limits{'having_with_alias'} = 0; # Can use aliases in HAVING
2669
$limits{'having_with_group'} = 1; # Can't use group functions in HAVING
2670
$limits{'like_with_column'} = 0; # Can use column1 LIKE column2
2671
$limits{'order_by_position'} = 1; # Can use 'ORDER BY 1'
2672
$limits{'group_by_position'} = 0; # Can use 'GROUP BY 1'
2673
$limits{'alter_table'} = 1;
2674
$limits{'alter_add_multi_col'}= 0;
2675
$limits{'alter_table_dropcol'}= 0;
2677
$limits{'group_func_extra_std'} = 0; # Have group function std().
2679
$limits{'func_odbc_mod'} = 1; # Have function mod.
2680
$limits{'func_extra_%'} = 0; # Has % as alias for mod()
2681
$limits{'func_odbc_floor'} = 1; # Has func_odbc_floor function
2682
$limits{'func_extra_if'} = 0; # Have function if.
2683
$limits{'column_alias'} = 1; # Alias for fields in select statement.
2684
$limits{'NEG'} = 1; # Supports -id
2685
$limits{'func_extra_in_num'} = 0; # Has function in
2686
$limits{'unique_index'} = 1; # Unique index works or not
2687
$limits{'insert_select'} = 1;
2688
$limits{'working_blobs'} = 1; # If big varchar/blobs works
2689
$limits{'order_by_unused'} = 1;
2690
$limits{'working_all_fields'} = 1;
2691
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
2696
# Get the version number of the database
2702
return "IBM DB2 5"; #DBI/ODBC can't return the server version
2709
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user, $main::opt_password) ||
2710
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
2715
# Returns a list of statements to create a table
2716
# The field types are in ANSI SQL format.
2721
my($self,$table_name,$fields,$index) = @_;
2722
my($query,@queries,$nr);
2724
$query="create table $table_name (";
2725
foreach $field (@$fields)
2727
$field =~ s/mediumint/integer/i;
2728
$field =~ s/float\(\d+,\d+\)/float/i;
2729
$field =~ s/integer\(\d+\)/integer/i;
2730
$field =~ s/int\(\d+\)/integer/i;
2731
$field =~ s/tinyint\(\d+\)/smallint/i;
2732
$field =~ s/tinyint/smallint/i;
2733
$field =~ s/smallint\(\d+\)/smallint/i;
2734
$field =~ s/smallinteger/smallint/i;
2735
$field =~ s/blob/varchar(256)/i;
2736
$query.= $field . ',';
2738
substr($query,-1)=")"; # Remove last ',';
2739
push(@queries,$query);
2741
foreach $index (@$index)
2743
$ext="WITH DISALLOW NULL";
2744
if (($index =~ s/primary key/unique index primary_key/i))
2746
$ext="WITH PRIMARY;"
2748
if ($index =~ /^unique.*\(([^\(]*)\)$/i)
2751
$index="unique index ${table_name}_$nr ($1)";
2753
$index =~ /^(.*)\s+(\(.*\))$/;
2754
push(@queries,"create ${1} on $table_name $2");
2760
# Do any conversions to the ANSI SQL query so that the database can handle it
2764
my($self,$sql) = @_;
2770
my ($self,$table,$index) = @_;
2771
return "DROP INDEX $table.$index";
2775
# Abort if the server has crashed
2777
# 1 question should be retried
2780
sub abort_if_fatal_error
2785
sub small_rollback_segment
2790
sub reconnect_on_errors
2797
my ($self,$cmd) = @_;
2801
#############################################################################
2802
# Configuration for MIMER
2803
#############################################################################
2809
my ($type,$host,$database)= @_;
2814
$self->{'cmp_name'} = "mimer";
2815
$self->{'data_source'} = "DBI:mimer:$database:$host";
2816
$self->{'limits'} = \%limits;
2817
$self->{'blob'} = "binary varying(15000)";
2818
$self->{'text'} = "character varying(15000)";
2819
$self->{'double_quotes'} = 1; # Can handle: 'Walker''s'
2820
$self->{'drop_attr'} = "";
2821
$self->{'transactions'} = 1; # Transactions enabled
2822
$self->{'char_null'} = "cast(NULL as char(1))";
2823
$self->{'numeric_null'} = "cast(NULL as int)";
2825
$limits{'max_conditions'} = 9999; # (Actually not a limit)
2826
$limits{'max_columns'} = 252; # Max number of columns in table
2827
$limits{'max_tables'} = 65000; # Should be big enough
2828
$limits{'max_text_size'} = 15000; # Max size with default buffers.
2829
$limits{'query_size'} = 1000000; # Max size with default buffers.
2830
$limits{'max_index'} = 32; # Max number of keys
2831
$limits{'max_index_parts'} = 16; # Max segments/key
2832
$limits{'max_column_name'} = 128; # max table and column name
2834
$limits{'join_optimizer'} = 1; # Can optimize FROM tables
2835
$limits{'load_data_infile'} = 1; # Has load data infile
2836
$limits{'lock_tables'} = 0; # Has lock tables
2837
$limits{'functions'} = 1; # Has simple functions (+/-)
2838
$limits{'group_functions'} = 1; # Have group functions
2839
$limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings
2840
$limits{'group_distinct_functions'}= 1; # Have count(distinct)
2841
$limits{'select_without_from'}= 0; # Cannot do 'select 1';
2842
$limits{'multi_drop'} = 0; # Drop table cannot take many tables
2843
$limits{'subqueries'} = 1; # Supports sub-queries.
2844
$limits{'left_outer_join'} = 1; # Supports left outer joins
2845
$limits{'table_wildcard'} = 1; # Has SELECT table_name.*
2846
$limits{'having_with_alias'} = 0; # Can use aliases in HAVING
2847
$limits{'having_with_group'} = 1; # Can use group functions in HAVING
2848
$limits{'like_with_column'} = 1; # Can use column1 LIKE column2
2849
$limits{'order_by_position'} = 1; # Can use 'ORDER BY 1'
2850
$limits{'group_by_position'} = 0; # Cannot use 'GROUP BY 1'
2851
$limits{'alter_table'} = 1; # Have ALTER TABLE
2852
$limits{'alter_add_multi_col'}= 0; # Have ALTER TABLE t add a int,add b int;
2853
$limits{'alter_table_dropcol'}= 1; # Have ALTER TABLE DROP column
2854
$limits{'insert_multi_value'} = 0; # Does not have INSERT ... values (1,2),(3,4)
2855
$limits{'multi_distinct'} = 0; # Does not allow select count(distinct a),count(distinct b)..
2857
$limits{'group_func_extra_std'} = 0; # Does not have group function std().
2859
$limits{'func_odbc_mod'} = 1; # Have function mod.
2860
$limits{'func_extra_%'} = 0; # Does not have % as alias for mod()
2861
$limits{'func_odbc_floor'} = 1; # Has func_odbc_floor function
2862
$limits{'func_extra_if'} = 0; # Does not have function if.
2863
$limits{'column_alias'} = 1; # Alias for fields in select statement.
2864
$limits{'NEG'} = 1; # Supports -id
2865
$limits{'func_extra_in_num'} = 1; # Has function in
2866
$limits{'limit'} = 0; # Does not support the limit attribute
2867
$limits{'unique_index'} = 1; # Unique index works or not
2868
$limits{'insert_select'} = 1;
2869
$limits{'working_blobs'} = 1; # If big varchar/blobs works
2870
$limits{'order_by_unused'} = 0;
2871
$limits{'working_all_fields'} = 1;
2877
# Get the version number of the database
2883
my ($dbh,$sth,$version,@row);
2885
$dbh=$self->connect();
2887
# Pick up SQLGetInfo option SQL_DBMS_VER (18)
2889
$version = $dbh->func(18, GetInfo);
2891
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
2896
# Connection with optional disabling of logging
2903
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
2904
$main::opt_password,{ PrintError => 0}) ||
2905
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
2907
$dbh->do("SET OPTION LOG_OFF=1,UPDATE_LOG=0");
2912
# Returns a list of statements to create a table
2913
# The field types are in ANSI SQL format.
2915
# If one uses $main::opt_fast then one is allowed to use
2916
# non standard types to get better speed.
2921
my($self,$table_name,$fields,$index,$options) = @_;
2922
my($query,@queries,@indexes);
2924
$query="create table $table_name (";
2925
foreach $field (@$fields)
2927
# $field =~ s/ decimal/ double(10,2)/i;
2928
# $field =~ s/ big_decimal/ double(10,2)/i;
2929
$field =~ s/ double/ double precision/i;
2930
$field =~ s/ tinyint\(.*\)/ smallint/i;
2931
$field =~ s/ smallint\(.*\)/ smallint/i;
2932
$field =~ s/ mediumint/ integer/i;
2933
$field =~ s/ float\(.*\)/ float/i;
2934
# $field =~ s/ date/ int/i; # Because of tcp ?
2935
$query.= $field . ',';
2937
foreach $index (@$index)
2939
if ( $index =~ /\bINDEX\b/i )
2941
my @fields = split(' ',$index);
2942
my $query="CREATE INDEX $fields[1] ON $table_name $fields[2]";
2943
push(@indexes,$query);
2946
$query.= $index . ',';
2949
substr($query,-1)=")"; # Remove last ',';
2950
$query.=" $options" if (defined($options));
2951
push(@queries,$query,@indexes);
2956
my($self,$dbname, $file) = @_;
2957
print "insert of an ascii file isn't supported by Mimer\n";
2962
# Do any conversions to the ANSI SQL query so that the database can handle it
2966
my($self,$sql) = @_;
2971
my ($self,$table,$index) = @_;
2972
return "DROP INDEX $index";
2976
# Abort if the server has crashed
2978
# 1 question should be retried
2981
sub abort_if_fatal_error
2983
return 1 if ($DBI::errstr =~ /Table locked by another cursor/);
2987
sub small_rollback_segment
2992
sub reconnect_on_errors
2999
my ($self,$cmd) = @_;
3003
#############################################################################
3004
# Configuration for InterBase
3005
#############################################################################
3007
package db_interbase;
3011
my ($type,$host,$database)= @_;
3016
$self->{'cmp_name'} = "interbase";
3017
$self->{'data_source'} = "DBI:InterBase:database=$database;ib_dialect=3";
3018
$self->{'limits'} = \%limits;
3019
$self->{'blob'} = "blob";
3020
$self->{'text'} = "";
3021
$self->{'double_quotes'} = 1; # Can handle: 'Walker''s'
3022
$self->{'drop_attr'} = "";
3023
$self->{'transactions'} = 1; # Transactions enabled
3024
$self->{'char_null'} = "";
3025
$self->{'numeric_null'} = "";
3027
$limits{'max_conditions'} = 9999; # (Actually not a limit)
3028
$limits{'max_columns'} = 252; # Max number of columns in table
3029
$limits{'max_tables'} = 65000; # Should be big enough
3030
$limits{'max_text_size'} = 15000; # Max size with default buffers.
3031
$limits{'query_size'} = 1000000; # Max size with default buffers.
3032
$limits{'max_index'} = 65000; # Max number of keys
3033
$limits{'max_index_parts'} = 8; # Max segments/key
3034
$limits{'max_column_name'} = 128; # max table and column name
3036
$limits{'join_optimizer'} = 1; # Can optimize FROM tables
3037
$limits{'load_data_infile'} = 0; # Has load data infile
3038
$limits{'lock_tables'} = 0; # Has lock tables
3039
$limits{'functions'} = 1; # Has simple functions (+/-)
3040
$limits{'group_functions'} = 1; # Have group functions
3041
$limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings
3042
$limits{'group_distinct_functions'}= 1; # Have count(distinct)
3043
$limits{'select_without_from'}= 0; # Cannot do 'select 1';
3044
$limits{'multi_drop'} = 0; # Drop table cannot take many tables
3045
$limits{'subqueries'} = 1; # Supports sub-queries.
3046
$limits{'left_outer_join'} = 1; # Supports left outer joins
3047
$limits{'table_wildcard'} = 1; # Has SELECT table_name.*
3048
$limits{'having_with_alias'} = 0; # Can use aliases in HAVING
3049
$limits{'having_with_group'} = 1; # Can use group functions in HAVING
3050
$limits{'like_with_column'} = 0; # Can use column1 LIKE column2
3051
$limits{'order_by_position'} = 1; # Can use 'ORDER BY 1'
3052
$limits{'group_by_position'} = 0; # Cannot use 'GROUP BY 1'
3053
$limits{'alter_table'} = 1; # Have ALTER TABLE
3054
$limits{'alter_add_multi_col'}= 1; # Have ALTER TABLE t add a int,add b int;
3055
$limits{'alter_table_dropcol'}= 1; # Have ALTER TABLE DROP column
3056
$limits{'insert_multi_value'} = 0; # Does not have INSERT ... values (1,2),(3,4)
3058
$limits{'group_func_extra_std'} = 0; # Does not have group function std().
3060
$limits{'func_odbc_mod'} = 0; # Have function mod.
3061
$limits{'func_extra_%'} = 0; # Does not have % as alias for mod()
3062
$limits{'func_odbc_floor'} = 0; # Has func_odbc_floor function
3063
$limits{'func_extra_if'} = 0; # Does not have function if.
3064
$limits{'column_alias'} = 1; # Alias for fields in select statement.
3065
$limits{'NEG'} = 0; # Supports -id
3066
$limits{'func_extra_in_num'} = 0; # Has function in
3067
$limits{'limit'} = 0; # Does not support the limit attribute
3068
$limits{'working_blobs'} = 1; # If big varchar/blobs works
3069
$limits{'order_by_unused'} = 1;
3070
$limits{'working_all_fields'} = 1;
3071
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
3077
# Get the version number of the database
3085
$version='Interbase ?';
3087
$dbh=$self->connect();
3088
eval { $version = $dbh->func('version','ib_database_info')->{'version'}; };
3090
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
3095
# Connection with optional disabling of logging
3102
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
3103
$main::opt_password,{ PrintError => 0, AutoCommit => 1}) ||
3104
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
3110
# Returns a list of statements to create a table
3111
# The field types are in ANSI SQL format.
3113
# If one uses $main::opt_fast then one is allowed to use
3114
# non standard types to get better speed.
3119
my($self,$table_name,$fields,$index,$options) = @_;
3120
my($query,@queries,@keys,@indexes);
3122
$query="create table $table_name (";
3123
foreach $field (@$fields)
3125
# $field =~ s/ big_decimal/ decimal/i;
3126
$field =~ s/ double/ double precision/i;
3127
$field =~ s/ tinyint/ smallint/i;
3128
$field =~ s/ mediumint/ integer/i;
3129
$field =~ s/\bint\b/integer/i;
3130
$field =~ s/ float\(\d,\d\)/ float/i;
3131
$field =~ s/ smallint\(\d\)/ smallint/i;
3132
$field =~ s/ integer\(\d\)/ integer/i;
3133
$query.= $field . ',';
3135
foreach $ind (@$index)
3137
if ( $ind =~ /(\bKEY\b)|(\bUNIQUE\b)/i ){
3138
push(@keys,"ALTER TABLE $table_name ADD $ind");
3140
my @fields = split(' ',$ind);
3141
my $query="CREATE INDEX $fields[1] ON $table_name $fields[2]";
3142
push(@indexes,$query);
3145
substr($query,-1)=")"; # Remove last ',';
3146
$query.=" $options" if (defined($options));
3147
push(@queries,$query,@keys,@indexes);
3152
my($self,$dbname, $file) = @_;
3153
print "insert of an ascii file isn't supported by InterBase\n";
3158
# Do any conversions to the ANSI SQL query so that the database can handle it
3162
my($self,$sql) = @_;
3167
my ($self,$table,$index) = @_;
3168
return "DROP INDEX $index";
3172
# Abort if the server has crashed
3174
# 1 question should be retried
3177
sub abort_if_fatal_error
3179
return 1 if ($DBI::errstr =~ /Table locked by another cursor/);
3183
sub small_rollback_segment
3188
sub reconnect_on_errors
3195
my ($self,$cmd) = @_;
3199
#############################################################################
3200
# Configuration for FrontBase
3201
#############################################################################
3203
package db_FrontBase;
3207
my ($type,$host,$database)= @_;
3212
$self->{'cmp_name'} = "FrontBase";
3213
$self->{'data_source'} = "DBI:FB:dbname=$database;host=$host";
3214
$self->{'limits'} = \%limits;
3215
$self->{'blob'} = "varchar(8000000)";
3216
$self->{'text'} = "varchar(8000000)";
3217
$self->{'double_quotes'} = 1; # Can handle: 'Walker''s'
3218
$self->{'drop_attr'} = ' restrict';
3219
$self->{'transactions'} = 1; # Transactions enabled
3220
$self->{'error_on_execute_means_zero_rows'}=1;
3222
$limits{'max_conditions'} = 5427; # (Actually not a limit)
3223
# The following should be 8192, but is smaller because Frontbase crashes..
3224
$limits{'max_columns'} = 150; # Max number of columns in table
3225
$limits{'max_tables'} = 5000; # 10000 crashed FrontBase
3226
$limits{'max_text_size'} = 65000; # Max size with default buffers.
3227
$limits{'query_size'} = 8000000; # Max size with default buffers.
3228
$limits{'max_index'} = 38; # Max number of keys
3229
$limits{'max_index_parts'} = 20; # Max segments/key
3230
$limits{'max_column_name'} = 128; # max table and column name
3232
$limits{'join_optimizer'} = 1; # Can optimize FROM tables
3233
$limits{'load_data_infile'} = 1; # Has load data infile
3234
$limits{'lock_tables'} = 0; # Has lock tables
3235
$limits{'functions'} = 1; # Has simple functions (+/-)
3236
$limits{'group_functions'} = 1; # Have group functions
3237
$limits{'group_distinct_functions'}= 0; # Have count(distinct)
3238
$limits{'select_without_from'}= 0;
3239
$limits{'multi_drop'} = 0; # Drop table cannot take many tables
3240
$limits{'subqueries'} = 1; # Supports sub-queries.
3241
$limits{'left_outer_join'} = 1; # Supports left outer joins
3242
$limits{'table_wildcard'} = 1; # Has SELECT table_name.*
3243
$limits{'having_with_alias'} = 0; # Can use aliases in HAVING
3244
$limits{'having_with_group'} = 0; # Can use group functions in HAVING
3245
$limits{'like_with_column'} = 1; # Can use column1 LIKE column2
3246
$limits{'order_by_position'} = 1; # Can use 'ORDER BY 1'
3247
$limits{'group_by_position'} = 0; # Use of 'GROUP BY 1'
3248
$limits{'alter_table'} = 1; # Have ALTER TABLE
3249
$limits{'alter_add_multi_col'}= 0; # Have ALTER TABLE t add a int,add b int;
3250
$limits{'alter_table_dropcol'}= 0; # Have ALTER TABLE DROP column
3251
$limits{'insert_multi_value'} = 1;
3253
$limits{'group_func_extra_std'} = 0; # Does not have group function std().
3255
$limits{'func_odbc_mod'} = 0; # Have function mod.
3256
$limits{'func_extra_%'} = 0; # Does not have % as alias for mod()
3257
$limits{'func_odbc_floor'} = 0; # Has func_odbc_floor function
3258
$limits{'func_extra_if'} = 0; # Does not have function if.
3259
$limits{'column_alias'} = 1; # Alias for fields in select statement.
3260
$limits{'NEG'} = 1; # Supports -id
3261
$limits{'func_extra_in_num'} = 0; # Has function in
3262
$limits{'limit'} = 0; # Does not support the limit attribute
3263
$limits{'insert_select'} = 0;
3264
$limits{'order_by_unused'} = 0;
3266
# We don't get an error for duplicate row in 'test-insert'
3267
$limits{'unique_index'} = 0; # Unique index works or not
3268
# We can't use a blob as a normal string (we got a wierd error)
3269
$limits{'working_blobs'} = 0;
3270
# 'select min(region),max(region) from bench1' kills the server after a while
3271
$limits{'group_func_sql_min_str'} = 0;
3272
# If you do select f1,f2,f3...f200 from table, Frontbase dies.
3273
$limits{'working_all_fields'} = 0;
3274
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
3280
# Get the version number of the database
3286
my ($dbh,$sth,$version,@row);
3288
# $dbh=$self->connect();
3290
# Pick up SQLGetInfo option SQL_DBMS_VER (18)
3292
#$version = $dbh->func(18, GetInfo);
3293
$version="FrontBase 3.3";
3295
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
3300
# Connection with optional disabling of logging
3307
$dbh=DBI->connect($self->{'data_source'},
3309
$main::opt_password,
3311
'fb_host'=>$main::opt_host
3313
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
3314
$db->{AutoCommit}=1;
3315
# $dbh->do("SET OPTION LOG_OFF=1,UPDATE_LOG=0");
3320
# Returns a list of statements to create a table
3321
# The field types are in ANSI SQL format.
3323
# If one uses $main::opt_fast then one is allowed to use
3324
# non standard types to get better speed.
3329
my($self,$table_name,$fields,$index,$options) = @_;
3330
my($query,@queries,@indexes,@keys);
3332
$query="create table $table_name (";
3333
foreach $field (@$fields)
3335
$field =~ s/ blob/ varchar(32000)/i;
3336
$field =~ s/ big_decimal/ float/i;
3337
$field =~ s/ double/ float/i;
3338
$field =~ s/ tinyint/ smallint/i;
3339
$field =~ s/ mediumint/ int/i;
3340
$field =~ s/ integer/ int/i;
3341
$field =~ s/ float\(\d,\d\)/ float/i;
3342
$field =~ s/ smallint\(\d\)/ smallint/i;
3343
$field =~ s/ int\(\d\)/ int/i;
3344
$query.= $field . ',';
3346
foreach $ind (@$index)
3349
if ( $ind =~ /(\bKEY\b)|(\bUNIQUE\b)/i ){
3350
push(@keys,"ALTER TABLE $table_name ADD $ind");
3352
my @fields = split(' ',$ind);
3353
my $query="CREATE INDEX $fields[1] ON $table_name $fields[2]";
3354
push(@indexes,$query);
3357
substr($query,-1)=")"; # Remove last ',';
3358
$query.=" $options" if (defined($options));
3359
push(@queries,$query,@keys,@indexes);
3364
my($self,$dbname, $file) = @_;
3365
print "insert of an ascii file isn't supported by InterBase\n";
3370
# Do any conversions to the ANSI SQL query so that the database can handle it
3374
my($self,$sql) = @_;
3379
my ($self,$table,$index) = @_;
3380
return "DROP INDEX $index";
3384
# Abort if the server has crashed
3386
# 1 question should be retried
3389
sub abort_if_fatal_error
3391
return 0 if ($DBI::errstr =~ /No raw data handle/);
3395
sub small_rollback_segment
3400
sub reconnect_on_errors
3407
my ($self,$cmd) = @_;
3411
#############################################################################
3412
# Configuration for SAPDB
3413
#############################################################################
3419
my ($type,$host,$database)= @_;
3424
$self->{'cmp_name'} = "sapdb";
3425
$self->{'data_source'} = "DBI:SAP_DB:$database";
3426
$self->{'limits'} = \%limits;
3427
$self->{'blob'} = "LONG"; # *
3428
$self->{'text'} = "LONG"; # *
3429
$self->{'double_quotes'} = 1; # Can handle: 'Walker''s'
3430
$self->{'drop_attr'} = "";
3431
$self->{'transactions'} = 1; # Transactions enabled *
3432
$self->{'char_null'} = "";
3433
$self->{'numeric_null'} = "";
3435
$limits{'max_conditions'} = 9999; # (Actually not a limit) *
3436
$limits{'max_columns'} = 1023; # Max number of columns in table *
3437
$limits{'max_tables'} = 65000; # Should be big enough * unlimited actually
3438
$limits{'max_text_size'} = 15000; # Max size with default buffers.
3439
$limits{'query_size'} = 64*1024; # Max size with default buffers. *64 kb by default. May be set by system variable
3440
$limits{'max_index'} = 510; # Max number of keys *
3441
$limits{'max_index_parts'} = 16; # Max segments/key *
3442
$limits{'max_column_name'} = 32; # max table and column name *
3444
$limits{'join_optimizer'} = 1; # Can optimize FROM tables *
3445
$limits{'load_data_infile'} = 0; # Has load data infile *
3446
$limits{'lock_tables'} = 1; # Has lock tables
3447
$limits{'functions'} = 1; # Has simple functions (+/-) *
3448
$limits{'group_functions'} = 1; # Have group functions *
3449
$limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings *
3450
$limits{'group_distinct_functions'}= 1; # Have count(distinct) *
3451
$limits{'select_without_from'}= 0; # Cannot do 'select 1'; *
3452
$limits{'multi_drop'} = 0; # Drop table cannot take many tables *
3453
$limits{'subqueries'} = 1; # Supports sub-queries. *
3454
$limits{'left_outer_join'} = 1; # Supports left outer joins *
3455
$limits{'table_wildcard'} = 1; # Has SELECT table_name.*
3456
$limits{'having_with_alias'} = 0; # Can use aliases in HAVING *
3457
$limits{'having_with_group'} = 1; # Can use group functions in HAVING *
3458
$limits{'like_with_column'} = 1; # Can use column1 LIKE column2 *
3459
$limits{'order_by_position'} = 1; # Can use 'ORDER BY 1' *
3460
$limits{'group_by_position'} = 0; # Cannot use 'GROUP BY 1' *
3461
$limits{'alter_table'} = 1; # Have ALTER TABLE *
3462
$limits{'alter_add_multi_col'}= 1; # Have ALTER TABLE t add a int,add b int; *
3463
$limits{'alter_table_dropcol'}= 1; # Have ALTER TABLE DROP column *
3464
$limits{'insert_multi_value'} = 0; # INSERT ... values (1,2),(3,4) *
3466
$limits{'group_func_extra_std'} = 0; # Does not have group function std().
3468
$limits{'func_odbc_mod'} = 0; # Have function mod. *
3469
$limits{'func_extra_%'} = 0; # Does not have % as alias for mod() *
3470
$limits{'func_odbc_floor'} = 1; # Has func_odbc_floor function *
3471
$limits{'func_extra_if'} = 0; # Does not have function if. *
3472
$limits{'column_alias'} = 1; # Alias for fields in select statement. *
3473
$limits{'NEG'} = 1; # Supports -id *
3474
$limits{'func_extra_in_num'} = 0; # Has function in *
3475
$limits{'limit'} = 0; # Does not support the limit attribute *
3476
$limits{'working_blobs'} = 1; # If big varchar/blobs works *
3477
$limits{'order_by_unused'} = 1; #
3478
$limits{'working_all_fields'} = 1; #
3479
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
3486
# Get the version number of the database
3492
my ($dbh,$sth,$version,@row);
3494
$dbh=$self->connect();
3495
$sth = $dbh->prepare("SELECT KERNEL FROM VERSIONS") or die $DBI::errstr;
3496
$version="SAP DB (unknown)";
3497
if ($sth->execute && (@row = $sth->fetchrow_array)
3498
&& $row[0] =~ /([\d\.]+)/)
3501
$version =~ s/KERNEL/SAP DB/i;
3505
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
3510
# Connection with optional disabling of logging
3517
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
3518
$main::opt_password,{ PrintError => 0, AutoCommit => 1}) ||
3519
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
3525
# Returns a list of statements to create a table
3526
# The field types are in ANSI SQL format.
3531
my($self,$table_name,$fields,$index,$options) = @_;
3532
my($query,@queries,$nr);
3536
$query="create table $table_name (";
3537
foreach $field (@$fields)
3539
$field =~ s/\bmediumint\b/int/i;
3540
$field =~ s/\btinyint\b/int/i;
3541
$field =~ s/ int\(\d\)/ int/i;
3542
$field =~ s/BLOB/LONG/i;
3543
$field =~ s/INTEGER\s*\(\d+\)/INTEGER/i;
3544
$field =~ s/SMALLINT\s*\(\d+\)/SMALLINT/i;
3545
$field =~ s/FLOAT\s*\((\d+),\d+\)/FLOAT\($1\)/i;
3546
$field =~ s/DOUBLE/FLOAT\(38\)/i;
3547
$field =~ s/DOUBLE\s+PRECISION/FLOAT\(38\)/i;
3548
$query.= $field . ',';
3551
foreach $ind (@$index)
3553
if ( $ind =~ /\bKEY\b/i ){
3554
push(@keys,"ALTER TABLE $table_name ADD $ind");
3555
} elsif ($ind =~ /^unique.*\(([^\(]*)\)$/i) {
3557
my $query="create unique index ${table_name}_$nr on $table_name ($1)";
3558
push(@index,$query);
3560
my @fields = split(' ',$ind);
3561
my $query="CREATE INDEX $fields[1] ON $table_name $fields[2]";
3562
push(@index,$query);
3565
substr($query,-1)=")"; # Remove last ',';
3566
$query.=" $options" if (defined($options));
3567
push(@queries,$query);
3568
push(@queries,@keys);
3569
push(@queries,@index);
3574
my($self,$dbname, $file) = @_;
3575
print "insert of an ascii file isn't supported by SAPDB\n";
3580
# Do any conversions to the ANSI SQL query so that the database can handle it
3584
my($self,$sql) = @_;
3589
my ($self,$table,$index) = @_;
3590
return "DROP INDEX $index";
3594
# Abort if the server has crashed
3596
# 1 question should be retried
3599
sub abort_if_fatal_error
3604
sub small_rollback_segment
3609
sub reconnect_on_errors
3616
my ($self,$cmd) = @_;