in reply to Re: Using prepared_cache with placholders
in thread Using prepared_cache with placholders

Why? The SQL never changes, so you're just using up memory for nothing.

Sorry, should have posted the error. I'm guessing that according to SQLite, the SQL does change. My prepared_cached statement goes from:

UPDATE twsJobs SET command = ? WHERE jobId = ?";

to:

UPDATE twsJobs SET ? = ? WHERE jobId = ?";

and the error I receive is:

DBD::SQLite::db prepare_cached failed: near "?": syntax error at...

Evidently, by changing the column name SQLite feels I'm altering the SQL and therefore I get the error with placeholders. By placing the column name in place of the 1st ?, the SQL runs fine. If I can't have a placeholder for the column names, I need to generate the SQL statement each time. I'm hoping some monk may be able to give me insight into how to have a placeholder for the column name.

Replies are listed 'Best First'.
Re^3: Using prepared_cache with placholders
by ikegami (Patriarch) on Apr 04, 2010 at 00:05 UTC

    DBD::SQLite::db prepare_cached failed: near "?": syntax error at...

    You're getting the error because placeholders can only replace values, not field names, table names, SQL clauses, etc.

    my $sth = $dbh->prepare(" UPDATE twsJobs SET ? = ? WHERE jobId = ? "); $dbh->execute($field_name, ..., ...);
    should be
    my $q_field = $dbh->quote_identifier($field_name); my $sth = $dbh->prepare(" UPDATE twsJobs SET $q_field = ? WHERE jobId = ? "); $dbh->execute(..., ...);