Here's a snippit of perl code:
sub insert_timesheet {
my $dbh = shift;
my $entryref = shift;
my $insertme = join(',', @_);
my $values_template = '?, ' x scalar(@_);
chop $values_template;
chop $values_template; #remove trailing comma
my $insert = "INSERT INTO timesheet( $insertme ) VALUES ( $values_template );";
my $sth = $dbh->prepare($insert);
debug("$insert");
my @values;
foreach my $entry (@_){
push @values, $$entryref{$entry}
}
debug("@values");
my $rv = $sth->execute( @values ) or die $dbh->errstr;
debug("sql return value: $rv");
$dbh->disconnect;
}
I'm seeing the error
DBD::SQLite::st execute failed: datatype mismatch at timesheet line 85.
The value of $insert:
[INSERT INTO timesheet( idx,Start_Time,End_Time,Project,Ticket_Number,Site,Duration,Notes ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ? );]
Here are @values:
[null '1270950742' '1270951642' 'asdf' 'asdf' 'adsf' 15 '']
Here's the schema of 'timesheet'
timesheet( idx INTEGER PRIMARY KEY AUTOINCREMENT, Start_Time VARCHAR, End_Time VARCHAR, Duration INTEGER, Project VARCHAR, Ticket_Number VARCHAR, Site VARCHAR, Notes VARCHAR)
Here's how things line up:
----
Insert Statement
Schema
@values
----
idx
idx INTEGER PRIMARY KEY AUTOINCREMENT
null: # this is not a mismatch, passing null will allow auto-increment.
Start_Time
Start_Time VARCHAR
'1270950742'
End_Time
End_Time VARCHAR
'1270951642'
Project
Project VARCHAR
'asdf'
Ticket_Number
Ticket_Number VARCHAR
'asdf'
Site
Site VARCHAR
'adsf'
Duration
Duration INTEGER
15
Notes
Notes VARCHAR
''
... I can't see the data-type mis-match.