Proximity provides two methods for running scripts:
from the Proximity Database Browser
from the command line
The exercises in this section demonstrate both methods of running scripts in Proximity. The script used in these exercises prints a “Hello world” greeting along with the connection information (host and port) for the database. See “Using the Proximity Python Interpreter” for information on using Proximity’s interactive Python interpreter.
This section describes the script found in
$PROX_HOME/doc/user/tutorial/examples/helloworld.py.
Proximity scripts use the prox object to access the
Proximity class’s methods.
The method getDbName()
returns a string containing the connection information for the current
database.
dbname = prox.getDbName() print "Hello world, you're using database ", dbname
Exercise 6.1. Running a script from the Proximity Database Browser:
Before beginning, make sure that you are serving the ProxWebKB database using Mserver. Start the Proximity Database Browser if it is not already running.
From the Script menu, choose Run Script. Proximity displays the Open dialog.
Navigate to the $PROX_HOME/doc/user/tutorial/examples directory and
choose helloworld.py.
Click Open.
Proximity opens a window to show you any output from the script along with a trace of the script execution. Your output should look similar to the following:
Status: starting running script:
/proximity/doc/user/tutorial/examples/helloworld.py
Hello world, you're using database [localhost, 30000]
Status: finished running script
You can close this window after the script finishes.
You can create shortcuts to commonly used directories for easier access to script files. Shortcuts appear in the Shortcuts pane of the Open dialog. See Creating a file or directory shortcut for information on creating shortcuts.
You can also execute Python scripts directly from the command line using the Proximity script.sh shell script or query.bat batch file.
Exercise 6.2. Running a script from the command line:
Before beginning, make sure that you are serving the ProxWebKB database using Mserver.
Execute the script.sh shell script or script.bat batch file, specifying
Substitute the appropriate host and port information if you are running the MonetDB server on a different machine or are using a different port.
>cd $PROX_HOME>bin/script.sh localhost:30000 \ $PROX_HOME/doc/user/tutorial/examples/helloworld.py
Proximity writes the execution trace to the window from which you executed the above command. The last lines should be similar to the following excerpt (leading information showing elapsed time and execution thread has been omitted from the trace for brevity):
INFO app.PythonScript: * connecting to db
INFO app.PythonScript: * executing script:
/proximity/doc/user/tutorial/examples/helloworld.py
Hello world, you're using database [localhost, 30000]
INFO app.PythonScript: * done executing script