473,399 Members | 4,254 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,399 software developers and data experts.

Perl, MS Access and searching with dates?

Hi. I've looked everywhere and tried an enourmous amount of different syntaxes for this, but I keep getting an error when trying to search my database table using a date.

Expand|Select|Wrap|Line Numbers
  1. use DBI;
  2.  
  3. my $dbh;
  4.  
  5. sub initialise {
  6.     #open connection to Access database
  7.     $dbh = DBI->connect("dbi:ODBC:TheatreWol", {AutoCommit => 1}) || die "Couldn't connect to DB\n";
  8. }
  9.  
  10. initialise();
  11. print "Enter command (search, quit): ";
  12. $opt = <STDIN>;
  13. chomp($opt);
  14.  
  15. while ($opt ne "quit") {
  16.     if ($opt ne "search") {
  17.         print "Invalid option - (search, quit):";
  18.         $opt = <STDIN>;
  19.         chomp($opt);
  20.         next;
  21.     }
  22.  
  23.     #prepare and execute SQL statement
  24.     $sqlstatement="SELECT * FROM TheatreWol2007Presentations WHERE startdate=2007-02-01";
  25.     $sth = $dbh->prepare($sqlstatement);
  26.     $sth->execute || die "Could not execute SQL statement ... maybe invalid?";
  27.  
  28.     #output database results
  29.     while (@row=$sth->fetchrow_array)
  30.     { print "@row\n" }
  31.  
  32.     print "Enter command (search, quit): ";
  33.     $opt = <STDIN>;
  34.     chomp($opt);
  35. }
  36.  
I've tried using ' ' around the date, I've tried using # # around the date, I've tried change the format (dd-mm-yyyy, mm-dd-yyyy). I've tried using / instead of - and nothing seems to work. I get this error message when running:

DBD::ODBC::st execute failed: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1. (SQL-07002?)(DBD: st_execute/SQLExecute err=-1) .

Any help would be greatly appreciated.
Apr 3 '07 #1
2 2131
Apologies for not having a code. I'm a bit flustered and in a rush to get this done...

Never mind my question though, it was my own tiredness that caught up with me.. me fields is startseason and not startdate.

Time to be shot...
Apr 3 '07 #2
miller
1,089 Expert 1GB
Hi Masereth,

I'm glad you figured out your own problem. Take this as a lesson that you should always try out your queries at a sql prompt before assuming that they are working right within perl code.

Also, I took a quick moment to reformat your code and add better error messages for your database operations.

Expand|Select|Wrap|Line Numbers
  1. use DBI;
  2.  
  3. our $dbh;
  4.  
  5. sub initialise {
  6.     #open connection to Access database
  7.     $dbh = DBI->connect("dbi:ODBC:TheatreWol", {AutoCommit => 1}) or die "Couldn't connect to DB\n";
  8. }
  9.  
  10. initialise();
  11.  
  12. for (;;) {
  13.     print "Enter command (search, quit): ";
  14.     my $opt = <STDIN>;
  15.     chomp($opt);
  16.  
  17.     if (! grep {$opt eq $_} qw(search quit)) {
  18.         print "Invalid option - $opt\n";
  19.         next;
  20.     }
  21.  
  22.     last if $opt eq 'quit';
  23.  
  24.     if ($opt eq 'search') {
  25.         my $sql = "SELECT * FROM TheatreWol2007Presentations WHERE startseason=2007-02-01";
  26.         $sth = $dbh->prepare($sql);
  27.         $sth->execute or die $dbh->errstr;
  28.  
  29.         #output database results
  30.         while (my @row = $sth->fetchrow_array) {
  31.             print "@row\n"
  32.         }
  33.  
  34.         $sth->finish;
  35.     }
  36. }
  37.  
- Miller
Apr 3 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Firewalker | last post by:
Hey guys, I am newbie to perl. I am trying to deal with dates ( such trying to find what the date would be after month). Is therea function or date class( I am a java programmer, I couldnt find...
33
by: Uwe Range | last post by:
Hi to all! A customer of mine told me some days ago that her IT-people told her ACCESS would not be such a good idea for continuing with our project, because Access will not be continued in the...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
2
by: hardik | last post by:
hi friends, i am really surprized the way access behaves in date fields i mean it's all ok when you have us time zone or us servers but if you have diffrent timezone like uk then access creates...
2
by: kcddoorman | last post by:
I'm am completely new to the world of Perl. It looks like a cross between C and linux scripting. I have some experience in both linux and C, but I'm using perl to query an Access database and post...
1
by: bpejman | last post by:
Hi Everyone, I've been reading and searching the web for days trying to figure out how exactly you can access and read a Perl array or hash from within JavaScript. I've been reading that JSON is...
11
by: sweetbox | last post by:
Hi Guys! I am new on this forum and I am hoping that I could acquire help to improve my PERL skill. My goal is to be able to create a report of all broken links from a website. Based from my...
223
by: Pilcrow | last post by:
Given that UNIX, including networking, is almost entirely coded in C, how come so many things are almost impossible in ordinary C? Examples: Network and internet access, access to UNIX...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
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,...
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.