繁体   English   中英

Perl DBD :: SQLite :: db失败:语法错误

[英]Perl DBD::SQLite::db do failed: syntax error

我正在开发一个Perl脚本,以使用线程和DBD :: SQLite来查询PasteBin API,以存储信息以供以后使用。

运行脚本后,出现以下错误:

DBD::SQLite::db do failed: near "day": syntax error at getpaste.pl line 113.
Thread 3 terminated abnormally: DBD::SQLite::db do failed: near "day": syntax error at getpaste.pl line 113.

使用我的代码进行调试,这就是我在thread 3看到的内容:

enum _Days {
  Monday,
  Tuesday,
  Wednesday,
  Thursday,
  Friday,
  Saturday,
  Sunday
}

class HeadingItem implements ListItem {
  String _weekday;
  final int time;
  final DocumentReference reference;

  set day(String weekday) {
    var value = _Days.values[int.parse(weekday) - 1].toString();
    var idx = value.indexOf(".") + 1;
    var result = value.substring(idx, value.length);
    _weekday = result;
  }

  String get day {
    return _weekday;
  }

  HeadingItem.fromMap(Map<String, dynamic> map, {this.reference})
      : assert(map['day'] != null),
        assert(map['time'] != null),
        day = map['day'], // 'day' isn't a field in the enclosing class  <--- this is the error that im stuck on...
        time = map['time'];

  HeadingItem.fromSnapshot(DocumentSnapshot snapshot) : this.fromMap(snapshot.data, reference: snapshot.reference);
}

如果我必须进行有根据的猜测,那就在String get day {炸弹炸开String get day {

这是我的代码中与此相关的部分:

sub threadCheckKey {
    my ($url, $key) = @_;
    my $fullURL = $url.$key;
    my @flaggedRegex = ();
    my $date = strftime "%D", localtime;
    my @data = ();

    my $thread = threads->create(sub {
        my $dbConnection = openDB();
        open(GET_DATA, "curl -s " . $fullURL . " -k 2>&1 |") or die("$!");
        open(WRITE_FILE, ">", $key . ".txt") or die("$!");
        while(my $line = <GET_DATA>) {
            print WRITE_FILE $line;
            foreach my $regex(@regexs) {
                if($line =~ m/$regex/) {
                    if(!($regex ~~ @flaggedRegex)) {
                        push(@flaggedRegex, $regex);
                    }
                }
            }
        }
        close(WRITE_FILE);
        close(GET_DATA);


        open(READ_FILE, $key . ".txt") or die("$!");
        while(my $line = <READ_FILE>) {
            push(@data, $line);
        }
        close(READ_FILE);

        my $updateRow = qq(UPDATE $tables[0] set data = \'@data\', date = \'$date\', regex = \'@flaggedRegex\' where pastekey = \'$key\');
        my $executeRowUpdate = $dbConnection->do($updateRow);

        if($executeRowUpdate < 0) {
            print $DBI::errstr;
        }

在这种情况下,第113行是my $executeRowUpdate = $dbConnection->do($updateRow); 知道Perl的确是在抱怨我上面的UPDATE语句。

我在哪里错呢? 与任何与sql相关的交互时,我都是新手。

您需要记录生成的$updateRow ,然后查看它并查看问题所在。 没有那个,没人知道。

ikegami在上面的评论中提到的其他问题可能值得针对他们的各个方面提出新的问题。 如您所见, https://codereview.stackexchange.com/不适用于有错误的代码。 但是鉴于所有注入问题,可能是时候尝试https://security.stackexchange.com/

如果您解决了这些问题,您的错误也可能会消失。 是否可以,但是值得尝试。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM