473,398 Members | 2,812 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,398 software developers and data experts.

problem with DBI statements in while loop

I hace3 a script that needs to write to a mysql database after pulling records from an ACCESS database. The select there are three loops, one outer loop gets the region, the next gets each building in that region and the next gets each room in that building, then moves on to the next region and starts over. The problem is that it writes the first region, the first building and all the rooms in that building. when it goes to the next building it crashes and says segmentation fault. I am very new with using the DBI like this and am stuck. The problem i think is to write to the database it must pull a variable from the previous loop iteration, any ideas would help
Expand|Select|Wrap|Line Numbers
  1.  my $sql = "SELECT District_ID,
  2.              ClientName,
  3.              Status,
  4.              Region,
  5.              ClientCode,
  6.              OriginalName,
  7.              JPA_ID FROM tblImportedDistricts";
  8.  
  9.  my $sth = $dbh->prepare($sql)
  10.       or die "Can't prepare statement: $DBI::errstr";
  11.  $sth->execute();
  12.  
  13.  warn "starting loops..";
  14.  while ( @region = $sth->fetchrow_array)
  15.   {
  16.     warn $region[1];
  17.     $dist_id = &guid;
  18.     $schema->resultset('customerDistrict')->create(
  19.       {
  20.         version_id                =>$version_guid,
  21.         region_id                 =>$dist_id,
  22.         district_id               =>"$region[0]",
  23.         clientname                =>"$region[1]",
  24.         jpa_id                    =>"$region[6]"
  25.       });
  26.  
  27.  my $sql_building = "SELECT building_ID, Name FROM tblImportedbuildings WHERE districts_ID =  ".$region[0];
  28.  my $sth_building = $dbh->prepare($sql_building)
  29.       or die "Can't prepare statement: $DBI::errstr";
  30.  $sth_building->execute();
  31.  
  32.   while ( @customer_building = $sth_building->fetchrow_array)
  33.   {
  34.  
  35.     warn $customer_building[1];
  36.     $building_id = &guid;
  37.  
  38.     $schema->resultset('customerbuilding')->create(
  39.      {
  40.       customer_building_id            =>$building_id,
  41.       building_id                   =>"$customer_building[0]",
  42.       name                      =>"$customer_building[1]",
  43.       region_id                 =>$dist_id
  44.     });
  45.  
  46.  my $sql_loc = "SELECT room_ID, Description FROM tblrooms WHERE building_ID = ".$customer_building[0];
  47.  my $sth_loc = $dbh->prepare($sql_loc)
  48.     or die "Can't prepare statement: $DBI::errstr";
  49.  $sth_loc->execute();
  50.  
  51.   while ( @customer_room = $sth_loc->fetchrow_array)
  52.    {
  53.      warn $customer_room[1];
  54.  
  55.     $loc_id = &guid;
  56.     $schema->resultset('customerroom')->create(
  57.    {
  58.     customer_room_id         =>$loc_id,
  59.     room_id                        =>"$customer_room[0]",
  60.     customer_building_id     =>$building_id,
  61.     name                           =>"$customer_room[1]"
  62.    });
  63.  
  64.    }
  65.     warn "done with this one";
  66.   }
  67.  
  68.     warn "starting next";
  69.  }
  70.  
  71.  
  72.  
  73. print "Done with: $datasource\n";
  74.  
  75. $dbh->disconnect || die;
  76. }
  77.  
Nov 10 '08 #1
2 1929
KevinADC
4,059 Expert 2GB
A segmentation error is very hard to debug. That generally means the program or operating system is reading/writing to system memory incorrectly. Remove as much code from your perl program as possible and run it. If it runs, add in a little more code and repeat the process untill you get to the part of the perl program that causes the error. You can try and run the program with the debugger on -d:

#!/usr/bin/perl -d

and see if you can figure it out.
Nov 10 '08 #2
Thanks, i have tried stripping it down but it appears that the multiple select statements are killing it. I guess from what i have read the odbc driver i am using for this does not like it.
Nov 10 '08 #3

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

Similar topics

6
by: Iain Bishop | last post by:
I'm trying to model objects for the following problem: A building site contains assemblies, each of which can contain other assemblies and/or materials. I have modelled this using a Site...
6
by: Ravi | last post by:
Hi All, I am trying to execute a select statement using the DBI module of perl in a for loop. I am getting a strange behaviour, the select statement is excuting correctly only for the last element...
7
by: Munzilla | last post by:
Ok, I have an ASP page that I use to add several pieces of information to a database and also display that information in an edit mode. The problem is, when I use the page for edit, not all of the...
5
by: jbruno4000 | last post by:
I'm having 2 problems and hope you can help: Fist Problem: Please see the code segment bellow. For this application I need to access an input file and also an output file, however, when I include...
4
by: James E Koehler | last post by:
I can't get the WHILE statement to work in MySQL. The version of MySQL that I am using is: Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32) running on Windows MX. Here is the relevant...
4
by: phantom | last post by:
Hi All. I am having a problem writing to a file. I can successfully open the file and write the contents using fprintf, however if the writing is not done for a while in the process the file...
6
by: JayCallas | last post by:
I am having a problem with "SET fmtonly ON" and a function I implemented in my database. (The function is actually Erland's delimited string to tmp table function for purposes of passing in...
0
by: satish | last post by:
hi, i have a problem while connecting the Folder in executing sql task in execute sql statements in loop example in Intergration Services --2005 the actual problem -- i have given the sql source...
6
by: weidongtom | last post by:
Hi, I was submitting a solution of a certain problem to the online judge, but it says my program is exceeding the time limit, I've been doing some tweaks to my codes but still it didn't get me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.