Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Global symbol "$prepare" requires explicit package name

by poj (Abbot)
on Sep 19, 2019 at 07:06 UTC ( [id://11106360]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Global symbol "$prepare" requires explicit package name
in thread Global symbol "$prepare" requires explicit package name

Try

$sth2 = $dbh->$prepare("update $schema.$table set $date_col = ? where $where_col = ?;") or die; $sth2->execute($date_new,1);
poj

Replies are listed 'Best First'.
Re^4: Global symbol "$prepare" requires explicit package name
by tukusejssirs (Beadle) on Sep 19, 2019 at 14:17 UTC

    And could someone tell why the following code does not work? It does not work either with or without placeholders, but with different errors.

    In this case, I want to select all unique dates from timestamps. It works as expected with select distinct cast(date as date) from table; issued directly in psql.

    # With placeholders my $sth_test = $dbh->prepare("select distinct cast($date_col as date) +from ?;") or die; $sth_test->execute($schema.$table); # Errors (on execute()) INFO: The database has been opened successfully. DBD::Pg::st execute failed: ERROR: syntax error at or near "$1" LINE 1: select distinct cast(date as date) from $1; ^ at ./refresh_ +dates.pl line n. DBD::Pg::st execute failed: ERROR: syntax error at or near "$1" LINE 1: select distinct cast(date as date) from $1; ^ at ./refresh_ +dates.pl line n. # Without placeholders my $sth_test = $dbh->prepare("select distinct cast($date_col as date) +from $schema.$table;") or die; $sth_test->execute(); $dbh->disconnect(); # Error (on disconnect) DBI::db=HASH(0x32cec98)->disconnect invalidates 1 active statement han +dle (either destroy statement handles or call finish on them before d +isconnecting) at ./refresh_dates.pl line n.

      Placeholders cannot be used for table names or schema names or anything within the schema. They may only be used for data.

        The problem was that the statement handle was not finished. Solution is to add $sth_test->finish(); before disconnecting the database (src).<\p>

        However, I never used this command before and never encountered this error. Should I use it always before disconnecting the database?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11106360]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-19 23:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found