--- loncom/lonsql 2001/03/27 19:57:53 1.26 +++ loncom/lonsql 2001/04/11 20:05:29 1.31 @@ -23,7 +23,6 @@ sub wanted { push(@metalist,"$dir/$_"); } - $childmaxattempts=10; $run =0;#running counter to generate the query-id @@ -39,6 +38,20 @@ while ($configline=) { } close(CONFIG); +# ------------------------------------- Make sure that database can be accessed +{ + my $dbh; + unless ( + $dbh = DBI->connect("DBI:mysql:loncapa","www",$perlvar{'lonSqlAccess'},{ RaiseError =>0,PrintError=>0}) + ) { + print "Cannot connect to database!\n"; + exit; + } + else { + $dbh->disconnect; + } +} + # --------------------------------------------- Check if other instance running my $pidfile="$perlvar{'lonDaemons'}/logs/lonsql.pid"; @@ -191,12 +204,11 @@ sub make_new_child { #open database handle # making dbh global to avoid garbage collector unless ( - $dbh = DBI->connect("DBI:mysql:loncapa","www","123",{ RaiseError =>0,PrintError=>0}) + $dbh = DBI->connect("DBI:mysql:loncapa","www",$perlvar{'lonSqlAccess'},{ RaiseError =>0,PrintError=>0}) ) { - my $st=120+int(rand(240)); + sleep(10+int(rand(20))); &logthis("WARNING: Couldn't connect to database ($st secs): $@"); print "database handle error\n"; - sleep($st); exit; }; @@ -251,7 +263,7 @@ sub make_new_child { } } # do custom metadata searching here and build into result - if ($custom) { + if ($custom or $customshow) { &logthis("am going to do custom query for $custom"); if ($query) { @metalist=map {$perlvar{'lonDocRoot'}.$_.'.meta'} @files; @@ -284,7 +296,7 @@ sub make_new_child { $m2=~s/\.meta$//; unless ($query) { my $q2="select * from metadata where url like '$m2'"; - my $sth = $dbh->prepare($query); + my $sth = $dbh->prepare($q2); $sth->execute(); my $r1=$sth->fetchall_arrayref; map {my $a=$_;