.
First we need to understand what a Database is and how they work.
A Database is a collection of organized data. If you created a file with organized entrees.
You could consider it a Database. Hear is an example.
Rogers
Joe
83
Johns
mick
14
Al-through most people think of a Database in a larger since.
We are going to use xBase 3 as an example. To write a simple database.
That uses HTML form to enter the data.
*So what is xBase?
It is a database format derived from dBase ®.
*So why use xBase with CGI scripts?
Because databases are fast, efficient, and proven.
We are going to write a raw database system.
Called a Flat-file database.
*So what is a Flat-file database?
A flat-file database is a database stored in a single file that follow a uniform format.
And are not structured for indexing or "recognizing relationships between records" (Relational database).
*Purpose -- Is not to show you how to manage a database (Database administrator).
It is to show you how they work, and how to write your own.
Using CGI scripts and HTML forms with them.
Order of study:
1) What a Database is and how they work.
2) Database terms.
3) Basic xBase 3 file structure.
4) Database system structure: Read and write.
5) Create an empty mollified Xbase 3 file.
6) Compile and test it.
Part 2: Howto Create a HTML form and read CGI script.
1) Install Apache 2 link.
2) Setup Apache 2 to execute CGI scripts.
3) Test Apache 2 setup.
4) Wright a CGI script to Receive, transcribe, And display the form's input.
5) POST and GET: What the difference.
Part 3: Howto add data to the Xbase 3 file.
1)
Fist you need to know a few terms:
xBase file like all files start with a header. xBase header has two parts.
The part that describes the xBase file. And the part that describes the columns.
The file header part (DB_HEADER):
This is a xBase 3 file header description.xBase version. Whether there is a memo fields. Year, Month, and Day last modified. Number of records. Offset to first record. Each record length. And a reserved fields.
Byte | Contents | Description |
0 | 1 byte | Valid dBASE III PLUS table file (03h without a memo 83h with a memo). |
1-3 | 3 bytes | Date of last update; in YYMMDD format. Like 210415 == April, 15, 2021 |
4-7 | 4 bytes | Number of records in the table. (Rows in table) also used as a ID. |
8-9 | 2 bytes | Number of bytes in the header. (32 bytes + column * 32 + terminator 1) data start. |
10-11 | 2 bytes | Number of bytes in the record. |
12-31 | 20 bytes | Reserved |
#pragma pack(1) typedef struct { unsigned int Ver; unsigned int Year_m; //Year last modified. unsigned int Month_m; //Month last modified. unsigned int Day_m; //Day last modified. long int Number_records; //Number of records. And used as a ID number. ///File header (32bytes) + (32bytes * Number of columns) + (1byte 0Dh field terminator.) short int R_offset; //Offset to first record. short int R_length; //Each record length. unsigned int Reserved[20]; //Do not use. } DB_HEADER;
typedef struct { char column_name[11] //Name of the column, upto 10 charters and terminator '\0'. char char_type; //The type of data in the column. N,C,L,M,D,F, OR P. long res_field; //Not used by most databases. //The column length + 1 (delete byte) is the R_length. in the DB_HEADER. unsigned char Col_length; //Column length. Not including the delete byte. //The format of the number in the column. 0 = integer, if > 0 = floating point. unsigned char decimalPlace; char Reserved[14]; //Do not use. } DB_COLUMN;In 1984 dBase 3 was grate. Provably the first really usable databases.
New "Build and run" button.
A console window will pop-up with Hello world! in it. Good.
In the main.cpp code box above.
Right-click in the box and selects "Select All" and copy.
In codeblocks Editor window, click on the main.cpp tab selected.
Overwrite the main.cpp code. By pasting the code from the main.cpp code box above.
Click the save button.
New "Build and run" button.
There will be a file called MyData.dbf.
This is your empty database file.
If you wont to check you MyData.dbf file. And do not have DBase file viewer.
You can download a free one at
Windows Dbf Table Manager Download.
And Codeblocks at
Windows CODEBLOCKS IDE Download.
Windows Apache 2 web server.
Choose either 32Bit or 64Bit. DO NOT FORGET to download the runtime too (vc_redist_x64/86.exe).
Do not download any modules.
LINUX -- Use the Software manager that comes with your distribution (distro) to install Apache 2 web server.
Howto compile Console apps.
Part 2 Create a HTML form and read CGI script.
Howto Create a HTML form and read CGI script.
.