|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Oct 12, 2009 11:05 pm
SQL commands coming to next version |
One of the features I've been working on that is important for TeSSH is adding SQL commands. This should also benefit CMUD users. I'm still trying to decide if this will only be a CMUDPro feature, or if I'll make it a normal part of CMUD.
The syntax is currently very simple. It's a two step process to use a database: 1) Declare the database, 2) Execute a query.
To declare a database, you can use either the #SQLDB command, or the %sqldb function. The difference is that the %sqldb function actually returns a database connection object (the same syntax as documented in zApp). Whereas the #SQLDB command creates a "named" connection but doesn't actually return any object. Normally you will use #SQLDB to assign a nice name to the connection. The syntax is:
#SQLDB Name Database Driver Server Port Username Password
where everything accept the Name is optional. If you only use a single argument, it is assumed to be the Database name (of a local database file) and the Name is given by the part of the filename up to the period. For example:
#SQLDB muds.db
will open the "muds.db" local database file and create a named connection called "muds".
The Driver defaults to SQLite3 (or SQLite2 if you reference an existing SQLite2 file format). The same list of database drivers supported in zApp can be used here.
Once a database connection has been defined, you can then execute an SQL query using the %sql function. The syntax is:
%sql(connectionName,SQL)
where connectionName is the name of the #SQLDB opened previously. The result of %sql is a zApp Query object. Most of the methods and properties of the zApp object are supported.
Here is a quick example of how you would loop through the MUD list database and display the title of each MUD:
Code: |
#SQLDB muds.db
row = %sql( "muds", "SELECT * FROM mudlist")
#WHILE (not(@row.eof)) {
#SHOW Name: @row.Item("Title")
#CALL @row.next
} |
If you are familiar with the zApp database routines, this will look really familiar. And it's pretty similar to how other programming languages work. The main difference between this and the SQL interface in PHP, for example, is that you use the EOF property of the dataset to determine if you have reached the end, and then use the NEXT method to move to the next row in the dataset, rather than calling something like fetchresult for each row.
To modify the data or a particular row, you use code like this:
Code: |
#CALL @row.edit
row.Item("Title") = "New Title"
#CALL @row.post |
The EDIT method puts the dataset into edit mode, then you can make changes to the row. Then the POST method saves the changes to the database.
This is the precursor to having a new rewrite of the database module. The TeSSH client needs a database manager tool, so that is moving higher on the priority list. But the user interface will take too long to write for this first public release of TeSSH, so I decided to just add some simple SQL scripting commands based upon the work I've done in the past with zApp.
For CMUD, these new commands will allow you to manipulate the new map database format without needing to install SQLite into Lua, or anything like that. And since these database commands work with remote databases, there are some interesting possibilities for scripts to post data to databases.
Still debugging some of this, but expect to see it in the October beta release. |
|
Last edited by Zugg on Wed Oct 14, 2009 4:44 pm; edited 1 time in total |
|
|
|
wrym Magician
Joined: 06 Jul 2007 Posts: 349 Location: The big palace, My own lil world
|
Posted: Tue Oct 13, 2009 3:02 pm |
Very cool Zugg!, but right as im getting pretty good with lua/luasql :(
Couple questions,
This sounds like your porting the whole db portion of zapp over to Cmud, how will you be handling then events of the Query object? As global events? or something more like Queryname.OnDeleted = { code to execute}? really the one that interests me most is the connection.OnCreate event, would save a lot of error checking code.
the zs.getmodule can retrieve the map module, but i was unable to find any ismap property or map property to assess the map filename /file path, could this be added?
Other questions got answered as I re-read the zapp documentation or will be answered as i play with the beta release.
Additionally, the zapp documentation viewer... doesn't appear to be vista friendly, I couldn't get it to run kept getting windows xxx application has stopped working messages.
This also sounds very much like a Cmud pro feature, It offers much of the capability of zmapper if you know what your doing, plus so much more. |
|
_________________ "To the engineer, all matter in the universe can be placed into one of two categories: (1) things that need to be fixed, and (2) things that will need to be fixed after you've had a few minutes to play with them" - Scott Adams, The Dilbert Principle |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Tue Oct 13, 2009 5:12 pm |
No events at this time, sorry. Maybe when the full zApp gets added to CMUD someday. But the event handling was done by the zApp core, which is not part of CMUD right now.
For the map file, try %pref(mapfile) and see what that says. I agree that a better way to get the database name from the actual Map Database object will be needed at some point.
zApp was never Vista friendly. It was one of the reasons (and lack of any sales) that caused zApp to be abandoned. Since the database portion of zApp was not a "visual" component, it was relatively easy to port over. You can still view the zApp documentation in your web browser HERE. No plans to update the zapp documentation viewer. |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Wed Oct 14, 2009 2:13 am |
Sounds like a good feature Zugg. I agree with wrym that this sounds like a Pro feature.
|
|
_________________ Asati di tempari! |
|
|
|
|
|
|
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
|
|