Favourites

Search

Server Side Pascal Scripts and NxCommand

Mon, 03/09/2009 - 21:59 | hdanzl

One major new feature of NexusDB V3 is the ability to run server side pascal scripts. These scripts have full access to the server infrastructure (like server engine, monitors, settings) as well as to all databases. The initial release will only include a simple access control to this feature on the basis of a security token which can be assigned to a user (same as the R, W and A tokens in NexusDB V2). Incremental updates will introduce finer access control to the server infra structure and databases.

Let's take a look at a small script that executes a query and dumps the data to the output.

As you can see, very straight forward, the only thing different to a standard Delphi function is the use of the global variable ServerEngine (which is a direct reference to the main server engine of the server where the script is executed) and the use of the global Output class instance (preliminary class members) to dump the data.

The script processing on the server side is implemented as a special handler of the also new nxRemoteRemoteCommands plugin. This plugin has an extensible Type parameter and one such type is cmdExecScript.

How to run a script?

Now that's the question is it. Simple to answer: All you need to do is call the plugins ExecCommand method. The server side implementation of the plugin creates an Alias 'ServerRemoteCommand' which will have the the output of the script buffered in a (per command unique) table.

One of the simplest ways start a script and get return the output is the following:

You can also execute a script directly by replacing the last parameter with

/Direct:"begin Output.Write('abc');end."

in future (together with updated security) we will of course add support for server, username and password arguments, but for the time being this will only work on a local server.

Script Repository

We will provide at least 2 scripts at launch which will be shipped with NexusDB and at the same time will be available from our upcoming online script repository. Every registered user of our web site will be able to access and add scripts in that global repository.

The first script runSQL.nxscript will execute a SQL command and allow to format the output with delimeters, quoting etc. This can be used to very quickly export some data to a CSV (or similar) file. Please look at the preliminary source for the details. You can call it like this (for a local server with no user/password):