Bug Tracker

ID:164 🔗
Status:Open
Category:datatool
Version:v2.32
Submitted by:Markus
Date:2020-06-28 12:59:22
Summary:Updating currentrow does not work as expected

Report

I try to create a dynamic project database which is updated in each run of LuaLaTeX and exported to a file. In the next run, the database is loaded from the file.

Starting from scratch (i.e. without any db-file), the database is produced and exported as expected. But in the second run, all updated row entries get modified to the entries of the last row in the database.

The index for currentrow is obtained correctly, but somehow the changes are distributed to the preceeding rows.

I am not sure if this is a bug or if I have missed something within datatool. Thanks!

MWE

\documentclass[a4paper,10pt]{article}

\usepackage[verbose,separator=;]{datatool}
\usepackage{csquotes}
\usepackage[english]{babel}
\usepackage[top=2cm,bottom=2cm,left=2.5cm,right=2cm]{geometry}
\usepackage{fontspec}

% numbering of projects
\newcounter{project}
\setcounter{project}{0}
\newcommand{\prepro}{P}
\renewcommand{\theproject}{\prepro\arabic{project}}

% create project database
\newcommand{\tabproj}{projects}
\IfFileExists{projects.csv}{\DTLloaddb[]{\tabproj}{projects.csv}}%
{\DTLnewdb{\tabproj}%
\DTLaddcolumn{\tabproj}{ID}%
\DTLaddcolumn{\tabproj}{project title}%
\DTLaddcolumn{\tabproj}{leaders}%
\DTLnewrow{\tabproj}
\DTLnewdbentry{\tabproj}{ID}{P0}
}

% updating project database when project ID, title or leaders have changed
\newcommand{\projtitle}{\relax}
\newcommand{\projlead}{\relax}
\NewDocumentCommand{\updateProjDB}{ m m m }{%
\xdtlgetrowindex{\myrowidx}{\tabproj}{\dtlcolumnindex{\tabproj}{ID}}{#1}
\ifx\myrowidx\dtlnovalue
Index not found.\\
  \DTLnewrow{\tabproj}
  {\dtlexpandnewvalue
  \DTLnewdbentry{\tabproj}{ID}{#1}
  \DTLnewdbentry{\tabproj}{project title}{#2}
  \DTLnewdbentry{\tabproj}{leaders}{#3}
  }
\else
Changing entry with index: \myrowidx\\
\dtlgetrow{\tabproj}{\myrowidx}%
\dtlreplaceentryincurrentrow{#2}{\dtlcolumnindex{\tabproj}{project title}}
\dtlreplaceentryincurrentrow{#3}{\dtlcolumnindex{\tabproj}{leaders}}
\dtlrecombine
\fi
}

\begin{document}

\DTLdisplaydb{\tabproj}

\refstepcounter{project}\label{author1}
\edef\projcount{\theproject}
\edef\projtitle{Title 1}
\edef\projlead{{author1,author2}}
\updateProjDB{\projcount}{\projtitle}{\projlead}

\DTLdisplaydb{\tabproj}

\refstepcounter{project}\label{author3}
\edef\projcount{\theproject}
\edef\projtitle{Title 2}
\edef\projlead{{author3,author4}}
\updateProjDB{\projcount}{\projtitle}{\projlead}

\DTLdisplaydb{\tabproj}

\refstepcounter{project}\label{author5}
\edef\projcount{\theproject}
\edef\projtitle{Title 3}
\edef\projlead{author5}
\updateProjDB{\projcount}{\projtitle}{\projlead}

\DTLdisplaydb{\tabproj}


\DTLsavedb{\tabproj}{projects.csv}

\end{document} 

Evaluation

It looks like the user manual is incorrect where it claims the value is expanded. It isn’t. Since it could cause a problem for existing documents if I change the behaviour to match the documentation, I think it would be better if I introduce new commands that expand the value.

Since you only need one level of expansion, the following will work:

\expandafter\dtlreplaceentryincurrentrow\expandafter{#2}{\dtlcolumnindex{\tabproj}{project title}}
\expandafter\dtlreplaceentryincurrentrow\expandafter{#3}{\dtlcolumnindex{\tabproj}{leaders}}

Comments

Comment from Markus. 2020-06-30 19:49 BST

Thanks, works perfectly!

Add comment or return to search results.

Watch This Report

If you would like to be notified whenever updates are made to this report, please fill in your email address in the box below and click on "Notify Me of Changes" button. (Please ensure the address is valid.) Your details won't be passed on to third parties in line with this site's Privacy Policy.

If you supply your name, it will be used in the email greeting, which provides a more personal message, otherwise you'll just get a generic greeting. If you have previously supplied your name when signing up for notifications, you don't need to resupply it unless you want to change it.

If you have previously subscribed to notifications for this report, you can unsubscribe by clicking on the "Stop Notification" button.

The "Confirm Bug ID" field helps to protect against spambots. Please enter the bug ID (which you can find at the top of this page).

(Optional.)
E mail:
Confirm E mail:
Confirm Bug ID:

To unsubscribe from all notifications use the notifications page.

Comment

You can append a comment to the report using the form below. Comments are checked first before being added. Any spam or offensive content will be removed first according to this site's Terms of Website Use. Please bear in mind that I develop and maintain free software in my spare time. If you want commerical level support then you can hire a TeX consultant.

The "Confirm Bug ID" field helps to protect against spambots. Please enter the bug ID (which you can find at the top of this page).

(Optional. If provided, it will be shown with the comment.)
Confirm Bug ID:

You can use the following markup:

[pre]Displayed verbatim[/pre]
[tt]monospace text[/tt]
[em]emphasized text[/em]
[b]bold text[/b]
[url]web address[/url]

Ordered list:
[ol]
[li]first item[/li]
[li]second item[/li]
[/ol]

Unordered list:
[ul]
[li]first item[/li]
[li]second item[/li]
[/ul]

Click on the Preview button to preview the message.

Return to search results.