5.8.3. Database Functions

getSql() provides convenient way to perform SQL query transaction which will return the result as string. Below is the usage and its parameters.

getSql([string] sql, [object] option)

[object] option format:
{ 
  dbgroup: 'xx',  // [string] database name created in database table,
  // default to all database if not supplied.
  offset: 0,      // [integer] skip the first stated number of result, default to no offset.
  limit: -1,      // [integer] limit to return stated number of result, default to no limit.
  skip: 0,        // [integer] skip certain number of rows between results, default to no skip.
  outfmt: 'xx'    // [string] output format, valid values are csv/csvh/json/xml, default to CSV.
}

Sample usage: var result = getSql( "select * from log", {dbgroup:"dblog",offset:2,limit:3,skip:2,outfmt:"json"});

Graphical representation of an example of the parameters usage. Note that only record 2, 5 and 8 are returned, the rest are ignored.

Record

Parameter

0

Offset 1

1

Offset 2

2

Result 1

3

Skip 1

4

Skip 2

5

Result 2

6

Skip 1

7

Skip 2

8

Result 3

9

Skip 1

10

Skip 2

11

Result 4

12

...

...

...

setSql() provides convenient way to perform SQL query transaction without returning anything. Below is the usage and its parameters.

setSql([string] sql, [object] option)

[object] option format:
{ 
  dbgroup: 'xx'   // [string] database name created in database table,
  // default to all database if not supplied.
}

Sample usage: setSql( "insert into alarm values (cell1, cell2...)", {dbgroup:"mdb"});