Tentativo di impostare un valore in PostgreSQL utilizzando Perl e DBI e quindi DBD :: Pg.
Ho uno strano errore.
2013-05-23 19:02:36.641139500 updating status to 0
2013-05-23 19:02:36.641410500 DBD::Pg::st execute failed: ERROR: syntax error at or near "$1"
2013-05-23 19:02:36.641418500 LINE 1: UPDATE instances SET $1 = $2
2013-05-23 19:02:36.641423500 ^at /usr/lib/perl5/vendor_perl/Mitel/MslRest/mbg.pm line 161.
2013-05-23 19:02:36.642425500 [Thu May 23 19:02:36 2013] [error] DBD::Pg::st execute failed: ERROR: syntax error at or near "$1"
2013-05-23 19:02:36.642438500 LINE 1: UPDATE instances SET $1 = $2
2013-05-23 19:02:36.642443500 ^at /usr/lib/perl5/vendor_perl/Mitel/MslRest/mbg.pm line 161.
2013-05-23 19:02:36.642447500
Il codice di riferimento è
my $sql = "UPDATE instances SET ? = ?";
my $dbh = Mitel::tug::getdbh();
$dbh->begin_work;
my $sth = $dbh->prepare($sql);
unless ($sth) {
return $self->internal_error("prepare failed: " . $dbh->errstr);
}
foreach my $propname (sort keys %{ $raw_data }) {
my $propval = $raw_data->{$propname};
print STDERR "updating $propname to $propval\n";
if (! $sth->execute($propname, $propval)) {
$dbh->rollback;
$sth->finish;
return $self->internal_error("execute: " . $dbh->errstr);
}
}
$dbh->commit;
$sth->finish;
Così sto cercando di aggiornare "status" per 0, utilizzando il metodo Execute per prevenire SQL injection, ma sto ottenendo un errore di sintassi per un po ' ragionare.
Qualcuno si imbatte in questo?
[email protected] ~]# perl -v
This is perl, v5.10.1 (*) built for i386-linux-thread-multi
perl-DBD-Pg-2.15.1-4.el6_3.i686
postgresql84-server-8.4.14-1PGDG.rhel6.i686
[email protected] ~]# uname -a
Linux miketug2 2.6.32-279.22.1.el6.i686 #1 SMP Wed Feb 6 00:31:03 UTC 2013 i686 i686 i386 GNU/Linux
Sì, questo risolve il problema. Grazie! –
+1 per: _non puoi usare segnaposto per identificatori (nomi di tabelle, nomi di colonne, ...) _ ... grazie! –