export databaseInfo, getDatabaseInfo, dataArray %Exports the callable parts of the program.
var streamIO : int %Used for keeping track of the file stream.
var row : string %Used to retreive an entire record of data from the database.
var file : string %Holds the file name of the database.
var delimiter : char %Holds the delimetre used in the database.
var dataLengthIndex : flexible array 1 .. 0, 1 .. 0 of int %Holds the lengths of all fields.
var dataArray : flexible array 1 .. 0, 1 .. 0 of string %Stores all the data for calling by the programer.
proc databaseInfo (fileInput : string, delimiterInput : char)
%Gets all of the data from the programer and stores it for future uses.
file := fileInput
delimiter := delimiterInput
end databaseInfo
function countRecords : int %Counts the number of records.
var numRecords : int := 0
open : streamIO, file, get
loop
get : streamIO, row : *
numRecords += 1
exit when eof (streamIO)
end loop
close : streamIO
result numRecords
end countRecords
function countFields : int %Counts the number of fields in the first line.
var numDelimeters : int := 0
open : streamIO, file, get
get : streamIO, row : *
for i : 1 .. length (row)
if row (i) = delimiter then
numDelimeters += 1
end if
end for
numDelimeters += 1
result numDelimeters
end countFields
proc sizeArrays %Sets the lengths of the 2 flexible arrays.
new dataLengthIndex, countRecords, countFields
new dataArray, countRecords, countFields
end sizeArrays
proc getLengthOfEachRecord %Gets the size of each field and stores it in the index array.
var fieldNum : int := 0
for recordNum : 1 .. countRecords
dataLengthIndex (recordNum, fieldNum) := 0
for j : 1 .. length (row)
if row (j) = delimiter then
fieldNum += 1
elsif row (j) = "\"" then %Is used to remove the quotes from strings.
else
dataLengthIndex (recordNum, fieldNum) += 1
end if
end for
end for
end getLengthOfEachRecord
proc populateArray %Stores each record in an array for exporting to the user.
open : streamIO, file, get
for recordNum : 1 .. countRecords
for fieldNum : 1 .. countRecords
get streamIO, dataArray (recordNum, fieldNum) : dataLengthIndex (recordNum, fieldNum)
end for
end for
end populateArray
proc getDatabaseInfo
getLengthOfEachRecord
populateArray
end getDatabaseInfo
end DatabaseIO
|