#my @col = ("machine","runas");
#my @val = ("bar","faa");
my $col = "machine";
my $val = "bar";
my $dbName = "fooDB.db";
#Create DB connection
my $dbh = DBI->connect( # connect to your database, create if
"dbi:SQLite:dbname=$dbName", # DSN: dbi, driver, database file
"", # no user
"", # no password
{ RaiseError => 1 }, # complain if something goes wrong
) or die $DBI::errstr;
#Create Table
$dbh->do('create table schedules
(schedId INTEGER PRIMARY KEY,
schedName TEXT,
machine TEXT,
runas TEXT,
owner TEXT)' );
#Insert 1 row
my $sth = $dbh->prepare_cached("INSERT into schedules (schedName) valu
+es ('foo')")
or die "Couldn't prepare statement: " . $dbh->errstr;
$sth->execute()
or die "Couldn't execute statement: " . $sth->errstr;
#Get row ID
my $rowId = $dbh->func('last_insert_rowid');
#Do an update with mutiple placeholders
my $sth1 = $dbh->prepare_cached("UPDATE schedules SET ? = ? WHERE sche
+dId = ?")
or die "Couldn't prepare statement: " . $dbh->errstr;
#Try with bind_param_array
#$sth1->bind_param_array(1, @col);
#$sth1->bind_param_array(2, @val);
#$sth1->bind_param_array(3, $rowId); # scalar will be reused for each
+row
#$sth1->execute_array()
$sth1->execute($col,$val,$rowId)
or die "Couldn't execute statement: " . $sth->errstr;
No matter how I use this, with bind_param_array or with straight scalars, I get the same error:
DBD::SQLite::db prepare_cached failed: near "?": syntax error at ./foo
+.pl line 37.
DBD::SQLite::db prepare_cached failed: near "?": syntax error at ./foo
+.pl line 37.
|