in reply to Re: DBI data types
in thread DBI data types

you need to call 'finish' on a statement handle after you are done using it.

This is a common mistake. You rarely need to call finish on a statement handle, and you should never call it for an insert statement. You should only call it on a select handle where you do not fetch the entire result set (the select after the last record). It exists to tell the database that you are done with any temporary resources required by the statement (e.g. temp tables for an order by, etc.).

I've never used bind_param, and as far as I can tell, it's completely unnecessary for what you are trying to do.

Bind_param is occasionally necessary to tell DBI what type of argument you have when DBI guesses wrong (though I admit I've never used it either and it probably IS unnecessary in this instance).

Update: I've also seen a case recently on the DBI list where a field is character, but the first value bound to it is numeric, so DBI (or the DBD?) assumes that the field is numeric and doesn't need quoting, which of course breaks when the value bound is non-numeric. Don't quote me on this, my memory is vague :)

Replies are listed 'Best First'.
Re: bind_param
by htoug (Deacon) on Aug 22, 2001 at 15:02 UTC
    I agree that bind_param is unneccessary in this case.

    bind_param is neccessary when the DBI (or rather the underlying DBD) cannot determine the type of the argument and when the type matters.

    eg when a value is NULL - (then the DBD has no clue as to what type it is), when the SV behind the value has both a string and a numeric value (it does matter for some drivers) etc.

    The DBI caches the type of the column, so you only have to give the type once, in subsequent calls the type will be remmebered.

    These situations are not common, but they do exist.
    They are not as uncommon as the cases where finish is needed though :-)

Re: Re: Re: DBI data types
by Dalin (Sexton) on Aug 21, 2001 at 23:54 UTC
    That seems to have corrected those problems, but I seem to be having a parsing problem. I made the change to the "Use DBI" line, and I get the following when I run the script -
    DBD::Pg::st execute failed: ERROR: parser: parse error at or near "al +bino" at . /dbtest.insert line 27, <CSV> line 1. DBD::Pg::st execute failed: ERROR: parser: parse error at or near "al +bino" at . /dbtest.insert line 27, <CSV> line 1.
    "albino" is part of a name from the file being read for the values. The file is "|" delimited, but two of the three fields have spaces between words within them. The other field is numeric. i.e. 12345|SWORDTAIL ALBINO REG|XIPHOPHORUS HELLERI (This is a fish in case you are wondering) Any ideas?????? Thanks for the help. Bradley Where ever there is confusion to be had... I'll be there.