Convert mysql module
authorJamie Cameron <jcameron@webmin.com>
Sun, 1 Mar 2009 20:31:33 +0000 (20:31 +0000)
committerJamie Cameron <jcameron@webmin.com>
Sun, 1 Mar 2009 20:31:33 +0000 (20:31 +0000)
mysql/exec.cgi
mysql/mysql-lib.pl
web-lib-funcs.pl

index e08669a..3c4469c 100755 (executable)
@@ -33,7 +33,7 @@ else {
                print "<b>$text{'exec_none'}</b> <p>\n";
                }
 
-       open(OLD, "$commands_file.$in{'db'}");
+       &open_readfile(OLD, "$commands_file.$in{'db'}");
        while(<OLD>) {
                s/\r|\n//g;
                $already++ if ($_ eq $in{'cmd'});
index 36f2773..4b0066a 100644 (file)
@@ -1,9 +1,9 @@
 # mysql-lib.pl
 # Common MySQL functions
 
-do '../web-lib.pl';
+BEGIN { push(@INC, ".."); };
+use WebminCore;
 &init_config();
-do '../ui-lib.pl';
 if ($config{'mysql_libs'}) {
        $ENV{$gconfig{'ld_env'}} .= ':' if ($ENV{$gconfig{'ld_env'}});
        $ENV{$gconfig{'ld_env'}} .= $config{'mysql_libs'};
@@ -150,6 +150,7 @@ sub list_databases
 local @rv;
 eval {
        # First try using SQL
+       local $main::error_must_die = 1;
        local $t = &execute_sql_safe($master_db, "show databases");
        @rv = map { $_->[0] } @{$t->{'data'}};
        };
@@ -168,35 +169,43 @@ return @rv;
 # Returns a list of tables in some database
 sub list_tables
 {
-local ($db, $empty_denied, $include_views) = @_;
-# XXX use SQL first
-if ($db =~ /_/) {
-       open(DBS, "\"$config{'mysqlshow'}\" $authstr ".quotemeta($db)." % 2>&1 |");
-       }
-else {
-       open(DBS, "\"$config{'mysqlshow'}\" $authstr ".quotemeta($db)." 2>&1 |");
-       }
-local $t = &parse_mysql_table(DBS);
-close(DBS);
-if ($t =~ /access denied/i) {
-       if ($empty_denied) {
-               return ( );
+my ($db, $empty_denied, $include_views) = @_;
+my @rv;
+eval {
+       # First try using SQL
+       local $main::error_must_die = 1;
+        local $t = &execute_sql_safe($db, "show tables");
+        @rv = map { $_->[0] } @{$t->{'data'}};
+       };
+if ($@) {
+       # Fall back to mysqlshow command
+       local $tspec = $db =~ /_/ ? "%" : "";
+       open(DBS, "\"$config{'mysqlshow'}\" $authstr ".
+                 quotemeta($db)." $tspec 2>&1 |");
+       local $t = &parse_mysql_table(DBS);
+       close(DBS);
+       if ($t =~ /access denied/i) {
+               if ($empty_denied) {
+                       return ( );
+                       }
+               else {
+                       &error($text{'edenied'});
+                       }
                }
-       else {
-               &error($text{'edenied'});
+       elsif (!ref($t)) {
+               &error("<tt>".&html_escape($t)."</tt>");
                }
+       @rv = map { $_->[0] } @{$t->{'data'}};
        }
-elsif (!ref($t)) {
-       &error("<tt>$t</tt>");
-       }
-local %views;
+
+# Filter out views
 if (!$include_views) {
-       # Filter out views
        if (&supports_views()) {
-               %views = map { $_, 1 } &list_views($_[0]);
+               my %views = map { $_, 1 } &list_views($db);
+               @rv = grep { !$views{$_} } @rv;
                }
        }
-return grep { !$views{$_} } map { $_->[0] } @{$t->{'data'}};
+return @rv;
 }
 
 # table_structure(database, table)
index 96eb2eb..ef9c565 100755 (executable)
@@ -7456,12 +7456,14 @@ but calls the unlock for you automatically when it is closed.
 =cut
 sub open_lock_tempfile
 {
-my $file = @_ == 1 ? $_[0] : $_[1];
-$file =~ s/^[^\/]*//;
-if ($file =~ /^\//) {
-       $main::open_templocks{$file} = &lock_file($file);
+my ($fh, $file, $noerror, $notemp, $safe) = @_;
+$fh = &callers_package($fh);
+my $lockfile = $file;
+$lockfile =~ s/^[^\/]*//;
+if ($lockfile =~ /^\//) {
+       $main::open_templocks{$lockfile} = &lock_file($lockfile);
        }
-return &open_tempfile(@_);
+return &open_tempfile($fh, $file, $noerror, $notemp, $safe);
 }
 
 sub END