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

Subroutine for insert template

hi,
I have designed a module, which contains a template for insert command.
The code is as under:
Expand|Select|Wrap|Line Numbers
  1.       my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
  2.                                                localtime(time);
  3.       $year+=1900;
  4.       $mon++;                                                
  5.  
  6.      my $col_name = "100"; 
  7.      my $ins_name = "pavan";
  8.      my $ins_id = 3;
  9.      my $ins_desc = "hi";
  10.      my $createdby = 1;
  11.      my $modifiedby = 1;
  12.      my $table_name = Institution;
  13.      my (@colnames,@values,@exec_arr);
  14.      my $now='now';
  15.     push(@colnames,Institution_Id,Institution_Name,Institution_Desc,Createdby,Createddtm,Modifiedby,Modifieddtm,Customer_Id);
  16.      my $count = @colnames; 
  17.      push(@values,$ins_id,$ins_name,$ins_desc,$createdby,$now,$modifiedby,$now,100);  
  18.      #print "@colnames";
  19.       #my @arr2 = sub1($table_name,@colnames,@values);
  20.      sub1($table_name,@colnames,@values);
  21.  
  22.      sub sub1
  23.      {
  24.  
  25.          push(my @arr,@_);
  26.          print "@arr";
  27.          my $tab_name = $arr[0];
  28.          shift(@arr);
  29.          print "--------------------------------------- \n";
  30.          print "$arr[0]";
  31.          print "--------------------------------------- \n";
  32.          print "\n<<@arr>>";
  33.          print " \n$tab_name \n";
  34.          my $count = scalar(@arr);
  35.  
  36.  
  37.          print "<<$count>>> \n";
  38.          my $limit = $count/2;
  39.  
  40.  
  41.          $i=0;
  42.          my $var='';
  43.           print "<$limit> \n";        
  44.          while($i<$limit)
  45.          {
  46.              if( ($i) == $limit-1 )
  47.              {
  48.                  $var = $var . $arr[$i];
  49.              }
  50.              else
  51.              {
  52.                  $var = $var . $arr[$i] . ",";
  53.              }
  54.              $i++;    
  55.          }
  56.          print "\n var:::::::$var";
  57.  
  58.          $i=$limit++;
  59.          my $vals='';
  60.  
  61.          while($i<$count)
  62.          {
  63.              if( ($i) == $count-1 )
  64.              {
  65.                  $vals = $vals . $arr[$i];
  66.              }
  67.              else
  68.              {
  69.                  $vals = $vals . $arr[$i] . ",";
  70.              }    
  71.              $i++;
  72.          }
  73.          print "\n vals:::::::$vals \n";
  74.          my $sth = $dbh->prepare("insert into $tab_name ($var) values ($vals)");
  75.          my $resp = $sth->execute();
  76.          if($resp ne '0E0')
  77.          {
  78.              print "Successfully inserted";
  79.          }
  80.  
  81.      }  
  82.  
I am able to get column names by $var scalar , and all the values in $vals,
but i am getting error while executing the query as under:

DBD::mysql::st execute failed: Unknown column 'pavan' in 'field list' at D:/pavan/Workspace/sample/insert_template.pl line 107.
Use of uninitialized value in string ne at D:/pavan/Workspace/sample/insert_template.pl line 108.

how to correct the mistake?

Thanks & Regards,
Pavan
Sep 12 '08 #1
3 1420
KevinADC
4,059 Expert 2GB
I don't know what the problem is, but looking at your code, you are using the push() function for no reason. You assign initial values to an array using the assignment operator "=", not push().

correct:

Expand|Select|Wrap|Line Numbers
  1. @array = ($var, $var2, $var3, etc, etc, etc);
  2.  
incorrect:

Expand|Select|Wrap|Line Numbers
  1. push @array,$var, $var2, $var3, etc, etc, etc;
Sep 12 '08 #2
KevinADC
4,059 Expert 2GB
your strings should also all be quoted, for example:

Expand|Select|Wrap|Line Numbers
  1. push(@colnames,Institution_Id,Institution_Name,Ins titution_Desc,Createdby,Createddtm,Modifiedby,Modifieddtm,Customer_Id);
should be:

Expand|Select|Wrap|Line Numbers
  1. @colnames = qw(Institution_Id Institution_Name Institution_Desc Createdby Createddtm Modifiedby Modifieddtm Customer_Id);
Sep 12 '08 #3
numberwhun
3,509 Expert Mod 2GB
Also, please note that your closing code tag should have a "/' character, not a "%" character.

Regards,

Jeff
Sep 12 '08 #4

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

Similar topics

18
by: deancoo | last post by:
I have gotten into the habit of often using copy along with an insert iterator. There are scenarios where I process quite a lot of data this way. Can someone give me a general feel as to how much...
1
by: Paul D. Fox | last post by:
I'd like to populate four dropdowns using code behind. Each dropdown contains the same list. How can I populate them using a subroutine. Something like: InitializeDropDownList(ddlQuadrant1)...
7
by: Lorenzino | last post by:
Hi, I have a problem with bindings in a formview. I have a formview; in the insert template i've created a wizard control and inside it i have an HTML table with some textboxes bound to the...
0
by: michga | last post by:
Hello, Using docbook 4.4, docbook-xsl 1.70.1 and fop, I've successfully used this snippet of code in a customized-layer stylesheet to insert one linebreak: <xsl:template...
5
by: Brad Baker | last post by:
I'm trying to write a simple asp.net page which updates some data in a SQL database. At the top of the page I have the following code: <%@ Page Language="C#" Debug="true" %> <%@ import...
6
by: AG | last post by:
ASP.NET 2.0 aspx page with a FormView bound to an ObjectDataSource to view, add and edit records. Can anyone point me to a sample of how to retain the user entered control values when an insert...
7
by: Jim Langston | last post by:
I'm working on a program, and at one time I find it necessary to load classes into a map. Now, these classes don't have default constructors, so I can't retrieve them using MyMap. So I wound...
5
by: =?Utf-8?B?bXBhaW5l?= | last post by:
Hello, I am completely lost as to why I can't update a DropDownList inside a DetailsView after I perform an insert into an object datasource. I tried to simply it down to the core demostration:...
2
by: Olumide | last post by:
Hello, I've got this nice inner class that I'm holds a set of "FrontPoint" objects as shown below. Unfortunately, the find and insert methods trigger massive C2784 errors. Would someone please...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.