DIY computer flatfile database program template.
Database is sort of a file cabinet. with a little bit of code we can emulate a file cabinet with a computer. This program is not relational, nor will it replace a full commercial program. For experimentation purposes it is alright. It is buggy and not idiot proof either. Use at you own risk. This program can be used with quickbasic, qibasic or true variants such as qb64. It will not work with Freebasic. You may remember the spreadsheet we did. (http://www.instructables.com/id/DIY-computer-spreadsheet-program-template/).

This program supports: Alpha-numeric (letters and numbers)
Numeric (numbers)
Logical (1 character field)
Date:
Time:
Alpha (Characters, but not numbers)

Plan to update this program and then do a follow up program that will print out invoices. Then be built into a whole accounting system.

Step 1: The code.

DIY computer flatfile database program template.
The code is down-loadable from the attachment. The file is qbasic source code. Putting the code in the instructable chokes it so the file had to be uploaded and made available as a download. Have not tried it on anything other than Linux or Redmond based systems. You will have to rename the file so that it does not have the .txt extension to work.


'**********************************
'* program : LizzyDB.bas *
'* author : Computothought * s
'* last fix: Jan. 1, 1996 *
'* Note : Pc clone flat file *
'* database from what *
'* we learned at school.*
'**********************************
...
...
...
DIY computer flatfile database program template.
tdb.bas.txt33 KB

Step 2: Structure.

DIY computer flatfile database program template.
DIY computer flatfile database program template.
DIY computer flatfile database program template.
DIY computer flatfile database program template.
DIY computer flatfile database program template.
DIY computer flatfile database program template.

The main parts of the program menus are as follows:

Main menu > Design, build, organize, report.
Design (Filename, screen size, and exit code,
Build menu > Append, Behold, Change, Delete.
Organize (sort records b key.
Report: printout to disk.

Step 3: Datafiles.

DIY computer flatfile database program template.
Four basic files are generated: meta, data, index and the report file. Some of the files you could edit manually, but you have to be careful the datafile structure is not disturbed.

Filename.met (Meta data or how the screens are presented.).
$ cat ab.met
5 ,-1,Name, 25 ,A, 0 ,Address, 25 ,A, 0 ,City, 15 ,A, 0 ,State, 2 ,A, 0 ,Zip, 5 ,N, 0 ,

Filename.key (sort key)
$ cat ab
1

Filename.ndx (record numbers in sorted order.
$ cat ab.ndx
2
1

Filename.dat (the data file)
$ cat ab.dat
Equine Test 12345 Test Test city TX88441Angel Bark 434 Heaven Sky City TX32165

Filename.rpt (the report file)
$ cat ab.rpt


This is a report of file: ab
On 12-15-2011 at 05:44:31.
Page number: 1

Name Address City StZip
------------------------------------------------------------------------
Angel Bark 434 Heaven Sky City TX32165 2


This is a report of file: ab
On 12-15-2011 at 05:44:31.
Page number: 2

Name Address City StZip
------------------------------------------------------------------------
Equine Test 12345 Test Test city TX88441 1



Step 4: Possible improvements.

DIY computer flatfile database program template.
Writing a program is just like playing a game, except you get to make the rules as you go along. There is alway room to improve. Things you could easily implement are:
Import/export.
Record search.
Better error checking
Idiot proof.
Multiple keys.
Relational database features.
etc.

Step 5: Line editor template.

DIY computer flatfile database program template.
If you are into writing code, them you might like this former instructable.
DIY computer flatfile database program template.
Line-editor-template.pdf161 KB
DIY computer flatfile database program template.
lw1bas.txt17 KB
DIY computer flatfile database program template.
qbwrite.zip25 KB
DIY computer flatfile database program template.
qbw.zip29 KB

Step 6: A simple database in other forms.

DIY computer flatfile database program template.

GNU Free Documentation License 1.2
Simple database You are encouraged to solve this task according to the task description, using any language you may know.

Write a simple tool to track a small set of data. The tool should have a command line interface to enter at least two different values. The entered data should be stored in a structured format and saved to disk.

It does not matter what kind of data is being tracked. It could be your CD collection, your friends birthdays, or diary.

You should track the following details:

A description of the item. (e.g., title, name) A category or tag (genre, topic, relationship such as "friend" or "family") A date (either the date when the entry was made or some other date that is meaningful, like the birthday); the date may be generated or entered manually Other optional fields

The command should support the following Command-line arguments to run:

Add a new entry Print the latest entry Print the latest entry for each category Print all entries sorted by a date

The category may be realized as a tag or as structure (by making all entries in that category subitems)

The file format on disk should be human readable, but it need not be standardized. A natively available format that doesn't need an external library is preferred. Avoid developing your own format however if you can use an already existing one. If there is no existing format available pick one of: JSON, S-Expressions, YAML, or others.

See also Take notes on the command line for a related task. Contents

C

COBOL

Java

Python

UNIX Shell

Step 7: A simple database in C.

DIY computer flatfile database program template.
DIY computer flatfile database program template.

A simple database in C with some error checking, even. A quick test with Valgrind revealed no obvious memory leaks. The following data was used for testing. -> database.csv

"Soon Rising","Dee","Lesace","10-12-2000","New Hat Press" "Brave Chicken","Tang","Owe","04-01-2008","Nowhere Press" "Aardvark Point","Dee","Lesace","5-24-2001","New Hat Press" "Bat Whisperer, The","Tang","Owe","01-03-2004","Nowhere Press" "Treasure Beach","Argus","Jemky","09-22-1999","Lancast"

$ ./db
Usage: ./db [commands] -c Create new entry. -p Print the latest entry. -t Print all entries sorted by title. -d Print all entries sorted by date. -a Print all entries sorted by author

$ ./db -d

-d Print all entries sorted by date. Title : Treasure Beach Author : Argus Jemky Date : 09-22-1999 Publication : Lancast

Title : Soon Rising Author : Dee Lesace Date : 10-12-2000 Publication : New Hat Press

Title : Aardvark Point Author : Dee Lesace Date : 05-24-2001 Publication : New Hat Press

Press Enter to continue.

Title : Bat Whisperer, The Author : Tang Owe Date : 01-03-2004 Publication : Nowhere Press

Title : Brave Chicken Author : Tang Owe Date : 04-01-2008 Publication : Nowhere Press

DIY computer flatfile database program template.
db.c6 KB
DIY computer flatfile database program template.
database.csv301 bytes

Step 8:

DIY computer flatfile database program template.

Step 9: A simple database in Cobol.

DIY computer flatfile database program template.

This is a souped-up version of the task from Take notes on the command line. It stores the current date, a tag, a title and a note as an entry in a file. The database produced is not particularly human-readable or easy to modify, but it is in a well-structured format.
Works with: OpenCOBOL

Compile with:

$ cobc -x -free db.cob

Sample session:
$ ./database -c "Reminder" "Bob's Birthday" "Buy birthday present for Bob." $ ./database -c "Wishlist" "Beethoven" "Beethoven's Ode to Joy" $ ./database -c "Reminder" "Add to Simple Database" "Add brainf*** example for Simple Database on Rosetta Code." ... $ ./database -f "Mozart" An entry with that title was not found. $ ./database -t Date added: 2013/08/13 Tag: Reminder Title: Bob's Birthday Contents: Buy birthday present for Bob. Date added: 2013/08/13 Tag: Reminder Title: Add to Simple Database Contents: Add brainf*** example for Simple Database on Rosetta Code. Date added: 2013/08/13 Tag: Wishlist Title: Beethoven Contents: Beethoven's Ode to Joy

$ ./database -r "Beethoven" $ ./database -l Date added: 2013/08/13 Tag: Reminder Title: Add to Simple Database Contents: Add brainf*** example for Simple Database on Rosetta Code. $

DIY computer flatfile database program template.
db.cob8 KB

Step 10: A simple database in java .

DIY computer flatfile database program template.

Java
Translation of: D Works with: Java version 7

C:\temp>java -jar SimpleDatabase.jar add item1
C:\temp>java -jar SimpleDatabase.jar add item2

C:\temp>java -jar SimpleDatabase.jar add item3 cat3

C:\temp>java -jar SimpleDatabase.jar add item4 cat3

C:\temp>java -jar SimpleDatabase.jar add item5 cat3

C:\temp>java -jar SimpleDatabase.jar latest item1,2014-06-03 19:30:05,none

C:\temp>java -jar SimpleDatabase.jar latest cat3 item3,2014-06-03 19:30:14,cat3

item4,2014-06-03 19:30:20,cat3

item5,2014-06-03 19:30:23,cat3

C:\temp>java -jar SimpleDatabase.jar all item1,2014-06-03 19:30:05,none

item2,2014-06-03 19:30:08,none

item3,2014-06-03 19:30:14,cat3

item4,2014-06-03 19:30:20,cat3

item5,2014-06-03 19:30:23,cat3

DIY computer flatfile database program template.
SimpleDatabase.java3 KB

Step 11: A simple database in Python 3.

DIY computer flatfile database program template.

Sample session (Unix)
paddy3118:~$ ./simple_db.py -h usage: simple_db.py [-h] [-d DESCRIPTION] [-t TAG] [-f FIELD FIELD] {add,pl,plc,pa}

positional arguments: {add,pl,plc,pa} add: Add a new entry pl: Print the latest entry plc: Print the latest entry for each category/tag pa: Print all entries sorted by a date

optional arguments: -h, --help show this help message and exit -d DESCRIPTION, --description DESCRIPTION A description of the item. (e.g., title, name) -t TAG, --tag TAG A category or tag (genre, topic, relationship such as "friend" or "family") -f FIELD FIELD, --field FIELD FIELD Other optional fields with value (can be repeated)

$ ./simple_db.py -d Book -f title 'Windy places' -f type hardback --tag DISCOUNT add Writing record to _simple_db_db

$ ./simple_db.py -d Book -f title 'RC spammers' -f type paperback -t DISCOUNT add Writing record to _simple_db_db.py

$ ./simple_db.py -d Book -f title 'Splat it' -f type hardback -f special 'first edition' -t PREMIUM add Writing record to _simple_db_db.py

$ ./simple_db.py pl Getting last record from _simple_db_db.py Namespace(description='Book', field=[['title', 'Splat it'], ['type', 'hardback'], ['special', 'first edition']], tag='PREMIUM')

$ ./simple_db.py plc Getting latest record for each tag from _simple_db_db.py Namespace(description='Book', field=[['title', 'Splat it'], ['type', 'hardback'], ['special', 'first edition']], tag='PREMIUM') Namespace(description='Book', field=[['title', 'RC spammers'], ['type', 'paperback']], tag='DISCOUNT')

$ ./simple_db.py pa Getting all records by date from _simple_db_db.py Namespace(description='Book', field=[['title', 'Windy places'], ['type', 'hardback']], tag='DISCOUNT') Namespace(description='Book', field=[['title', 'RC spammers'], ['type', 'paperback']], tag='DISCOUNT') Namespace(description='Book', field=[['title', 'Splat it'], ['type', 'hardback'], ['special', 'first edition']], tag='PREMIUM')

$ cat _simple_db_db.py Namespace(_date='2012-08-18T06:02:44.947091', description='Book', field=[['title', 'Windy places'], ['type', 'hardback']], tag='DISCOUNT') Namespace(_date='2012-08-18T06:03:11.477429', description='Book', field=[['title', 'RC spammers'], ['type', 'paperback']], tag='DISCOUNT') Namespace(_date='2012-08-18T06:03:34.319799', description='Book', field=[['title', 'Splat it'], ['type', 'hardback'], ['special', 'first edition']], tag='PREMIUM')

$

DIY computer flatfile database program template.
dbpython3.py3 KB

Step 12: A simple database in sh.

DIY computer flatfile database program template.

Sample usage (assuming script is named "sdb"):
$ sdb create CDs Create DB `CDs'

$ sdb add CDs Bookends

$ sdb prop CDs Bookends artists "Simon & Garfunkel"

$ sdb add CDs "Ode to joy"

$ sdb prop CDs "Ode to joy" artist "Beethoven"

$ sdb tag CDs Bookends rock folk

# I'm not sure about this

$ sdb tag CDs "Ode to joy" classical

$ sdb show CDs Bookends Description: artists: Simon & Garfunkel Tags: folk rock

$ sdb prop CDs "Ode to joy" Description "Sym. No. 9"

$ sdb show CDs "Ode to joy" Description: Sym. No. 9 artist: Beethoven Tags: classical

$ sdb last-all CDs Tag: classical Ode to joy Tag: folk Bookends Tag: rock Bookends

$ sdb drop CDs Delete DB `CDs'

$

DIY computer flatfile database program template.
db.sh1 KB
 
 

Tag cloud

make build easy simple arduino making homemade solar laser printed portable cheap mini building custom cardboard wooden create super lego turn paracord chocolate your paper light intel