Processing Data Records
This is so common!
In lots of programming tasks we need to be able to process records sequentially. The records can be in files, databases, entered live, or even from data on a distant server that was brought to your program with AJAX.
A record is like a row in a spreadsheet. Here's an example of an employee record:
1000, "John", "Smith", "Engineer", "555-1234"
-
The record has discrete pieces of data that have been separated with commas. Each of the pieces of datum in the record is called a field.
-
In data processing we sometimes call the commas a delineator.
-
A Record Set (a file) is a bunch of records like the one above. The number of records in a record set can vary from just a few to many millions.
-
Records can exist in many ways and you will learn lots of ways in your coming semesters. The most important way that organizations store data records these days are in databases. This is why there are several semesters of database courses in our programming degree.
Record Processing¶
One step at a time.
-
JavaScript has an important security feature, it can't access your local hard drive in any way. This is to prevent malicious JavaScript code from doing damage to your computer. This is a really good thing when you are creating applications for real use, but it makes learning how to process records more difficult.
-
Because JavaScript running in the browser traditionally has no file Input/Output (I/O) capabilities we will be using a record processing system that has been custom-made to simulate record processing for the course. It allows us to learn to process records and data in a way that is similar to what you will be using in your future courses.
Filesystem access
Most browsers now have a filesystem API that can be used to read and write to files on your computer, but it must ask for permission to do so. That's a pretty good thing too. Can you imagine if any website you visited could change files on your computer?
-
In the unit04/unit04/js/ directory there is a special JavaScript file that contains all the data and some code which allows us to use the data. Feel free to find it and look it over, but you won't need to edit the file in any way. It also might be a little difficult to understand at this point in your programming knowledge. You'll understand all of it before you are done with the degree.
-
Here's how it works. When you are writing a program that needs to process records you will create a variable that stores all the records you need. For example, it might be named "records" as in the following example:
let records;
- You then use a system function that starts with "open" to make the data available for use in your application. The particular one to use for any given record set will be documented in the lab or project file. After this function has been run your program will be ready to read the first record in the set.
records = openSampleDataRecords();
- A function to read the next record. This makes the next record available if there are any more to be read. If there aren't anymore records then the function returns
false
. If there are more records then the function returnstrue
. This is typically called as the loop conditional.
records.readNextRecord();
- Let's see how this all works
Available Record Sets¶
Here is a list of the available records sets for this unit. We'll be using these for labs, projects, and demos for this unit. Each one is a link to more details about the set.
Student Exam Records¶
Student Enrollment Records¶
Inventory Items Records¶
Employee Payroll Records¶
Record Processing Demo¶
Here's a demo of how to loop through one of these record sets.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
** Click me to run processingDataRecords()
**
Note: Refresh the page to return to the course content
Labs
- Lab03: Record Set Processing
- unit04/labs/lab-03-recordSet.html
- Lab04: A Simple Start with Student Enrollment Records
- unit04/labs/lab-04-student-enroll.html