~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/csv.test

  • Committer: Monty Taylor
  • Date: 2009-04-14 19:16:51 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 994.
  • Revision ID: mordred@inaugust.com-20090414191651-ltbww6hpqks8k7qk
Clarified instructions in README.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
 
2
# Test for the CSV engine
 
3
#
 
4
 
 
5
--source include/have_csv.inc
 
6
 
 
7
#
2
8
# Simple select test
3
9
#
4
10
 
6
12
drop table if exists t1,t2,t3,t4;
7
13
--enable_warnings
8
14
 
9
 
CREATE TEMPORARY TABLE t1 (
 
15
CREATE TABLE t1 (
10
16
  Period int DEFAULT 0 NOT NULL,
11
17
  Varor_period int DEFAULT 0 NOT NULL
12
18
) ENGINE = CSV;
21
27
# Create test table
22
28
#
23
29
 
24
 
CREATE TEMPORARY TABLE t2 (
 
30
CREATE TABLE t2 (
25
31
  auto int not null,
26
32
  fld1 int DEFAULT 0 NOT NULL,
27
33
  companynr int DEFAULT 0 NOT NULL,
1299
1305
 
1300
1306
 
1301
1307
DROP TABLE t1;
1302
 
CREATE TEMPORARY TABLE t1 (
 
1308
CREATE TABLE t1 (
1303
1309
  Period int DEFAULT 0 NOT NULL,
1304
1310
  Varor_period int DEFAULT 0 NOT NULL
1305
1311
) ENGINE = CSV;
1318
1324
DROP TABLE IF EXISTS bug13894;
1319
1325
--enable_warnings
1320
1326
 
1321
 
CREATE TEMPORARY TABLE bug13894 ( val integer not null ) ENGINE = CSV;
 
1327
CREATE TABLE bug13894 ( val integer not null ) ENGINE = CSV;
1322
1328
INSERT INTO bug13894 VALUES (5);
1323
1329
INSERT INTO bug13894 VALUES (10);
1324
1330
INSERT INTO bug13894 VALUES (11);
1336
1342
DROP TABLE IF EXISTS bug14672;
1337
1343
--enable_warnings
1338
1344
 
1339
 
CREATE TEMPORARY TABLE bug14672 (c1 integer not null) engine = CSV;   
 
1345
CREATE TABLE bug14672 (c1 integer not null) engine = CSV;   
1340
1346
INSERT INTO bug14672 VALUES (1), (2), (3);
1341
1347
SELECT * FROM bug14672;  
1342
1348
DELETE FROM bug14672 WHERE c1 = 2;   
1350
1356
# End of 4.1 tests
1351
1357
 
1352
1358
#
 
1359
# Test CONCURRENT INSERT (5.1)
 
1360
#
 
1361
 
 
1362
CREATE TABLE test_concurrent_insert ( val integer not null ) ENGINE = CSV;
 
1363
 
 
1364
connect (con1,localhost,root,,);
 
1365
connect (con2,localhost,root,,);
 
1366
 
 
1367
connection con1;
 
1368
# obtain TL_READ lock on the table
 
1369
LOCK TABLES test_concurrent_insert READ LOCAL;
 
1370
 
 
1371
connection con2;
 
1372
# should pass despite of the lock
 
1373
INSERT INTO test_concurrent_insert VALUES (1);
 
1374
SELECT * FROM test_concurrent_insert;
 
1375
 
 
1376
connection con1;
 
1377
# first connection should not notice the changes
 
1378
SELECT * FROM test_concurrent_insert;
 
1379
 
 
1380
UNLOCK TABLES;
 
1381
 
 
1382
# Now check that we see our own changes
 
1383
 
 
1384
LOCK TABLES test_concurrent_insert WRITE;
 
1385
INSERT INTO test_concurrent_insert VALUES (2);
 
1386
SELECT * FROM test_concurrent_insert;
 
1387
UNLOCK TABLES;
 
1388
 
 
1389
# cleanup
 
1390
DROP TABLE test_concurrent_insert;
 
1391
 
 
1392
#
 
1393
# Test REPAIR/CHECK TABLE (5.1)
 
1394
#
 
1395
 
 
1396
# Check that repair on the newly created table works fine
 
1397
 
 
1398
CREATE TABLE test_repair_table ( val integer not null ) ENGINE = CSV;
 
1399
 
 
1400
CHECK TABLE test_repair_table;
 
1401
REPAIR TABLE test_repair_table;
 
1402
 
 
1403
DROP TABLE test_repair_table;
 
1404
 
 
1405
#
 
1406
# Check autorepair. Here we also check that we can work w/o metafile
 
1407
# restore the meta-file
 
1408
#
 
1409
 
 
1410
CREATE TABLE test_repair_table2 ( val integer not null ) ENGINE = CSV;
 
1411
--remove_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table2.CSM
 
1412
 
 
1413
# Should give a warning and perform autorepair. We also disable ps-protocol
 
1414
# here, as mysql-test eats up warnings in ps-protocol mode
 
1415
 
 
1416
--disable_ps_protocol
 
1417
SELECT * from test_repair_table2;
 
1418
--enable_ps_protocol
 
1419
# this should work ok, as the table is already repaired
 
1420
SELECT * from test_repair_table2;
 
1421
# check that the metafile appeared again.
 
1422
--file_exists $MYSQLTEST_VARDIR/master-data/test/test_repair_table2.CSM
 
1423
CHECK TABLE test_repair_table2;
 
1424
DROP TABLE test_repair_table2;
 
1425
 
 
1426
 
 
1427
# Corrupt csv file and see if we can repair it
 
1428
CREATE TABLE test_repair_table3 ( val integer not null ) ENGINE = CSV;
 
1429
--remove_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table3.CSV
 
1430
--write_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table3.CSV
 
1431
"1"
 
1432
"4"
 
1433
"3
 
1434
EOF
 
1435
CHECK TABLE test_repair_table3;
 
1436
REPAIR TABLE test_repair_table3;
 
1437
SELECT * FROM test_repair_table3;
 
1438
DROP TABLE test_repair_table3;
 
1439
 
 
1440
# Test with more sophisticated table
 
1441
 
 
1442
CREATE TABLE test_repair_table4 (
 
1443
  num int not null,
 
1444
  magic_no int DEFAULT 0 NOT NULL,
 
1445
  company_name char(30) DEFAULT '' NOT NULL,
 
1446
  founded char(4) DEFAULT '' NOT NULL
 
1447
) ENGINE = CSV;
 
1448
 
 
1449
--remove_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table4.CSM
 
1450
--disable_ps_protocol
 
1451
SELECT * FROM test_repair_table4;
 
1452
--enable_ps_protocol
 
1453
SELECT * FROM test_repair_table4;
 
1454
CHECK TABLE test_repair_table4;
 
1455
 
 
1456
INSERT INTO test_repair_table4 VALUES (2,101,'SAP','1972');
 
1457
INSERT INTO test_repair_table4 VALUES (1,101,'Microsoft','1978');
 
1458
INSERT INTO test_repair_table4 VALUES (2,101,'MySQL','1995');
 
1459
 
 
1460
# list table content
 
1461
SELECT * FROM test_repair_table4;
 
1462
CHECK TABLE test_repair_table4;
 
1463
REPAIR TABLE test_repair_table4;
 
1464
# check that nothing changed
 
1465
SELECT * FROM test_repair_table4;
 
1466
# verify that check/repair did non corrupt the table itself
 
1467
CHECK TABLE test_repair_table4;
 
1468
REPAIR TABLE test_repair_table4;
 
1469
SELECT * FROM test_repair_table4;
 
1470
DROP TABLE test_repair_table4;
 
1471
 
 
1472
# Run CHECK/REPAIR on the CSV file with a single row, which misses a column.
 
1473
 
 
1474
CREATE TABLE test_repair_table5 (
 
1475
  num int not null,
 
1476
  magic_no int DEFAULT 0 NOT NULL,
 
1477
  company_name char(30) DEFAULT '' NOT NULL,
 
1478
  founded char(4) DEFAULT '' NOT NULL
 
1479
) ENGINE = CSV;
 
1480
 
 
1481
# Corrupt a table -- put a file with wrong # of columns
 
1482
--remove_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table5.CSV
 
1483
--write_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table5.CSV
 
1484
"1","101","IBM"
 
1485
EOF
 
1486
 
 
1487
CHECK TABLE test_repair_table5;
 
1488
REPAIR TABLE test_repair_table5;
 
1489
SELECT * FROM test_repair_table5;
 
1490
INSERT INTO test_repair_table5 VALUES (1, 102, "CORRECT", 1876);
 
1491
SELECT * FROM test_repair_table5;
 
1492
 
 
1493
# Corrupt a table -- put a row with wrong # of columns at end of file
 
1494
--append_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table5.CSV
 
1495
"1","101","IBM"
 
1496
EOF
 
1497
 
 
1498
FLUSH TABLES;
 
1499
CHECK TABLE test_repair_table5;
 
1500
REPAIR TABLE test_repair_table5;
 
1501
# The correct record inserted should still be in the file
 
1502
SELECT * FROM test_repair_table5;
 
1503
INSERT INTO test_repair_table5 VALUES (1, 102, "CORRECT2", 1876);
 
1504
SELECT * FROM test_repair_table5;
 
1505
 
 
1506
# Corrupt table again -- put a row with wrong # of columns at end of file
 
1507
--append_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table5.CSV
 
1508
"1","101","IBM"
 
1509
EOF
 
1510
 
 
1511
FLUSH TABLES;
 
1512
CHECK TABLE test_repair_table5;
 
1513
REPAIR TABLE test_repair_table5;
 
1514
# The two correct records inserted should still be in the file
 
1515
SELECT * FROM test_repair_table5;
 
1516
DROP TABLE test_repair_table5;
 
1517
 
 
1518
#
1353
1519
# BUG#13406 - incorrect amount of "records deleted"
1354
1520
#
1355
1521
 
1356
 
create temporary table t1 (a int not null) engine=csv;
 
1522
create table t1 (a int not null) engine=csv;
1357
1523
insert t1 values (1);
1358
1524
--enable_info
1359
1525
delete from t1;                 # delete_row
1381
1547
drop table t1;
1382
1548
 
1383
1549
#
 
1550
# Some additional tests for new, faster alter table.  Note that most of the
 
1551
# whole alter table code is being tested all around the test suite already.
 
1552
#
 
1553
 
 
1554
create table t1 (v varchar(32) not null);
 
1555
insert into t1 values ('def'),('abc'),('hij'),('3r4f');
 
1556
select * from t1;
 
1557
# Fast alter, no copy performed
 
1558
alter table t1 change v v2 varchar(32);
 
1559
select * from t1;
 
1560
# Fast alter, no copy performed
 
1561
alter table t1 change v2 v varchar(64);
 
1562
select * from t1;
 
1563
update t1 set v = 'lmn' where v = 'hij';
 
1564
select * from t1;
 
1565
# Regular alter table
 
1566
alter table t1 add i int auto_increment not null primary key first;
 
1567
select * from t1;
 
1568
update t1 set i=5 where i=3;
 
1569
select * from t1;
 
1570
alter table t1 change i i bigint;
 
1571
select * from t1;
 
1572
alter table t1 add unique key (i, v);
 
1573
select * from t1 where i between 2 and 4 and v in ('def','3r4f','lmn');
 
1574
drop table t1;
 
1575
 
 
1576
#
1384
1577
# Bug #15205   Select from CSV table without the datafile causes crash
1385
1578
#
1386
1579
# NOTE: the bug is not deterministic
1408
1601
#drop table bug15205;
1409
1602
#drop table bug15205_2;
1410
1603
 
 
1604
 
 
1605
#
 
1606
# Bug#22080 "CHECK fails to identify some corruption"
 
1607
#
 
1608
 
 
1609
create table bug22080_1 (id int not null,string varchar(64) not null) Engine=CSV;
 
1610
create table bug22080_2 (id int not null,string varchar(64) not null) Engine=CSV;
 
1611
create table bug22080_3 (id int not null,string varchar(64) not null) Engine=CSV;
 
1612
insert into bug22080_1 values(1,'string');
 
1613
insert into bug22080_1 values(2,'string');
 
1614
insert into bug22080_1 values(3,'string');
 
1615
 
 
1616
# Create first corrupt file as described in bug report
 
1617
--remove_file $MYSQLTEST_VARDIR/master-data/test/bug22080_2.CSV
 
1618
--write_file $MYSQLTEST_VARDIR/master-data/test/bug22080_2.CSV
 
1619
1,"string"
 
1620
2","string"
 
1621
3,"string"
 
1622
EOF
 
1623
 
 
1624
# Create second corrupt file as described in bug report
 
1625
--remove_file $MYSQLTEST_VARDIR/master-data/test/bug22080_3.CSV
 
1626
--write_file $MYSQLTEST_VARDIR/master-data/test/bug22080_3.CSV
 
1627
1,"string"
 
1628
"2",string"
 
1629
3,"string"
 
1630
EOF
 
1631
 
 
1632
check table bug22080_2;
 
1633
 
 
1634
check table bug22080_3;
 
1635
 
 
1636
drop tables bug22080_1,bug22080_2,bug22080_3;
 
1637
 
1411
1638
#
1412
1639
# Testing float type
1413
1640
#
1414
 
create temporary table float_test (id float not null,string varchar(64) not null) Engine=CSV;
 
1641
create table float_test (id float not null,string varchar(64) not null) Engine=CSV;
1415
1642
insert into float_test values(1.0,'string');
1416
1643
insert into float_test values(2.23,'serg.g');
1417
1644
insert into float_test values(0.03,'string');
1425
1652
# Bug #21328 mysqld issues warnings on ALTER CSV table to MyISAM
1426
1653
#
1427
1654
 
1428
 
CREATE TEMPORARY TABLE `bug21328` (
 
1655
CREATE TABLE `bug21328` (
1429
1656
  `col1` int NOT NULL,
1430
1657
  `col2` int NOT NULL,
1431
1658
  `col3` int NOT NULL
1439
1666
# BUG#28971 - ALTER TABLE followed by UPDATE for a CSV table make server
1440
1667
# crash
1441
1668
#
1442
 
create temporary table t1(a blob not null, b int not null) engine=csv;
 
1669
create table t1(a blob not null, b int not null) engine=csv;
1443
1670
insert into t1 values('a', 1);
1444
1671
flush tables;
1445
1672
update t1 set b=2;
1449
1676
#
1450
1677
# Bug #29353: negative values
1451
1678
#
1452
 
create temporary table t1(a int not null) engine=csv;
 
1679
create table t1(a int not null) engine=csv;
1453
1680
insert into t1 values(-1), (-123.34), (2), (-23);
1454
1681
select * from t1;
1455
1682
check table t1;
1456
1683
drop table t1;
1457
1684
 
 
1685
create table t1(a int not null, b int not null) engine=csv;
 
1686
--remove_file $MYSQLTEST_VARDIR/master-data/test/t1.CSV
 
1687
--write_file $MYSQLTEST_VARDIR/master-data/test/t1.CSV
 
1688
1, 1E-2
 
1689
-2E2, .9
 
1690
-10E-1, -.9
 
1691
-1, -100.1
 
1692
1a, -2b
 
1693
EOF
 
1694
repair table t1;
 
1695
check table t1;
 
1696
select * from t1;
 
1697
check table t1;
 
1698
drop table t1;
 
1699
 
1458
1700
#
1459
1701
# Bug #29411: deleting from a csv table leads to the table corruption
1460
1702
#
1461
 
create temporary table t1(a int not null) engine=csv;
 
1703
create table t1(a int not null) engine=csv;
1462
1704
insert into t1 values (0), (1), (2);
1463
1705
delete from t1 limit 2;
1464
1706
check table t1;
1471
1713
#
1472
1714
# Bug #31473: does not work with NULL value in datetime field
1473
1715
#
1474
 
create temporary table t1(a datetime not null) engine=csv;
1475
 
--error 1364
1476
 
insert into t1 values();
1477
 
select * from t1;
1478
 
drop table t1;
1479
 
create temporary table t1(a varchar(32) not null) engine=csv;
1480
 
--error 1364
1481
 
insert into t1 values();
1482
 
select * from t1;
1483
 
drop table t1;
1484
 
create temporary table t1(a int not null) engine=csv;
1485
 
--error 1364
1486
 
insert into t1 values();
1487
 
select * from t1;
1488
 
drop table t1;
1489
 
create temporary table t1(a blob not null) engine=csv;
 
1716
create table t1(a datetime not null) engine=csv;
 
1717
--error 1364
 
1718
insert into t1 values();
 
1719
select * from t1;
 
1720
drop table t1;
 
1721
create table t1(a varchar(32) not null) engine=csv;
 
1722
--error 1364
 
1723
insert into t1 values();
 
1724
select * from t1;
 
1725
drop table t1;
 
1726
create table t1(a int not null) engine=csv;
 
1727
--error 1364
 
1728
insert into t1 values();
 
1729
select * from t1;
 
1730
drop table t1;
 
1731
create table t1(a blob not null) engine=csv;
1490
1732
--error 1364
1491
1733
insert into t1 values();
1492
1734
select * from t1;
1493
1735
drop table t1;
1494
1736
# We prevent creation of table with nullable ENUM
1495
1737
--error ER_CHECK_NOT_IMPLEMENTED
1496
 
create temporary table t1(a enum('foo','bar') default null) engine=csv;
 
1738
create table t1(a enum('foo','bar') default null) engine=csv;
1497
1739
--error ER_CHECK_NOT_IMPLEMENTED
1498
 
create temporary table t1(a enum('foo','bar') default 'foo') engine=csv;
 
1740
create table t1(a enum('foo','bar') default 'foo') engine=csv;
1499
1741
# Enum columns must be specified as NOT NULL
1500
 
create temporary table t1(a enum('foo','bar') default 'foo' not null) engine=csv;
 
1742
create table t1(a enum('foo','bar') default 'foo' not null) engine=csv;
1501
1743
insert into t1 values();
1502
1744
select * from t1;
1503
1745
drop table t1;
1507
1749
#             with error 1005.
1508
1750
#
1509
1751
--error ER_CHECK_NOT_IMPLEMENTED
1510
 
CREATE TEMPORARY TABLE t1(a INT) ENGINE=CSV;
 
1752
CREATE TABLE t1(a INT) ENGINE=CSV;
1511
1753
SHOW WARNINGS;
1512
1754
 
1513
1755
#
1514
1756
# BUG#33067 - .
1515
1757
#
1516
 
create temporary table t1 (c1 blob not null) engine=csv;
 
1758
create table t1 (c1 blob not null) engine=csv;
1517
1759
insert into t1 values("This");
1518
1760
--enable_info            
1519
1761
update t1 set c1="That" where c1="This";
1530
1772
drop table if exists t1;
1531
1773
--enable_warnings
1532
1774
 
 
1775
create table t1 (val int not null) engine=csv;
 
1776
--remove_file $MYSQLTEST_VARDIR/master-data/test/t1.CSV
 
1777
 
 
1778
--error 1017
 
1779
select * from t1;
 
1780
 
1533
1781
--echo End of 5.1 tests