Name

sqlDo — executes an arbitrary SQL statement

Synopsis

my $rows = $slashdb->sqlDo($sql);

sqlDo prepares and executes an arbitrary SQL statement in one fell swoop. It performs no processing or quoting, passing the contents of $sql to the database verbatim. When an error occurs, it logs the failed SQL statement and returns a false value. If the statement succeeds, it returns the number of affected rows. Note that if the statement succeeds but affected zero rows, the return value will be the special Perl value 0E0, which evaluates to “zero but true”. This function can be used destructively. Be very careful, especially if anything in $sql can come from outside of the Slash code itself.

Example

# don't do this unless you really really mean it
my $rows = $slashdb->sqlDo("DROP DATABASE slash");
if ($rows) {
    print "It was nice while it lasted.\n";
} else {
    print "Dodged a bullet there!\n";
}

Get Running Weblogs with Slash now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.