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_INTEGE R";
} else {
$type = "SQL_VARCHA R";
}
$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 3047
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_INTEGE R"; } else { $type = "SQL_VARCHA R"; } $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 candidate for a primary key which we all know it's not.
Now I want to add a new field, i.e. called ID, with a normal number
sequence as primary...
|
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 from data type char to data type
varbinary, table 'test.dbo.testalter', column 'col1'. Use the CONVERT
function to run this query.
|
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 since DBNull cannot be converted to int. I
wrote the following method that looks up the column's
data type and if it is a ValueType, returns the...
|
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 .Net know what value I want
used for the sort?
Sometimes it's going to be sorted as a decimal and other times a string. I
don't really know which...
|
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 dataset already. But I need
to add another column which should calculate the difference between these
two columns. I don't know how to write code in 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 doesn't want to allow the
different datatype..
The currency amounts are stored as number in the db...
How can I accomplish this?
|
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 have
tried both "bit', "bool", and "boolean" and all cause an error.
One would think that a simple search for "System.Type.GetType" in Books On
Line...
|
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 As Integer
Dim colName(99) As String
Dim colType(99) As String
cn.Open()
tbl = cn.GetSchema("Orders") 'Orders is a table in the
|
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 parsing: line 1, character 15, illegal name character"
i have idea that xml parsing & is represented as 'amp' , but i cannot do that
my requirement is...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |