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 -
my $sql = "SELECT District_ID,
-
ClientName,
-
Status,
-
Region,
-
ClientCode,
-
OriginalName,
-
JPA_ID FROM tblImportedDistricts";
-
-
my $sth = $dbh->prepare($sql)
-
or die "Can't prepare statement: $DBI::errstr";
-
$sth->execute();
-
-
warn "starting loops..";
-
while ( @region = $sth->fetchrow_array)
-
{
-
warn $region[1];
-
$dist_id = &guid;
-
$schema->resultset('customerDistrict')->create(
-
{
-
version_id =>$version_guid,
-
region_id =>$dist_id,
-
district_id =>"$region[0]",
-
clientname =>"$region[1]",
-
jpa_id =>"$region[6]"
-
});
-
-
my $sql_building = "SELECT building_ID, Name FROM tblImportedbuildings WHERE districts_ID = ".$region[0];
-
my $sth_building = $dbh->prepare($sql_building)
-
or die "Can't prepare statement: $DBI::errstr";
-
$sth_building->execute();
-
-
while ( @customer_building = $sth_building->fetchrow_array)
-
{
-
-
warn $customer_building[1];
-
$building_id = &guid;
-
-
$schema->resultset('customerbuilding')->create(
-
{
-
customer_building_id =>$building_id,
-
building_id =>"$customer_building[0]",
-
name =>"$customer_building[1]",
-
region_id =>$dist_id
-
});
-
-
my $sql_loc = "SELECT room_ID, Description FROM tblrooms WHERE building_ID = ".$customer_building[0];
-
my $sth_loc = $dbh->prepare($sql_loc)
-
or die "Can't prepare statement: $DBI::errstr";
-
$sth_loc->execute();
-
-
while ( @customer_room = $sth_loc->fetchrow_array)
-
{
-
warn $customer_room[1];
-
-
$loc_id = &guid;
-
$schema->resultset('customerroom')->create(
-
{
-
customer_room_id =>$loc_id,
-
room_id =>"$customer_room[0]",
-
customer_building_id =>$building_id,
-
name =>"$customer_room[1]"
-
});
-
-
}
-
warn "done with this one";
-
}
-
-
warn "starting next";
-
}
-
-
-
-
print "Done with: $datasource\n";
-
-
$dbh->disconnect || die;
-
}
-
2 1929
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.
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.
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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,...
|
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: 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...
|
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...
|
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,...
| |