]> lifelog.hopto.org Git - PerlCNF.git/commitdiff
Added option die_in_html.
authorWill Budic <redacted>
Fri, 31 Oct 2025 01:06:27 +0000 (12:06 +1100)
committerWill Budic <redacted>
Fri, 31 Oct 2025 01:06:27 +0000 (12:06 +1100)
apps/sql.cnf
apps/sql.pl
system/modules/CNFSQL.pm

index e02d47a04e02dbd9d6878db50776effa38e70f2a..d134eaf58f63f7037cb139dbdaa5fa1969ade4ac 100644 (file)
@@ -1,6 +1,7 @@
 !CNF3.3
 <<<CONST
     TZ  = Australia/Sydney
+    die_in_html = false
 >>>
 <<<ARGUMENTS
    -DB              = lifelog
index 3cc0e01255e56dd9ea069b79e54585007369c79e..948c412f7f6955161893358edf64a5e5d742fedb 100644 (file)
@@ -11,13 +11,26 @@ require CNFParser;
 require CNFSQL;
 
 our $CNF = CNFParser->new('apps/sql.cnf');
-my $arguments = $CNF->property(CNFParser::APP_ARGS());
-my $db = CNFSQL::_connectDB(CNFSQL::_credentialsToArray($arguments->{DB_CREDENTIALS}),
-                                    $arguments->{DB_SQL_SOURCE},$arguments->{DB});
 our $SQL = $CNF->SQL();
-$SQL->initDatabase($db,1);
-my %schema = $SQL->schema();
+our $db;
 
+my $arguments = $CNF->property(CNFParser::APP_ARGS());
+try{
+$db = CNFSQL::_connectDB(
+      CNFSQL::_credentialsToArray($arguments->{DB_CREDENTIALS}),
+                                  $arguments->{DB_SQL_SOURCE},
+                                  $arguments->{DB}
+      );
+}catch($e){
+   if($e =~ /connection to server at \"(.*)\"/){
+      say `nmap $1` if  (-x "/usr/bin/nmap") 
+   }
+   die $e
+}
+
+$CNF->log("Connected to DB_SQL_SOURCE -> ".$arguments->{DB_SQL_SOURCE}) if $db;
+$SQL->initDatabase($db,1); 
+my %schema = $SQL->schema();
 my $action = $arguments->{action};
 my $table  = $arguments->{table};
 die "Config error: Table $table not found in database -> ".$arguments->{DB} if not exists $schema{$table};
index c5b2a2a1e56e40f99655c3d5895201f6bc2351b7..3a0c4ff445d5072f9fae3a19bfc898e31e5d946e 100644 (file)
@@ -18,7 +18,7 @@ our %views  = ();
 our %mig    = ();
 our @sql    = ();
 our @statements;
-
+our $die_in_html = 1;
 my %schema_tables;
 my $isPostgreSQL = 0;
 my $TZ;
@@ -31,6 +31,9 @@ sub new {
     # By convention any tables and views as appearing in the CNF script should in that order also be created.
     tie %tables_create_stmts, "Tie::IxHash";
     tie %views, "Tie::IxHash";
+    if(exists $attrs->{parser}->{die_in_html}){
+       $die_in_html = CNFParser::_isTrue($attrs->{parser}->{die_in_html})
+    }
     bless $self, $class;
 }
 
@@ -451,7 +454,8 @@ sub _connectDB {
     try{
         return DBI->connect($dsn, $user, $pass, {AutoCommit => 0, RaiseError => 1, PrintError => 0, show_trace=>1});
     }catch{
-       die "<p>Error->$@</p><br><pre>DSN: $dsn</pre>";
+       die "<p>Error->$@</p><br><pre>DSN: $dsn</pre>" if $die_in_html;
+       die $@
     }
 }
 sub _credentialsToArray{