GlobalScope Class Reference

functions available in global scope More...

List of all members.

Public Member Functions

DataSource sql (string table_or_query, void connection_name)
void include (string file)
numeric simulationrun (void value)
string database (string driver, string params)
void cls (string column, string keyname)
void dumpDataSource (DataSource ds, integer n)
void p (object what)
DataSource loadFile (string file_name, string file_type)
numeric simulationrun2 (number id)
void load (string table_name, string file_name, bool delete)

Static Public Attributes

static int loadTable


Detailed Description

functions available in global scope

Functions in GlobalScope are general purpose helping functions. Global functions can be accessed without a "Object". e.g. you can use print("foo"); instead of GlobalScope.print("foo");. In addition, no instantiation or creation of objects is necessary.

Most of the specific functionality of the Motive Client is encapsulated in objects like DataSource or Bindings that are used in an object oriented programming style. In addition, some helping function are provided in the "global" scope.

These helping functions are defined either as C++ functions exposed to the scripting environment, or as a JavaScript libary that is include() into the script code. While there is no way to change the former (except with new versions of the client), the latter can be modified and adapted by the user. Modifying the library files is not recommended, though.

Library functions in "library.js"

To use this functions, add a call to include "libary.js"; in your script file! See also http://motive.corporate-wiki.net/index.php/Javascript_library

Built in functions


Member Function Documentation

void GlobalScope::cls ( string  column,
string  keyname 
) [inline]

use a user-defined classification in a Binding. See the Keys reference for examples.

Parameters:
column source column / source expression within a Binding.
keyname name of the Keys object to use for the classification.

string GlobalScope::database ( string  driver,
string  params 
) [inline]

opens a database connection and returns a 'handle'

Parameters:
driver name of the database driver, i.e. database type. Values: 'SQLITE', 'ODBC', 'MYSQL'. See DataSource for details.
params list of additional parameters; the type and meaning of the parameters depend on the driver
Returns:
database reference string The function throws exceptions and displays an error message if the connection is not possible.
Here is an example of the usage:
function testSQL() {
    var ds = new DataSource;
    //var db=database('MYSQL', 'host', 'user', 'pwd');
    var db=database('SQLITE', 'E:/dev/motive/client/src/tests/data/iland.sqlite');
    print("using now database" + db);
    ds.connection = db; // set database 'db' as the connection for this datasource
    ds.open('sql', 'stand'); // query the table 'stand' from the database
    ds.showInfo(); // show some overview information
}

void GlobalScope::dumpDataSource ( DataSource  ds,
integer  n 
) [inline]

print 'n' lines of the datasource ds to the debug output.

The function is part of the default library.js

Parameters:
ds an (opened) DataSource
n number of lines to print

void GlobalScope::include ( string  file  )  [inline]

loads a script library file.

Parameters:
file filename to be included. Use include to add libraries written in JavaScript to your project. if file is a relative path, the client looks for file first in the current directory, then in the libraries that are built into the client.

void GlobalScope::load ( string  table_name,
string  file_name,
bool  delete 
) [inline]

load the content of a file into the motive database. This function is useful for a simple and quick import of data that follows exaclty the required data structure from the MOTIVE database. The table_name is the name of a existing table in the MOTIVE database (e.g. 'standtype').

Parameters:
table_name table name of the MOTIVE target table
file_name filename to be loaded.
delete if true, records are deleted before the import operation

DataSource GlobalScope::loadFile ( string  file_name,
string  file_type 
) [inline]

file() loads and returns a file base data source from file_name. If file_type is omitted, the type of the data source is autodetected (based on the file-extension of file_name).

The function is part of the default library.js

Parameters:
file_name source file (see DataSource documentation)
file_type file type of the source
Returns:
the opened DataSource object

void GlobalScope::p ( object  what  )  [inline]

prints custom information to the console depending on the type of what:

  • DataSource: first ten lines of the content of DataSource (note: printing the contents change the position within the DataSource)
  • javascript objects: prints name/value pairs.
  • others: the plain text/numbers The p() function is very useful for debugging purposes.

The function is part of the default library.js

Parameters:
what thing to print

numeric GlobalScope::simulationrun ( void  value  )  [inline]

creates an or selects a entry in the simulation run table. If a simulation run with the provided combination of parameters does not exist, a new simulation run is created. The ID of the simulation run is returned and set as the current default simulation run. All subsequent import for simulation result tables share this simulation run id. See also the WIKI page on "simuation run"

Parameters:
structure defining the meta data keys that define a single simulation run
Returns:
simulation run id
See also:
simulationrun

numeric GlobalScope::simulationrun2 ( number  id  )  [inline]

sets the current simulation run (used for future import operations) to the provided id. If the ID does not exist, an error is thrown. see also the alternate version of simulationrun() allowing the creation of simulation runs.

Parameters:
id of the simulation run
Returns:
simulation run id

DataSource GlobalScope::sql ( string  table_or_query,
void  connection_name 
) [inline]

create and return a SQL data source. connection_name is the name of the database connection (see the database() function). If omitted, the "temporary" database is the default.

The function is part of the default library.js

Parameters:
table_or_query source to be selected from; either a table (if provided as a single table name) or a SQL query.
name of the database connection (see GlobalScope::database()).
Returns:
the (opened) SQL datasource


The documentation for this class was generated from the following file:

Generated on Tue Jun 26 09:45:50 2012 for Motive Database Client API by  doxygen 1.5.9