Failed to execute DBD :: SQLite :: st: data mismatch

Here is a snippet 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 see a mistake

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 the @ values:

[null '1270950742' '1270951642' 'asdf' 'asdf' 'adsf' 15 '']

Here is the schedule chart

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 the lines add 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 do not see the incorrect data type matching.

+3
source share
2 answers

Try reducing your code to smaller and similar pieces to see how small you can get it and still show the error (or, alternatively, see at what stage the problem disappears). You can remove a lot of code simply by calling execute()with a simple query string, and then start removing the fields from the insert statement.

@values, - , , , .

+2

"null" idx. "idx" , ...

.

+2

Source: https://habr.com/ru/post/1740620/


All Articles