I actually wrote this 2 years ago but lost the source and binarys, but I recently found a copy of the dll. I released it as WIP last time, but since I cannot do any more work on it (Was orginally supposed to be part of gamecrypt) I am giving it a full program announcement, since it was almost completely ignored last time.
Anyway I think it will be useful for people who are making RPG's or Text adventures and need to store a lot of information that is randomly accessable.
Here is the demo program I wrote for the system. I do not have a keywords file(sorry). So the only commands I know are the ones in this source.
Give it a try. SQL access on a file can be useful sometimes.
result=open database("bank.db")
`If result is 0 then opening the database failed, otherwise 1 is returned
if result=0 then end
`The database is now open. We are going to write a program to keep an account statement.
`We need to create a table in the database for this so we use an SQL query. We shall call
`database 'statement'. First check if the table exists
if table exist("statement")=0
`The table does not yet exist. Lets create it
query$="CREATE TABLE statement (key INTEGER PRIMARY KEY,date TEXT,amount double,description TEXT)"
result=execute query(query$)
if result=-1 then print get error()
if result=0 then print "Table created"
endif
REMSTART
If the query above looks complicated, we can break it down.
First of all is "CREATE TABLE statement" which means the query is going to create a table
called statement. Following this in brackets is the list of fields that will be in
the statement table. Each one has a name and a type. They are as follows:
1. key INTEGER PRIMARY KEY
2. date TEXT
3. amount double
4. description TEXT
INTEGER PRIMARY KEY means that the field is going to be the primary key, and for each
record that is entered into the table, this will go up by 1. This will make more sense later
date is a text field, which will simply hold the date of the transaction.
amount is a double, which is going to hold the sum of money from the transaction
description is a text field which is going to hold details of the transaction
REMEND
`Lets add a transaction to the database. Each time this program runs it will ask you if you
`want to add a new transaction, and then list all the transactions so far
input "Do you want to do a transaction y/n?";tran$
if tran$="y"
input "Please enter an amount. Negative values debit the account: ";amt
input "Please enter a description for this transaction: ";desc$
`Now prepare the query
query$="INSERT INTO statement (date,amount,description) VALUES (CURRENT_DATE," + str$(amt) + ",'" + desc$ + "')"
result=execute query(query$)
if result=-1 then print get error()
if result=0 then print "Record successfully added"
endif
`Now we must display all records in the account
`We use a select query for this
query$="SELECT * FROM statement"
resource=execute query(query$)
if resource=-1 then print get error():wait key:end
`The resource returned from a select statement holds the records returned from the database
`We must now fetch these values and display them
for t=1 to count rows(resource)
key$=SQL RESULT(resource,t,"key")
date$=SQL RESULT(resource,t,"date")
amount$=SQL RESULT(resource,t,"amount")
description$=SQL RESULT(resource,t,"description")
print key$ ; ". "; date$ ; " £" ;amount$ ;" (" ; description$ ;")"
next t
print "Thank you..."
wait key
TheSturgeon(playing me at chess) : I will use my powers of the horse and pwnzor you.