+use Getopt::Long qw(GetOptions);
+Getopt::Long::config ('bundling');
+
+################################# Subroutines ##################################
+
+sub PrepareDB {
+### initialise database connection, prepare statement
+### and catch errors
+### IN : \%Conf : reference to configuration hash
+### OUT: $DBHandle: database handle
+### $DBQuery : prepared statement
+ our ($DBHandle, $DBQuery, $OptQuiet);
+ my ($ConfigR) = @_;
+ my %Conf = %$ConfigR;
+ # drop current database connection - hard, if necessary
+ if ($DBHandle) {
+ $DBHandle->disconnect;
+ undef $DBHandle;
+ };
+ # connect to database; try again every 5 seconds
+ while (!$DBHandle) {
+ $DBHandle = InitDB($ConfigR,0);
+ if (!$DBHandle) {
+ syslog(LOG_CRIT, 'Database connection failed: %s', $DBI::errstr);
+ sleep(5);
+ } else {;
+ syslog(LOG_NOTICE, "Database connection (re-)established successfully.") if !$OptQuiet;
+ }
+ };
+ $DBQuery = $DBHandle->prepare(sprintf("INSERT INTO %s.%s (day,date,mid,
+ timestamp,token,size,peer,path,
+ newsgroups,headers)
+ VALUES (?,?,?,?,?,?,?,?,?,?)",
+ $Conf{'DBDatabase'},
+ $Conf{'DBTableRaw'}));
+ return ($DBHandle,$DBQuery);
+}
+