| 1 |
% This file is embedded in datatool-user.pdf version 3.4.3 2025-12-04 |
| 2 |
% Example 111 Loading and Saving Data (Be Careful of Category Codes) |
| 3 |
% Label: "ex:loadcustomers" |
| 4 |
% arara: pdflatex |
| 5 |
% arara: pdfcrop |
| 6 |
\documentclass[12pt]{article} |
| 7 |
\pagestyle{empty} |
| 8 |
\begin{filecontents}[noheader,overwrite]{customers.csv} |
| 9 |
Id,Organisation,Surname,Forename,Email,Age |
| 10 |
1,,Parrot,Polly,[email protected],42 |
| 11 |
2,University of Somewhere,Canary,Mabel,[email protected] |
| 12 |
3,University of Somewhere,Zebra,Zoë,[email protected],21 |
| 13 |
4,Zinnia Florestry,Arara,José,[email protected],42 |
| 14 |
5,,Duck,Dickie,[email protected], |
| 15 |
6,Newt Fellowship,Axolotl,Lizzie,[email protected] |
| 16 |
7,Avian Emporium,Canary,Fred,[email protected],19 |
| 17 |
8,Newt Fellowship,,Molgina,[email protected] |
| 18 |
9,,Mander,Sally |
| 19 |
10,Élite Emporium,Fant,Eli,[email protected],101 |
| 20 |
\end{filecontents} |
| 21 |
|
| 22 |
\usepackage{datatool} |
| 23 |
\DTLsetup{default-name=customers} |
| 24 |
\DTLread{customers} |
| 25 |
\begin{document} |
| 26 |
\DTLaction[key=Email,[email protected]]{select row} |
| 27 |
Row: \number\dtlrownum. |
| 28 |
% Save as DBTEX v3.0: |
| 29 |
\DTLwrite[format=dbtex-3,overwrite=allow]{customers-v3} |
| 30 |
|
| 31 |
% Read this new file back: |
| 32 |
\DTLread[format=dbtex,name=customers-v3]{customers-v3} |
| 33 |
\DTLaction[ |
| 34 |
name=customers-v3, |
| 35 |
key=Email,[email protected] |
| 36 |
]{select row} |
| 37 |
Row: \number\dtlrownum. |
| 38 |
|
| 39 |
|
| 40 |
% Save original as DBTEX v2.0: |
| 41 |
\DTLwrite[format=dbtex-2,overwrite=allow]{customers-v2} |
| 42 |
|
| 43 |
% `customers' database needs to be deleted as DBTEX v2.0 has the name hard-coded: |
| 44 |
\DTLaction{delete} |
| 45 |
% Read this new file back: |
| 46 |
\DTLread[format=dbtex]{customers-v2} |
| 47 |
% Row will no longer be found as DBTEX v2.0 changes category code of `@': |
| 48 |
\DTLaction[key=Email,[email protected]]{select row} |
| 49 |
Row: \number\dtlrownum. |
| 50 |
\end{document} |