473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DBI SQL column datatype not jiving with SQL statement requirement

dna

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

Jul 19 '05 #1
1 3041
Jim
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.
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
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...
1
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...
4
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...
2
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...
3
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...
5
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...
1
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...
5
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.