comp.lang.ada
 help / color / mirror / Atom feed
From: Laurent <daemon2@internet.lu>
Subject: Re: Reading data from file
Date: Sun, 9 Mar 2014 15:39:05 -0700 (PDT)
Date: 2014-03-09T15:39:05-07:00	[thread overview]
Message-ID: <cb082534-18ee-4f22-b7df-bc3d6065843a@googlegroups.com> (raw)
In-Reply-To: <d0607df2-83bc-4019-bff7-59580f4fad82@googlegroups.com>

Hi

I have a quite strange error/behavior of my code
which I don't understand (the error):

if this Debugging_Enabled     : Boolean := True; then
the procedure below reads the 3 records
from my text file. 2 are inserted into the
database, the 3rd is not because same
ID as the 1st.

If Debugging_Enabled     : Boolean := False; then
only the 1st record is read. Same txt file.
I have localized the error:

if  Debugging_Enabled then
     Ada.Text_IO.Put_Line ("Database Manager: read file loop");
     Ada.Text_IO.Put_Line ("Status: End of file: " & Boolean'Image (End_Of_File));
     Ada.Text_IO.Put_Line ("Status: End of record: " & Boolean'Image (End_Of_Record));
     Ada.Text_IO.Put_Line ("Successfully integrated: " & Natural'Image (Successful_Integration));
     Ada.Text_IO.Put_Line ("Failed integration(s) :" & Natural'Image (Failed_Integration));
     Ada.Text_IO.New_Line;
end if;

If this is executed everything is fine.
I had commented out everything
except Ada.Text_IO.New_Line; and the it worked.
With just a null statement it fails.?!

No idea what is wrong. I don't see why this happens.

https://github.com/Chutulu/Chapter-11.git

Is the database_manager.adb

Will not compile because the screen.ads/adb is missing.
just needs to be commented out.

Thanks

Laurent

/snip

declare

            End_Of_Record : Boolean := False; -- Import_File is not empty
            End_Of_File   : Boolean := False;    -- Import_File is not empty
            Debugging_Enabled     : Boolean := True; -- hope we don't need this
            
            Import_File           : Ada.Text_IO.File_Type;
            
            Successful_Integration : Natural := 0;
            Failed_Integration     : Natural := 0;
            Record_Counter        : Natural := 0;

         begin -- declare
            
            -- open the file and associate it with the file variable name
            Ada.Text_IO.Open (File => Import_File, Mode => Ada.Text_IO.In_File,
                              Name => "Datafile.txt");


            Read_From_File : loop

               Screen.ClearScreen;
               Screen.MoveCursor (Row => 3, Column => 5);
               Ada.Text_IO.Put_Line ("Read data from file");
               Ada.Text_IO.New_Line;

               Read_File : loop                  
                  
                  if  Debugging_Enabled then
                     Ada.Text_IO.Put_Line ("Database Manager: read file loop");
                     Ada.Text_IO.Put_Line ("Status: End of file: " & Boolean'Image (End_Of_File));
                     Ada.Text_IO.Put_Line ("Status: End of record: " & Boolean'Image (End_Of_Record));
                     Ada.Text_IO.Put_Line ("Successfully integrated: " & Natural'Image (Successful_Integration));
                     Ada.Text_IO.Put_Line ("Failed integration(s) :" & Natural'Image (Failed_Integration));
                     Ada.Text_IO.New_Line;
                  end if;
                  
                  exit when End_Of_File;
                  
                  Read_Record : loop

                     --if Debugging_Enabled then
                        --Ada.Text_IO.Put_Line ("Database Manager: read record loop");
                        --Ada.Text_IO.Put_Line ("Status: End of file: " & Boolean'Image (End_Of_File));
                        --Ada.Text_IO.Put_Line ("Status: End of record: " & Boolean'Image (End_Of_Record));
                        --Ada.Text_IO.Put_Line ("Successfully integrated: " & Natural'Image     (Successful_Integration));
                        --Ada.Text_IO.Put_Line ("Failed integration(s) :" & Natural'Image (Failed_Integration));
                        --Ada.Text_IO.New_Line;
                     --end if;

                     Employees.IO.Read_Employee_From_File (File => Import_File,
                                                           Item          => E,
                                                           End_Of_Record => End_Of_Record,
                                                           EOF           => End_Of_File);

                     if not End_Of_Record then
                        Database.Insert (E => E, Success => Success);
                        Record_Counter := Record_Counter + 1;
                        if Success then
                           Successful_Integration := Successful_Integration + 1;
                        else
                           Failed_Integration := Failed_Integration + 1;
                           Ada.Text_IO.Put_Line("Record failed to be read:" & Natural'Image(Record_Counter));
                        end if;
                     end if;

                     exit when End_Of_Record;

                  end loop Read_Record;
               end loop Read_File;

               Ada.Text_IO.New_Line;
               Ada.Text_IO.Put_Line ("Succesfully integrated:" & Natural'Image(Successful_Integration));
               Ada.Text_IO.Put_Line ("Failed integration(s):" & Natural'Image (Failed_Integration));
               Ada.Text_IO.Put_Line("Total number of records in file:" & Natural'Image(Record_Counter));
               Ada.Text_IO.New_Line;
               Ada.Text_IO.Put (Item => "Enter Q to go back to main menu: ");
               Command_IO.Get (Item => MenuSelection);

               exit when MenuSelection = Q;
               Ada.Text_IO.New_Line;

            end loop Read_From_File;
         end; -- declare Read_From_File
snip/

  reply	other threads:[~2014-03-09 22:39 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-04  9:46 Reading data from file Laurent
2014-03-04 16:17 ` adambeneschan
2014-03-04 18:08 ` Mike H
2014-03-04 21:27   ` Laurent
2014-03-04 21:35     ` Laurent
2014-03-04 21:42     ` Niklas Holsti
2014-03-05 13:59     ` Mike H
2014-03-05 20:33       ` Laurent
2014-03-05 21:00         ` Jeffrey Carter
2014-03-05 21:13           ` Laurent
2014-03-05 21:25             ` Niklas Holsti
2014-03-05 21:56               ` Laurent
2014-03-06  8:35                 ` Dmitry A. Kazakov
2014-03-07 21:55                   ` Laurent
2014-03-08  6:56                     ` Dmitry A. Kazakov
2014-03-08 21:21                       ` Laurent
2014-03-09 22:39                         ` Laurent [this message]
2014-03-10  2:42                           ` Jeffrey Carter
2014-03-11 20:54                             ` Laurent
2014-03-08  9:00                     ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox