Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

emptying tables

Quote Reply
emptying tables
Hi All,

Im going through a process of removing all information from all tables before re-importing.

As this is a lengthy process i was wondering how to create an add in to editor.cgi that will do this for you.

Ive found the section in the script that does this.

Code:
sub execute_sql {
# --------------------------------------------------------
# Execute an SQL statement.
#
my ($in, $db) = @_;
my $query = $in->param('command') || return "No query entered!";
my $file = $in->param('command-file');

$file and (-w $file or return "Unable to write to file '$file'. Reason: $!");
my ($sth, $rv, $output);

eval { $sth = $db->prepare ($query); };
($@ or !defined $sth) and return "Query Error: $Links::DBSQL::error";

eval { $rv = $sth->execute(); };
($@ or !defined $rv) and return "Query Error: $DBI::errstr";

my $rows = $sth->rows || 0;
$file and (open (FILE, ">$file") or return "Unable to open file: '$file'. Reason: $!");
if ($query =~ /SELECT|DESCRIBE|SHOW/i) {
$output = "<pre>Your query returned $rows rows. \n\n";
while (my $arr = $sth->fetchrow_arrayref) {
$file ? (print FILE join ("\t", @$arr), "\n") : ($output .= join ("\t", @$arr) . "\n");
}
$output .= "</pre>";
}
else {
$output = "Rows affected: $rows";
}
return $output;
}
I see that the command is passed through $query Would i be correct in saying that if i created a link with the valiable passed in a form this would empty the individual tables?

I think i could also put a basic perl security feature on this aswell.

Regards

MDJ1
http://www.isee-multimedia.co.uk
Subject Author Views Date
Thread emptying tables mdj1 2061 Jul 31, 2000, 4:43 PM
Thread Re: emptying tables
Stealth 2007 Jul 31, 2000, 4:53 PM
Thread Re: emptying tables
mdj1 2012 Jul 31, 2000, 6:21 PM
Thread Re: emptying tables
Stealth 1996 Jul 31, 2000, 8:42 PM
Post Re: emptying tables
mdj1 1991 Aug 1, 2000, 4:54 AM