Guest
May 20, 2012, 3:28 pm UTCHome arrow Then Do Something arrow Database Related Functions
header image
Database Related Functions
Written by Dream Dancer   
Nov 26, 2007 at 10:04 PM

Using database's in Furbot is not mysterious, just takes time to plan out how you want to use your database and to lay it out correctly. There is a whole bunch of database commands which can be used in the bot, some of them don't work, but they will one day, but of those which work, there's not much missing from the available commands.

$DATABASE: ~ (!) Give SQL-command {#0} in database {#1}
0 SQL-line
1 Database ID
Not implemented, may never be, use WolfScript instead if you need to get this complicated with the DB.
$DATABASE: ~ (!) Remove table {#0} from database {#1}
0 Table Name
1 Database ID

Not yet implemented, will look into putting this onto the priority list.

Note: You CAN use WolfScript to remove a table using the &DBEXECUTE command. Dangerous. 

$DATABASE: ~ (!) Set variable {#0} to contain list of all entrys in db {#1} in table {#2} value {#3} filter away if value is {#4}
0 Variable Name
1 Database ID
2 Table Name
3 Entry Name
4 Filter away -string
Not implemented.

Have no idea at this time what it's supposed to do, ...
$DATABASE: ~ (!) Set variable {#0} to contain list of all entrys in db {#1} in table {#2} values taken from table {#3} value {#4} where final value is not {#5}
0 Variable Name
1 Database ID
2 Table Name
3 Table 2 Name
4 Table 2 value
5 Filter away -string
Not implemented.

Have no idea at this time what it's supposed to do, ...
$DATABASE: Add record named {#0} to table {#1} database {#2}
0 Record Name
1 Table Name
2 Database ID
Specifically adds a record to the database into the field named ID. Will fail quite nicely, not crash nor deliver an error code if said field ID does not exist.
Eq: DB(ID).AddRecord(TableName)("ID") = RecordName
$DATABASE: Add record where field {#0} value is {#1} to table {#2} database {#3}
0 Field ID
1 Entry data
2 Table Name
3 Database ID
Adds a new record to the table in databaseID. Rather a bit leery of how this is done, if I'm reading this right, you can add a phantom record just because you can point to any field other than ID for the new record, and not be able to access it otherwise because the ID is blank. Will create a record which is blank if the field name is not a field of the DB's selected Table.
Eq: DB(ID).AddRecord(TableName)(FieldName) = RecordName
$DATABASE: Close database {#0}
0 Database ID
Close's the selected Database.
$DATABASE: Convert From DataBase ID to String for variable {#0}, store result to {#1}
0 Variable to convert
1 Variable to store the result
This takes a string and converts it from a DBID format into a "normal" string.

Right now, the translations are   # -> §     " -> '     ' -> +     ¦ -> "SP"  . This will have to improve. But that's for later, currently if you feed &strtodb() (which is done automatically whenever you use any of the Database commands that deal with ID's) a string like: Furre"Name¦#SM', it will return as Furre+Name §SM+. Which means this function will convert it back to: Furre'Name¦#SM', and it's not quite the same, I'm not 100% certain that the server will work correctly with that.

There should be more, there's a bunch of characters which can be used in Furcadia which cannot be used in ADO, like ? and * are illegal characters in ADO, they're used for queries.
$DATABASE: Create field {#0} in database {#1} in table {#2}
0 Field Name
1 Database ID
2 Table Name
Adds a Field to the named Table in the Database. Keep it legal, only use AlphaNumeric Characters and the first character should be strictly Alpha.
SQL: "ALTER TABLE " & TableName & " ADD COLUMN " & FieldName & " TEXT"
$DATABASE: Create table {#0} in database {#1}
0 Table Name
1 Database ID
Creates a Table in the Database. Keep it legal, only use AlphaNumeric Characters and the first character should be strictly Alpha.
SQL: "CREATE TABLE " & TableName & "(ID TEXT)"
$DATABASE: List all IDs from database {#0} table {#1} which start with {#2} to variable {#3}
0 Database ID
1 Table Name
2 ID start text
3 variable to store
Search function, (#2) can be wildcard formatted, so if you want all the "a's" from the DB, you would pass the function "A". The Option Compare on the functions for the DB is TEXT mode, so:
(A=a) < ( À=à) < (B=b) < (E=e) < (Ê=ê) < (Z=z) < (Ø=ø)
Note that unlike the $LOG search functions, you do not need to use the wildcard * for this to work, the function adds that automatically to the search query.
$DATABASE: Open database {#0} to filenumber {#1} (1-4)
0 Database FileName
1 Database ID (1-4)
Opens the named Database to file number (DBID). One of the early mistakes people make when developing FurBot DB's and $Logs is not putting in the [appdir] or any type of solid path to the file. Depending on what the program did before launching the open, this can be anywhere on the hard drive. I've found my FDB's lurking in the root of my C: drive. This should be fairly corrected with the current implementation, the program will notice that there's no path and use it's folder under the Furcadia folder in your documents folder. The extension for this can be whatever you desire, FurBot won't care.

 

Specifics: 1-4 is an absolute, you cannot have more than 4 or less than 0 for the ID of the Database, FurBot will up and die on you if you try for a 5. Yes, there is a DB ID of 0 available, how about that. I do not know if I would recommend using it however, technically, that"s a "feature" because there's an allocation of "4" slots for the DB management, and array's are zero based in the program internally.

Note: The database utilities on the File menu Do use slot 0 for their work.

$DATABASE: Remove field {#0} from table {#1} from database {#2}
0 Field Name
1 Table Name
2 Database ID
Removes (drops) the named Field from Table in the Database.
SQL: "ALTER TABLE " & TableName & " DROP COLUMN " & FieldName
$DATABASE: Remove record {#0} from table {#1} in database {#2} (Redundant command)
0 Record ID
1 Table Name
2 Database ID
Yeah, both this and (61) do the exact same thing, just different wording. This one may become obsolete, or turn into removing a Record by number.
$DATABASE: Remove record from database {#0} table {#1} where ID is {#2}
0 Database ID
1 Table Name
2 Record ID
This removes a Record by name from the Database from Table.
$DATABASE: Set field {#0} in database {#1} in table {#2} to be {#3} in record ID {#4}
0 Field Name
1 Database ID
2 Table Name
3 New data
4 Record ID
Updates Field with New Data in Database in Table in Record. Note that it is possible to update the ID field with the New Data, however, I would not recommend using this as is, naked, without first processing the data with StrToDb first, otherwise you may render your Database inaccessable.
$DATABASE: Set variable [DBret] to contain list of all entrys in db {#0} in table {#1} values taken from table {#2} value {#3} where final value is not {#4} ID {#5}
0 Database ID
1 Table Name
2 Table 2 Name
3 Table 2 value
4 Filter away -string
5 Record ID
Not exactly sure, as soon as I figure it out, I'll update this, ...
$DATABASE: Set variable {#0} to be number of entries in database {#1} table {#2} where field {#3} is {#4} (text comparison)
0 Variable Name
1 Database ID
2 Table Name
3 Field Name
4 Text to compare
Set Variable to contain the number of Records in Database whose Field contains Text.
SQL: "SELECT * FROM " & TableName & " WHERE " & FieldNname & " LIKE " & Chr$(34) & StrToDb(Text) & Chr$(34)

You will note that you should be able to use wildcards in the search at this time, however, the StrToDb function will render all Double Quotes to Single Quotes, all Single Quotes to Plus Signs, and all # to § marks.

$DATABASE: Set variable {#0} to be number of records in database {#1} table {#2}
0 Variable Name
1 Database ID
2 Table Name
Returns the number of Records in Table in Database.
$DATABASE: Set variable {#0} to be value of field {#1} in database {#2} in table {#3} from record {#4}
0 Variable Name
1 Field Name
2 Database ID
3 Table Name
4 Record ID
Retrieves the value contained in Field of the Record in Table in Database. Will return an empty string if the Field entry is empty or the Record does not exist, will also return ID without conversion through DbToStr().
SQL: "SELECT * FROM " & TableName & " WHERE ID LIKE " & Chr$(34) & StrToDb(RecordName) & Chr$(34) & " ORDER BY ID"
$DATABASE: Set variable {#0} to contain list of all entrys in db {#1} in table {#2} field {#3}
0 Variable Name
1 Database ID
2 Table Name
3 Field Name
This will return a list of the entries from Field in Table in Database as a comma space delineated line of text. It will process the entries through DbToStr so if you use it:
$DATABASE: Set variable {names} to contain list of all entrys in db {1} in table {members} field {ID}
Then you will get an ordered list of all the ID's from the Table for:
SQL: "SELECT * FROM " & TableN & " ORDER BY ID"
So if you were to use it on a table which contained, say, random quotes, as a field entry, then each quote will be returned "corrected", that is, all spaces replaced by pipes, plus with single quotes, ...
Last Updated ( Jun 21, 2008 at 09:00 AM )
<Previous   Next>
header image