WARNING: This server provides a static reference view of the NetKernel documentation. Links to dynamic content do not work. For the best experience we recommend you install NetKernel and view the documentation in the live system .

Endpoint
Name:sqlBatch
Description:The active:sqlBatch service sends a set (batch) of separate SQL statements to a database as a single group.
Id:mod-db:sqlBatch
Category:accessor
Identifier Syntax

sqlBatch is an accessor using Active URI syntax with the following base identifiers:

Base
active:sqlBatch

and the following arguments: (for more details on argument passing details see here)

ArgumentRulesTypingDescription
operand
Mandatory
Representation (java.lang.Object)Document with multiple SQL statements to be executed
configuration
Optional
Representation (java.lang.Object)Connection pool configuration
Request Verbs

The following verb is supported:

Verb
SOURCE
Response

The response representation of this accessor for SOURCE requests is unknown.

This accessor throws no documented exceptions.

Import Requirements

To use sqlBatch accessor you must import the module urn:org:netkernel:mod:db:

<import>
  <uri>urn:org:netkernel:mod:db</uri>
</import>

When a request with the SOURCE verb is issued to active:sqlBatch the set of SQL queries specified in the required operand argument is used with the database connection pool specified in the optional configuration argument. (If the configuration argument is not supplied then the service issues a request for the resource res:/etc/ConfigRDBMS.xml in the current space.) The response representation is returned as an HDS structure in which each updated-rows node contains the number of rows changed by each of the multiple SQL statements.

For example, the following HDS will create a new database for an application:

<batch>
  <sql>DROP TABLE users IF EXISTS;</sql>
  <sql> CREATE CACHED TABLE users ( user_id VARCHAR( 100) NOT NULL, fullname VARCHAR( 100), password VARCHAR( 100), email VARCHAR( 200) );</sql>
  <sql>CREATE PRIMARY KEY ON users(user_id);</sql>
  <sql>INSERT INTO users (user_id, fullname, email, password) VALUES ( 'jim', 'James Tobin', 'jim@myco.com', 'meto');</sql>
  <sql>INSERT INTO users (user_id, fullname, email, password) VALUES ( 'chuck', 'Charles Burst', 'cb@myco.com', 'meto');</sql>
</batch>

Will return an HDS:

<hds>
  <updated-rows>0</updated-rows>
  <updated-rows>0</updated-rows>
  <updated-rows>0</updated-rows>
  <updated-rows>1</updated-rows>
  <updated-rows>1</updated-rows>
</hds>

The argument operand is requested by the service as a HDS which allows the supplied representation type to be any of the forms that can be transrepted to a DeterminateString.

Example

The following code implements the example illustrated above.

request = context.createRequest("active:sqlBatch");
builder = new HDSBuilder();
builder.pushNode("batch");
builder.addNode("sql","DROP TABLE users IF EXISTS;");
builder.addNode("sql","CREATE CACHED TABLE users (user_id VARCHAR(100) NOT NULL, fullname VARCHAR(100), password VARCHAR(100), email VARCHAR(200));");
builder.addNode("sql","CREATE PRIMARY KEY ON users(user_id);");
builder.addNode("sql","INSERT INTO (user_id, fullname, email, password) VALUES ('jim',   'James Tobin',   'jim@myco.com', 'meto');");
builder.addNode("sql","INSERT INTO (user_id, fullname, email, password) VALUES ('chuck', 'Charles Burst', 'cb@myco.com',  'meto');");
request.addArgumentByValue("operand", builder.getRoot())
hds = context.issueRequest(request);

Another alternative implementation uses an externally define resource:

request = context.createRequest("active:sqlBatch");
request.addArgument("operand","res:/resources/sql/databaseInitialization.xml");
hds = context.issueRequest(request);