Available in versions: Dev (3.22) | Latest (3.21) | 3.20 | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12
This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.
Reading text
Supported by ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
DSLContext.fetchFromTXT() is the inverse operation of exporting text. It parses a human-readable, formatted text table into a Result<Record>. Two formats are supported, the format produced by Result.format():
Result<Record> result = create.fetchFromTXT(
"+---+---------+-----------+\n"
+ "| ID|AUTHOR_ID|TITLE |\n"
+ "+---+---------+-----------+\n"
+ "| 1| 1|1984 |\n"
+ "| 2| 1|Animal Farm|\n"
+ "+---+---------+-----------+\n"
);
... and the format used by H2 in its test data, where column groups are delimited by dashes in the second line:
Result<Record> result = create.fetchFromTXT(
"ID AUTHOR_ID TITLE \n"
+ "-- --------- -----------\n"
+ "1 1 1984 \n"
+ "2 1 Animal Farm\n"
);
In both formats, the width of each column is defined by its dashes, and values are trimmed. By default, the literal {null}, which is also what Result.format() produces for NULL values, is interpreted as NULL. A different literal can be specified explicitly:
Result<Record> result = create.fetchFromTXT(text, "N/A");
All fields of the resulting Result are of type String. See the section about working with in-memory results to learn how to convert such results to other types.
This format is particularly readable in test code. It is also one of the formats accepted by the MockFileDatabase.
Feedback
Do you have any feedback about this page? We'd love to hear it!