Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8447621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:13:28+00:00 2026-06-10T10:13:28+00:00

I am running Perl 5.10 on Ubuntu 10.04 and using perl DBI module. I

  • 0

I am running Perl 5.10 on Ubuntu 10.04 and using perl DBI module.
I am trying to use the “AND” condition in “WHERE” clause in SQL Query under Perl DBI. I am using the DBD::CSV driver.

Please consoider below test.csv:

OS,RELEASE,VERSION
Ubuntu,Warty,4
Ubuntu,Hoary,5
Ubuntu,Breezy,5
Fedora,Yarrow,1
Fedora,Tettnang,2
Fedora,Stentz,4

Here I want to retrieve the VERSION for Fedora Stentz.
Here is my code:

#!/usr/bin/perl -w

use strict;
use DBI;

my $table = "test.csv";

my $dbh = DBI->connect ("dbi:CSV:") or die "Cannot connect to the CSV file: $DBI::errstr()";
$dbh->{RaiseError} = 1;
$dbh->{TraceLevel} = 0;

my $query = "select VERSION from $table where OS='Fedora' and RELEASE='Yarrow'";
my $sth = $dbh->prepare ($query);
$sth->execute ();
$sth->dump_results();
$sth->finish();
$dbh->disconnect();

Here is hte output;

0 rows

If I use Placeholders in my query instead of the actual values as below:

my $query = "select VERSION from $table where OS=? and RELEASE=?";
my $sth = $dbh->prepare ($query);
$sth->execute ('Fedora', 'Yarrow');
$sth->dump_results();
$sth->finish();
$dbh->disconnect();

then the output is an error as below:

DBD::CSV::st execute failed: You passed 2 parameters where 0 required [for Statement "select VERSION from test.csv where OS=? and RELEASE=?"] at count.pl line 14.
DBD::CSV::st execute failed: You passed 2 parameters where 0 required [for Statement "select VERSION from test.csv where OS=? and RELEASE=?"] at count.pl line 14.

But if i use only one condition in hte WEHRE clause as below, then the script gives me the right output:

my $query = "select VERSION from $table where OS=?";
my $sth = $dbh->prepare ($query);
$sth->execute ('Fedora');
$sth->dump_results();
$sth->finish();
$dbh->disconnect();

And hte output is:

'1'
'2'
'4'
3 rows

so, the bottom line and my issue is, when I write the “and” condition in “where” clause, it is not working. I doubt that there is something wrong with my query syntax but not able to figure that out yet. Any pointers or suggestion would be of great help.

Also, I have an ongoing thread on perlmonks for the same issue: http://www.perlmonks.org/?node_id=990214

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:13:29+00:00Added an answer on June 10, 2026 at 10:13 am

    All of your snippets work fine for me. Make sure your modules are up to date. From Devel::VersionDump (called on exit):

    Perl version: v5.16.0 on linux (/home/eric/usr/perlbrew/perls/5.16.0t/bin/perl)
    AutoLoader                      -     5.72
    Carp                            -     1.26
    Clone                           -     0.31
    Config                          -  Unknown
    Cwd                             -  3.39_02
    DBD::CSV                        -     0.36
    DBD::File                       -     0.40
    DBI                             -    1.620
    DBI::DBD::SqlEngine             -     0.03
    DBI::SQL::Nano                  - 1.014600
    Data::Dumper                    - 2.135_06
    Devel::VersionDump              -     0.02
    DynaLoader                      -     1.14
    Errno                           -     1.15
    Exporter                        -     5.66
    Exporter::Heavy                 -     5.66
    Fcntl                           -     1.11
    File::Basename                  -     2.84
    File::Spec                      -  3.39_02
    File::Spec::Unix                -  3.39_02
    IO                              -  1.25_06
    IO::File                        -     1.16
    IO::Handle                      -     1.33
    IO::Seekable                    -      1.1
    List::Util                      -     1.23
    Params::Util                    -     1.07
    SQL::Dialects::AnyData          -     1.33
    SQL::Dialects::Role             -     1.33
    SQL::Eval                       -     1.33
    SQL::Parser                     -     1.33
    SQL::Statement                  -     1.33
    SQL::Statement::Function        -     1.33
    SQL::Statement::Functions       -     1.33
    SQL::Statement::Operation       -     1.33
    SQL::Statement::Placeholder     -     1.33
    SQL::Statement::RAM             -     1.33
    SQL::Statement::Term            -     1.33
    SQL::Statement::TermFactory     -     1.33
    SQL::Statement::Util            -     1.33
    Scalar::Util                    -     1.23
    SelectSaver                     -     1.02
    Symbol                          -     1.07
    Text::CSV_XS                    -     0.91
    Tie::Hash                       -     1.04
    XSLoader                        -     0.16
    base                            -     2.18
    bytes                           -     1.04
    constant                        -     1.23
    overload                        -     1.18
    overloading                     -     0.02
    sort                            -     2.01
    strict                          -     1.07
    unicore::Heavy.pl               -  Unknown
    unicore::lib::Perl::Word.pl     -  Unknown
    unicore::lib::Perl::_PerlIDS.pl -  Unknown
    utf8                            -     1.09
    utf8_heavy.pl                   -  Unknown
    vars                            -     1.02
    warnings                        -     1.13
    warnings::register              -     1.02
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get perl running under on my Apache 2 macports install. I'm
I have a Perl/POE/Tk script running on Win32 ActivePerl that calls executables using system
Using Perl, how do I check if a particular Windows process is running or
I've got a Perl script I'm using for running a file processing tool which
I am running Active Perl 5.14 on Windows 7. I am trying to write
I installed the Statistics::Descriptive module using cpan then test the example: use Statistics::Descriptive; $stat
I am running multiple perl scripts (about 2-5) within a ASP.net page using VB.net.
I am running Perl script under cygwin which takes input from <STDIN> and process
I'm using Perl 5.10.1 on Ubuntu 11.04. I want Perl to execute a shell
How to run together: PSGI and PHP? I have Perl/PSGI application (running under pure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.