~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/csv.test

Merged in latest plugin-slot-reorg.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
drop table if exists t1,t2,t3,t4;
13
13
--enable_warnings
14
14
 
15
 
CREATE TABLE t1 (
16
 
  Period int(4) zerofill DEFAULT '0000' NOT NULL,
17
 
  Varor_period int(4) DEFAULT '0' NOT NULL
 
15
CREATE TEMPORARY TABLE t1 (
 
16
  Period int DEFAULT 0 NOT NULL,
 
17
  Varor_period int DEFAULT 0 NOT NULL
18
18
) ENGINE = CSV;
19
19
 
20
20
INSERT INTO t1 VALUES (9410,9412);
27
27
# Create test table
28
28
#
29
29
 
30
 
CREATE TABLE t2 (
 
30
CREATE TEMPORARY TABLE t2 (
31
31
  auto int not null,
32
 
  fld1 int(6) zerofill DEFAULT '000000' NOT NULL,
33
 
  companynr int(2) zerofill DEFAULT '00' NOT NULL,
 
32
  fld1 int DEFAULT 0 NOT NULL,
 
33
  companynr int DEFAULT 0 NOT NULL,
34
34
  fld3 char(30) DEFAULT '' NOT NULL,
35
35
  fld4 char(35) DEFAULT '' NOT NULL,
36
36
  fld5 char(35) DEFAULT '' NOT NULL,
42
42
#
43
43
 
44
44
--disable_query_log
 
45
begin;
45
46
INSERT INTO t2 VALUES (1,000001,00,'Omaha','teethe','neat','');
46
47
INSERT INTO t2 VALUES (2,011401,37,'breaking','dreaded','Steinberg','W');
47
48
INSERT INTO t2 VALUES (3,011402,37,'Romans','scholastics','jarring','');
1241
1242
INSERT INTO t2 VALUES (1191,068504,00,'bonfire','corresponds','positively','');
1242
1243
INSERT INTO t2 VALUES (1192,068305,00,'Colombo','hardware','colicky','');
1243
1244
INSERT INTO t2 VALUES (1193,000000,00,'nondecreasing','implant','thrillingly','');
 
1245
commit;
1244
1246
--enable_query_log
1245
1247
 
1246
1248
#
1303
1305
 
1304
1306
 
1305
1307
DROP TABLE t1;
1306
 
CREATE TABLE t1 (
1307
 
  Period int(4) zerofill DEFAULT '0000' NOT NULL,
1308
 
  Varor_period int(4) DEFAULT '0' NOT NULL
 
1308
CREATE TEMPORARY TABLE t1 (
 
1309
  Period int DEFAULT 0 NOT NULL,
 
1310
  Varor_period int DEFAULT 0 NOT NULL
1309
1311
) ENGINE = CSV;
1310
1312
 
1311
1313
INSERT INTO t1 VALUES (9410,9412);
1322
1324
DROP TABLE IF EXISTS bug13894;
1323
1325
--enable_warnings
1324
1326
 
1325
 
CREATE TABLE bug13894 ( val integer not null ) ENGINE = CSV;
 
1327
CREATE TEMPORARY TABLE bug13894 ( val integer not null ) ENGINE = CSV;
1326
1328
INSERT INTO bug13894 VALUES (5);
1327
1329
INSERT INTO bug13894 VALUES (10);
1328
1330
INSERT INTO bug13894 VALUES (11);
1340
1342
DROP TABLE IF EXISTS bug14672;
1341
1343
--enable_warnings
1342
1344
 
1343
 
CREATE TABLE bug14672 (c1 integer not null) engine = CSV;   
 
1345
CREATE TEMPORARY TABLE bug14672 (c1 integer not null) engine = CSV;   
1344
1346
INSERT INTO bug14672 VALUES (1), (2), (3);
1345
1347
SELECT * FROM bug14672;  
1346
1348
DELETE FROM bug14672 WHERE c1 = 2;   
1354
1356
# End of 4.1 tests
1355
1357
 
1356
1358
#
1357
 
# Test CONCURRENT INSERT (5.1)
1358
 
#
1359
 
 
1360
 
CREATE TABLE test_concurrent_insert ( val integer not null ) ENGINE = CSV;
1361
 
 
1362
 
connect (con1,localhost,root,,);
1363
 
connect (con2,localhost,root,,);
1364
 
 
1365
 
connection con1;
1366
 
# obtain TL_READ lock on the table
1367
 
LOCK TABLES test_concurrent_insert READ LOCAL;
1368
 
 
1369
 
connection con2;
1370
 
# should pass despite of the lock
1371
 
INSERT INTO test_concurrent_insert VALUES (1);
1372
 
SELECT * FROM test_concurrent_insert;
1373
 
 
1374
 
connection con1;
1375
 
# first connection should not notice the changes
1376
 
SELECT * FROM test_concurrent_insert;
1377
 
 
1378
 
UNLOCK TABLES;
1379
 
 
1380
 
# Now check that we see our own changes
1381
 
 
1382
 
LOCK TABLES test_concurrent_insert WRITE;
1383
 
INSERT INTO test_concurrent_insert VALUES (2);
1384
 
SELECT * FROM test_concurrent_insert;
1385
 
UNLOCK TABLES;
1386
 
 
1387
 
# cleanup
1388
 
DROP TABLE test_concurrent_insert;
1389
 
 
1390
 
#
1391
 
# Test REPAIR/CHECK TABLE (5.1)
1392
 
#
1393
 
 
1394
 
# Check that repair on the newly created table works fine
1395
 
 
1396
 
CREATE TABLE test_repair_table ( val integer not null ) ENGINE = CSV;
1397
 
 
1398
 
CHECK TABLE test_repair_table;
1399
 
REPAIR TABLE test_repair_table;
1400
 
 
1401
 
DROP TABLE test_repair_table;
1402
 
 
1403
 
#
1404
 
# Check autorepair. Here we also check that we can work w/o metafile
1405
 
# restore the meta-file
1406
 
#
1407
 
 
1408
 
CREATE TABLE test_repair_table2 ( val integer not null ) ENGINE = CSV;
1409
 
--remove_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table2.CSM
1410
 
 
1411
 
# Should give a warning and perform autorepair. We also disable ps-protocol
1412
 
# here, as mysql-test eats up warnings in ps-protocol mode
1413
 
 
1414
 
--disable_ps_protocol
1415
 
SELECT * from test_repair_table2;
1416
 
--enable_ps_protocol
1417
 
# this should work ok, as the table is already repaired
1418
 
SELECT * from test_repair_table2;
1419
 
# check that the metafile appeared again.
1420
 
--file_exists $MYSQLTEST_VARDIR/master-data/test/test_repair_table2.CSM
1421
 
CHECK TABLE test_repair_table2;
1422
 
DROP TABLE test_repair_table2;
1423
 
 
1424
 
 
1425
 
# Corrupt csv file and see if we can repair it
1426
 
CREATE TABLE test_repair_table3 ( val integer not null ) ENGINE = CSV;
1427
 
--remove_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table3.CSV
1428
 
--write_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table3.CSV
1429
 
"1"
1430
 
"4"
1431
 
"3
1432
 
EOF
1433
 
CHECK TABLE test_repair_table3;
1434
 
REPAIR TABLE test_repair_table3;
1435
 
SELECT * FROM test_repair_table3;
1436
 
DROP TABLE test_repair_table3;
1437
 
 
1438
 
# Test with more sophisticated table
1439
 
 
1440
 
CREATE TABLE test_repair_table4 (
1441
 
  num int not null,
1442
 
  magic_no int(4) zerofill DEFAULT '0000' NOT NULL,
1443
 
  company_name char(30) DEFAULT '' NOT NULL,
1444
 
  founded char(4) DEFAULT '' NOT NULL
1445
 
) ENGINE = CSV;
1446
 
 
1447
 
--remove_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table4.CSM
1448
 
--disable_ps_protocol
1449
 
SELECT * FROM test_repair_table4;
1450
 
--enable_ps_protocol
1451
 
SELECT * FROM test_repair_table4;
1452
 
CHECK TABLE test_repair_table4;
1453
 
 
1454
 
INSERT INTO test_repair_table4 VALUES (2,101,'SAP','1972');
1455
 
INSERT INTO test_repair_table4 VALUES (1,101,'Microsoft','1978');
1456
 
INSERT INTO test_repair_table4 VALUES (2,101,'MySQL','1995');
1457
 
 
1458
 
# list table content
1459
 
SELECT * FROM test_repair_table4;
1460
 
CHECK TABLE test_repair_table4;
1461
 
REPAIR TABLE test_repair_table4;
1462
 
# check that nothing changed
1463
 
SELECT * FROM test_repair_table4;
1464
 
# verify that check/repair did non corrupt the table itself
1465
 
CHECK TABLE test_repair_table4;
1466
 
REPAIR TABLE test_repair_table4;
1467
 
SELECT * FROM test_repair_table4;
1468
 
DROP TABLE test_repair_table4;
1469
 
 
1470
 
# Run CHECK/REPAIR on the CSV file with a single row, which misses a column.
1471
 
 
1472
 
CREATE TABLE test_repair_table5 (
1473
 
  num int not null,
1474
 
  magic_no int(4) zerofill DEFAULT '0000' NOT NULL,
1475
 
  company_name char(30) DEFAULT '' NOT NULL,
1476
 
  founded char(4) DEFAULT '' NOT NULL
1477
 
) ENGINE = CSV;
1478
 
 
1479
 
# Corrupt a table -- put a file with wrong # of columns
1480
 
--remove_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table5.CSV
1481
 
--write_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table5.CSV
1482
 
"1","101","IBM"
1483
 
EOF
1484
 
 
1485
 
CHECK TABLE test_repair_table5;
1486
 
REPAIR TABLE test_repair_table5;
1487
 
SELECT * FROM test_repair_table5;
1488
 
INSERT INTO test_repair_table5 VALUES (1, 102, "CORRECT", 1876);
1489
 
SELECT * FROM test_repair_table5;
1490
 
 
1491
 
# Corrupt a table -- put a row with wrong # of columns at end of file
1492
 
--append_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table5.CSV
1493
 
"1","101","IBM"
1494
 
EOF
1495
 
 
1496
 
FLUSH TABLES;
1497
 
CHECK TABLE test_repair_table5;
1498
 
REPAIR TABLE test_repair_table5;
1499
 
# The correct record inserted should still be in the file
1500
 
SELECT * FROM test_repair_table5;
1501
 
INSERT INTO test_repair_table5 VALUES (1, 102, "CORRECT2", 1876);
1502
 
SELECT * FROM test_repair_table5;
1503
 
 
1504
 
# Corrupt table again -- put a row with wrong # of columns at end of file
1505
 
--append_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table5.CSV
1506
 
"1","101","IBM"
1507
 
EOF
1508
 
 
1509
 
FLUSH TABLES;
1510
 
CHECK TABLE test_repair_table5;
1511
 
REPAIR TABLE test_repair_table5;
1512
 
# The two correct records inserted should still be in the file
1513
 
SELECT * FROM test_repair_table5;
1514
 
DROP TABLE test_repair_table5;
1515
 
 
1516
 
#
1517
1359
# BUG#13406 - incorrect amount of "records deleted"
1518
1360
#
1519
1361
 
1520
 
create table t1 (a int not null) engine=csv;
 
1362
create temporary table t1 (a int not null) engine=csv;
1521
1363
insert t1 values (1);
1522
1364
--enable_info
1523
1365
delete from t1;                 # delete_row
1545
1387
drop table t1;
1546
1388
 
1547
1389
#
1548
 
# Some additional tests for new, faster alter table.  Note that most of the
1549
 
# whole alter table code is being tested all around the test suite already.
1550
 
#
1551
 
 
1552
 
create table t1 (v varchar(32) not null);
1553
 
insert into t1 values ('def'),('abc'),('hij'),('3r4f');
1554
 
select * from t1;
1555
 
# Fast alter, no copy performed
1556
 
alter table t1 change v v2 varchar(32);
1557
 
select * from t1;
1558
 
# Fast alter, no copy performed
1559
 
alter table t1 change v2 v varchar(64);
1560
 
select * from t1;
1561
 
update t1 set v = 'lmn' where v = 'hij';
1562
 
select * from t1;
1563
 
# Regular alter table
1564
 
alter table t1 add i int auto_increment not null primary key first;
1565
 
select * from t1;
1566
 
update t1 set i=5 where i=3;
1567
 
select * from t1;
1568
 
alter table t1 change i i bigint;
1569
 
select * from t1;
1570
 
alter table t1 add unique key (i, v);
1571
 
select * from t1 where i between 2 and 4 and v in ('def','3r4f','lmn');
1572
 
drop table t1;
1573
 
 
1574
 
#
1575
1390
# Bug #15205   Select from CSV table without the datafile causes crash
1576
1391
#
1577
1392
# NOTE: the bug is not deterministic
1583
1398
# resulted in scanning through deleted memory and we were geting a crash.
1584
1399
# that's why we need two tables in the bugtest
1585
1400
 
1586
 
create table bug15205 (val int(11) not null) engine=csv;
1587
 
create table bug15205_2 (val int(11) not null) engine=csv;
1588
 
--remove_file $MYSQLTEST_VARDIR/master-data/test/bug15205.CSV
1589
 
# system error (can't open the datafile)
1590
 
--replace_result $MYSQLTEST_VARDIR . master-data/ ''
1591
 
--error 13
1592
 
select * from bug15205;
1593
 
select * from bug15205_2;
1594
 
# Create empty file
1595
 
--write_file $MYSQLTEST_VARDIR/master-data/test/bug15205.CSV
1596
 
EOF
1597
 
select * from bug15205;
1598
 
drop table bug15205;
1599
 
drop table bug15205_2;
1600
 
 
1601
 
 
1602
 
#
1603
 
# Bug#28862 "Extended Latin1 characters get lost in CVS engine"
1604
 
#
1605
 
set names latin1;
1606
 
create table t1 (
1607
 
  c varchar(1) not null,
1608
 
  name varchar(64) not null
1609
 
) character set latin1 engine=csv;
1610
 
insert into t1 values (0xC0,'LATIN CAPITAL LETTER A WITH GRAVE');
1611
 
insert into t1 values (0xE0,'LATIN SMALL LETTER A WITH GRAVE');
1612
 
insert into t1 values (0xEE,'LATIN SMALL LETTER I WITH CIRCUMFLEX');
1613
 
insert into t1 values (0xFE,'LATIN SMALL LETTER THORN');
1614
 
insert into t1 values (0xF7,'DIVISION SIGN');
1615
 
insert into t1 values (0xFF,'LATIN SMALL LETTER Y WITH DIAERESIS');
1616
 
select hex(c), c, name from t1 order by 1;
1617
 
drop table t1;
1618
 
 
1619
 
--echo End of 5.0 tests
1620
 
 
1621
 
 
1622
 
#
1623
 
# Bug#22080 "CHECK fails to identify some corruption"
1624
 
#
1625
 
 
1626
 
create table bug22080_1 (id int not null,string varchar(64) not null) Engine=CSV;
1627
 
create table bug22080_2 (id int not null,string varchar(64) not null) Engine=CSV;
1628
 
create table bug22080_3 (id int not null,string varchar(64) not null) Engine=CSV;
1629
 
insert into bug22080_1 values(1,'string');
1630
 
insert into bug22080_1 values(2,'string');
1631
 
insert into bug22080_1 values(3,'string');
1632
 
 
1633
 
# Create first corrupt file as described in bug report
1634
 
--remove_file $MYSQLTEST_VARDIR/master-data/test/bug22080_2.CSV
1635
 
--write_file $MYSQLTEST_VARDIR/master-data/test/bug22080_2.CSV
1636
 
1,"string"
1637
 
2","string"
1638
 
3,"string"
1639
 
EOF
1640
 
 
1641
 
# Create second corrupt file as described in bug report
1642
 
--remove_file $MYSQLTEST_VARDIR/master-data/test/bug22080_3.CSV
1643
 
--write_file $MYSQLTEST_VARDIR/master-data/test/bug22080_3.CSV
1644
 
1,"string"
1645
 
"2",string"
1646
 
3,"string"
1647
 
EOF
1648
 
 
1649
 
check table bug22080_2;
1650
 
 
1651
 
check table bug22080_3;
1652
 
 
1653
 
drop tables bug22080_1,bug22080_2,bug22080_3;
 
1401
# TODO: Bug lp:311104
 
1402
#create table bug15205 (val int not null) engine=csv;
 
1403
#create table bug15205_2 (val int not null) engine=csv;
 
1404
#--remove_file $MYSQLTEST_VARDIR/master-data/test/bug15205.CSV
 
1405
## system error (can't open the datafile)
 
1406
#--replace_result $MYSQLTEST_VARDIR . master-data/ ''
 
1407
#--error 13
 
1408
#select * from bug15205;
 
1409
#select * from bug15205_2;
 
1410
## Create empty file
 
1411
#--write_file $MYSQLTEST_VARDIR/master-data/test/bug15205.CSV
 
1412
#EOF
 
1413
#select * from bug15205;
 
1414
#drop table bug15205;
 
1415
#drop table bug15205_2;
1654
1416
 
1655
1417
#
1656
1418
# Testing float type
1657
1419
#
1658
 
create table float_test (id float not null,string varchar(64) not null) Engine=CSV;
 
1420
create temporary table float_test (id float not null,string varchar(64) not null) Engine=CSV;
1659
1421
insert into float_test values(1.0,'string');
1660
1422
insert into float_test values(2.23,'serg.g');
1661
1423
insert into float_test values(0.03,'string');
1669
1431
# Bug #21328 mysqld issues warnings on ALTER CSV table to MyISAM
1670
1432
#
1671
1433
 
1672
 
CREATE TABLE `bug21328` (
1673
 
  `col1` int(11) NOT NULL,
1674
 
  `col2` int(11) NOT NULL,
1675
 
  `col3` int(11) NOT NULL
 
1434
CREATE TEMPORARY TABLE `bug21328` (
 
1435
  `col1` int NOT NULL,
 
1436
  `col2` int NOT NULL,
 
1437
  `col3` int NOT NULL
1676
1438
) ENGINE=CSV;
1677
1439
 
1678
1440
insert into bug21328 values (1,0,0);
1683
1445
# BUG#28971 - ALTER TABLE followed by UPDATE for a CSV table make server
1684
1446
# crash
1685
1447
#
1686
 
create table t1(a blob not null, b int not null) engine=csv;
 
1448
create temporary table t1(a blob not null, b int not null) engine=csv;
1687
1449
insert into t1 values('a', 1);
1688
1450
flush tables;
1689
1451
update t1 set b=2;
1693
1455
#
1694
1456
# Bug #29353: negative values
1695
1457
#
1696
 
create table t1(a int not null) engine=csv;
 
1458
create temporary table t1(a int not null) engine=csv;
1697
1459
insert into t1 values(-1), (-123.34), (2), (-23);
1698
1460
select * from t1;
1699
1461
check table t1;
1700
1462
drop table t1;
1701
1463
 
1702
 
create table t1(a int not null, b int not null) engine=csv;
1703
 
--remove_file $MYSQLTEST_VARDIR/master-data/test/t1.CSV
1704
 
--write_file $MYSQLTEST_VARDIR/master-data/test/t1.CSV
1705
 
1, 1E-2
1706
 
-2E2, .9
1707
 
-10E-1, -.9
1708
 
-1, -100.1
1709
 
1a, -2b
1710
 
EOF
1711
 
repair table t1;
1712
 
check table t1;
1713
 
select * from t1;
1714
 
check table t1;
1715
 
drop table t1;
1716
 
 
1717
1464
#
1718
1465
# Bug #29411: deleting from a csv table leads to the table corruption
1719
1466
#
1720
 
create table t1(a int not null) engine=csv;
 
1467
create temporary table t1(a int not null) engine=csv;
1721
1468
insert into t1 values (0), (1), (2);
1722
1469
delete from t1 limit 2;
1723
1470
check table t1;
1730
1477
#
1731
1478
# Bug #31473: does not work with NULL value in datetime field
1732
1479
#
1733
 
create table t1(a datetime not null) engine=csv;
1734
 
insert into t1 values();
1735
 
select * from t1;
1736
 
drop table t1;
1737
 
create table t1(a set('foo','bar') not null) engine=csv;
1738
 
insert into t1 values();
1739
 
select * from t1;
1740
 
drop table t1;
1741
 
create table t1(a varchar(32) not null) engine=csv;
1742
 
insert into t1 values();
1743
 
select * from t1;
1744
 
drop table t1;
1745
 
create table t1(a int not null) engine=csv;
1746
 
insert into t1 values();
1747
 
select * from t1;
1748
 
drop table t1;
1749
 
create table t1(a blob not null) engine=csv;
1750
 
insert into t1 values();
1751
 
select * from t1;
1752
 
drop table t1;
1753
 
create table t1(a bit(1) not null) engine=csv;
1754
 
insert into t1 values();
1755
 
select BIN(a) from t1;
 
1480
create temporary table t1(a datetime not null) engine=csv;
 
1481
--error 1364
 
1482
insert into t1 values();
 
1483
select * from t1;
 
1484
drop table t1;
 
1485
create temporary table t1(a varchar(32) not null) engine=csv;
 
1486
--error 1364
 
1487
insert into t1 values();
 
1488
select * from t1;
 
1489
drop table t1;
 
1490
create temporary table t1(a int not null) engine=csv;
 
1491
--error 1364
 
1492
insert into t1 values();
 
1493
select * from t1;
 
1494
drop table t1;
 
1495
create temporary table t1(a blob not null) engine=csv;
 
1496
--error 1364
 
1497
insert into t1 values();
 
1498
select * from t1;
1756
1499
drop table t1;
1757
1500
# We prevent creation of table with nullable ENUM
1758
1501
--error ER_CHECK_NOT_IMPLEMENTED
1759
 
create table t1(a enum('foo','bar') default null) engine=csv;
 
1502
create temporary table t1(a enum('foo','bar') default null) engine=csv;
1760
1503
--error ER_CHECK_NOT_IMPLEMENTED
1761
 
create table t1(a enum('foo','bar') default 'foo') engine=csv;
 
1504
create temporary table t1(a enum('foo','bar') default 'foo') engine=csv;
1762
1505
# Enum columns must be specified as NOT NULL
1763
 
create table t1(a enum('foo','bar') default 'foo' not null) engine=csv;
 
1506
create temporary table t1(a enum('foo','bar') default 'foo' not null) engine=csv;
1764
1507
insert into t1 values();
1765
1508
select * from t1;
1766
1509
drop table t1;
1770
1513
#             with error 1005.
1771
1514
#
1772
1515
--error ER_CHECK_NOT_IMPLEMENTED
1773
 
CREATE TABLE t1(a INT) ENGINE=CSV;
 
1516
CREATE TEMPORARY TABLE t1(a INT) ENGINE=CSV;
1774
1517
SHOW WARNINGS;
1775
1518
 
1776
1519
#
1777
1520
# BUG#33067 - .
1778
1521
#
1779
 
create table t1 (c1 tinyblob not null) engine=csv;
 
1522
create temporary table t1 (c1 blob not null) engine=csv;
1780
1523
insert into t1 values("This");
1781
1524
--enable_info            
1782
1525
update t1 set c1="That" where c1="This";
1784
1527
select * from t1;
1785
1528
drop table t1;
1786
1529
 
 
1530
#
 
1531
# Bug#311104
 
1532
# CSV engine reports "out of memory" when you select
 
1533
# from a missing file
 
1534
#
 
1535
--disable_warnings
 
1536
drop table if exists t1;
 
1537
--enable_warnings
 
1538
 
1787
1539
--echo End of 5.1 tests