Commit 8eccf8dd authored by Alexander Barkov's avatar Alexander Barkov

Adding DBF stored procedures to dump the underlying DBF file structure.

  
  modified:
    mysql-test/suite/connect/r/dbf.result
    mysql-test/suite/connect/t/dbf.test
parent ad41e7ee
CREATE PROCEDURE test.dbf_field(in fieldno INT, in content BLOB) DETERMINISTIC
BEGIN
SELECT '---';
SELECT fieldno AS `FieldN`;
SELECT TRIM(TRAILING 0x00 FROM LEFT(content, 10)) AS `Name`;
SELECT SUBSTRING(content, 12, 1) AS `Type`;
SELECT CONV(HEX(REVERSE(SUBSTRING(content,13,4))),16,10) AS `Offset`;
SELECT CONV(HEX(REVERSE(SUBSTRING(content,17,1))),16,10) AS `Length`;
SELECT CONV(HEX(REVERSE(SUBSTRING(content,18,1))),16,10) AS `Dec`;
SELECT HEX(REVERSE(SUBSTRING(content,19,1))) AS `Flags`;
-- SELECT CONV(HEX(REVERSE(SUBSTRING(content,20,4))),16,10) AS `Next`;
-- SELECT CONV(HEX(REVERSE(SUBSTRING(content,24,4))),16,10) AS `Step`;
END//
CREATE PROCEDURE test.dbf_header(in fname VARCHAR(1024)) DETERMINISTIC
BEGIN
DECLARE content BLOB;
DECLARE offset INT;
DECLARE fieldno INT;
SELECT '--------';
SELECT LOAD_FILE(fname) INTO content;
SELECT LENGTH(content) AS FileSize;
SELECT HEX(LEFT(content, 1)) AS DBF_Version;
SELECT CONV(HEX(REVERSE(SUBSTRING(content,5,4))),16,10) AS NRecords;
SELECT CONV(HEX(REVERSE(SUBSTRING(content,9,2))),16,10) AS FirstRecPos;
SELECT CONV(HEX(REVERSE(SUBSTRING(content,11,2))),16,10) AS RecLength;
SELECT HEX(REVERSE(SUBSTRING(content,29,2))) AS TableFlags;
SELECT HEX(REVERSE(SUBSTRING(content,30,1))) AS CodePageMark;
SET offset=33;
SET fieldno=0;
WHILE SUBSTR(content, offset, 1) <> 0x0D AND offset + 32 < LENGTH(content) DO
CALL dbf_field(fieldno, SUBSTRING(content, offset, 32));
SET offset=offset + 32;
SET fieldno=fieldno + 1;
END WHILE;
SELECT '--------';
END//
CREATE TABLE t1 (a INT) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.dbf'; CREATE TABLE t1 (a INT) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.dbf';
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
Table Create Table Table Create Table
...@@ -34,6 +70,24 @@ INSERT INTO t1 VALUES ('test'); ...@@ -34,6 +70,24 @@ INSERT INTO t1 VALUES ('test');
SELECT * FROM t1; SELECT * FROM t1;
a a
test test
CALL dbf_header('MYSQLD_DATADIR/test/t1.dbf');
-------- --------
FileSize 77
DBF_Version 03
NRecords 1
FirstRecPos 66
RecLength 11
TableFlags 0000
CodePageMark 00
--- ---
FieldN 0
Name a
Type C
Offset 0
Length 10
Dec 0
Flags 00
-------- --------
DROP TABLE t1; DROP TABLE t1;
# #
# Testing multiple columns # Testing multiple columns
...@@ -50,6 +104,40 @@ SELECT * FROM t1; ...@@ -50,6 +104,40 @@ SELECT * FROM t1;
a b c a b c
1 1 1 1 1 1
2 2 2 2 2 2
CALL dbf_header('MYSQLD_DATADIR/test/t1.dbf');
-------- --------
FileSize 194
DBF_Version 03
NRecords 2
FirstRecPos 130
RecLength 32
TableFlags 0000
CodePageMark 00
--- ---
FieldN 0
Name a
Type N
Offset 0
Length 11
Dec 0
Flags 00
--- ---
FieldN 1
Name b
Type C
Offset 0
Length 10
Dec 0
Flags 00
--- ---
FieldN 2
Name c
Type C
Offset 0
Length 10
Dec 0
Flags 00
-------- --------
DROP TABLE t1; DROP TABLE t1;
# #
# Testing long column name # Testing long column name
...@@ -87,6 +175,24 @@ INSERT INTO t1 VALUES (REPEAT('a',255)); ...@@ -87,6 +175,24 @@ INSERT INTO t1 VALUES (REPEAT('a',255));
SELECT LENGTH(a) FROM t1; SELECT LENGTH(a) FROM t1;
LENGTH(a) LENGTH(a)
255 255
CALL dbf_header('MYSQLD_DATADIR/test/t1.dbf');
-------- --------
FileSize 322
DBF_Version 03
NRecords 1
FirstRecPos 66
RecLength 256
TableFlags 0000
CodePageMark 00
--- ---
FieldN 0
Name a
Type C
Offset 0
Length 255
Dec 0
Flags 00
-------- --------
DROP TABLE t1; DROP TABLE t1;
# #
# Testing too long CHAR # Testing too long CHAR
...@@ -150,6 +256,24 @@ INSERT INTO t1 VALUES ('2001-01-01'); ...@@ -150,6 +256,24 @@ INSERT INTO t1 VALUES ('2001-01-01');
SELECT * FROM t1; SELECT * FROM t1;
a a
2001-01-01 2001-01-01
CALL dbf_header('MYSQLD_DATADIR/test/t1.dbf');
-------- --------
FileSize 75
DBF_Version 03
NRecords 1
FirstRecPos 66
RecLength 9
TableFlags 0000
CodePageMark 00
--- ---
FieldN 0
Name a
Type D
Offset 0
Length 8
Dec 0
Flags 00
-------- --------
DROP TABLE t1; DROP TABLE t1;
# #
# Testing FLOAT # Testing FLOAT
...@@ -162,6 +286,24 @@ INSERT INTO t1 VALUES (123); ...@@ -162,6 +286,24 @@ INSERT INTO t1 VALUES (123);
SELECT * FROM t1; SELECT * FROM t1;
a a
123.0000 123.0000
CALL dbf_header('MYSQLD_DATADIR/test/t1.dbf');
-------- --------
FileSize 79
DBF_Version 03
NRecords 1
FirstRecPos 66
RecLength 13
TableFlags 0000
CodePageMark 00
--- ---
FieldN 0
Name a
Type F
Offset 0
Length 12
Dec 4
Flags 00
-------- --------
DROP TABLE t1; DROP TABLE t1;
# #
# Testing double # Testing double
...@@ -176,4 +318,24 @@ SELECT * FROM t1; ...@@ -176,4 +318,24 @@ SELECT * FROM t1;
a a
123.00000 123.00000
123456789.12345 123456789.12345
CALL dbf_header('MYSQLD_DATADIR/test/t1.dbf');
-------- --------
FileSize 108
DBF_Version 03
NRecords 2
FirstRecPos 66
RecLength 21
TableFlags 0000
CodePageMark 00
--- ---
FieldN 0
Name a
Type F
Offset 0
Length 20
Dec 5
Flags 00
-------- --------
DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t1;
DROP PROCEDURE test.dbf_field;
DROP PROCEDURE test.dbf_header;
let $MYSQLD_DATADIR= `select @@datadir`; let $MYSQLD_DATADIR= `select @@datadir`;
DELIMITER //;
CREATE PROCEDURE test.dbf_field(in fieldno INT, in content BLOB) DETERMINISTIC
BEGIN
SELECT '---';
SELECT fieldno AS `FieldN`;
SELECT TRIM(TRAILING 0x00 FROM LEFT(content, 10)) AS `Name`;
SELECT SUBSTRING(content, 12, 1) AS `Type`;
SELECT CONV(HEX(REVERSE(SUBSTRING(content,13,4))),16,10) AS `Offset`;
SELECT CONV(HEX(REVERSE(SUBSTRING(content,17,1))),16,10) AS `Length`;
SELECT CONV(HEX(REVERSE(SUBSTRING(content,18,1))),16,10) AS `Dec`;
SELECT HEX(REVERSE(SUBSTRING(content,19,1))) AS `Flags`;
-- SELECT CONV(HEX(REVERSE(SUBSTRING(content,20,4))),16,10) AS `Next`;
-- SELECT CONV(HEX(REVERSE(SUBSTRING(content,24,4))),16,10) AS `Step`;
END//
CREATE PROCEDURE test.dbf_header(in fname VARCHAR(1024)) DETERMINISTIC
BEGIN
DECLARE content BLOB;
DECLARE offset INT;
DECLARE fieldno INT;
SELECT '--------';
SELECT LOAD_FILE(fname) INTO content;
SELECT LENGTH(content) AS FileSize;
SELECT HEX(LEFT(content, 1)) AS DBF_Version;
SELECT CONV(HEX(REVERSE(SUBSTRING(content,5,4))),16,10) AS NRecords;
SELECT CONV(HEX(REVERSE(SUBSTRING(content,9,2))),16,10) AS FirstRecPos;
SELECT CONV(HEX(REVERSE(SUBSTRING(content,11,2))),16,10) AS RecLength;
SELECT HEX(REVERSE(SUBSTRING(content,29,2))) AS TableFlags;
SELECT HEX(REVERSE(SUBSTRING(content,30,1))) AS CodePageMark;
SET offset=33;
SET fieldno=0;
WHILE SUBSTR(content, offset, 1) <> 0x0D AND offset + 32 < LENGTH(content) DO
CALL dbf_field(fieldno, SUBSTRING(content, offset, 32));
SET offset=offset + 32;
SET fieldno=fieldno + 1;
END WHILE;
SELECT '--------';
END//
DELIMITER ;//
CREATE TABLE t1 (a INT) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.dbf'; CREATE TABLE t1 (a INT) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.dbf';
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
INSERT INTO t1 VALUES (10),(20); INSERT INTO t1 VALUES (10),(20);
...@@ -21,10 +63,18 @@ CREATE TABLE t1 (a CHAR(10)) ENGINE=CONNECT Table_Type=dbf File_Name='t1.dbf'; ...@@ -21,10 +63,18 @@ CREATE TABLE t1 (a CHAR(10)) ENGINE=CONNECT Table_Type=dbf File_Name='t1.dbf';
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
INSERT INTO t1 VALUES ('test'); INSERT INTO t1 VALUES ('test');
SELECT * FROM t1; SELECT * FROM t1;
--chmod 0777 $MYSQLD_DATADIR/test/t1.dbf
--vertical_results
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
eval CALL dbf_header('$MYSQLD_DATADIR/test/t1.dbf');
--horizontal_results
DROP TABLE t1; DROP TABLE t1;
--remove_file $MYSQLD_DATADIR/test/t1.dbf --remove_file $MYSQLD_DATADIR/test/t1.dbf
#
# TODO: this creates DBF record with length=32, which looks wrong
#
--echo # --echo #
--echo # Testing multiple columns --echo # Testing multiple columns
--echo # --echo #
...@@ -37,6 +87,11 @@ CREATE TABLE t1 ...@@ -37,6 +87,11 @@ CREATE TABLE t1
INSERT INTO t1 VALUES (1,'1','1'); INSERT INTO t1 VALUES (1,'1','1');
INSERT INTO t1 VALUES (2,'2','2'); INSERT INTO t1 VALUES (2,'2','2');
SELECT * FROM t1; SELECT * FROM t1;
--chmod 0777 $MYSQLD_DATADIR/test/t1.dbf
--vertical_results
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
eval CALL dbf_header('$MYSQLD_DATADIR/test/t1.dbf');
--horizontal_results
DROP TABLE t1; DROP TABLE t1;
--remove_file $MYSQLD_DATADIR/test/t1.dbf --remove_file $MYSQLD_DATADIR/test/t1.dbf
...@@ -126,6 +181,11 @@ CREATE TABLE t1 ...@@ -126,6 +181,11 @@ CREATE TABLE t1
) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.dbf'; ) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.dbf';
INSERT INTO t1 VALUES (REPEAT('a',255)); INSERT INTO t1 VALUES (REPEAT('a',255));
SELECT LENGTH(a) FROM t1; SELECT LENGTH(a) FROM t1;
--chmod 0777 $MYSQLD_DATADIR/test/t1.dbf
--vertical_results
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
eval CALL dbf_header('$MYSQLD_DATADIR/test/t1.dbf');
--horizontal_results
DROP TABLE t1; DROP TABLE t1;
--remove_file $MYSQLD_DATADIR/test/t1.dbf --remove_file $MYSQLD_DATADIR/test/t1.dbf
...@@ -212,6 +272,11 @@ CREATE TABLE t1 ...@@ -212,6 +272,11 @@ CREATE TABLE t1
) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.dbf'; ) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.dbf';
INSERT INTO t1 VALUES ('2001-01-01'); INSERT INTO t1 VALUES ('2001-01-01');
SELECT * FROM t1; SELECT * FROM t1;
--chmod 0777 $MYSQLD_DATADIR/test/t1.dbf
--vertical_results
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
eval CALL dbf_header('$MYSQLD_DATADIR/test/t1.dbf');
--horizontal_results
DROP TABLE t1; DROP TABLE t1;
--remove_file $MYSQLD_DATADIR/test/t1.dbf --remove_file $MYSQLD_DATADIR/test/t1.dbf
...@@ -226,6 +291,11 @@ CREATE TABLE t1 ...@@ -226,6 +291,11 @@ CREATE TABLE t1
) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.dbf'; ) ENGINE=CONNECT TABLE_TYPE=DBF FILE_NAME='t1.dbf';
INSERT INTO t1 VALUES (123); INSERT INTO t1 VALUES (123);
SELECT * FROM t1; SELECT * FROM t1;
--chmod 0777 $MYSQLD_DATADIR/test/t1.dbf
--vertical_results
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
eval CALL dbf_header('$MYSQLD_DATADIR/test/t1.dbf');
--horizontal_results
DROP TABLE t1; DROP TABLE t1;
--remove_file $MYSQLD_DATADIR/test/t1.dbf --remove_file $MYSQLD_DATADIR/test/t1.dbf
# #
...@@ -286,6 +356,11 @@ CREATE TABLE t1 ...@@ -286,6 +356,11 @@ CREATE TABLE t1
INSERT INTO t1 VALUES (123); INSERT INTO t1 VALUES (123);
INSERT INTO t1 VALUES (123456789.12345); INSERT INTO t1 VALUES (123456789.12345);
SELECT * FROM t1; SELECT * FROM t1;
--chmod 0777 $MYSQLD_DATADIR/test/t1.dbf
--vertical_results
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
eval CALL dbf_header('$MYSQLD_DATADIR/test/t1.dbf');
--horizontal_results
DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t1;
--remove_file $MYSQLD_DATADIR/test/t1.dbf --remove_file $MYSQLD_DATADIR/test/t1.dbf
...@@ -298,4 +373,5 @@ DROP TABLE IF EXISTS t1; ...@@ -298,4 +373,5 @@ DROP TABLE IF EXISTS t1;
#CREATE TABLE t1 (a INT) ENGINE=CONNECT TABLE_TYPE=DBF; #CREATE TABLE t1 (a INT) ENGINE=CONNECT TABLE_TYPE=DBF;
DROP PROCEDURE test.dbf_field;
DROP PROCEDURE test.dbf_header;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment