ARCHIVE SERIES
PART 24 : IS ARCHIVE A RELATIONAL DATABASE?
I began working as a programmer again after a long break. My new working environment is on SUN and SEQUENT computers using the UNIX operating system and the ORACLE relational database. Since I get to work with what is probably the premiere relational database currently available I thought it would be fun to discuss how using a “real” relational database compares with using ARCHIVE.
Obviously ARCHIVE can’t work with huge databases like ORACLE can. ARCHIVE has problems with databases with more than 2900 records when ordered on 2 fields. ORACLE can handle databases with 50 million records with no problem. But this difference of scale is not usually important to most QL users because our databases are relatively small. What I want to focus on is the conceptual and functional differences between ARCHIVE and a standard relational database. Are we missing anything?
What is a relational database?
This is not easy to answer. I still have not come across a good succinct description of what a relational database is. Non relational databases are often referred to as “flat file” databases. Some of the promotional material for ARCHIVE refer to it as a multifile relational database. Is it or isn’t it? What is this mystical power possessed by relational databases?
Relational databases are based on a precise mathematical model first formulated in 1970 by E.F. Codd at IBM. This was a theoretical mathematical model for organizing data not a real implemented database. By special organization of the data powerful and fast data handling features became available. The fields (columns) and records (rows) could be manipulated and combined with simple commands in ways difficult to achieve in non relational databases. There are many practical problems when trying to turn this model into a real functioning database. Many database systems have attempted to be relational so they could take advantage of the power that would then be available to them. Even today, relational databases still vary in how much they actually conform to this model.
In addition to a theoretical model to strive for there has evolved a common language to interact with this relational model. It is known as SQL (commonly pronounced ‘sequel’). You often hear that SQL stands for Structured Query Language but the language was not really a structured language in its original form. Anyway, SQL is a universal standard that is controlled and updated by the American National Standards Institute (ANSI). This means that any serious relational database will conformed to this language standard. A relational database system may have additional features of its own but at least it will support the standard features of the SQL language. SQL is not a procedural language like the ARCHIVE language or SuperBASIC. To solve a problem with a procedural language you write a series of procedures in which each accomplishes a small part of the problem. They use primarily a linear step by step approach to solving the problem. One procedure after another is used and the programmer lays out the order of the sequence. With SQL you simply tell the system what you want and the system decides the best way to get it. You might say it is a very high level language because you don’t worry much about the details. This is nice because it has an almost standard English syntax. SQL can do things with just a few simple statements that would take a lot of ARCHIVE code to accomplish. SQL has real smarts about how to quickly get data and even assemble it in different ways because of its relational underpinnings. For example you could take 2 databases (SQL refers to them as tables) and link them together in a view that becomes a kind of virtual database of its own. You can do the same thing within ARCHIVE by writing procedures to keep the data linked together as long as you are in the procedure but SQL does it automatically and can maintain the view permanently.
As usual there is a down side to this power. It is impossible or difficult to do many simple things with SQL. You can’t position yourself at one record and then move to the next. SQL works with arrays of data (columns and rows) and not single rows (records). There are no conditional statements such as ‘if this do this otherwise do that’. Also there are no looping constructs that we take for granted with procedural languages. Gradually some features that allow for these more procedural tasks are being added to the SQL language. But the traditional way to handle procedural tasks are to mix SQL commands with a traditional language such as C or COBOL. This is called ’embedded’ programming because SQL statements are embedded in a C or COBOL program which is precompiled into a file which a standard C or COBOL compiler can accept. As I become more experienced with SQL I find that some things I thought it couldn’t do directly can be done. Although the language looks like almost standard English there are subtle features. This is both good and bad. You can make something work but because the language is not structured you can’t be sure of the interactions of the syntax without very careful study and experimentation. Perhaps as I gain more experience it will become more intuitive but the language certainly is more complex than it seems at first.
So in one way you can say ARCHIVE is definitely not a relational database system. It doesn’t use the standard language of relational databases. But it is interesting that many of the commands in SQL are almost the same as the ARCHIVE command. There is ‘create table’ to create a database. Insert, update, and delete are also common to both languages. The select command works very similar. Perhaps at the time ARCHIVE came out it could have been considered a partial relation database. But now it differs quite a bit from standard relational databases.
In order to illustrate some of the differences between ARCHIVE and an SQL database like ORACLE let us create some comparable databases on each system and see how the uses differ. I will give the basic key presses to create the ARCHIVE databases and then give both the ARCHIVE and SQL commands to do similar tasks.
Comparing ARCHIVE and Relational commands
We will create create 2 related databases or tables as they are known in relational terminology. We have already done something like this in parts 19 and 20 of this series. Suppose we sold firewood and wanted to keep the information in our computer. We keep the wood in piles by species and keep track of the amount in cords. We will create a woodpile database to keep track of what is going into and coming out of our piles. We can cut some wood and add it to a pile or sell some wood and remove it from a pile. We will create a type (species) database to define the types of wood we stock. We will sell each species at a different price per cord as the work involved in collecting the wood varies with its abundance and ease of processing. The commands to set up these database within ARCHIVE are given below.
create "flp1_woodtype"<ENTER> {create woodtype}
type_id$<ENTER>
type_desc$<ENTER>
cordcost<ENTER>
<ENTER> {end create}
insert<ENTER> {insert our woodtype data}
b<ENTER>
beech (american)<ENTER>
70<F5>
m<ENTER>
maple (sugar)<ENTER>
80<F5>
o<ENTER> {o for oak not 0}
oak (red)<ENTER>
90<F5>
p<ENTER>
pine (white)
50<F5>
<F4> {finished woodtype}
order type_id$,a<ENTER> {order type_id ascending}
close<ENTER> {close database}
create "flp1_woodpile"<ENTER> {create woodplie}
event_id<ENTER>
who$<ENTER>
desc$<ENTER>
type_id$<ENTER>
quantity<ENTER>
cost<ENTER>
<ENTER> {end create}
insert {insert our initial stock}
1<ENTER>
me<ENTER>
add wood<ENTER>
b<ENTER>
3<ENTER>
0<ENTER>
2<ENTER>
me<ENTER>
add wood<ENTER>
m<ENTER>
4<ENTER>
0<ENTER>
3<ENTER>
me<ENTER>
add wood<ENTER>
o<ENTER>
3<ENTER>
0<ENTER>
4<ENTER>
me<ENTER>
add wood<ENTER>
p<ENTER>
4<ENTER>
0<ENTER>
Also suppose we sold a few cords.
5<ENTER>
John Jones<ENTER>
sale<ENTER>
b<ENTER>
-2<ENTER>
140<ENTER>
6<ENTER>
Harry Smith<ENTER>
sale<ENTER>
m<ENTER>
-1<ENTER>
80<ENTER>
7<ENTER>
Jean Rogers<ENTER>
sale<ENTER>
0<ENTER>
-1<ENTER>
90<ENTER>
8<ENTER>
Andy Wlaker<ENTER>
sale<ENTER>
p<ENTER>
-2<ENTER>
100<ENTER>
<F4> {done entering into woodpile}
order event_id;a<ENTER>
close<ENTER>
Now we have some data to play with. With ARCHIVE we could look at our sales with a statement like :
look 'flp1_woodpile'<ENTER>
select who$<>'me' : display : while not eof() : sprint : next
: endwhile<ENTER>
And we could get a total sum with :
let sum=0 : first : while not eof() : let sum = cost + sum
: next : endwhile : print sum <ENTER>
Except for the select command we approach the data one record at a time. But with SQL we always work with sets and everything comes at once. To see sales type :
select * from woodpile where who$ <> 'me';<ENTER>
And to sum sales we would type :
select sum(cost) from woodpile;<ENTER>
Notice that the statements are more simple in SQL and we don’t need to use while loops to work through it. It all comes at once. Sum() above is a SQL function. To look at individual records or rows as they are called in SQL, we have to use a select to select one at a time :
select * from woodpile where event_id = 1;<ENTER>
select * from woodpile where event_id = 2;<ENTER>
But in ARCHIVE we would just :
reset<ENTER>
locate event_id = 1 : display<ENTER>
next<ENTER>
So it is much easier to browse individual records in ARCHIVE. Suppose we wanted to see how much oak we have in stock :
let sum = 0 : reset : select type_id$ = 'o' : while not eof()
: let sum = quantity + sum : next : endwhile
: print sum<ENTER>
But with SQL it is much easier :
select sum(quantity) from woodpile
where woodtype = 'o';<ENTER>
Suppose we wanted to see the 2 files linked together. With ARCHIVE it is fairly complex :
close : look 'flp1_woodpile' logical 'w'<ENTER>
look 'flp1_woodtype' logical 't'<ENTER>
first : while not eof('w') : use 't' locate w.type_id$ : use 'w'
: print event_id;tab 5;who$;tab 25;desc$; tab 40;
t.type_desc$; tab 50;quantity;tab 60;cost : next
: endwhile<ENTER>
It would be easier if we put the above in a procedure but it would still be pretty long. With SQL it is quite easy :
select
event_id,who$,desc$,type_desc$,quantity,cost<ENTER>
from woodpile,woodtype<ENTER>
where woodpile.type_id = woodtype.type_id<ENTER>
This is just scratching the surface but it may give you a little feel for what a relational database is and how ARCHIVE compares to one. A real flat file is just that, a file with raw data in it. ARCHIVE is more complex than that. The database file holds the data plus information about what kind of data goes in each field (text or numeric) and the file also holds the index information if the field is ordered. Much of the terminology to ARCHIVE is very similar to SQL. And I haven’t seen anything yet that you can’t do in ARCHIVE as long as you can write procedures to help you out. So ARCHIVE along with its language can perform any tasks you need, relational or otherwise. It might not work fast but it will work. SQL relational databases on the other hand are fast and efficient. That can do array manipulations (row and column) very fast from simple commands. If you need individual record (row) manipulations you may have to resort to using a language like C and embed your SQL statements in them. This can get to be very complex.
In conclusion I would have to say that for most uses on a QL, ARCHIVE is as good as anything I have seen for putting together any kind of database application of small to medium complexity. Of course the newer GUI interfaces might make it easier but I don’t even have that in my job. Until next time, Happy ARCHIVING.
SEE YOU AT THE QL SHOW IN BOSTON ON MAY 18