Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl sql query reuse ? variable

Status
Not open for further replies.
Jun 3, 2007
84
US
Hello wondering if someone could please point me in the right direction.

I am trying to figure out if/how to use the ? variable twice in the same query.

example

example
Code:
my @lines = read_file('/tmp/test.txt');
chomp(@lines);

my $sql = q|select * from table_name where srcaddr = ? or dstaddr = ?;

Looks like the problem is that I am using the ? variable twice which the script doesn't like. How do you use the ? variable twice in the same query, or what is another way to do this?

Thanks for the help in advance.
 
well you didn't end your statement to begin with. Your missing the ending |.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Thanks for the reply but I have the ending | in my script. Like I mentioned above the error that i am getting is related to the use to ? twice. If I remove the second ? in the query everything works fine. So what I am guessing is the problem is that it doesn't like that I am using ? twice.

Thanks,
 
Perl:
my $sql = 'select * from table_name where srcaddr = ? or dstaddr = ?';
my $sqh = $dbh->prepare($sql);
$sqh->execute('parm1', parm2');
'parm1' gets inserted into the first placeholder ?, and 'parm2' into the second.

HTH

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top