\hypertarget{classkdb_1_1KDB}{}\doxysection{kdb\+::KDB Class Reference}
\label{classkdb_1_1KDB}\index{kdb::KDB@{kdb::KDB}}


Constructs a class \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}.  




{\ttfamily \#include $<$kdb.\+hpp$>$}



Inheritance diagram for kdb\+::KDB\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=191pt]{classkdb_1_1KDB__inherit__graph}
\end{center}
\end{figure}
\doxysubsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} ()
\begin{DoxyCompactList}\small\item\em Constructs a class \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}. \end{DoxyCompactList}\item 
\mbox{\hyperlink{classkdb_1_1KDB_a98e25c7fe2f47c5a90461676c6d219e7}{KDB}} (\mbox{\hyperlink{classkdb_1_1Key}{Key}} \&error\+Key)
\begin{DoxyCompactList}\small\item\em Constructs a class \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}. \end{DoxyCompactList}\item 
\mbox{\hyperlink{classkdb_1_1KDB_adecb001cb936bd869ef06c7c71fdf0ef}{KDB}} (\mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} \&contract)
\begin{DoxyCompactList}\small\item\em Constructs a class \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}. \end{DoxyCompactList}\item 
\mbox{\hyperlink{classkdb_1_1KDB_a95ef4570ac2d7ddbe2b4c0ad7810c742}{KDB}} (\mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} \&contract, \mbox{\hyperlink{classkdb_1_1Key}{Key}} \&error\+Key)
\begin{DoxyCompactList}\small\item\em Constructs a class \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}. \end{DoxyCompactList}\item 
virtual void \mbox{\hyperlink{classkdb_1_1KDB_aee37484b06164eacc0cc11b7b40ab892}{open}} (\mbox{\hyperlink{classkdb_1_1Key}{Key}} \&error\+Key)
\begin{DoxyCompactList}\small\item\em Open the database. \end{DoxyCompactList}\item 
virtual void \mbox{\hyperlink{classkdb_1_1KDB_a8bd17da51bd531a2726185e7bbf4ecf9}{open}} (\mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} \&contract, \mbox{\hyperlink{classkdb_1_1Key}{Key}} \&error\+Key)
\begin{DoxyCompactList}\small\item\em Open the database. \end{DoxyCompactList}\item 
virtual void \mbox{\hyperlink{classkdb_1_1KDB_a1b3ff4a68c2c935d67dce843bc4ad01b}{close}} ()  throw ()
\begin{DoxyCompactList}\small\item\em Close the database. \end{DoxyCompactList}\item 
virtual void \mbox{\hyperlink{classkdb_1_1KDB_aa027a8f798a2cfee11ff712eb204c35d}{close}} (\mbox{\hyperlink{classkdb_1_1Key}{Key}} \&error\+Key)  throw ()
\begin{DoxyCompactList}\small\item\em Close the database. \end{DoxyCompactList}\item 
virtual int \mbox{\hyperlink{classkdb_1_1KDB_a0419ffbc273c89756bc523b4223ec25a}{get}} (\mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} \&returned, std\+::string const \&keyname)
\begin{DoxyCompactList}\small\item\em Get all keys below keyname inside returned. \end{DoxyCompactList}\item 
virtual int \mbox{\hyperlink{classkdb_1_1KDB_a48770a7290699bf2b7529f3ab67e378f}{get}} (\mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} \&returned, \mbox{\hyperlink{classkdb_1_1Key}{Key}} \&parent\+Key)
\begin{DoxyCompactList}\small\item\em Get all keys below parent\+Key inside returned. \end{DoxyCompactList}\item 
virtual int \mbox{\hyperlink{classkdb_1_1KDB_a29087a6a1a7de334f4e5b62ffe5d6e6e}{set}} (\mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} \&returned, std\+::string const \&keyname)
\begin{DoxyCompactList}\small\item\em Set all keys below keyname. \end{DoxyCompactList}\item 
virtual int \mbox{\hyperlink{classkdb_1_1KDB_a62a4fafbe21d9519b31a7868aa05f3e3}{set}} (\mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} \&returned, \mbox{\hyperlink{classkdb_1_1Key}{Key}} \&parent\+Key)
\begin{DoxyCompactList}\small\item\em Set all keys below parent\+Key. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
Constructs a class \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}. 


\begin{DoxyExceptions}{Exceptions}
{\em KDBException} & if database could not be opened\\
\hline
\end{DoxyExceptions}
Opens the session with the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database. \begin{DoxyPrecond}{Precondition}
error\+Key must be a valid key, e.\+g. created with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}
\end{DoxyPrecond}
You must always call this method before retrieving or committing any keys to the database. At the end of a program, after using the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database (\mbox{\hyperlink{classkdb_1_1KDB}{KDB}}), you must not forget to call \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} to free resources.

The method will bootstrap itself in the following way. The first step is to open the default backend. With it {\ttfamily system\+:/elektra/mountpoints} will be loaded and all needed libraries and mountpoints will be determined. Then the global plugins and global keyset data from the {\ttfamily contract} is processed. Finally, the libraries for backends will be loaded and with it the {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} data structure will be initialized.

The pointer to the {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} structure returned will be initialized like described above, and it must be passed along on any kdb$\ast$() method your application calls.

Get a {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} handle for every thread using elektra. Don\textquotesingle{}t share the handle across threads, and also not the pointer accessing it\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keywordtype}{void} thread1 (\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{        Key * parent = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}/app/part1"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{        \mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * h = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, parent);}
\DoxyCodeLine{        \textcolor{comment}{// fetch keys and work with them}}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (h, parent);}
\DoxyCodeLine{\}}
\DoxyCodeLine{\textcolor{keywordtype}{void} thread2 (\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{        Key * parent = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}/app/part2"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{        \mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * h = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, parent);}
\DoxyCodeLine{        \textcolor{comment}{// fetch keys and work with them}}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (h, parent);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 You don\textquotesingle{}t need \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} if you only want to manipulate plain in-\/memory \mbox{\hyperlink{classkdb_1_1Key}{Key}} or \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} objects.

\begin{DoxyPrecond}{Precondition}
error\+Key must be a valid key, e.\+g. created with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}
\end{DoxyPrecond}

\begin{DoxyParams}{Parameters}
{\em contract} & the contract that should be ensured before opening the \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} all data is copied and the \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} can safely be used for e.\+g. \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} later \\
\hline
{\em error\+Key} & the key which holds errors and warnings which were issued\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
handle to the newly created \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} on success 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em NULL} & on failure\\
\hline
\end{DoxyRetVals}
\begin{DoxySince}{Since}
1.\+0.\+0
\end{DoxySince}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} to \mbox{\hyperlink{classkdb_1_1KDB_a1b3ff4a68c2c935d67dce843bc4ad01b}{close}} the session of a \mbox{\hyperlink{classkdb_1_1Key}{Key}} database opened by \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}}
\end{DoxySeeAlso}
Access to the key database.

\begin{DoxyInvariant}{Invariant}
the object holds a valid connection to the key database or is empty 
\end{DoxyInvariant}


\doxysubsection{Constructor \& Destructor Documentation}
\mbox{\Hypertarget{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}\label{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}} 
\index{kdb::KDB@{kdb::KDB}!KDB@{KDB}}
\index{KDB@{KDB}!kdb::KDB@{kdb::KDB}}
\doxysubsubsection{\texorpdfstring{KDB()}{KDB()}\hspace{0.1cm}{\footnotesize\ttfamily [1/4]}}
{\footnotesize\ttfamily kdb\+::\+KDB\+::\+KDB (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Constructs a class \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}. 


\begin{DoxyExceptions}{Exceptions}
{\em KDBException} & if database could not be opened\\
\hline
\end{DoxyExceptions}
Opens the session with the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database. \begin{DoxyPrecond}{Precondition}
error\+Key must be a valid key, e.\+g. created with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}
\end{DoxyPrecond}
You must always call this method before retrieving or committing any keys to the database. At the end of a program, after using the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database (\mbox{\hyperlink{classkdb_1_1KDB}{KDB}}), you must not forget to call \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} to free resources.

The method will bootstrap itself in the following way. The first step is to open the default backend. With it {\ttfamily system\+:/elektra/mountpoints} will be loaded and all needed libraries and mountpoints will be determined. Then the global plugins and global keyset data from the {\ttfamily contract} is processed. Finally, the libraries for backends will be loaded and with it the {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} data structure will be initialized.

The pointer to the {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} structure returned will be initialized like described above, and it must be passed along on any kdb$\ast$() method your application calls.

Get a {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} handle for every thread using elektra. Don\textquotesingle{}t share the handle across threads, and also not the pointer accessing it\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keywordtype}{void} thread1 (\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{        Key * parent = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}/app/part1"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{        \mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * h = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, parent);}
\DoxyCodeLine{        \textcolor{comment}{// fetch keys and work with them}}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (h, parent);}
\DoxyCodeLine{\}}
\DoxyCodeLine{\textcolor{keywordtype}{void} thread2 (\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{        Key * parent = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}/app/part2"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{        \mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * h = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, parent);}
\DoxyCodeLine{        \textcolor{comment}{// fetch keys and work with them}}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (h, parent);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 You don\textquotesingle{}t need \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} if you only want to manipulate plain in-\/memory \mbox{\hyperlink{classkdb_1_1Key}{Key}} or \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} objects.

\begin{DoxyPrecond}{Precondition}
error\+Key must be a valid key, e.\+g. created with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}
\end{DoxyPrecond}

\begin{DoxyParams}{Parameters}
{\em contract} & the contract that should be ensured before opening the \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} all data is copied and the \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} can safely be used for e.\+g. \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} later \\
\hline
{\em error\+Key} & the key which holds errors and warnings which were issued\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
handle to the newly created \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} on success 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em NULL} & on failure\\
\hline
\end{DoxyRetVals}
\begin{DoxySince}{Since}
1.\+0.\+0
\end{DoxySince}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} to \mbox{\hyperlink{classkdb_1_1KDB_a1b3ff4a68c2c935d67dce843bc4ad01b}{close}} the session of a \mbox{\hyperlink{classkdb_1_1Key}{Key}} database opened by \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{classkdb_1_1KDB_a98e25c7fe2f47c5a90461676c6d219e7}\label{classkdb_1_1KDB_a98e25c7fe2f47c5a90461676c6d219e7}} 
\index{kdb::KDB@{kdb::KDB}!KDB@{KDB}}
\index{KDB@{KDB}!kdb::KDB@{kdb::KDB}}
\doxysubsubsection{\texorpdfstring{KDB()}{KDB()}\hspace{0.1cm}{\footnotesize\ttfamily [2/4]}}
{\footnotesize\ttfamily kdb\+::\+KDB\+::\+KDB (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{classkdb_1_1Key}{Key}} \&}]{error\+Key }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [explicit]}}



Constructs a class \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}. 


\begin{DoxyParams}{Parameters}
{\em error\+Key} & is useful if you want to get the warnings in the successful case, when no exception is thrown.\\
\hline
\end{DoxyParams}

\begin{DoxyExceptions}{Exceptions}
{\em KDBException} & if database could not be opened\\
\hline
\end{DoxyExceptions}
Opens the session with the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database. \begin{DoxyPrecond}{Precondition}
error\+Key must be a valid key, e.\+g. created with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}
\end{DoxyPrecond}
You must always call this method before retrieving or committing any keys to the database. At the end of a program, after using the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database (\mbox{\hyperlink{classkdb_1_1KDB}{KDB}}), you must not forget to call \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} to free resources.

The method will bootstrap itself in the following way. The first step is to open the default backend. With it {\ttfamily system\+:/elektra/mountpoints} will be loaded and all needed libraries and mountpoints will be determined. Then the global plugins and global keyset data from the {\ttfamily contract} is processed. Finally, the libraries for backends will be loaded and with it the {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} data structure will be initialized.

The pointer to the {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} structure returned will be initialized like described above, and it must be passed along on any kdb$\ast$() method your application calls.

Get a {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} handle for every thread using elektra. Don\textquotesingle{}t share the handle across threads, and also not the pointer accessing it\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keywordtype}{void} thread1 (\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{        Key * parent = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}/app/part1"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{        \mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * h = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, parent);}
\DoxyCodeLine{        \textcolor{comment}{// fetch keys and work with them}}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (h, parent);}
\DoxyCodeLine{\}}
\DoxyCodeLine{\textcolor{keywordtype}{void} thread2 (\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{        Key * parent = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}/app/part2"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{        \mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * h = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, parent);}
\DoxyCodeLine{        \textcolor{comment}{// fetch keys and work with them}}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (h, parent);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 You don\textquotesingle{}t need \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} if you only want to manipulate plain in-\/memory \mbox{\hyperlink{classkdb_1_1Key}{Key}} or \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} objects.

\begin{DoxyPrecond}{Precondition}
error\+Key must be a valid key, e.\+g. created with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}
\end{DoxyPrecond}

\begin{DoxyParams}{Parameters}
{\em contract} & the contract that should be ensured before opening the \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} all data is copied and the \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} can safely be used for e.\+g. \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} later \\
\hline
{\em error\+Key} & the key which holds errors and warnings which were issued\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
handle to the newly created \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} on success 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em NULL} & on failure\\
\hline
\end{DoxyRetVals}
\begin{DoxySince}{Since}
1.\+0.\+0
\end{DoxySince}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} to \mbox{\hyperlink{classkdb_1_1KDB_a1b3ff4a68c2c935d67dce843bc4ad01b}{close}} the session of a \mbox{\hyperlink{classkdb_1_1Key}{Key}} database opened by \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{classkdb_1_1KDB_adecb001cb936bd869ef06c7c71fdf0ef}\label{classkdb_1_1KDB_adecb001cb936bd869ef06c7c71fdf0ef}} 
\index{kdb::KDB@{kdb::KDB}!KDB@{KDB}}
\index{KDB@{KDB}!kdb::KDB@{kdb::KDB}}
\doxysubsubsection{\texorpdfstring{KDB()}{KDB()}\hspace{0.1cm}{\footnotesize\ttfamily [3/4]}}
{\footnotesize\ttfamily kdb\+::\+KDB\+::\+KDB (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} \&}]{contract }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [explicit]}}



Constructs a class \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}. 


\begin{DoxyParams}{Parameters}
{\em contract} & the contract that should be ensured \\
\hline
{\em error\+Key} & is useful if you want to get the warnings in the successful case, when no exception is thrown.\\
\hline
\end{DoxyParams}

\begin{DoxyExceptions}{Exceptions}
{\em KDBException} & if database could not be opened\\
\hline
\end{DoxyExceptions}
Opens the session with the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database. \begin{DoxyPrecond}{Precondition}
error\+Key must be a valid key, e.\+g. created with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}
\end{DoxyPrecond}
You must always call this method before retrieving or committing any keys to the database. At the end of a program, after using the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database (\mbox{\hyperlink{classkdb_1_1KDB}{KDB}}), you must not forget to call \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} to free resources.

The method will bootstrap itself in the following way. The first step is to open the default backend. With it {\ttfamily system\+:/elektra/mountpoints} will be loaded and all needed libraries and mountpoints will be determined. Then the global plugins and global keyset data from the {\ttfamily contract} is processed. Finally, the libraries for backends will be loaded and with it the {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} data structure will be initialized.

The pointer to the {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} structure returned will be initialized like described above, and it must be passed along on any kdb$\ast$() method your application calls.

Get a {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} handle for every thread using elektra. Don\textquotesingle{}t share the handle across threads, and also not the pointer accessing it\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keywordtype}{void} thread1 (\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{        Key * parent = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}/app/part1"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{        \mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * h = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, parent);}
\DoxyCodeLine{        \textcolor{comment}{// fetch keys and work with them}}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (h, parent);}
\DoxyCodeLine{\}}
\DoxyCodeLine{\textcolor{keywordtype}{void} thread2 (\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{        Key * parent = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}/app/part2"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{        \mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * h = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, parent);}
\DoxyCodeLine{        \textcolor{comment}{// fetch keys and work with them}}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (h, parent);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 You don\textquotesingle{}t need \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} if you only want to manipulate plain in-\/memory \mbox{\hyperlink{classkdb_1_1Key}{Key}} or \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} objects.

\begin{DoxyPrecond}{Precondition}
error\+Key must be a valid key, e.\+g. created with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}
\end{DoxyPrecond}

\begin{DoxyParams}{Parameters}
{\em contract} & the contract that should be ensured before opening the \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} all data is copied and the \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} can safely be used for e.\+g. \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} later \\
\hline
{\em error\+Key} & the key which holds errors and warnings which were issued\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
handle to the newly created \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} on success 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em NULL} & on failure\\
\hline
\end{DoxyRetVals}
\begin{DoxySince}{Since}
1.\+0.\+0
\end{DoxySince}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} to \mbox{\hyperlink{classkdb_1_1KDB_a1b3ff4a68c2c935d67dce843bc4ad01b}{close}} the session of a \mbox{\hyperlink{classkdb_1_1Key}{Key}} database opened by \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{classkdb_1_1KDB_a95ef4570ac2d7ddbe2b4c0ad7810c742}\label{classkdb_1_1KDB_a95ef4570ac2d7ddbe2b4c0ad7810c742}} 
\index{kdb::KDB@{kdb::KDB}!KDB@{KDB}}
\index{KDB@{KDB}!kdb::KDB@{kdb::KDB}}
\doxysubsubsection{\texorpdfstring{KDB()}{KDB()}\hspace{0.1cm}{\footnotesize\ttfamily [4/4]}}
{\footnotesize\ttfamily kdb\+::\+KDB\+::\+KDB (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} \&}]{contract,  }\item[{\mbox{\hyperlink{classkdb_1_1Key}{Key}} \&}]{error\+Key }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Constructs a class \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}. 


\begin{DoxyParams}{Parameters}
{\em contract} & the contract that should be ensured \\
\hline
{\em error\+Key} & is useful if you want to get the warnings in the successful case, when no exception is thrown.\\
\hline
\end{DoxyParams}

\begin{DoxyExceptions}{Exceptions}
{\em KDBException} & if database could not be opened\\
\hline
\end{DoxyExceptions}
Opens the session with the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database. \begin{DoxyPrecond}{Precondition}
error\+Key must be a valid key, e.\+g. created with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}
\end{DoxyPrecond}
You must always call this method before retrieving or committing any keys to the database. At the end of a program, after using the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database (\mbox{\hyperlink{classkdb_1_1KDB}{KDB}}), you must not forget to call \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} to free resources.

The method will bootstrap itself in the following way. The first step is to open the default backend. With it {\ttfamily system\+:/elektra/mountpoints} will be loaded and all needed libraries and mountpoints will be determined. Then the global plugins and global keyset data from the {\ttfamily contract} is processed. Finally, the libraries for backends will be loaded and with it the {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} data structure will be initialized.

The pointer to the {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} structure returned will be initialized like described above, and it must be passed along on any kdb$\ast$() method your application calls.

Get a {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} handle for every thread using elektra. Don\textquotesingle{}t share the handle across threads, and also not the pointer accessing it\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keywordtype}{void} thread1 (\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{        Key * parent = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}/app/part1"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{        \mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * h = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, parent);}
\DoxyCodeLine{        \textcolor{comment}{// fetch keys and work with them}}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (h, parent);}
\DoxyCodeLine{\}}
\DoxyCodeLine{\textcolor{keywordtype}{void} thread2 (\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{        Key * parent = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}/app/part2"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{        \mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * h = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, parent);}
\DoxyCodeLine{        \textcolor{comment}{// fetch keys and work with them}}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (h, parent);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 You don\textquotesingle{}t need \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} if you only want to manipulate plain in-\/memory \mbox{\hyperlink{classkdb_1_1Key}{Key}} or \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} objects.

\begin{DoxyPrecond}{Precondition}
error\+Key must be a valid key, e.\+g. created with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}
\end{DoxyPrecond}

\begin{DoxyParams}{Parameters}
{\em contract} & the contract that should be ensured before opening the \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} all data is copied and the \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} can safely be used for e.\+g. \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} later \\
\hline
{\em error\+Key} & the key which holds errors and warnings which were issued\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
handle to the newly created \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} on success 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em NULL} & on failure\\
\hline
\end{DoxyRetVals}
\begin{DoxySince}{Since}
1.\+0.\+0
\end{DoxySince}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} to \mbox{\hyperlink{classkdb_1_1KDB_a1b3ff4a68c2c935d67dce843bc4ad01b}{close}} the session of a \mbox{\hyperlink{classkdb_1_1Key}{Key}} database opened by \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} 
\end{DoxySeeAlso}


\doxysubsection{Member Function Documentation}
\mbox{\Hypertarget{classkdb_1_1KDB_a1b3ff4a68c2c935d67dce843bc4ad01b}\label{classkdb_1_1KDB_a1b3ff4a68c2c935d67dce843bc4ad01b}} 
\index{kdb::KDB@{kdb::KDB}!close@{close}}
\index{close@{close}!kdb::KDB@{kdb::KDB}}
\doxysubsubsection{\texorpdfstring{close()}{close()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily void kdb\+::\+KDB\+::close (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) throw ( ) \hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [virtual]}}



Close the database. 

The return value does not matter because its only a null pointer check.

Closes the session with the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database. \begin{DoxyPrecond}{Precondition}
The handle must be a valid handle as returned from \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} 

error\+Key must be a valid key, e.\+g. created with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}
\end{DoxyPrecond}
This is the counterpart of \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}}.

You must call this method when you are finished working with the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database. You can manipulate \mbox{\hyperlink{classkdb_1_1Key}{Key}} and \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} objects also after \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}}, but you must not use any kdb$\ast$() call afterwards.

The {\ttfamily handle} parameter will be finalized and all resources associated to it will be freed. After a \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}}, the {\ttfamily handle} cannot be used anymore.


\begin{DoxyParams}{Parameters}
{\em handle} & contains internal information of \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{opened }} key database \\
\hline
{\em error\+Key} & the key which holds error/warning information\\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em 0} & on success \\
\hline
{\em -\/1} & on NULL pointer\\
\hline
\end{DoxyRetVals}
\begin{DoxySince}{Since}
1.\+0.\+0
\end{DoxySince}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} for opening a session with a \mbox{\hyperlink{classkdb_1_1Key}{Key}} database 
\end{DoxySeeAlso}
\mbox{\Hypertarget{classkdb_1_1KDB_aa027a8f798a2cfee11ff712eb204c35d}\label{classkdb_1_1KDB_aa027a8f798a2cfee11ff712eb204c35d}} 
\index{kdb::KDB@{kdb::KDB}!close@{close}}
\index{close@{close}!kdb::KDB@{kdb::KDB}}
\doxysubsubsection{\texorpdfstring{close()}{close()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily void kdb\+::\+KDB\+::close (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{classkdb_1_1Key}{Key}} \&}]{error\+Key }\end{DoxyParamCaption}) throw ( ) \hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [virtual]}}



Close the database. 

The return value does not matter because its only a null pointer check.


\begin{DoxyParams}{Parameters}
{\em error\+Key} & is useful if you want to get the warnings\\
\hline
\end{DoxyParams}
Closes the session with the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database. \begin{DoxyPrecond}{Precondition}
The handle must be a valid handle as returned from \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} 

error\+Key must be a valid key, e.\+g. created with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}
\end{DoxyPrecond}
This is the counterpart of \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}}.

You must call this method when you are finished working with the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database. You can manipulate \mbox{\hyperlink{classkdb_1_1Key}{Key}} and \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} objects also after \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}}, but you must not use any kdb$\ast$() call afterwards.

The {\ttfamily handle} parameter will be finalized and all resources associated to it will be freed. After a \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}}, the {\ttfamily handle} cannot be used anymore.


\begin{DoxyParams}{Parameters}
{\em handle} & contains internal information of \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{opened }} key database \\
\hline
{\em error\+Key} & the key which holds error/warning information\\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em 0} & on success \\
\hline
{\em -\/1} & on NULL pointer\\
\hline
\end{DoxyRetVals}
\begin{DoxySince}{Since}
1.\+0.\+0
\end{DoxySince}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} for opening a session with a \mbox{\hyperlink{classkdb_1_1Key}{Key}} database 
\end{DoxySeeAlso}
\mbox{\Hypertarget{classkdb_1_1KDB_a48770a7290699bf2b7529f3ab67e378f}\label{classkdb_1_1KDB_a48770a7290699bf2b7529f3ab67e378f}} 
\index{kdb::KDB@{kdb::KDB}!get@{get}}
\index{get@{get}!kdb::KDB@{kdb::KDB}}
\doxysubsubsection{\texorpdfstring{get()}{get()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily int kdb\+::\+KDB\+::get (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} \&}]{returned,  }\item[{\mbox{\hyperlink{classkdb_1_1Key}{Key}} \&}]{parent\+Key }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [virtual]}}



Get all keys below parent\+Key inside returned. 

Retrieve Keys from the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database in an atomic and universal way. \begin{DoxyPrecond}{Precondition}
The {\ttfamily handle} must be a valid \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} handle as returned from \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}}. 

The \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} {\ttfamily returned} must be a valid \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}}, i.\+e., constructed with \mbox{\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ks\+New()}}. 

The \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} {\ttfamily returned} must contain keys only from the {\ttfamily spec\+:/}, {\ttfamily dir\+:/}, {\ttfamily user\+:/}, {\ttfamily system\+:/}, {\ttfamily default\+:/} or {\ttfamily proc\+:/} namespaces. 

The \mbox{\hyperlink{classkdb_1_1Key}{Key}} {\ttfamily parent\+Key} must be a valid \mbox{\hyperlink{classkdb_1_1Key}{Key}}, i.\+e., constructed with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}. 

The \mbox{\hyperlink{classkdb_1_1Key}{Key}} {\ttfamily parent\+Key} must not have read-\/only name, value or metadata. 

The \mbox{\hyperlink{classkdb_1_1Key}{Key}} {\ttfamily parent\+Key} must use the {\ttfamily spec\+:/}, {\ttfamily dir\+:/}, {\ttfamily user\+:/}, {\ttfamily system\+:/}, {\ttfamily default\+:/}, {\ttfamily proc\+:/} or cascading namespace.
\end{DoxyPrecond}
If you pass {\ttfamily NULL} or a key with read-\/only metadata as {\ttfamily parent\+Key}, \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} will fail immediately without doing anything. If you pass another invalid {\ttfamily parent\+Key}, or {\ttfamily NULL} as {\ttfamily ks} or {\ttfamily handle}, \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} will set an error on {\ttfamily parent\+Key} and then return immediately.

\begin{DoxyNote}{Note}
If you pass a non-\/\+NULL {\ttfamily parent\+Key} with writable metadata, \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} will {\bfseries{always}} remove any existing errors and warnings from {\ttfamily parent\+Key}.
\end{DoxyNote}
\begin{DoxyWarning}{Warning}
If you later call \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} with the same {\ttfamily handle} you must make sure to pass all keys from {\ttfamily ks}, which you do not want to remove.
\end{DoxyWarning}
\begin{DoxyParagraph}{Loadable Namespaces}

\end{DoxyParagraph}
Not all namespace can be loaded.


\begin{DoxyItemize}
\item {\ttfamily spec\+:/}, {\ttfamily dir\+:/}, {\ttfamily user\+:/} and {\ttfamily system\+:/} can be loaded via \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}}.
\item {\ttfamily proc\+:/} keys can be loaded via \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}}, but are not persisted or cached.
\item {\ttfamily default\+:/} keys can be inserted by \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} but they will always stem from a specification in {\ttfamily spec\+:/} keys.
\item If {\ttfamily ks} contains a key with any other namespace, an error will be returned.
\end{DoxyItemize}

\begin{DoxyParagraph}{Parent Key}

\end{DoxyParagraph}
The {\ttfamily parent\+Key} defines which parts of {\ttfamily ks} will be loaded. Everything that is at or below {\ttfamily parent\+Key} wil be loaded together with any key that shares a backend with such a key. Backends are always loaded as an atomic unit.

\begin{DoxyNote}{Note}
If {\ttfamily parent\+Key} is in the cascading namespace, keys of all loadable namespaces (see above) will be loaded. This is generally the recommended approach.
\end{DoxyNote}
Upon sucessfully returning \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} also sets the value of {\ttfamily parent\+Key} to the storage identifier used by the backend that contains (or would contain) {\ttfamily parent\+Key}. For file-\/based backends this is the absolute path of the underlying file. Other backends may use different identifiers, but it always uniquely identifies the underlying storage unit.

\begin{DoxyNote}{Note}
If {\ttfamily parent\+Key} is in the cascading, {\ttfamily default\+:/} or \`{}proc\+:/ namespace, the value of {\ttfamily parent\+Key} will be set to an empty string. This is done, because those namespaces are not persistable (see \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}}) and therfore have no storage identifier.
\end{DoxyNote}
\begin{DoxyParagraph}{Key\+Set Modifications}

\end{DoxyParagraph}
Below or at {\ttfamily parent\+Key}, the \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} {\ttfamily ks} will mostly contain keys loaded from backends. The only exception are {\ttfamily proc\+:/} and {\ttfamily spec\+:/} keys that were already present, before \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} was called and do not overlap with an existing backend (for those namespaces). This can be used to provide a hard-\/coded fallback specifications and/or process-\/specific data.

Keys not below (or at) {\ttfamily parent\+Key} that were present when \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} was called, may still be removed. For example, this could be because they overlap with a backend that also has keys below {\ttfamily parent\+Key} (backends are atomic units).

\begin{DoxyParagraph}{Example\+:}
This example demonstrates the typical usecase within an application (without error handling).
\end{DoxyParagraph}

\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <kdb.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <stdio.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int} \mbox{\hyperlink{testio__doc_8c_a3c04138a5bfe5d72780bb7e82a18e627}{main}} (\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{        KeySet * myConfig = \mbox{\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew}} (0, \mbox{\hyperlink{group__keyset_ga7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END}});}
\DoxyCodeLine{}
\DoxyCodeLine{        \textcolor{comment}{// for error handling see kdbget\_error.c}}
\DoxyCodeLine{}
\DoxyCodeLine{        \textcolor{comment}{// clang-\/format off}}
\DoxyCodeLine{\textcolor{comment}{}Key * key = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}/sw/tests/myapp/\#0/current/"{}},  \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{\mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * handle = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, key);}
\DoxyCodeLine{\mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet}} (handle, myConfig, key);}
\DoxyCodeLine{Key * result = \mbox{\hyperlink{group__keyset_gad65d2cdcbb5381194a1688e169af8a83}{ksLookupByName}} (myConfig, \textcolor{stringliteral}{"{}/sw/tests/myapp/\#0/current/testkey1"{}}, 0);}
\DoxyCodeLine{        \textcolor{comment}{// clang-\/format on}}
\DoxyCodeLine{}
\DoxyCodeLine{        \mbox{\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel}} (key);}
\DoxyCodeLine{}
\DoxyCodeLine{        \textcolor{keyword}{const} \textcolor{keywordtype}{char} * key\_name = \mbox{\hyperlink{group__keyname_ga8e805c726a60da921d3736cda7813513}{keyName}} (result);}
\DoxyCodeLine{        \textcolor{keyword}{const} \textcolor{keywordtype}{char} * key\_value = \mbox{\hyperlink{group__keyvalue_ga880936f2481d28e6e2acbe7486a21d05}{keyString}} (result);}
\DoxyCodeLine{        \textcolor{keyword}{const} \textcolor{keywordtype}{char} * key\_comment = \mbox{\hyperlink{group__keyvalue_ga880936f2481d28e6e2acbe7486a21d05}{keyString}} (\mbox{\hyperlink{group__keymeta_ga9ed3875495ddb3d8a8d29158a60a147c}{keyGetMeta}} (result, \textcolor{stringliteral}{"{}comment/\#0"{}}));}
\DoxyCodeLine{        printf (\textcolor{stringliteral}{"{}key: \%s value: \%s comment: \%s\(\backslash\)n"{}}, key\_name, key\_value, key\_comment);}
\DoxyCodeLine{}
\DoxyCodeLine{        \mbox{\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel}} (myConfig); \textcolor{comment}{// delete the in-\/memory configuration}}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{        \textcolor{comment}{// maybe you want kdbSet() myConfig here}}
\DoxyCodeLine{}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (handle, 0); \textcolor{comment}{// no more affairs with the key database.}}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


When a backend fails \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} will return -\/1 with all error and warning information in the {\ttfamily parent\+Key}. The parameter {\ttfamily returned} will not be changed.

\begin{DoxyParagraph}{Optimization\+:}
In the first run of kdb\+Get all requested (or more) Keys are retrieved. On subsequent calls only the Keys are retrieved where something was changed inside the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database. The other Keys stay in the \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} returned as passed.
\end{DoxyParagraph}
It is your responsibility to save the original \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} if you need it afterwards.

If you want to be sure to get a fresh \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} again, you need to open a second handle to the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database using \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}}.


\begin{DoxyParams}{Parameters}
{\em handle} & contains internal information of \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{opened }} key database \\
\hline
{\em parent\+Key} & Keys below {\ttfamily parent\+Key} will be retrieved from {\ttfamily handle}. It is also used to add warnings and set error information. \\
\hline
{\em ks} & the (pre-\/initialized) \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} returned with all keys found will not be changed on error or if no update is required\\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em 2} & if only {\ttfamily proc\+:/} backends were executed. This means no data was loaded from storage. There might be warnings attached to the parent\+Key! Depending on your use case, you might need to treat them as erorrs! \\
\hline
{\em 1} & if the Keys were retrieved successfully. There might be warnings attached to the parent\+Key! Depending on your use case, you might need to treat them as errors! \\
\hline
{\em 0} & if there was no update at all -\/ no changes are made to the \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} then. There might be warnings attached to the parent\+Key! Depending on your use case, you might need to treat them as erorrs! \\
\hline
{\em -\/1} & on failure -\/ no changes are made to the \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} then\\
\hline
\end{DoxyRetVals}
\begin{DoxySince}{Since}
1.\+0.\+0
\end{DoxySince}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{group__keyset_ga60f1ddcf23272f2b29b90e92ebe9b56f}{ks\+Lookup()}}, \mbox{\hyperlink{group__keyset_gad65d2cdcbb5381194a1688e169af8a83}{ks\+Lookup\+By\+Name()}} for powerful lookups after the \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} was retrieved 

\mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} which needs to be called before 

\mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} to save the configuration afterwards 

\mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} to finish affairs with the \mbox{\hyperlink{group__key}{Key}} database.
\end{DoxySeeAlso}

\begin{DoxyParams}{Parameters}
{\em returned} & the keyset where the keys will be in \\
\hline
{\em parent\+Key} & the parent\+Key of returned\\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em 0} & if no key was updated \\
\hline
{\em 1} & if user or system keys were updated \\
\hline
{\em 2} & if user and system keys were updated\\
\hline
\end{DoxyRetVals}

\begin{DoxyExceptions}{Exceptions}
{\em KDBException} & if there were problems with the database \\
\hline
\end{DoxyExceptions}


Reimplemented in \mbox{\hyperlink{classkdb_1_1tools_1_1merging_1_1MergingKDB_a062b1dac733aa3999691f8d70635b09c}{kdb\+::tools\+::merging\+::\+Merging\+KDB}}.

\mbox{\Hypertarget{classkdb_1_1KDB_a0419ffbc273c89756bc523b4223ec25a}\label{classkdb_1_1KDB_a0419ffbc273c89756bc523b4223ec25a}} 
\index{kdb::KDB@{kdb::KDB}!get@{get}}
\index{get@{get}!kdb::KDB@{kdb::KDB}}
\doxysubsubsection{\texorpdfstring{get()}{get()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily int kdb\+::\+KDB\+::get (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} \&}]{returned,  }\item[{std\+::string const \&}]{keyname }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [virtual]}}



Get all keys below keyname inside returned. 

Retrieve Keys from the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database in an atomic and universal way. \begin{DoxyPrecond}{Precondition}
The {\ttfamily handle} must be a valid \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} handle as returned from \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}}. 

The \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} {\ttfamily returned} must be a valid \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}}, i.\+e., constructed with \mbox{\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ks\+New()}}. 

The \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} {\ttfamily returned} must contain keys only from the {\ttfamily spec\+:/}, {\ttfamily dir\+:/}, {\ttfamily user\+:/}, {\ttfamily system\+:/}, {\ttfamily default\+:/} or {\ttfamily proc\+:/} namespaces. 

The \mbox{\hyperlink{classkdb_1_1Key}{Key}} {\ttfamily parent\+Key} must be a valid \mbox{\hyperlink{classkdb_1_1Key}{Key}}, i.\+e., constructed with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}. 

The \mbox{\hyperlink{classkdb_1_1Key}{Key}} {\ttfamily parent\+Key} must not have read-\/only name, value or metadata. 

The \mbox{\hyperlink{classkdb_1_1Key}{Key}} {\ttfamily parent\+Key} must use the {\ttfamily spec\+:/}, {\ttfamily dir\+:/}, {\ttfamily user\+:/}, {\ttfamily system\+:/}, {\ttfamily default\+:/}, {\ttfamily proc\+:/} or cascading namespace.
\end{DoxyPrecond}
If you pass {\ttfamily NULL} or a key with read-\/only metadata as {\ttfamily parent\+Key}, \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} will fail immediately without doing anything. If you pass another invalid {\ttfamily parent\+Key}, or {\ttfamily NULL} as {\ttfamily ks} or {\ttfamily handle}, \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} will set an error on {\ttfamily parent\+Key} and then return immediately.

\begin{DoxyNote}{Note}
If you pass a non-\/\+NULL {\ttfamily parent\+Key} with writable metadata, \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} will {\bfseries{always}} remove any existing errors and warnings from {\ttfamily parent\+Key}.
\end{DoxyNote}
\begin{DoxyWarning}{Warning}
If you later call \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} with the same {\ttfamily handle} you must make sure to pass all keys from {\ttfamily ks}, which you do not want to remove.
\end{DoxyWarning}
\begin{DoxyParagraph}{Loadable Namespaces}

\end{DoxyParagraph}
Not all namespace can be loaded.


\begin{DoxyItemize}
\item {\ttfamily spec\+:/}, {\ttfamily dir\+:/}, {\ttfamily user\+:/} and {\ttfamily system\+:/} can be loaded via \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}}.
\item {\ttfamily proc\+:/} keys can be loaded via \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}}, but are not persisted or cached.
\item {\ttfamily default\+:/} keys can be inserted by \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} but they will always stem from a specification in {\ttfamily spec\+:/} keys.
\item If {\ttfamily ks} contains a key with any other namespace, an error will be returned.
\end{DoxyItemize}

\begin{DoxyParagraph}{Parent Key}

\end{DoxyParagraph}
The {\ttfamily parent\+Key} defines which parts of {\ttfamily ks} will be loaded. Everything that is at or below {\ttfamily parent\+Key} wil be loaded together with any key that shares a backend with such a key. Backends are always loaded as an atomic unit.

\begin{DoxyNote}{Note}
If {\ttfamily parent\+Key} is in the cascading namespace, keys of all loadable namespaces (see above) will be loaded. This is generally the recommended approach.
\end{DoxyNote}
Upon sucessfully returning \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} also sets the value of {\ttfamily parent\+Key} to the storage identifier used by the backend that contains (or would contain) {\ttfamily parent\+Key}. For file-\/based backends this is the absolute path of the underlying file. Other backends may use different identifiers, but it always uniquely identifies the underlying storage unit.

\begin{DoxyNote}{Note}
If {\ttfamily parent\+Key} is in the cascading, {\ttfamily default\+:/} or \`{}proc\+:/ namespace, the value of {\ttfamily parent\+Key} will be set to an empty string. This is done, because those namespaces are not persistable (see \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}}) and therfore have no storage identifier.
\end{DoxyNote}
\begin{DoxyParagraph}{Key\+Set Modifications}

\end{DoxyParagraph}
Below or at {\ttfamily parent\+Key}, the \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} {\ttfamily ks} will mostly contain keys loaded from backends. The only exception are {\ttfamily proc\+:/} and {\ttfamily spec\+:/} keys that were already present, before \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} was called and do not overlap with an existing backend (for those namespaces). This can be used to provide a hard-\/coded fallback specifications and/or process-\/specific data.

Keys not below (or at) {\ttfamily parent\+Key} that were present when \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} was called, may still be removed. For example, this could be because they overlap with a backend that also has keys below {\ttfamily parent\+Key} (backends are atomic units).

\begin{DoxyParagraph}{Example\+:}
This example demonstrates the typical usecase within an application (without error handling).
\end{DoxyParagraph}

\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <kdb.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <stdio.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int} \mbox{\hyperlink{testio__doc_8c_a3c04138a5bfe5d72780bb7e82a18e627}{main}} (\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{        KeySet * myConfig = \mbox{\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew}} (0, \mbox{\hyperlink{group__keyset_ga7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END}});}
\DoxyCodeLine{}
\DoxyCodeLine{        \textcolor{comment}{// for error handling see kdbget\_error.c}}
\DoxyCodeLine{}
\DoxyCodeLine{        \textcolor{comment}{// clang-\/format off}}
\DoxyCodeLine{\textcolor{comment}{}Key * key = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}/sw/tests/myapp/\#0/current/"{}},  \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{\mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * handle = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, key);}
\DoxyCodeLine{\mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet}} (handle, myConfig, key);}
\DoxyCodeLine{Key * result = \mbox{\hyperlink{group__keyset_gad65d2cdcbb5381194a1688e169af8a83}{ksLookupByName}} (myConfig, \textcolor{stringliteral}{"{}/sw/tests/myapp/\#0/current/testkey1"{}}, 0);}
\DoxyCodeLine{        \textcolor{comment}{// clang-\/format on}}
\DoxyCodeLine{}
\DoxyCodeLine{        \mbox{\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel}} (key);}
\DoxyCodeLine{}
\DoxyCodeLine{        \textcolor{keyword}{const} \textcolor{keywordtype}{char} * key\_name = \mbox{\hyperlink{group__keyname_ga8e805c726a60da921d3736cda7813513}{keyName}} (result);}
\DoxyCodeLine{        \textcolor{keyword}{const} \textcolor{keywordtype}{char} * key\_value = \mbox{\hyperlink{group__keyvalue_ga880936f2481d28e6e2acbe7486a21d05}{keyString}} (result);}
\DoxyCodeLine{        \textcolor{keyword}{const} \textcolor{keywordtype}{char} * key\_comment = \mbox{\hyperlink{group__keyvalue_ga880936f2481d28e6e2acbe7486a21d05}{keyString}} (\mbox{\hyperlink{group__keymeta_ga9ed3875495ddb3d8a8d29158a60a147c}{keyGetMeta}} (result, \textcolor{stringliteral}{"{}comment/\#0"{}}));}
\DoxyCodeLine{        printf (\textcolor{stringliteral}{"{}key: \%s value: \%s comment: \%s\(\backslash\)n"{}}, key\_name, key\_value, key\_comment);}
\DoxyCodeLine{}
\DoxyCodeLine{        \mbox{\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel}} (myConfig); \textcolor{comment}{// delete the in-\/memory configuration}}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{        \textcolor{comment}{// maybe you want kdbSet() myConfig here}}
\DoxyCodeLine{}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (handle, 0); \textcolor{comment}{// no more affairs with the key database.}}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


When a backend fails \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} will return -\/1 with all error and warning information in the {\ttfamily parent\+Key}. The parameter {\ttfamily returned} will not be changed.

\begin{DoxyParagraph}{Optimization\+:}
In the first run of kdb\+Get all requested (or more) Keys are retrieved. On subsequent calls only the Keys are retrieved where something was changed inside the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database. The other Keys stay in the \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} returned as passed.
\end{DoxyParagraph}
It is your responsibility to save the original \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} if you need it afterwards.

If you want to be sure to get a fresh \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} again, you need to open a second handle to the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database using \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}}.


\begin{DoxyParams}{Parameters}
{\em handle} & contains internal information of \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{opened }} key database \\
\hline
{\em parent\+Key} & Keys below {\ttfamily parent\+Key} will be retrieved from {\ttfamily handle}. It is also used to add warnings and set error information. \\
\hline
{\em ks} & the (pre-\/initialized) \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} returned with all keys found will not be changed on error or if no update is required\\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em 2} & if only {\ttfamily proc\+:/} backends were executed. This means no data was loaded from storage. There might be warnings attached to the parent\+Key! Depending on your use case, you might need to treat them as erorrs! \\
\hline
{\em 1} & if the Keys were retrieved successfully. There might be warnings attached to the parent\+Key! Depending on your use case, you might need to treat them as errors! \\
\hline
{\em 0} & if there was no update at all -\/ no changes are made to the \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} then. There might be warnings attached to the parent\+Key! Depending on your use case, you might need to treat them as erorrs! \\
\hline
{\em -\/1} & on failure -\/ no changes are made to the \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} then\\
\hline
\end{DoxyRetVals}
\begin{DoxySince}{Since}
1.\+0.\+0
\end{DoxySince}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{group__keyset_ga60f1ddcf23272f2b29b90e92ebe9b56f}{ks\+Lookup()}}, \mbox{\hyperlink{group__keyset_gad65d2cdcbb5381194a1688e169af8a83}{ks\+Lookup\+By\+Name()}} for powerful lookups after the \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} was retrieved 

\mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} which needs to be called before 

\mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} to save the configuration afterwards 

\mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} to finish affairs with the \mbox{\hyperlink{group__key}{Key}} database.
\end{DoxySeeAlso}

\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <\mbox{\hyperlink{kdb_8hpp}{kdb.hpp}}>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <\mbox{\hyperlink{keyio_8hpp}{keyio.hpp}}>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{using namespace }\mbox{\hyperlink{namespacekdb}{kdb}};}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int} \mbox{\hyperlink{testio__doc_8c_a3c04138a5bfe5d72780bb7e82a18e627}{main}} ()}
\DoxyCodeLine{\{}
\DoxyCodeLine{        KeySet config;}
\DoxyCodeLine{        \mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} \mbox{\hyperlink{namespacekdb}{kdb}};}
\DoxyCodeLine{        \mbox{\hyperlink{namespacekdb}{kdb}}.get (config, \textcolor{stringliteral}{"{}/sw/MyApp"{}});}
\DoxyCodeLine{}
\DoxyCodeLine{        Key k = config.lookup (\textcolor{stringliteral}{"{}/sw/MyApp/mykey"{}});}
\DoxyCodeLine{        \textcolor{keywordflow}{if} (k)}
\DoxyCodeLine{        \{}
\DoxyCodeLine{                std::cout << k << \textcolor{stringliteral}{"{} is "{}} << k.get<\textcolor{keywordtype}{int}> () << std::endl;}
\DoxyCodeLine{        \}}
\DoxyCodeLine{        \textcolor{keywordflow}{else}}
\DoxyCodeLine{        \{}
\DoxyCodeLine{                std::cerr << \textcolor{stringliteral}{"{}No key found"{}} << std::endl;}
\DoxyCodeLine{                \textcolor{keywordflow}{return} 1;}
\DoxyCodeLine{        \}}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}



\begin{DoxyParams}{Parameters}
{\em returned} & the keyset where the keys will be in \\
\hline
{\em keyname} & the root keyname which should be used to get keys below it\\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em 0} & if no key was updated \\
\hline
{\em 1} & if user or system keys were updated \\
\hline
{\em 2} & if user and system keys were updated\\
\hline
\end{DoxyRetVals}

\begin{DoxyExceptions}{Exceptions}
{\em KDBException} & if there were problems with the database\\
\hline
\end{DoxyExceptions}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{classkdb_1_1KDB_a0419ffbc273c89756bc523b4223ec25a}{KDB\+::get}} (\mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} \& returned, \mbox{\hyperlink{classkdb_1_1Key}{Key}} \& parent\+Key) 
\end{DoxySeeAlso}


Reimplemented in \mbox{\hyperlink{classkdb_1_1tools_1_1merging_1_1MergingKDB_a0d2a28f24aeb6ba3e81af73ef8b98df7}{kdb\+::tools\+::merging\+::\+Merging\+KDB}}.

\mbox{\Hypertarget{classkdb_1_1KDB_aee37484b06164eacc0cc11b7b40ab892}\label{classkdb_1_1KDB_aee37484b06164eacc0cc11b7b40ab892}} 
\index{kdb::KDB@{kdb::KDB}!open@{open}}
\index{open@{open}!kdb::KDB@{kdb::KDB}}
\doxysubsubsection{\texorpdfstring{open()}{open()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily void kdb\+::\+KDB\+::open (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{classkdb_1_1Key}{Key}} \&}]{error\+Key }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [virtual]}}



Open the database. 


\begin{DoxyParams}{Parameters}
{\em error\+Key} & is useful if you want to get the warnings in the successful case, when no exception is thrown.\\
\hline
\end{DoxyParams}
Opens the session with the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database. \begin{DoxyPrecond}{Precondition}
error\+Key must be a valid key, e.\+g. created with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}
\end{DoxyPrecond}
You must always call this method before retrieving or committing any keys to the database. At the end of a program, after using the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database (\mbox{\hyperlink{classkdb_1_1KDB}{KDB}}), you must not forget to call \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} to free resources.

The method will bootstrap itself in the following way. The first step is to open the default backend. With it {\ttfamily system\+:/elektra/mountpoints} will be loaded and all needed libraries and mountpoints will be determined. Then the global plugins and global keyset data from the {\ttfamily contract} is processed. Finally, the libraries for backends will be loaded and with it the {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} data structure will be initialized.

The pointer to the {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} structure returned will be initialized like described above, and it must be passed along on any kdb$\ast$() method your application calls.

Get a {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} handle for every thread using elektra. Don\textquotesingle{}t share the handle across threads, and also not the pointer accessing it\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keywordtype}{void} thread1 (\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{        Key * parent = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}/app/part1"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{        \mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * h = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, parent);}
\DoxyCodeLine{        \textcolor{comment}{// fetch keys and work with them}}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (h, parent);}
\DoxyCodeLine{\}}
\DoxyCodeLine{\textcolor{keywordtype}{void} thread2 (\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{        Key * parent = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}/app/part2"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{        \mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * h = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, parent);}
\DoxyCodeLine{        \textcolor{comment}{// fetch keys and work with them}}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (h, parent);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 You don\textquotesingle{}t need \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} if you only want to manipulate plain in-\/memory \mbox{\hyperlink{classkdb_1_1Key}{Key}} or \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} objects.

\begin{DoxyPrecond}{Precondition}
error\+Key must be a valid key, e.\+g. created with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}
\end{DoxyPrecond}

\begin{DoxyParams}{Parameters}
{\em contract} & the contract that should be ensured before opening the \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} all data is copied and the \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} can safely be used for e.\+g. \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} later \\
\hline
{\em error\+Key} & the key which holds errors and warnings which were issued\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
handle to the newly created \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} on success 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em NULL} & on failure\\
\hline
\end{DoxyRetVals}
\begin{DoxySince}{Since}
1.\+0.\+0
\end{DoxySince}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} to \mbox{\hyperlink{classkdb_1_1KDB_a1b3ff4a68c2c935d67dce843bc4ad01b}{close}} the session of a \mbox{\hyperlink{classkdb_1_1Key}{Key}} database opened by \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{classkdb_1_1KDB_a8bd17da51bd531a2726185e7bbf4ecf9}\label{classkdb_1_1KDB_a8bd17da51bd531a2726185e7bbf4ecf9}} 
\index{kdb::KDB@{kdb::KDB}!open@{open}}
\index{open@{open}!kdb::KDB@{kdb::KDB}}
\doxysubsubsection{\texorpdfstring{open()}{open()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily void kdb\+::\+KDB\+::open (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} \&}]{contract,  }\item[{\mbox{\hyperlink{classkdb_1_1Key}{Key}} \&}]{error\+Key }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [virtual]}}



Open the database. 


\begin{DoxyParams}{Parameters}
{\em contract} & the contract that should be ensured \\
\hline
{\em error\+Key} & is useful if you want to get the warnings in the successful case, when no exception is thrown.\\
\hline
\end{DoxyParams}
Opens the session with the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database. \begin{DoxyPrecond}{Precondition}
error\+Key must be a valid key, e.\+g. created with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}
\end{DoxyPrecond}
You must always call this method before retrieving or committing any keys to the database. At the end of a program, after using the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database (\mbox{\hyperlink{classkdb_1_1KDB}{KDB}}), you must not forget to call \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} to free resources.

The method will bootstrap itself in the following way. The first step is to open the default backend. With it {\ttfamily system\+:/elektra/mountpoints} will be loaded and all needed libraries and mountpoints will be determined. Then the global plugins and global keyset data from the {\ttfamily contract} is processed. Finally, the libraries for backends will be loaded and with it the {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} data structure will be initialized.

The pointer to the {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} structure returned will be initialized like described above, and it must be passed along on any kdb$\ast$() method your application calls.

Get a {\ttfamily \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}} handle for every thread using elektra. Don\textquotesingle{}t share the handle across threads, and also not the pointer accessing it\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{keywordtype}{void} thread1 (\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{        Key * parent = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}/app/part1"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{        \mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * h = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, parent);}
\DoxyCodeLine{        \textcolor{comment}{// fetch keys and work with them}}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (h, parent);}
\DoxyCodeLine{\}}
\DoxyCodeLine{\textcolor{keywordtype}{void} thread2 (\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{        Key * parent = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}/app/part2"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{        \mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * h = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, parent);}
\DoxyCodeLine{        \textcolor{comment}{// fetch keys and work with them}}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (h, parent);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}
 You don\textquotesingle{}t need \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} if you only want to manipulate plain in-\/memory \mbox{\hyperlink{classkdb_1_1Key}{Key}} or \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} objects.

\begin{DoxyPrecond}{Precondition}
error\+Key must be a valid key, e.\+g. created with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}
\end{DoxyPrecond}

\begin{DoxyParams}{Parameters}
{\em contract} & the contract that should be ensured before opening the \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} all data is copied and the \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} can safely be used for e.\+g. \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} later \\
\hline
{\em error\+Key} & the key which holds errors and warnings which were issued\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
handle to the newly created \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} on success 
\end{DoxyReturn}

\begin{DoxyRetVals}{Return values}
{\em NULL} & on failure\\
\hline
\end{DoxyRetVals}
\begin{DoxySince}{Since}
1.\+0.\+0
\end{DoxySince}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} to \mbox{\hyperlink{classkdb_1_1KDB_a1b3ff4a68c2c935d67dce843bc4ad01b}{close}} the session of a \mbox{\hyperlink{classkdb_1_1Key}{Key}} database opened by \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{classkdb_1_1KDB_a62a4fafbe21d9519b31a7868aa05f3e3}\label{classkdb_1_1KDB_a62a4fafbe21d9519b31a7868aa05f3e3}} 
\index{kdb::KDB@{kdb::KDB}!set@{set}}
\index{set@{set}!kdb::KDB@{kdb::KDB}}
\doxysubsubsection{\texorpdfstring{set()}{set()}\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily int kdb\+::\+KDB\+::set (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} \&}]{returned,  }\item[{\mbox{\hyperlink{classkdb_1_1Key}{Key}} \&}]{parent\+Key }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [virtual]}}



Set all keys below parent\+Key. 

If the keyname of the parent\+Key is invalid (e.\+g. empty) all keys will be set.

Set Keys to the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database in an atomic and universal way. \begin{DoxyPrecond}{Precondition}
\mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} must be called before \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}}\+:
\begin{DoxyItemize}
\item initially (after \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}})
\item after conflict errors in \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}}. 
\end{DoxyItemize}

The \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} {\ttfamily returned} must be a valid \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}}, i.\+e., constructed with \mbox{\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ks\+New()}}. 

The \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} {\ttfamily returend} must only contain only keys in the {\ttfamily spec\+:/}, {\ttfamily dir\+:/}, {\ttfamily user\+:/}, {\ttfamily system\+:/}, {\ttfamily default\+:/} or {\ttfamily proc\+:/} namespaces. 

The \mbox{\hyperlink{classkdb_1_1Key}{Key}} {\ttfamily parent\+Key} must be a valid \mbox{\hyperlink{classkdb_1_1Key}{Key}}, e.\+g. constructed with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}. 

The \mbox{\hyperlink{classkdb_1_1Key}{Key}} {\ttfamily parent\+Key} must not have read-\/only name, value or metadata. 

The \mbox{\hyperlink{classkdb_1_1Key}{Key}} {\ttfamily parent\+Key} must use the {\ttfamily spec\+:/}, {\ttfamily dir\+:/}, {\ttfamily user\+:/}, {\ttfamily system\+:/}, {\ttfamily default\+:/}, {\ttfamily proc\+:/} or cascading namespace.
\end{DoxyPrecond}
If you pass {\ttfamily NULL} or a key with read-\/only metadata as {\ttfamily parent\+Key}, \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} will fail immediately without doing anything. If you pass another invalid {\ttfamily parent\+Key}, or {\ttfamily NULL} as {\ttfamily ks} or {\ttfamily handle}, \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} will set an error on {\ttfamily parent\+Key} and then return immediately.

\begin{DoxyNote}{Note}
If you pass a non-\/\+NULL {\ttfamily parent\+Key} with writable metadata, \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} will {\bfseries{always}} remove any existing errors and warnings from {\ttfamily parent\+Key}.
\end{DoxyNote}
\begin{DoxyParagraph}{Persistable Namespaces}

\end{DoxyParagraph}
Not all namespace can be persisted.


\begin{DoxyItemize}
\item {\ttfamily spec\+:/}, {\ttfamily dir\+:/}, {\ttfamily user\+:/} and {\ttfamily system\+:/} will be persisted by \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}}.
\item {\ttfamily default\+:/} and {\ttfamily proc\+:/} keys are ignored by \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}}.
\item If {\ttfamily ks} contains a key with any other namespace, an error will be returned.
\end{DoxyItemize}

In general it is recommended to use a {\ttfamily parent\+Key} in the cascading namespace to cover all namespaces at once.

\begin{DoxyParagraph}{Parent Key}

\end{DoxyParagraph}
The {\ttfamily parent\+Key} defines which parts of {\ttfamily ks} will be stored. Everything that is at or below {\ttfamily parent\+Key} wil be persisted together with any key that shares a backend with such a key. Backends are always stored as an atomic unit.

\begin{DoxyNote}{Note}
If {\ttfamily parent\+Key} is in the cascading namespace, keys of all persistable namspaces (see above) will be stored. This is generally the recommended approach.
\end{DoxyNote}
\begin{DoxyParagraph}{Key\+Set modifications}

\end{DoxyParagraph}
The contents of {\ttfamily ks} will mostly not be modified by \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}}. The only modifications made are those caused by applying the specification in {\ttfamily spec\+:/} to {\ttfamily dir\+:/}, {\ttfamily user\+:/} and {\ttfamily system\+:/}.

\begin{DoxyParagraph}{Errors}
If {\ttfamily parent\+Key == NULL} or {\ttfamily parent\+Key} has read-\/only metadata, \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} will immediately return the error code -\/1. In all other error cases the following happens\+:
\begin{DoxyItemize}
\item Error information will be written into the metadata of the parent key, if possible.
\item None of the keys are actually committed in this situation, i.\+e. no configuration file will be modified.
\end{DoxyItemize}
\end{DoxyParagraph}
In case of errors you should present the error message to the user and let the user decide what to do. Possible solutions are\+:
\begin{DoxyItemize}
\item remove the problematic key and use \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} again (for validation or type errors)
\item change the value of the problematic key and use \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} again (for validation errors)
\item do a \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} (for conflicts, i.\+e. error C02000) and then
\begin{DoxyItemize}
\item set the same keyset again (in favour of what was set by this user)
\item drop the old keyset (in favour of what was set from another application)
\item merge the original, your own and the other keyset
\end{DoxyItemize}
\item export the configuration into a file (for unresolvable errors)
\item repeating the same \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} might be of limited use, if the user does not explicitly request it, because temporary errors are rare and its unlikely that they fix themselves (e.\+g. disc full, permission problems)
\end{DoxyItemize}

\begin{DoxyParagraph}{Optimization}
Only backends that
\begin{DoxyItemize}
\item contain at least changed key according to \mbox{\hyperlink{group__keytest_gaf247df0de7aca04b32ef80e39ef12950}{key\+Need\+Sync()}},
\item contain fewer keys than at the end of \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} will be called. There won\textquotesingle{}t be an unnecessary write for unchanged keys.
\end{DoxyItemize}
\end{DoxyParagraph}
If none of the backends need an update, \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} returns 0 and does nothing.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{KeySet * myConfig = \mbox{\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew}} (0, \mbox{\hyperlink{group__keyset_ga7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END}});}
\DoxyCodeLine{Key * parentKey = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}system:/sw/MyApp"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{\mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * handle = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, parentKey);}
\DoxyCodeLine{}
\DoxyCodeLine{\mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet}} (handle, myConfig, parentKey); \textcolor{comment}{// kdbGet needs to be called first!}}
\DoxyCodeLine{KeySet * base = \mbox{\hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ksDup}} (myConfig);     \textcolor{comment}{// save a copy of original keyset}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{// change the keys within myConfig}}
\DoxyCodeLine{\mbox{\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey}} (myConfig, \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}system:/sw/MyApp/Test"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE}}, \textcolor{stringliteral}{"{}5"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}}));}
\DoxyCodeLine{}
\DoxyCodeLine{KeySet * ours = \mbox{\hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ksDup}} (myConfig); \textcolor{comment}{// save a copy of our keyset}}
\DoxyCodeLine{KeySet * theirs;                  \textcolor{comment}{// needed for 3-\/way merging}}
\DoxyCodeLine{\textcolor{keywordtype}{int} ret = \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdbSet}} (handle, myConfig, parentKey);}
\DoxyCodeLine{\textcolor{keywordflow}{while} (ret == -\/1) \textcolor{comment}{// as long as we have an error}}
\DoxyCodeLine{\{}
\DoxyCodeLine{        \textcolor{keywordtype}{int} strategy = showElektraErrorDialog (parentKey);}
\DoxyCodeLine{        theirs = \mbox{\hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ksDup}} (ours);}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet}} (handle, theirs, parentKey); \textcolor{comment}{// refresh key database}}
\DoxyCodeLine{        KeySet * result = \mbox{\hyperlink{kdbmerge_8h_a2cc0dc19c99b2bc86feb1f2607df343a}{elektraMerge}}(}
\DoxyCodeLine{                \mbox{\hyperlink{group__keyset_ga6b00cf82b59af4d883a9bad6cf4a4a4a}{ksCut}}(ours, parentKey), parentKey,}
\DoxyCodeLine{                \mbox{\hyperlink{group__keyset_ga6b00cf82b59af4d883a9bad6cf4a4a4a}{ksCut}}(theirs, parentKey), parentKey,}
\DoxyCodeLine{                \mbox{\hyperlink{group__keyset_ga6b00cf82b59af4d883a9bad6cf4a4a4a}{ksCut}}(base, parentKey), parentKey,}
\DoxyCodeLine{                parentKey, strategy, parentKey);}
\DoxyCodeLine{        \textcolor{keywordtype}{int} numberOfConflicts = \mbox{\hyperlink{kdbmerge_8h_aa4b4c9a6f50a1f5d602fc84c8abce208}{elektraMergeGetConflicts}} (parentKey);}
\DoxyCodeLine{        \mbox{\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel}} (theirs);}
\DoxyCodeLine{        \textcolor{keywordflow}{if} (result != NULL) \{}
\DoxyCodeLine{                ret = \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdbSet}} (handle, result, parentKey);}
\DoxyCodeLine{        \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{                \textcolor{comment}{// an error happened while merging}}
\DoxyCodeLine{                \textcolor{keywordflow}{if} (numberOfConflicts > 0 \&\& strategy == \mbox{\hyperlink{kdbmerge_8h_a2c76c3f8b54a741ba9fdbfe6b5e0ee5caeaf7be70515ee5bc9b6dae1c844ec492}{MERGE\_STRATEGY\_ABORT}})}
\DoxyCodeLine{                \{}
\DoxyCodeLine{                        \textcolor{comment}{// Error due to merge conflicts}}
\DoxyCodeLine{                        ret = -\/1;}
\DoxyCodeLine{                \}}
\DoxyCodeLine{                \textcolor{keywordflow}{else}}
\DoxyCodeLine{                \{}
\DoxyCodeLine{                        \textcolor{comment}{// Internal errors, out of memory etc.}}
\DoxyCodeLine{                        ret = -\/1;}
\DoxyCodeLine{                \}}
\DoxyCodeLine{        \}}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\mbox{\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel}} (ours);}
\DoxyCodeLine{\mbox{\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel}} (base);}
\DoxyCodeLine{\mbox{\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel}} (myConfig); \textcolor{comment}{// delete the in-\/memory configuration}}
\DoxyCodeLine{}
\DoxyCodeLine{\mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (handle, parentKey); \textcolor{comment}{// no more affairs with the key database.}}
\DoxyCodeLine{\mbox{\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel}} (parentKey);}

\end{DoxyCodeInclude}
 show\+Elektra\+Error\+Dialog() and do\+Elektra\+Merge() need to be implemented by the user of Elektra. For do\+Elektra\+Merge a 3-\/way merge algorithm exists in libelektra-\/tools.


\begin{DoxyParams}{Parameters}
{\em handle} & contains internal information of \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{opened }} key database \\
\hline
{\em ks} & a \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} which should contain changed keys, otherwise nothing is done \\
\hline
{\em parent\+Key} & Keys below {\ttfamily parent\+Key} will be set to {\ttfamily handle}. It is also used to add warnings and set error information.\\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em 1} & on success \\
\hline
{\em 0} & if nothing had to be done, no changes in \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} \\
\hline
{\em -\/1} & on failure, no changes in \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}, an error will be set on {\ttfamily parent\+Key} if possible (see \char`\"{}\+Errors\char`\"{} above)\\
\hline
\end{DoxyRetVals}
\begin{DoxySince}{Since}
1.\+0.\+0
\end{DoxySince}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} for getting {\ttfamily handle} 

\mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} that must be called afterwards 

\mbox{\hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()}} contains the error \mbox{\hyperlink{classkdb_1_1Key}{Key}}
\end{DoxySeeAlso}

\begin{DoxyRetVals}{Return values}
{\em 0} & if no key was updated \\
\hline
{\em 1} & if user or system keys were updated \\
\hline
{\em 2} & if user and system keys were updated\\
\hline
\end{DoxyRetVals}

\begin{DoxyParams}{Parameters}
{\em returned} & the keyset where the keys are passed to the user \\
\hline
{\em parent\+Key} & the parent\+Key of returned\\
\hline
\end{DoxyParams}

\begin{DoxyExceptions}{Exceptions}
{\em KDBException} & if there were problems with the database \\
\hline
\end{DoxyExceptions}
\mbox{\Hypertarget{classkdb_1_1KDB_a29087a6a1a7de334f4e5b62ffe5d6e6e}\label{classkdb_1_1KDB_a29087a6a1a7de334f4e5b62ffe5d6e6e}} 
\index{kdb::KDB@{kdb::KDB}!set@{set}}
\index{set@{set}!kdb::KDB@{kdb::KDB}}
\doxysubsubsection{\texorpdfstring{set()}{set()}\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily int kdb\+::\+KDB\+::set (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} \&}]{returned,  }\item[{std\+::string const \&}]{keyname }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [virtual]}}



Set all keys below keyname. 

If the keyname of the parent\+Key is invalid (e.\+g. empty) all keys will be set.

Set Keys to the \mbox{\hyperlink{classkdb_1_1Key}{Key}} database in an atomic and universal way. \begin{DoxyPrecond}{Precondition}
\mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} must be called before \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}}\+:
\begin{DoxyItemize}
\item initially (after \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}})
\item after conflict errors in \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}}. 
\end{DoxyItemize}

The \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} {\ttfamily returned} must be a valid \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}}, i.\+e., constructed with \mbox{\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ks\+New()}}. 

The \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} {\ttfamily returend} must only contain only keys in the {\ttfamily spec\+:/}, {\ttfamily dir\+:/}, {\ttfamily user\+:/}, {\ttfamily system\+:/}, {\ttfamily default\+:/} or {\ttfamily proc\+:/} namespaces. 

The \mbox{\hyperlink{classkdb_1_1Key}{Key}} {\ttfamily parent\+Key} must be a valid \mbox{\hyperlink{classkdb_1_1Key}{Key}}, e.\+g. constructed with \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{key\+New()}}. 

The \mbox{\hyperlink{classkdb_1_1Key}{Key}} {\ttfamily parent\+Key} must not have read-\/only name, value or metadata. 

The \mbox{\hyperlink{classkdb_1_1Key}{Key}} {\ttfamily parent\+Key} must use the {\ttfamily spec\+:/}, {\ttfamily dir\+:/}, {\ttfamily user\+:/}, {\ttfamily system\+:/}, {\ttfamily default\+:/}, {\ttfamily proc\+:/} or cascading namespace.
\end{DoxyPrecond}
If you pass {\ttfamily NULL} or a key with read-\/only metadata as {\ttfamily parent\+Key}, \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} will fail immediately without doing anything. If you pass another invalid {\ttfamily parent\+Key}, or {\ttfamily NULL} as {\ttfamily ks} or {\ttfamily handle}, \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} will set an error on {\ttfamily parent\+Key} and then return immediately.

\begin{DoxyNote}{Note}
If you pass a non-\/\+NULL {\ttfamily parent\+Key} with writable metadata, \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} will {\bfseries{always}} remove any existing errors and warnings from {\ttfamily parent\+Key}.
\end{DoxyNote}
\begin{DoxyParagraph}{Persistable Namespaces}

\end{DoxyParagraph}
Not all namespace can be persisted.


\begin{DoxyItemize}
\item {\ttfamily spec\+:/}, {\ttfamily dir\+:/}, {\ttfamily user\+:/} and {\ttfamily system\+:/} will be persisted by \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}}.
\item {\ttfamily default\+:/} and {\ttfamily proc\+:/} keys are ignored by \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}}.
\item If {\ttfamily ks} contains a key with any other namespace, an error will be returned.
\end{DoxyItemize}

In general it is recommended to use a {\ttfamily parent\+Key} in the cascading namespace to cover all namespaces at once.

\begin{DoxyParagraph}{Parent Key}

\end{DoxyParagraph}
The {\ttfamily parent\+Key} defines which parts of {\ttfamily ks} will be stored. Everything that is at or below {\ttfamily parent\+Key} wil be persisted together with any key that shares a backend with such a key. Backends are always stored as an atomic unit.

\begin{DoxyNote}{Note}
If {\ttfamily parent\+Key} is in the cascading namespace, keys of all persistable namspaces (see above) will be stored. This is generally the recommended approach.
\end{DoxyNote}
\begin{DoxyParagraph}{Key\+Set modifications}

\end{DoxyParagraph}
The contents of {\ttfamily ks} will mostly not be modified by \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}}. The only modifications made are those caused by applying the specification in {\ttfamily spec\+:/} to {\ttfamily dir\+:/}, {\ttfamily user\+:/} and {\ttfamily system\+:/}.

\begin{DoxyParagraph}{Errors}
If {\ttfamily parent\+Key == NULL} or {\ttfamily parent\+Key} has read-\/only metadata, \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} will immediately return the error code -\/1. In all other error cases the following happens\+:
\begin{DoxyItemize}
\item Error information will be written into the metadata of the parent key, if possible.
\item None of the keys are actually committed in this situation, i.\+e. no configuration file will be modified.
\end{DoxyItemize}
\end{DoxyParagraph}
In case of errors you should present the error message to the user and let the user decide what to do. Possible solutions are\+:
\begin{DoxyItemize}
\item remove the problematic key and use \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} again (for validation or type errors)
\item change the value of the problematic key and use \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} again (for validation errors)
\item do a \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} (for conflicts, i.\+e. error C02000) and then
\begin{DoxyItemize}
\item set the same keyset again (in favour of what was set by this user)
\item drop the old keyset (in favour of what was set from another application)
\item merge the original, your own and the other keyset
\end{DoxyItemize}
\item export the configuration into a file (for unresolvable errors)
\item repeating the same \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} might be of limited use, if the user does not explicitly request it, because temporary errors are rare and its unlikely that they fix themselves (e.\+g. disc full, permission problems)
\end{DoxyItemize}

\begin{DoxyParagraph}{Optimization}
Only backends that
\begin{DoxyItemize}
\item contain at least changed key according to \mbox{\hyperlink{group__keytest_gaf247df0de7aca04b32ef80e39ef12950}{key\+Need\+Sync()}},
\item contain fewer keys than at the end of \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdb\+Get()}} will be called. There won\textquotesingle{}t be an unnecessary write for unchanged keys.
\end{DoxyItemize}
\end{DoxyParagraph}
If none of the backends need an update, \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdb\+Set()}} returns 0 and does nothing.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{KeySet * myConfig = \mbox{\hyperlink{group__keyset_ga671e1aaee3ae9dc13b4834a4ddbd2c3c}{ksNew}} (0, \mbox{\hyperlink{group__keyset_ga7a28fce3773b2c873c94ac80b8b4cd54}{KS\_END}});}
\DoxyCodeLine{Key * parentKey = \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}system:/sw/MyApp"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}});}
\DoxyCodeLine{\mbox{\hyperlink{classkdb_1_1KDB_a7e0637995ce9f294cdbc6f167df6db40}{KDB}} * handle = \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdbOpen}} (NULL, parentKey);}
\DoxyCodeLine{}
\DoxyCodeLine{\mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet}} (handle, myConfig, parentKey); \textcolor{comment}{// kdbGet needs to be called first!}}
\DoxyCodeLine{KeySet * base = \mbox{\hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ksDup}} (myConfig);     \textcolor{comment}{// save a copy of original keyset}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{// change the keys within myConfig}}
\DoxyCodeLine{\mbox{\hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey}} (myConfig, \mbox{\hyperlink{group__key_gad23c65b44bf48d773759e1f9a4d43b89}{keyNew}} (\textcolor{stringliteral}{"{}system:/sw/MyApp/Test"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8ac66e4a49d09212b79f5754ca6db5bd2e}{KEY\_VALUE}}, \textcolor{stringliteral}{"{}5"{}}, \mbox{\hyperlink{group__key_gga9b703ca49f48b482def322b77d3e6bc8aa8adb6fcb92dec58fb19410eacfdd403}{KEY\_END}}));}
\DoxyCodeLine{}
\DoxyCodeLine{KeySet * ours = \mbox{\hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ksDup}} (myConfig); \textcolor{comment}{// save a copy of our keyset}}
\DoxyCodeLine{KeySet * theirs;                  \textcolor{comment}{// needed for 3-\/way merging}}
\DoxyCodeLine{\textcolor{keywordtype}{int} ret = \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdbSet}} (handle, myConfig, parentKey);}
\DoxyCodeLine{\textcolor{keywordflow}{while} (ret == -\/1) \textcolor{comment}{// as long as we have an error}}
\DoxyCodeLine{\{}
\DoxyCodeLine{        \textcolor{keywordtype}{int} strategy = showElektraErrorDialog (parentKey);}
\DoxyCodeLine{        theirs = \mbox{\hyperlink{group__keyset_gac59e4b328245463f1451f68d5106151c}{ksDup}} (ours);}
\DoxyCodeLine{        \mbox{\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet}} (handle, theirs, parentKey); \textcolor{comment}{// refresh key database}}
\DoxyCodeLine{        KeySet * result = \mbox{\hyperlink{kdbmerge_8h_a2cc0dc19c99b2bc86feb1f2607df343a}{elektraMerge}}(}
\DoxyCodeLine{                \mbox{\hyperlink{group__keyset_ga6b00cf82b59af4d883a9bad6cf4a4a4a}{ksCut}}(ours, parentKey), parentKey,}
\DoxyCodeLine{                \mbox{\hyperlink{group__keyset_ga6b00cf82b59af4d883a9bad6cf4a4a4a}{ksCut}}(theirs, parentKey), parentKey,}
\DoxyCodeLine{                \mbox{\hyperlink{group__keyset_ga6b00cf82b59af4d883a9bad6cf4a4a4a}{ksCut}}(base, parentKey), parentKey,}
\DoxyCodeLine{                parentKey, strategy, parentKey);}
\DoxyCodeLine{        \textcolor{keywordtype}{int} numberOfConflicts = \mbox{\hyperlink{kdbmerge_8h_aa4b4c9a6f50a1f5d602fc84c8abce208}{elektraMergeGetConflicts}} (parentKey);}
\DoxyCodeLine{        \mbox{\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel}} (theirs);}
\DoxyCodeLine{        \textcolor{keywordflow}{if} (result != NULL) \{}
\DoxyCodeLine{                ret = \mbox{\hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdbSet}} (handle, result, parentKey);}
\DoxyCodeLine{        \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{                \textcolor{comment}{// an error happened while merging}}
\DoxyCodeLine{                \textcolor{keywordflow}{if} (numberOfConflicts > 0 \&\& strategy == \mbox{\hyperlink{kdbmerge_8h_a2c76c3f8b54a741ba9fdbfe6b5e0ee5caeaf7be70515ee5bc9b6dae1c844ec492}{MERGE\_STRATEGY\_ABORT}})}
\DoxyCodeLine{                \{}
\DoxyCodeLine{                        \textcolor{comment}{// Error due to merge conflicts}}
\DoxyCodeLine{                        ret = -\/1;}
\DoxyCodeLine{                \}}
\DoxyCodeLine{                \textcolor{keywordflow}{else}}
\DoxyCodeLine{                \{}
\DoxyCodeLine{                        \textcolor{comment}{// Internal errors, out of memory etc.}}
\DoxyCodeLine{                        ret = -\/1;}
\DoxyCodeLine{                \}}
\DoxyCodeLine{        \}}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{}
\DoxyCodeLine{\mbox{\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel}} (ours);}
\DoxyCodeLine{\mbox{\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel}} (base);}
\DoxyCodeLine{\mbox{\hyperlink{group__keyset_ga27e5c16473b02a422238c8d970db7ac8}{ksDel}} (myConfig); \textcolor{comment}{// delete the in-\/memory configuration}}
\DoxyCodeLine{}
\DoxyCodeLine{\mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose}} (handle, parentKey); \textcolor{comment}{// no more affairs with the key database.}}
\DoxyCodeLine{\mbox{\hyperlink{group__key_ga3df95bbc2494e3e6703ece5639be5bb1}{keyDel}} (parentKey);}

\end{DoxyCodeInclude}
 show\+Elektra\+Error\+Dialog() and do\+Elektra\+Merge() need to be implemented by the user of Elektra. For do\+Elektra\+Merge a 3-\/way merge algorithm exists in libelektra-\/tools.


\begin{DoxyParams}{Parameters}
{\em handle} & contains internal information of \mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{opened }} key database \\
\hline
{\em ks} & a \mbox{\hyperlink{classkdb_1_1KeySet}{Key\+Set}} which should contain changed keys, otherwise nothing is done \\
\hline
{\em parent\+Key} & Keys below {\ttfamily parent\+Key} will be set to {\ttfamily handle}. It is also used to add warnings and set error information.\\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em 1} & on success \\
\hline
{\em 0} & if nothing had to be done, no changes in \mbox{\hyperlink{classkdb_1_1KDB}{KDB}} \\
\hline
{\em -\/1} & on failure, no changes in \mbox{\hyperlink{classkdb_1_1KDB}{KDB}}, an error will be set on {\ttfamily parent\+Key} if possible (see \char`\"{}\+Errors\char`\"{} above)\\
\hline
\end{DoxyRetVals}
\begin{DoxySince}{Since}
1.\+0.\+0
\end{DoxySince}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{group__kdb_ga844e1299a84c3fbf1d3a905c5c893ba5}{kdb\+Open()}} for getting {\ttfamily handle} 

\mbox{\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdb\+Close()}} that must be called afterwards 

\mbox{\hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ks\+Current()}} contains the error \mbox{\hyperlink{classkdb_1_1Key}{Key}}
\end{DoxySeeAlso}

\begin{DoxyRetVals}{Return values}
{\em 0} & if no key was updated \\
\hline
{\em 1} & if user or system keys were updated \\
\hline
{\em 2} & if user and system keys were updated\\
\hline
\end{DoxyRetVals}

\begin{DoxyParams}{Parameters}
{\em returned} & the keyset where the keys will be in \\
\hline
{\em keyname} & the keyname below the names should be set\\
\hline
\end{DoxyParams}

\begin{DoxyExceptions}{Exceptions}
{\em KDBException} & if there were problems with the database \\
\hline
\end{DoxyExceptions}


The documentation for this class was generated from the following file\+:\begin{DoxyCompactItemize}
\item 
\mbox{\hyperlink{kdb_8hpp}{kdb.\+hpp}}\end{DoxyCompactItemize}
