2

I'm currently learning how to use the datatool package. I have a lot of .txt-files that need to be processed automatically. But if datatool loads a wrong kind of .txt-file I need to be able to check it. The way I want to do it is to check the key's of the columns, but the command \DTLgetkeyforcolumn returns the error:

Undefined control sequence.
<argument> \db@row@id@w

l.58 \DTLgetkeyforcolumn{\colkey}{data}{1}

I have absolutely no clue what that means... The source code can be found in the datatool manual. Search for the function and you will get to it. I really don't understand it, and can't see anywhere \db@row@id@w. Could it be a bug in the package? Trying to redefine the function only results in errors.

Edit:
Minimal working example:

\documentclass{article}

\usepackage{datatool}
\DTLloadrawdb{data}{data.txt} %load data.txt, store in database data

\begin{document}
  % Display the table, bold are the headers
  \DTLdisplaydb{data}

  % Search for header ColTwo and store index into \colindex
  \DTLgetcolumnindex{\colindex}{data}{ColTwo}
  \colindex % returns 2

  % Search the index and store the header into \colkey
  \DTLgetkeyforcolumn{\colkey}{data}{\colindex} % Error
  \colkey

\end{document}

data.txt

ColOne,ColTwo,ColThree
a,b,2
c,d,5

Gives no output at all.

  • Could you post a minimal working example (MWE) that illustrates your problem? It helps us to track the error down. :) – Paulo Cereda Jul 13 '12 at 16:51
  • Added, but it doesn't work mind you ;) – Didii Jul 16 '12 at 7:43
  • Seems like a bug. Maybe you should contact the package maintainer. – bodo Jul 16 '12 at 7:55
  • I've sent a mail to him, thanks for the reply. – Didii Jul 16 '12 at 8:56
1

I've sent a mail to the package maintainer (Nicola Talbot) who gave me a temporary workaround. Paste the following under \usepackage{datatool}. This bug will be fixed in a future patch.

\makeatletter
\renewcommand*{\@dtl@getkeyforcolumn}[3]{%
 \def\@dtl@get@keyforcolumn##1% before stuff
   \db@plist@elt@w% start of block
   \db@col@id@w #3\db@col@id@end@% index
   \db@key@id@w ##2\db@key@id@end@% key
   \db@type@id@w ##3\db@type@id@end@% data type
   \db@header@id@w ##4\db@header@id@end@% header
   \db@col@id@w #3\db@col@id@end@% index
   \db@plist@elt@end@% end of block
   ##5\q@nil{\def#1{##2}}%
 \edef\@dtl@tmp{\expandafter\the\csname dtlkeys@#2\endcsname}%
 \expandafter\@dtl@get@keyforcolumn\@dtl@tmp
   \db@plist@elt@w% start of block
   \db@col@id@w #3\db@col@id@end@ %index
   \db@key@id@w \@nil\db@key@id@end@% key
   \db@type@id@w \db@type@id@end@% data type
   \db@header@id@w \db@header@id@end@% header
   \db@col@id@w #3\db@col@id@end@% index
   \db@plist@elt@end@% end of block
   \q@nil
}
\makeatother
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.