473,226 Members | 1,416 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,226 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";
  9.  my $sth = $dbh->prepare($sql)
  10.       or die "Can't prepare statement: $DBI::errstr";
  11.  $sth->execute();
  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.       });
  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();
  32.   while ( @customer_building = $sth_building->fetchrow_array)
  33.   {
  35.     warn $customer_building[1];
  36.     $building_id = &guid;
  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.     });
  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();
  51.   while ( @customer_room = $sth_loc->fetchrow_array)
  52.    {
  53.      warn $customer_room[1];
  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.    });
  64.    }
  65.     warn "done with this one";
  66.   }
  68.     warn "starting next";
  69.  }
  73. print "Done with: $datasource\n";
  75. $dbh->disconnect || die;
  76. }
Nov 10 '08 #1
2 1924
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

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...
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...
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...
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...
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...
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...
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...
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...
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...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...

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.