return errors for invalid SQL
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 27 Mar 2011 17:16:36 +0000 (19:16 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 27 Mar 2011 17:16:36 +0000 (19:16 +0200)
lib/APKPM/Store.pm
t/Store.t

index d63f481..e801108 100644 (file)
@@ -45,7 +45,8 @@ sub sql : Job : Encode(e_json) {
        my ( $self, $job, $workload ) = @_;
 
        my $sth = $self->dbh->prepare($workload);
-       my $rows = $sth->execute;
+       my $rows = eval { $sth->execute };
+       return { error => $@ } if $@;
 
        warn "# $rows rows get_username_table $workload\n";
 
index 1370ba2..a32a737 100755 (executable)
--- a/t/Store.t
+++ b/t/Store.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 5;
+use Test::More tests => 7;
 use Data::Dump qw(dump);
 
 use lib 'lib';
@@ -38,3 +38,7 @@ diag dump($r);
 
 ok my $r = $o->sql('job', "select rtt from ping where username='nobody'"), 'sql';
 diag dump($r);
+
+ok my $r = $o->sql('job', "select xx from fake"), 'sql with error';
+ok exists $r->{error}, 'error';
+diag dump($r);