\hypertarget{group__kdb}{
\section{KDB :: Low Level Methods}
\label{group__kdb}\index{KDB :: Low Level Methods@{KDB :: Low Level Methods}}
}


General methods to access the Key database.  


\subsection*{Enumerations}
\begin{DoxyCompactItemize}
\item 
enum \hyperlink{group__kdb_ga98a3d6a4016c9dad9cbd1a99a9c2a45a}{option\_\-t} \{ \par
\hyperlink{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa00738455e0ae843c8720809d8287f370}{KDB\_\-O\_\-NONE} = 0, 
\hyperlink{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa66a5380c120f25f28f49848c4a863ead}{KDB\_\-O\_\-DEL} = 1, 
\hyperlink{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa52fb5f2cc86773d393da62bebebf7984}{KDB\_\-O\_\-POP} = 1$<$$<$1, 
\hyperlink{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa1a70738b2126badb8db7b012c8a1c610}{KDB\_\-O\_\-NODIR} = 1$<$$<$2, 
\par
\hyperlink{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa131e99d60253d0b887a1e5886f8aa96c}{KDB\_\-O\_\-DIRONLY} = 1$<$$<$3, 
\hyperlink{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa7649f575c2eb0adeaf2c9173ae16e0e6}{KDB\_\-O\_\-NOREMOVE} = 1$<$$<$6, 
\hyperlink{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaf6ed09cee8aa8cf0d6a0e318a7105440}{KDB\_\-O\_\-REMOVEONLY} = 1$<$$<$7, 
\hyperlink{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa789926d8a8e15b029cf7dded4154bcda}{KDB\_\-O\_\-INACTIVE} = 1$<$$<$8, 
\par
\hyperlink{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaa7d5265eacbb1590982b718f35443e2e}{KDB\_\-O\_\-SYNC} = 1$<$$<$9, 
\hyperlink{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aad9d03b36ee88ca5a774cc01b190c99b8}{KDB\_\-O\_\-SORT} = 1$<$$<$10, 
\hyperlink{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa6adaa17b267027ce50e670bf8cc6e824}{KDB\_\-O\_\-NORECURSIVE} = 1$<$$<$11, 
\hyperlink{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaa5586d229e048f816bf7982765442b86}{KDB\_\-O\_\-NOCASE} = 1$<$$<$12, 
\par
\hyperlink{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aab2ff402f5de9aa67b7f786fb715a7a31}{KDB\_\-O\_\-WITHOWNER} = 1$<$$<$13, 
\hyperlink{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aae8dd1961707e7d0c27228a3f98b0a94d}{KDB\_\-O\_\-NOALL} = 1$<$$<$14
 \}
\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{struct__KDB}{KDB} $\ast$ \hyperlink{group__kdb_ga6808defe5870f328dd17910aacbdc6ca}{kdbOpen} (\hyperlink{struct__Key}{Key} $\ast$errorKey)
\item 
int \hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose} (\hyperlink{struct__KDB}{KDB} $\ast$handle, \hyperlink{struct__Key}{Key} $\ast$errorKey)
\item 
int \hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet} (\hyperlink{struct__KDB}{KDB} $\ast$handle, \hyperlink{struct__KeySet}{KeySet} $\ast$ks, \hyperlink{struct__Key}{Key} $\ast$parentKey)
\item 
int \hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdbSet} (\hyperlink{struct__KDB}{KDB} $\ast$handle, \hyperlink{struct__KeySet}{KeySet} $\ast$ks, \hyperlink{struct__Key}{Key} $\ast$parentKey)
\end{DoxyCompactItemize}


\subsection{Detailed Description}
General methods to access the Key database. To use them: 
\begin{DoxyCode}
 #include <kdb.h>
\end{DoxyCode}


The kdb$\ast$() class of methods are used to access the storage, to get and set \hyperlink{group__key}{Keys } or \hyperlink{group__keyset}{KeySets }.

The most important functions are:
\begin{DoxyItemize}
\item \hyperlink{group__kdb_ga6808defe5870f328dd17910aacbdc6ca}{kdbOpen()}
\item \hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose()}
\item \hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet()}
\item \hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdbSet()}
\end{DoxyItemize}

The two essential functions for dynamic information about backends are:
\begin{DoxyItemize}
\item kdbGetMountpoint()
\end{DoxyItemize}

They use some backend implementation to know the details about how to access the storage. Currently we have this backends:
\begin{DoxyItemize}
\item {\ttfamily berkeleydb:} the keys are stored in a Berkeley DB database, providing very small footprint, speed, and other advantages.
\item {\ttfamily filesys:} the key hierarchy and data are saved as plain text files in the filesystem.
\item {\ttfamily ini:} the key hierarchy are saved into configuration files. \begin{DoxySeeAlso}{See also}
\href{http://www.libelektra.org/Ini}{\tt http://www.libelektra.org/Ini}
\end{DoxySeeAlso}

\item {\ttfamily fstab:} a reference backend used to interpret the {\ttfamily /etc/fstab} file as a set of keys under {\ttfamily system/filesystems} .
\item {\ttfamily gconf:} makes Elektra use the GConf daemon to access keys. Only the {\ttfamily user/} tree is available since GConf is not system wide.
\end{DoxyItemize}

Backends are physically a library named {\ttfamily /lib/libelektra-\/\{NAME\}}.so.

See \hyperlink{group__plugin}{writing a new plugin } for information about how to write a plugin.

Language binding writers should follow the same rules:
\begin{DoxyItemize}
\item You must relay completely on the backend-\/dependent methods.
\item You may use or reimplement the second set of methods.
\item You should completely reimplement in your language the higher lever methods.
\item Many methods are just for comfort in C. These methods are marked and need not to be implemented if the binding language has e.g. string operators which can do the operation easily. 
\end{DoxyItemize}

\subsection{Enumeration Type Documentation}
\hypertarget{group__kdb_ga98a3d6a4016c9dad9cbd1a99a9c2a45a}{
\index{kdb@{kdb}!option\_\-t@{option\_\-t}}
\index{option\_\-t@{option\_\-t}!kdb@{kdb}}
\subsubsection[{option\_\-t}]{\setlength{\rightskip}{0pt plus 5cm}enum {\bf option\_\-t}}}
\label{group__kdb_ga98a3d6a4016c9dad9cbd1a99a9c2a45a}
Options to change the default behavior of \hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet()}, \hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdbSet()} and \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ksLookup()} functions.

These options can be ORed. That is the $|$-\/Operator in C.

\begin{DoxySeeAlso}{See also}
\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet()}, \hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdbSet()} 
\end{DoxySeeAlso}
\begin{Desc}
\item[Enumerator: ]\par
\begin{description}
\index{KDB\_\-O\_\-NONE@{KDB\_\-O\_\-NONE}!kdb@{kdb}}\index{kdb@{kdb}!KDB\_\-O\_\-NONE@{KDB\_\-O\_\-NONE}}\item[{\em 
\hypertarget{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa00738455e0ae843c8720809d8287f370}{
KDB\_\-O\_\-NONE}
\label{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa00738455e0ae843c8720809d8287f370}
}]No Option set. Will be recursive with no inactive keys.

\begin{DoxySeeAlso}{See also}
\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet()}, \hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdbSet()}, \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ksLookup()} 
\end{DoxySeeAlso}
\index{KDB\_\-O\_\-DEL@{KDB\_\-O\_\-DEL}!kdb@{kdb}}\index{kdb@{kdb}!KDB\_\-O\_\-DEL@{KDB\_\-O\_\-DEL}}\item[{\em 
\hypertarget{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa66a5380c120f25f28f49848c4a863ead}{
KDB\_\-O\_\-DEL}
\label{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa66a5380c120f25f28f49848c4a863ead}
}]Delete parentKey key in \hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet()}, \hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdbSet()} or \hyperlink{group__keyset_gaa34fc43a081e6b01e4120daa6c112004}{ksLookup()}.

\begin{DoxySeeAlso}{See also}
\hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet()}, \hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdbSet()} 
\end{DoxySeeAlso}
\index{KDB\_\-O\_\-POP@{KDB\_\-O\_\-POP}!kdb@{kdb}}\index{kdb@{kdb}!KDB\_\-O\_\-POP@{KDB\_\-O\_\-POP}}\item[{\em 
\hypertarget{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa52fb5f2cc86773d393da62bebebf7984}{
KDB\_\-O\_\-POP}
\label{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa52fb5f2cc86773d393da62bebebf7984}
}]Pop Parent out of keyset key in \hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet()}.

\begin{DoxySeeAlso}{See also}
\hyperlink{group__keyset_gae42530b04defb772059de0600159cf69}{ksPop()}. 
\end{DoxySeeAlso}
\index{KDB\_\-O\_\-NODIR@{KDB\_\-O\_\-NODIR}!kdb@{kdb}}\index{kdb@{kdb}!KDB\_\-O\_\-NODIR@{KDB\_\-O\_\-NODIR}}\item[{\em 
\hypertarget{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa1a70738b2126badb8db7b012c8a1c610}{
KDB\_\-O\_\-NODIR}
\label{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa1a70738b2126badb8db7b012c8a1c610}
}]Exclude keys containing other keys in result.

Only return leaves.

\begin{DoxySeeAlso}{See also}
\hyperlink{group__keytest_gac0a10c602d52a35f81347e8a32312017}{keyIsDir()} 
\end{DoxySeeAlso}
\index{KDB\_\-O\_\-DIRONLY@{KDB\_\-O\_\-DIRONLY}!kdb@{kdb}}\index{kdb@{kdb}!KDB\_\-O\_\-DIRONLY@{KDB\_\-O\_\-DIRONLY}}\item[{\em 
\hypertarget{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa131e99d60253d0b887a1e5886f8aa96c}{
KDB\_\-O\_\-DIRONLY}
\label{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa131e99d60253d0b887a1e5886f8aa96c}
}]Retrieve only directory keys (keys containing other keys). This will give you an skeleton without leaves. This must not be used together with KDB\_\-O\_\-NODIR. \begin{DoxySeeAlso}{See also}
\hyperlink{group__keytest_gac0a10c602d52a35f81347e8a32312017}{keyIsDir()} 
\end{DoxySeeAlso}
\index{KDB\_\-O\_\-NOREMOVE@{KDB\_\-O\_\-NOREMOVE}!kdb@{kdb}}\index{kdb@{kdb}!KDB\_\-O\_\-NOREMOVE@{KDB\_\-O\_\-NOREMOVE}}\item[{\em 
\hypertarget{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa7649f575c2eb0adeaf2c9173ae16e0e6}{
KDB\_\-O\_\-NOREMOVE}
\label{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa7649f575c2eb0adeaf2c9173ae16e0e6}
}]Don't remove any keys. This must not be used together with KDB\_\-O\_\-REMOVEONLY. \index{KDB\_\-O\_\-REMOVEONLY@{KDB\_\-O\_\-REMOVEONLY}!kdb@{kdb}}\index{kdb@{kdb}!KDB\_\-O\_\-REMOVEONLY@{KDB\_\-O\_\-REMOVEONLY}}\item[{\em 
\hypertarget{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaf6ed09cee8aa8cf0d6a0e318a7105440}{
KDB\_\-O\_\-REMOVEONLY}
\label{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaf6ed09cee8aa8cf0d6a0e318a7105440}
}]Only remove keys. This must not be used together with KDB\_\-O\_\-NOREMOVE. \index{KDB\_\-O\_\-INACTIVE@{KDB\_\-O\_\-INACTIVE}!kdb@{kdb}}\index{kdb@{kdb}!KDB\_\-O\_\-INACTIVE@{KDB\_\-O\_\-INACTIVE}}\item[{\em 
\hypertarget{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa789926d8a8e15b029cf7dded4154bcda}{
KDB\_\-O\_\-INACTIVE}
\label{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa789926d8a8e15b029cf7dded4154bcda}
}]Do not ignore inactive keys (that name begins with .). \begin{DoxySeeAlso}{See also}
\hyperlink{group__keytest_gaa25f699f592031c1a0abc1504d14e13e}{keyIsInactive()} 
\end{DoxySeeAlso}
\index{KDB\_\-O\_\-SYNC@{KDB\_\-O\_\-SYNC}!kdb@{kdb}}\index{kdb@{kdb}!KDB\_\-O\_\-SYNC@{KDB\_\-O\_\-SYNC}}\item[{\em 
\hypertarget{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaa7d5265eacbb1590982b718f35443e2e}{
KDB\_\-O\_\-SYNC}
\label{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaa7d5265eacbb1590982b718f35443e2e}
}]Set keys independent of sync status. \begin{DoxySeeAlso}{See also}
\hyperlink{group__keytest_gaf247df0de7aca04b32ef80e39ef12950}{keyNeedSync()} 
\end{DoxySeeAlso}
\index{KDB\_\-O\_\-SORT@{KDB\_\-O\_\-SORT}!kdb@{kdb}}\index{kdb@{kdb}!KDB\_\-O\_\-SORT@{KDB\_\-O\_\-SORT}}\item[{\em 
\hypertarget{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aad9d03b36ee88ca5a774cc01b190c99b8}{
KDB\_\-O\_\-SORT}
\label{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aad9d03b36ee88ca5a774cc01b190c99b8}
}]This option has no effect. KeySets are always sorted. \begin{Desc}
\item[\hyperlink{deprecated__deprecated000001}{Deprecated}]dont use \end{Desc}
\index{KDB\_\-O\_\-NORECURSIVE@{KDB\_\-O\_\-NORECURSIVE}!kdb@{kdb}}\index{kdb@{kdb}!KDB\_\-O\_\-NORECURSIVE@{KDB\_\-O\_\-NORECURSIVE}}\item[{\em 
\hypertarget{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa6adaa17b267027ce50e670bf8cc6e824}{
KDB\_\-O\_\-NORECURSIVE}
\label{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aa6adaa17b267027ce50e670bf8cc6e824}
}]Do not call \hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet()} for every key containing other keys (\hyperlink{group__keytest_gac0a10c602d52a35f81347e8a32312017}{keyIsDir()}). \index{KDB\_\-O\_\-NOCASE@{KDB\_\-O\_\-NOCASE}!kdb@{kdb}}\index{kdb@{kdb}!KDB\_\-O\_\-NOCASE@{KDB\_\-O\_\-NOCASE}}\item[{\em 
\hypertarget{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaa5586d229e048f816bf7982765442b86}{
KDB\_\-O\_\-NOCASE}
\label{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aaa5586d229e048f816bf7982765442b86}
}]Ignore case. \index{KDB\_\-O\_\-WITHOWNER@{KDB\_\-O\_\-WITHOWNER}!kdb@{kdb}}\index{kdb@{kdb}!KDB\_\-O\_\-WITHOWNER@{KDB\_\-O\_\-WITHOWNER}}\item[{\em 
\hypertarget{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aab2ff402f5de9aa67b7f786fb715a7a31}{
KDB\_\-O\_\-WITHOWNER}
\label{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aab2ff402f5de9aa67b7f786fb715a7a31}
}]Search with owner. \index{KDB\_\-O\_\-NOALL@{KDB\_\-O\_\-NOALL}!kdb@{kdb}}\index{kdb@{kdb}!KDB\_\-O\_\-NOALL@{KDB\_\-O\_\-NOALL}}\item[{\em 
\hypertarget{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aae8dd1961707e7d0c27228a3f98b0a94d}{
KDB\_\-O\_\-NOALL}
\label{group__kdb_gga98a3d6a4016c9dad9cbd1a99a9c2a45aae8dd1961707e7d0c27228a3f98b0a94d}
}]Only search from start -\/$>$ cursor to cursor -\/$>$ end. \end{description}
\end{Desc}



\subsection{Function Documentation}
\hypertarget{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{
\index{kdb@{kdb}!kdbClose@{kdbClose}}
\index{kdbClose@{kdbClose}!kdb@{kdb}}
\subsubsection[{kdbClose}]{\setlength{\rightskip}{0pt plus 5cm}int kdbClose (
\begin{DoxyParamCaption}
\item[{{\bf KDB} $\ast$}]{ handle, }
\item[{{\bf Key} $\ast$}]{ errorKey}
\end{DoxyParamCaption}
)}}
\label{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}
Closes the session with the Key database.

You should call this method when you finished your affairs with the key database. You can manipulate Key and KeySet objects also after \hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose()}. You must not use any kdb$\ast$ call afterwards. You can implement \hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose()} in the atexit() handler.

This is the counterpart of \hyperlink{group__kdb_ga6808defe5870f328dd17910aacbdc6ca}{kdbOpen()}.

The {\ttfamily handle} parameter will be finalized and all resources associated to it will be freed. After a \hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose()}, this {\ttfamily handle} can't be used anymore, unless it gets initialized again with another call to \hyperlink{group__kdb_ga6808defe5870f328dd17910aacbdc6ca}{kdbOpen()}.

\begin{DoxySeeAlso}{See also}
\hyperlink{group__kdb_ga6808defe5870f328dd17910aacbdc6ca}{kdbOpen()} 
\end{DoxySeeAlso}

\begin{DoxyParams}{Parameters}
\item[{\em handle}]contains internal information of \hyperlink{group__kdb_ga6808defe5870f328dd17910aacbdc6ca}{opened } key database \item[{\em errorKey}]the key which holds error information \end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 on success 

-\/1 on NULL pointer 
\end{DoxyReturn}
\hypertarget{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{
\index{kdb@{kdb}!kdbGet@{kdbGet}}
\index{kdbGet@{kdbGet}!kdb@{kdb}}
\subsubsection[{kdbGet}]{\setlength{\rightskip}{0pt plus 5cm}int kdbGet (
\begin{DoxyParamCaption}
\item[{{\bf KDB} $\ast$}]{ handle, }
\item[{{\bf KeySet} $\ast$}]{ ks, }
\item[{{\bf Key} $\ast$}]{ parentKey}
\end{DoxyParamCaption}
)}}
\label{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}
Retrieve keys in an atomic and universal way, all other kdbGet Functions rely on that one.

The {\ttfamily returned} KeySet must be initialized or may already contain some keys. The new retrieved keys will be appended using \hyperlink{group__keyset_gaa5a1d467a4d71041edce68ea7748ce45}{ksAppendKey()}.

It will fully retrieve all keys under the {\ttfamily parentKey} folder, with all subfolders and their children.\hypertarget{group__kdb_kdbgetexample}{}\subsection{Example}\label{group__kdb_kdbgetexample}
This example demonstrates the typical usecase within an application without updating.

\begin{DoxyParagraph}{Example:}

\begin{DoxyCode}
KeySet *myConfig = ksNew(0);
Key *key = keyNew("system/sw/MyApp",KEY_END);
KDB *handle = kdbOpen(key);

kdbGet(handle, myConfig, key);

keySetName(key, "user/sw/MyApp");
kdbGet(handle, myConfig, key);

// check for errors by in key
keyDel(key);

key = ksLookupByName(myConfig,"/sw/MyApp/key", 0);
// check if key is not 0 and work with it...

ksDel (myConfig); // delete the in-memory configuration


// maybe you want kdbSet() myConfig here

kdbClose(handle, 0); // no more affairs with the key database.
\end{DoxyCode}

\end{DoxyParagraph}
\hypertarget{group__kdb_kdbgetdetail}{}\subsection{Details}\label{group__kdb_kdbgetdetail}
When no backend could be found (e.g. no backend mounted) the default backend will be used.

If you pass NULL on any parameter \hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet()} will fail immediately without doing anything.

When a backend fails \hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet()} will return -\/1 without any changes to one of the parameter.\hypertarget{group__kdb_kdbgetupdate}{}\subsection{Updating}\label{group__kdb_kdbgetupdate}
In the first run of kdbGet all keys are retrieved. On subsequent calls only the keys are retrieved where something was changed inside the key database. The other keys stay unchanged in the keyset, even when they were manipulated.

It is your responsibility to save the original keyset if you need it afterwards. If you must get it again, e.g. in another thread a second connection to the key database must be opened using \hyperlink{group__kdb_ga6808defe5870f328dd17910aacbdc6ca}{kdbOpen()}.


\begin{DoxyParams}{Parameters}
\item[{\em handle}]contains internal information of \hyperlink{group__kdb_ga6808defe5870f328dd17910aacbdc6ca}{opened } key database \item[{\em parentKey}]parent key -\/ invalid name gets all keys \item[{\em ks}]the (pre-\/initialized) KeySet returned with all keys found will not be changed on error or if no update is required \end{DoxyParams}
\begin{DoxySeeAlso}{See also}
\hyperlink{}{kdb higher level Methods } that rely on \hyperlink{group__kdb_ga28e385fd9cb7ccfe0b2f1ed2f62453a1}{kdbGet()} 

\hyperlink{group__keyset_gad2e30fb6d4739d917c5abb2ac2f9c1a1}{ksLookupByName()} for powerful lookups after the KeySet was retrieved 
\end{DoxySeeAlso}
\begin{DoxyReturn}{Returns}
1 if the keys were retrieved successfully 

0 if there was no update -\/ no changes are made to the keyset then 

-\/1 on failure -\/ no changes are made to the keyset then 
\end{DoxyReturn}
\hypertarget{group__kdb_ga6808defe5870f328dd17910aacbdc6ca}{
\index{kdb@{kdb}!kdbOpen@{kdbOpen}}
\index{kdbOpen@{kdbOpen}!kdb@{kdb}}
\subsubsection[{kdbOpen}]{\setlength{\rightskip}{0pt plus 5cm}{\bf KDB}$\ast$ kdbOpen (
\begin{DoxyParamCaption}
\item[{{\bf Key} $\ast$}]{ errorKey}
\end{DoxyParamCaption}
)}}
\label{group__kdb_ga6808defe5870f328dd17910aacbdc6ca}
Opens the session with the Key database.

The first step is to open the default backend. With it system/elektra/mountpoints will be loaded and all needed libraries and mountpoints will be determined. These libraries for backends will be loaded and with it the {\ttfamily KDB} datastructure will be initialized.

You must always call this method before retrieving or commiting any keys to the database. In the end of the program, after using the key database, you must not forget to \hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose()}. You can use the atexit () handler for it.

The pointer to the {\ttfamily 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 KDB} handle for every thread using elektra. Don't share the handle across threads, and also not the pointer accessing it: 
\begin{DoxyCode}
thread1 {
        KDB * h;
        h = kdbOpen(0);
        // fetch keys and work with them
        kdbClose(h, 0);
}
thread2 {
        KDB * h;
        h = kdbOpen(0);
        // fetch keys and work with them
        kdbClose(h, 0);
}
\end{DoxyCode}


You don't need to use the \hyperlink{group__kdb_ga6808defe5870f328dd17910aacbdc6ca}{kdbOpen()} if you only want to manipulate plain in-\/memory Key or KeySet objects without any affairs with the backend key database,


\begin{DoxyParams}{Parameters}
\item[{\em errorKey}]the key which holds errors and warnings which were issued must be given \end{DoxyParams}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__kdb_gadb54dc9fda17ee07deb9444df745c96f}{kdbClose()} to end all affairs to the \hyperlink{group__key}{Key :: Basic Methods} database. 
\end{DoxySeeAlso}
\begin{DoxyReturn}{Returns}
a KDB pointer on success 

NULL on failure 
\end{DoxyReturn}
\hypertarget{group__kdb_ga11436b058408f83d303ca5e996832bcf}{
\index{kdb@{kdb}!kdbSet@{kdbSet}}
\index{kdbSet@{kdbSet}!kdb@{kdb}}
\subsubsection[{kdbSet}]{\setlength{\rightskip}{0pt plus 5cm}int kdbSet (
\begin{DoxyParamCaption}
\item[{{\bf KDB} $\ast$}]{ handle, }
\item[{{\bf KeySet} $\ast$}]{ ks, }
\item[{{\bf Key} $\ast$}]{ parentKey}
\end{DoxyParamCaption}
)}}
\label{group__kdb_ga11436b058408f83d303ca5e996832bcf}
Set keys in an atomic and universal way.

All other kdbSet Functions rely on that one.\hypertarget{group__kdb_kdbsetparent}{}\subsection{parentKey}\label{group__kdb_kdbsetparent}
With parentKey you can only store a part of the given keyset.


\begin{DoxyCode}
KeySet *ks = ksNew(0);
Key *parentKey = keyNew("user/app/myapp/default", KEY_END);
kdbGet (h, ks, parentKey));

//now only set everything below user
if (kdbSet (h, ks, parentKey) == -1)
{
        // in parentKey you can check the error cause
        // ksCurrent(ks) is the faulty key
}

ksDel (ks);
\end{DoxyCode}


If you pass a parentKey without a name the whole keyset will be set in an atomic way.\hypertarget{group__kdb_kdbsetupdate}{}\subsection{Update}\label{group__kdb_kdbsetupdate}
Each key is checked with \hyperlink{group__keytest_gaf247df0de7aca04b32ef80e39ef12950}{keyNeedSync()} before being actually committed. So only changed keys are updated. If no key of a backend needs to be synced any affairs to backends omitted and 0 is returned.\hypertarget{group__kdb_kdbseterror}{}\subsection{Error Situations}\label{group__kdb_kdbseterror}
If some error occurs, \hyperlink{group__kdb_ga11436b058408f83d303ca5e996832bcf}{kdbSet()} will stop. In this situation the KeySet internal cursor will be set on the key that generated the error.

None of the keys are actually commited.

You should present the error message to the user and let the user decide what to do. Possible solutions are:
\begin{DoxyItemize}
\item repeat the same kdbSet (for temporary errors)
\item remove the key and set it again (for validation or type errors)
\item change the value and try it again (for validation errors)
\item do a kdbGet and then (for conflicts ...)
\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 elsewhere)
\end{DoxyItemize}
\item export the configuration into a file (for unresolvable errors)
\end{DoxyItemize}

\begin{DoxyParagraph}{Example of how this method can be used:}

\begin{DoxyCode}
int i;
KeySet *ks;  // the KeySet I want to set
// fill ks with some keys
for (i=0; i< NR_OF_TRIES; i++) // limit to NR_OF_TRIES tries
{
        ret=kdbSet(handle, ks, parentKey);
        if (ret == -1)
        {
                // We got an error. Warn user.
                Key *problemKey = ksCurrent(ks);
                // parentKey has the errorInformation
                // problemKey is the faulty key (may be null)
                int userInput = showElektraErrorDialog (parentKey, problemKey);
                switch (userInput)
                {
                case INPUT_REPEAT: continue;
                case INPUT_REMOVE: ksLookup (ks, parentKey, KDB_O_POP); break;
                ...
                }
        }
}
\end{DoxyCode}

\end{DoxyParagraph}

\begin{DoxyParams}{Parameters}
\item[{\em handle}]contains internal information of \hyperlink{group__kdb_ga6808defe5870f328dd17910aacbdc6ca}{opened } key database \item[{\em ks}]a KeySet which should contain changed keys, otherwise nothing is done \item[{\em parentKey}]holds the information below which key keys should be set, see above \end{DoxyParams}
\begin{DoxyReturn}{Returns}
1 on success 

0 if nothing had to be done 

-\/1 on failure 
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__keytest_gaf247df0de7aca04b32ef80e39ef12950}{keyNeedSync()}, \hyperlink{group__keyset_ga317321c9065b5a4b3e33fe1c399bcec9}{ksNext()}, \hyperlink{group__keyset_ga4287b9416912c5f2ab9c195cb74fb094}{ksCurrent()} 
\end{DoxySeeAlso}
