|
zrjones Newbie
Joined: 19 Dec 2007 Posts: 5
|
Posted: Wed Mar 09, 2011 2:29 am
Monster Database Update |
I'm trying to create a Monster Database with stats on each monster. I'm having serious problems with syntax and updating records in the database with new data. Before storing data, I would like to search the database to make sure the monster doesn't already exist. If he exist, I would like to check certain values to see if the database should be updated, and if the monster doesn't exist, I'd like to create a new record. I've done a lot of reading, but I'm not sure if what I have so far is the best method. Can someone make this method work?
recordexists=0
#DBLOAD mo
#DBFIRST
#WHILE (!%null(%rec)) {
#IF (&Name=@mon) {
#ECHO RECORD FOUND
recordexists=1
temphp=&HP
#ECHO @dmg " " @temphp
#IF (@dmg<@temphp) { <- Is there a problem with NESTED #IFs
#ECHO Needs update
//#DBPUT %rec {HP=@dmg} <- This line doesn't update the HP field correctly
}
}
#DBNEXT}
#IF (recordexists=0) {#ECHO STORE NEW RECORD HERE} |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Wed Mar 09, 2011 2:35 pm |
I don't have enough experience with the old built-in database to help much with this, but if you are familiar with SQL, you might find it easier to use the new functionality in version 3.xx to work with an external SQLite database file. Look up the documentation for #SQLDB, #SQLCLOSE, and %sql(). The entire process of adding a record only if one doesn't exist could be done with a single command line.
|
|
|
|
zrjones Newbie
Joined: 19 Dec 2007 Posts: 5
|
Posted: Thu Mar 10, 2011 11:37 am |
I'm currently not running 3.xx, but 2.??, so I might give that a try if I can upgrade. Is anyone else out there would can help me run this on the built-in database module of CMUD 2.**.
|
|
|
|
zrjones Newbie
Joined: 19 Dec 2007 Posts: 5
|
Posted: Thu Mar 10, 2011 11:38 am |
Thanks though for the help.
|
|
|
|
|
|