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
Quote Reply
Re: emptying tables In reply to
I would recommend downloading, installing, and using MySQLMan. It is very easy to EMPTY data as well as run other SQL commands. A lot easier than the editor.cgi script. As mentioned in other Threads in this forum, there many bugs in editor.cgi.

Regards,

Eliot Lee

Quote Reply
Re: emptying tables In reply to
Thanks eliot, ive installed this but im having problems, ive posted these in the correct forum.

Regards

MDJ1
http://www.isee-multimedia.co.uk
Quote Reply
Re: emptying tables In reply to
Well, it looks like you got it working...Good.

Regards,

Eliot

Quote Reply
Re: emptying tables In reply to
Thanks Eliot.

A couple of things i mucked up when installing, but got there in the end, Tiredness I think.



Regards

MDJ1
http://www.isee-multimedia.co.uk