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 1 3041
dna wrote: 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
# one way:
my $idlist = '10, 20, 30';
my $query = "SELECT ID, Name from tblUsers WHERE ID IN ($idlist)";
# etc. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ken1 |
last post by:
I am going to drop a primary key from one column and create a new
column to be used as primary key in an existing database.
The old column was a date column which someone earlier though was a
good...
|
by: Bruce |
last post by:
Hi,
I want to change the datatype of an existing column from char to
varbinary. When I run the "Alter Table" statement, I get the
following error message -
Disallowed implicit conversion...
|
by: Brian Brane |
last post by:
I have properties that wrap DataRow columns as in:
public int aNumber
{ get{ return m_DataRow; }
set{ m_DataRow = value; } }
If the column happens to contain DBNull, I get a cast
exception...
|
by: Clinton Pierce |
last post by:
I've filled a DataTable with columns that have custom type (a class that I'm
using to keep track of other things, not just a value). When the .Select
method goes to sort this column, how do I let...
|
by: Reney |
last post by:
I am using Access in my project. In one of the forms, I am calling two
tables, and two of the columns have date/time type, namely "ClockIn" and
"ClockOut". I created a dataset and filled the...
|
by: drdave |
last post by:
Hi,
In a bound column I have currency datatypes, but the client does not
like $ 0.00 and wants to show a blank instead.. I'm trying to use an if
statement to write out string.empty but it...
|
by: keithb |
last post by:
The following code sets a DataTable column DataType to "String"
column.DataType = System.Type.GetType("System.String");
What is the corresponding statement when the data type is boolean? I...
|
by: Ken |
last post by:
I'm trying to run a loop to capture column property information from a
table in my datasource. Can anybody see where this is going wrong?
Dim tbl As New DataTable
Dim col As DataColumn
Dim x...
|
by: nmsreddi |
last post by:
HI Friends
i am using sqlserver2005 .
I have column in my table with xml DataType .and while i am inserting data into it ,if '&' is there in data it is giving xml parser error as
"XML...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |