3
# This is a test with uses two processes to a database.
4
# The other inserts records in two tables, the other does a lot of joins
7
# Warning, the output from this test will differ in 'found' from time to time,
8
# but there should never be any errors
17
$org_file="/tmp/export-org.$$";
18
$tmp_file="/tmp/export-old.$$";
19
$tmp_file2="/tmp/export-new.$$";
21
print "Connection to database $test_db\n";
23
$dbh = Mysql->Connect($host) || die "Can't connect: $Mysql::db_errstr\n";
24
$dbh->SelectDB($test_db) || die "Can't use database $test_db: $Mysql::db_errstr\n";
26
$dbh->Query("drop table if exists export"); # Ignore this error
28
print "Creating table\n";
32
auto int(5) unsigned NOT NULL DEFAULT '0' auto_increment,
33
string char(11) NOT NULL,
34
tiny tinyint(4) NOT NULL DEFAULT '0',
35
short smallint(6) NOT NULL DEFAULT '0',
36
medium mediumint(8) NOT NULL DEFAULT '0',
37
longint int(11) NOT NULL DEFAULT '0',
38
longlong bigint(20) NOT NULL DEFAULT '0',
39
real_float float(13,1) NOT NULL DEFAULT '0.0',
40
real_double double(13,1) NOT NULL,
41
utiny tinyint(3) unsigned NOT NULL DEFAULT '0',
42
ushort smallint(5) unsigned zerofill NOT NULL DEFAULT '00000',
43
umedium mediumint(8) unsigned NOT NULL DEFAULT '0',
44
ulong int(11) unsigned NOT NULL DEFAULT '0',
45
ulonglong bigint(20) unsigned NOT NULL DEFAULT '0',
48
tinyblob_col tinyblob,
49
mediumblob_col tinyblob not null,
50
longblob_col longblob not null,
53
KEY unsigned_tinykey (utiny),
56
FOREIGN KEY (medium) references export,
64
KEY (ulonglong,ulong))")) or die $Mysql::db_errstr;
66
print "Inserting data\n";
68
@A=("insert into export values (10, 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1)",
69
"insert into export values (NULL,2,2,2,2,2,2,2,2,2,2,2,2,2,NULL,NULL,NULL,2,2)",
70
"insert into export values (0,1/3,3,3,3,3,3,3,3,3,3,3,3,3,3,'','','','3')",
71
"insert into export values (0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,'-1')",
72
"insert into export values (0,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,-4294967295,'-4294967295')",
73
"insert into export values (0,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,4294967295,'4294967295')",
74
"insert into export (string,tinyblob_col) values ('special','''\\0\\t\t\n''')",
75
"insert into export (string) values (',,!!\\\\##')",
76
"insert into export (tinyblob_col) values (',,!!!\\\\\\##')"
81
$dbh->Query($A) or die "query: $A returned: " . $Mysql::db_errstr;
85
print "Doing dump, load, check on different formats\n";
89
# Field terminated by something
90
"fields optionally enclosed by '+' escaped by '' terminated by ',,,' lines terminated by ',,,,'",
91
"fields enclosed by '' terminated by ',' lines terminated by ''",
92
"fields enclosed by '' terminated by ',' lines terminated by '!!'",
94
#"fields enclosed by '+' terminated by ''",
95
#"fields enclosed by '+' terminated by '' lines terminated by ''",
96
"fields enclosed by '+' terminated by ',,' lines terminated by '!!!'",
97
"fields enclosed by '+' terminated by ',,' lines terminated by '##'",
98
"fields enclosed by '+' escaped by '' terminated by ',,' lines terminated by '###'",
99
"fields enclosed by '+' escaped by '' terminated by '!' lines terminated by ''",
100
"fields enclosed by '+' terminated by ',' lines terminated by ''",
101
#Fields optionally enclosed by
102
"fields optionally enclosed by '+' terminated by ','",
103
"fields optionally enclosed by '+' terminated by ',' lines terminated by ''",
104
"fields optionally enclosed by '''' terminated by ',' lines starting by 'INSERT INTO a VALUES(' terminated by ');\n'",
107
$dbh->Query("select * into outfile '$org_file' from export") or die $Mysql::db_errstr;
114
$dbh->Query("select * into outfile '$tmp_file' $A from export") or die $Mysql::db_errstr;
115
$dbh->Query("delete from export") or die $Mysql::db_errstr;
116
$dbh->Query("load data infile '$tmp_file' into table export $A") or die $Mysql::db_errstr . " with format: $A\n";
117
$dbh->Query("select * into outfile '$tmp_file2' from export") or die $Mysql::db_errstr;
118
if (`cmp $tmp_file2 $org_file`)
120
print "Using format $A\n";
121
print "$tmp_file2 and $org_file differ. Plese check files\n";
127
@A=(#Fixed size fields
128
"fields enclosed by '' escaped by '' terminated by ''",
129
"fields enclosed by '' escaped by '' terminated by '' lines terminated by '\\r\\n'",
130
"fields enclosed by '' terminated by '' lines terminated by ''"
135
$field_list="auto,ifnull(string,''),tiny,short,medium,longint,longlong,real_float,ifnull(real_double,''),utiny,ushort,umedium,ulong,ulonglong,time_stamp";
137
$dbh->Query("select $field_list into outfile '$org_file' from export") or die $Mysql::db_errstr;
139
$field_list="auto,string,tiny,short,medium,longint,longlong,real_float,real_double,utiny,ushort,umedium,ulong,ulonglong,time_stamp";
145
$dbh->Query("select $field_list into outfile '$tmp_file' $A from export") or die $Mysql::db_errstr;
146
$dbh->Query("delete from export") or die $Mysql::db_errstr;
147
$dbh->Query("load data infile '$tmp_file' into table export $A ($field_list)") or die $Mysql::db_errstr;
148
$dbh->Query("select $field_list into outfile '$tmp_file2' from export") or die $Mysql::db_errstr;
149
if (`cmp $tmp_file2 $org_file`)
151
print "Using format $A\n";
152
print "$tmp_file2 and $org_file differ. Plese check files\n";
161
$dbh->Query("drop table export") or die $Mysql::db_errstr;