# Conditional execution based on existence of key/value pair in datatool

This question is a confirmation and a follow-up using the code from this question

I'm preparing a template, which relies on some texts which will be provided in a CSV file (ex, disclaimer text, large chunk of text). Maybe I'm overthinking it, but the idea is to automatize some parts of my documents' production using Latex.

Among some other requirements, the code

• must not throw an error if some text is not present and
• must be clever enough to process some conditional, like if DB contains "disclaimer2" then display it, otherwise try to display "disclaimer" (default).

The code from the link above do not treat the case of 2-dimension array but seems to contain only 1-dimension list. So I've tried to expand it. Good point, my code compiles fine on Sharelatex, but still I'd have some question, as sanity check from more exper users than me.

\documentclass{article}
\usepackage{datatool}
\usepackage{lipsum}

\makeatletter
% Patch \DTLgetlocation to gobble the error
\let\ErrorFreeDTLgetlocation\DTLgetlocation%
\patchcmd{\ErrorFreeDTLgetlocation}{\PackageError}{\@gobbletwo}{}{}%
\def\@@dtlnovalue{\@dtlnovalue}%
% Conditional on Existence of entry in DB
\newcommand*{\IfIsInDB}[4]{
% #1 = DB name, #2 = member to check for
% #3 = code to execute if member is in DB
% #4 = code to execute if member is not in DB
\ErrorFreeDTLgetlocation{\RowIndex}{\ColIndex}{#1}{#2}
\ifx\RowIndex\@@dtlnovalue
#4%
\else
#3
\fi
}
\makeatother

\DTLnewdb{dbDocOptions}
\DTLnewrow{dbDocOptions}
\DTLnewdbentry{dbDocOptions}{key}{disclaimer}
\DTLnewdbentry{dbDocOptions}{value}{\lipsum[1]}
\DTLnewrow{dbDocOptions}
\DTLnewdbentry{dbDocOptions}{key}{disclaimer2}
\DTLnewdbentry{dbDocOptions}{value}{\lipsum[2]}

\newcommand{\disclaimerFormatted}{%
\IfIsInDB{dbDocOptions}{disclaimer}{\begin{center}%
\begin{tabular}{l}%
\multicolumn{1}{c}{\Large{\textbf{Disclaimer}}\vspace*{0.5cm}}\\%
\begin{minipage}[t]{0.9\textwidth}
\DTLfetch{dbDocOptions}{key}{disclaimer}{value}%
\end{minipage}\\
\end{tabular}%
\end{center}%
}{}%
}

\newcommand{\disclaimerTwoFormatted}{%
\IfIsInDB{dbDocOptions}{disclaimer2}{\begin{center}%
\begin{tabular}{ll}%
\multicolumn{1}{c}{\Large{\textbf{Second Disclaimer}}\vspace*{0.5cm}} \\ \hline
\textit{highlights} & \begin{minipage}[t]{0.45\textwidth}\DTLfetch{dbDocOptions}{key}{disclaimer2}{value}\end{minipage} \\ \hline
\end{tabular}%
\end{center}%
}{}%
}

\begin{document}
\disclaimerFormatted
\noindent\lipsum[3]
\disclaimerTwoFormatted

\end{document}


## Question

1. I've noted that my code compile without the package xparse & etoolbox. Is it necessary ?
2. Sorry for the generality, but have I missed some important caveat which may break this code or cause a cryptic error ?