|
cingulli Wanderer
Joined: 30 Aug 2001 Posts: 53 Location: Finland
|
Posted: Tue Aug 20, 2002 7:56 am
HOWTO create database, load/save records ? |
im totally lost with the database system and dont even get the simpliest things to work, so if somebody would be kind enough to show me how to create a database, how set the records, how to write to them and how to read from them, etc...
id want the name of the database to be car-database and it should have two records 'model' and 'year'
so could someone show me from scratch how to do this how to use that #dbload and #new etc... and make it so that i can give the commands from the command line |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Tue Aug 20, 2002 1:12 pm |
First, 'model' and 'year' are fields. Records are each entry in the datbase. Each entry in the datbase, or record, would then be composed of two fields: 'model' and 'year'
Now, you need to first create the structure of the datbase. Open the datbase window and choose to create a new datbase. Give the datbase the name you want. Next, once you have a new database, click on the Fields button. You then create your two fields by click on Add to create a new field. Give each field a name and select the type of values it may contain from the list (text, number, etc.) In your case, 'model' should be text and 'year' should be number. After creating the fields, you are ready to add records to your database.
You can add a record manually, using the datbase window or by script, using the commands and functions zMUD provides. To do it manually, make sure you have the List button selected and then click on the blank record line that appears (there will always be a blank record at the bottom of the rest of your records; when you write in this record, you are creating a new one.) Fill in the information that you want and click Save.
For the next part, you should keep in mind that the database window must be open for any of the datbase command and functions to work. Now, to add a record by script, you use the #NEW command. The #NEW command has this syntax:
#NEW view key-value list
where view is the view in the database that you want the new record to be added into and key-value list is a lits of all the fields in the datbase and their corresponding value that you want for that record. You should not bother about view and you may leave it blank since you will not be using views. An example would be:
#NEW "" model="Toyota Corolla" year=1997
If you want to retrieve a record from the datbase, you use the #DBGET command. For this command, you need to know the record number of the record you want to retrieve. The record number is an automatic number given to each new record by the datbase. It may not necessarily be sequential (the number may skip from 3 in one record to 6 in the next), so it may not be of much use to you. Anyway, an example is:
#DBGET 2
If you want to get a little more advanced, you can use %find. This function returns a list of all record numbers that match some text you supply. The syntax is:
%find(s, view, col)
where s is the value to search for and col is the name of the Field to search the value in. s need not be the exact value contained in col, partial matches are possible. Example:
%find("Toyota", "", "model")
would return a list of all records that have "Toyota" somewhere in 'model'. Another example:
%find(1995, "", "year")
would return all cars with a year of 1995.
Now, the problem with %find is that it returns a list of record numbers, not the actual records. To view the contents of the records returned you could do this:
#FORALL %find(1995, "", "year") {#SAY %expanddb(%dbget(%i), " ")}
Kjata |
|
|
|
cingulli Wanderer
Joined: 30 Aug 2001 Posts: 53 Location: Finland
|
Posted: Tue Aug 20, 2002 3:07 pm |
>> For the next part, you should keep in mind that the database window must be >> open for any of the datbase command and functions to work.
:)
Thank you very much, now it works. |
|
|
|
whovind Newbie
Joined: 11 Nov 2002 Posts: 5 Location: Canada
|
Posted: Wed Nov 20, 2002 7:22 pm |
quote:
#FORALL %find(1995, "", "year") {#SAY %expanddb(%dbget(%i), " ")}
Is that function (expanddb) supported in version 6.16? I'm trying to do something similar to no avail. If it isn't supported could you please help me out with a way to format the raw record into something readable?
Thanks |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Wed Nov 20, 2002 11:20 pm |
It's not documented anywhere, so it's probably not available in 6.16. You could try using it anyway, just to be certain.
Formatting the record is just a matter of using the various commands and functions designed to work with databases. You can come up with something general, or (since you know the database and its fields) something very specific.
#FORALL %find(1995, "", "year") {#LOOPDB %rec {#VAR output {%key: %val - }};#SAY @output}
#FORALL %find(1995, "", "year") {#SAY 1995 %rec.model}
LightBulb
Senior Member |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|