473,387 Members | 1,530 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,387 software developers and data experts.

unable to execute insert command in perl script: Can't call method on undefined value

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.          # Here Module's are define
  3.          use DBI;
  4.                                                          # For database Connectivity
  5.          my $DSN = q/dbi:ODBC:SQLSERVER/;
  6.          my $uid = q/ivr/;
  7.          my $pwd = q/ivr/;
  8.  
  9.  
  10.          my $DRIVER = "Freetds";
  11.          my $dbh = DBI->connect($DSN,$uid,$pwd) or die "Coudn't Connect SQL";
  12.  
  13. $fund_code=103;
  14. $mobile_number='7702004546';
  15. $city_address='Karvy Computershare Private Limited,2E / 23, Jhandewalan Extn New Delhi - 110055';
  16.  
  17.  $sql_query4 = "INSERT INTO [192.168.14.28].CommunicationLog.dbo.sms_processedfeeds (pf_Fund,pf_trtype,pf_acno,pf_ihno,pf_Mobile,pf_msgtrtype,pf_msg,pf_entdt ) VALUES (?,?,?,?,?,?,Getdate())";
  18.               $sql_sms = $dbh->prepare($sql_query4);
  19.               $sql_sms->execute($fund_code,'CALL', 0, undef, $mobile_number, 'CALL',$city_address,);
  20.  
  21.  
whenever i'm executing the code, i have gotten following error:

Can't call method "execute" on an undefined value at M_CHECK_SMS_STDCODE.pl line 19
Dec 31 '12 #1
2 2847
RonB
589 Expert Mod 512MB
First problem, which is the most important, is that you didn't enable strictures and warnings. You enable them by adding the strict and warnings pragmas to the beginning of EVERY script you write.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Carp;  # not actually required, but is one of my preferences.
  6.  
The next problem, unrelated to your error, is your improper use of indentation and lack of proper use of horizontal/vertical white space.

The cause of your error is that the prepare statement failed, but due to the lack of error checking, you implicitly told perl not tell you that it failed.

Here's an adjusted version which should shed some light on the reason it failed.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Carp;
  6. use DBI;
  7.  
  8. my $DSN    = q/dbi:ODBC:SQLSERVER/;
  9. my $uid    = q/ivr/;
  10. my $pwd    = q/ivr/;
  11. my $DRIVER = "Freetds";
  12. my $dbh    = DBI->connect($DSN,$uid,$pwd, { RaiseError => 1 })  # enables error checking on all db calls
  13.            or croak "Coudn't Connect SQL " . $DBI::errstr;
  14.  
  15. my $fund_code     = 103;
  16. my $mobile_number = '7702004546';
  17. my $city_address  = 'Karvy Computershare Private Limited,2E / 23, Jhandewalan Extn New Delhi - 110055';
  18.  
  19. my $sql_query4 = "INSERT INTO [192.168.14.28].CommunicationLog.dbo.sms_processedfeeds (pf_Fund,
  20.                                                                                        pf_trtype,
  21.                                                                                        pf_acno,
  22.                                                                                        pf_ihno,
  23.                                                                                        pf_Mobile,
  24.                                                                                        pf_msgtrtype,
  25.                                                                                        pf_msg,pf_entdt)
  26.                 VALUES (?,?,?,?,?,?,Getdate())";
  27.  
  28. my $sql_sms = $dbh->prepare($sql_query4);
  29.  
  30. $sql_sms->execute($fund_code,'CALL', 0, undef, $mobile_number, 'CALL',$city_address,);
Dec 31 '12 #2
numberwhun
3,509 Expert Mod 2GB
Also, I just noticed that in the execute() function, you are providing 7 values, but the "VALUES" portion of your query only has 6 "?" characters. I am not sure if that matters, but it may.
Jan 5 '13 #3

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

Similar topics

2
by: Sandman | last post by:
The subject says it all. I am doing a: I have a perl script in which I am using a ReadParse routine that parses the $ENV{'QUERY_STRING'} or $ENV{'CONTENT_LENGTH'} which are two variables passed...
2
by: george | last post by:
This is like the bug from hell. It is kind of hard to explain, so please bear with me. Background Info: SQL Server 7.0, on an NT box, Active Server pages with Javascript, using ADO objects. ...
2
by: lilush | last post by:
Hello, i have a project where every time i want to add or update something in the DB i use the datatable and dataadpter and i build an insert sql command or an update sql command to the...
2
by: Michael | last post by:
Question. Is it possible to run Server.execute command inside global.asa file. if it is where. Inside Application onstart? Another ideas appreciated. Michael
9
by: skyy | last post by:
Hi i am trying to use the system() command to run some linux command using perl script... Eg.. Deleting files. system("rm $filename"); However, when my $filename contain " character, the...
4
by: jram01 | last post by:
Hi Folks, I am facing problem to to execute .sql command in sql prompt using perl script. I am able to connect sql promt using " my $odbcinput = "odbcinput.txt"; my...
3
fungazid
by: fungazid | last post by:
Hello guys, I have a Perl script that calls other Perl scripts: ### Main script: ### my @command; $command="step1.pl"; $command="step2.pl";
2
by: jagjot | last post by:
hey Can anybody tell me How to convert my perl scripts in binary executables? Which command should I make use of? Please revert back as soon as possible and if possible drop me a mail at ...
1
by: syminder | last post by:
Hi guy, I using the batch program to trigger specific main class in JAR. It is simplest JAVA -cp %classpath% Main_class cmd instruction. Initialy the jdk is not installing cause JAVA command...
4
by: lilly07 | last post by:
I am trying to use a shell grep command inside a perl script using system command as below. system "cat $source_path/s_${i}_${j}_0*testing.txt | grep ' $1' | head > $path/s_${i}_${j}.txt";...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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...

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.