How to select specfic row for \DTLnewdbentry to apply to

After a pair of \DTLnewrow/\DTLnewdbentry which creates two rows with the key1 data, I want to add the key2 data to the earlier row. I thought that \dtlgetrow{myDB}{1} would make the current row the one with rowid=1, but that does not appear to be the case as the data just got added to second row.

The MWE below yields:

Question: What do I replace instead of \dtlgetrow{myDB}{1} so that I obtain the results where xprime and NULL are swapped. Basically, how can I select which row is the current row for subsequent operations?

Notes:

• A simple solution would be to change the order in which I do these operations, but I can't easily do that.

Code:

\documentclass{article}
\usepackage{datatool}

\begin{document}
\DTLnewdb{myDB}

\DTLnewrow{myDB}% create first row
\DTLnewdbentry{myDB}{key1}{x}

\DTLnewrow{myDB}% create second row
\DTLnewdbentry{myDB}{key1}{y}

\dtlgetrow{myDB}{1}% ????? Thought this would make row 1 the current row

\DTLnewdbentry{myDB}{key2}{xprime}% This needs to be in the first row
\DTLdisplaydb{myDB}
\end{document}

-

\dtlgetrow gets the given row and stores it in the current token register \dtlcurrentrow. Only those commands listed in the "Operating on Current Row" section of the manual affect this register. Those commands modify the token register not the database. Once the modifications are made, you can merge the changes back into the database using \dtlrecombine.

\documentclass{article}
\usepackage{datatool}

\begin{document}
\DTLnewdb{myDB}

\DTLnewrow{myDB}% create first row
\DTLnewdbentry{myDB}{key1}{x}

\DTLnewrow{myDB}% create second row
\DTLnewdbentry{myDB}{key1}{y}

\dtlgetrow{myDB}{1}% store row 1 in \dtlcurrentrow register
\dtlappendentrytocurrentrow{key2}{xprime}% make local modification to current row
\dtlrecombine% merge modification into database.

\DTLdisplaydb{myDB}

\end{document}


This is the most efficient way to edit a particular row in the database.

-

I can't see why you can't just put \value{DTLrowi}=1 in the optional argument to filter the rows, but that generates an error, but this works:

\documentclass{article}
\usepackage{datatool}

\begin{document}
\DTLnewdb{myDB}

\DTLnewrow{myDB}% create first row
\DTLnewdbentry{myDB}{key1}{x}

\DTLnewrow{myDB}% create second row
\DTLnewdbentry{myDB}{key1}{y}

\DTLforeach{myDB}{}{%
\ifnum\value{DTLrowi}=1
\DTLappendtorow{key2}{xprime}% This needs to be in the first row
\fi
}

\DTLdisplaydb{myDB}
\end{document}

-
 Wow I guess I am rubbing off on you. I thought of doing this, but felt it was too much of a hack, even for me. :-) But it does work.. – Peter Grill Nov 19 '12 at 19:28