DBI SQL column datatype not jiving with SQL statement requirement

From: dna (magmalianathotmaildotcom)
Date: 01/16/04


Date: Fri, 16 Jan 2004 17:42:01 -0500


I have a sql query:

SELECT ID, Name from tblUsers
WHERE ID IN (10, 20, 30)

and, as it probably is obvious to most, ID is of datatype INT

In my perl module, using DBI, I have converted this statement to:

SELECT ID, Name from tblUsers
WHERE ID IN (?)

i have a nice little for loop that will go through my passed in array of
arguments for this query and then it will bind_param each of the arguments
to the query.

        for (my $i = 0; $i <= $#{@$args}; $i++) {
                my $type;
                if ($args->[$i] =~ /^\d+$/) {
                        $type = "SQL_INTEGER";
                } else {
                        $type = "SQL_VARCHAR";
                }
                $sth->bind_param(($i+1), $args->[$i], { TYPE => $type });
        }

the thing is, the argument that is used to populate the '?' in the query is
a STRING as i need to make the list of possible id's dynamic. then, when i
$sth->execute my handle that holds the query, setup with the bind_params, it
craps out.

this seems like an obvious error, but does anyone have any idea of how to
get around it without having to do a loop and test each ID individually (not
very efficient)?

perhaps i'm simply missing something. any input would be appreciated!!!

Thanks in advance,
Dan



Relevant Pages

  • Re: Do While not Statement
    ... How about just doing a count query or queries? ... intBasePaper = odoCon.ExecuteFROM tblUsers WHERE ... > the same recordset. ... > 'Initialise the strSQL variable with an SQL statement to query the ...
    (microsoft.public.inetserver.asp.general)
  • Re: Do While not Statement
    ... query, returning one row, and eliminating the need to loop at all, never ... For SQL Server: ... to include what type of database they are working with... ... > intMale = odoCon.ExecuteFROM tblUsers WHERE ...
    (microsoft.public.inetserver.asp.general)
  • Re: Display result of combo box selection on form?
    ... you need 3 copies of tblUsers. ... >>>>>Currently, on frmBugs, for the field CreatedBy, the user selects from ... >>>> both the main table the report is currently based on AND ... All three tables are in the query. ...
    (microsoft.public.access.reports)
  • Re: Display result of combo box selection on form?
    ... Drag the main table field user ID field to ... >> the UserID field in tblUsers. ... >> query's field list so you can use it in the report. ... All three tables are in the query. ...
    (microsoft.public.access.reports)
  • Re: DBI SQL column datatype not jiving with SQL statement requirement
    ... > I have a sql query: ... > SELECT ID, Name from tblUsers ... > and, as it probably is obvious to most, ID is of datatype INT ... > arguments for this query and then it will bind_param each of the arguments ...
    (comp.lang.perl)