Database library

<< Click to Display Table of Contents >>

Navigation:  Project > Scripts > ST language > Embedded functions >

Database library

Previous pageReturn to chapter overviewNext page

createdbsqlliteconnection(Input1) - used to create create connection to SQLLite database with name in Input1. Database file is created in DB folder.

 

Example:

createdbsqlliteconnection(”filename”);

 


createdbconnection(Input1, Input2, Input3) - used to create connection to database with name in Input1, with username in Input2 and password in Input3.

 

Example:

createdbconnection(“jdbc:mysql://192.168.0.76:3306/test”, “username”, “password”); in this example MySQL database is created. (“jdbc:mysql” in the beginning means that MySQL connection is created).

 


closedbconnection(Input1) - used to close database connection with name in Input1.

 

Example:

closedbconnection(”filename”);

 


createdbtable(Input1, Input2, Input3) - used to create table in database with name of database in Input1, table name in Input2 and columns in Input3 (columns should be separated by commas, every table has auto incremented column “_id”).

 

Example:

createdbtable(“databasename”, “tablename”, “title, parameter1, parameter2”);

 


insertvaluesintodb(Input1, Input2, Input3) - used to insert row into database with name of database in Input1, table name in Input2 and values in Input3 (values should be separated by commas).

 

Example:

insertvaluesintodb(“databasename”, “tablename”, “Title, 10, 20”);

 


readvaluefromdb(Input1, Input2, Input3, Input4) - used to read value from database with name of database in Input1, table name in Input2,  name of the read column in Input3 and condition of read row in Input4 (if several rows fit to condition first row is read).

 

Example:

string parameter = readvaluefromdb(“databasename”, “tablename”, “parameter1”,”_id=1”);

 


readvaluefromdbinpos(Input1, Input2, Input3, Input4, Input5) - used to read value from database with name of database in Input1, table name in Input2,  name of the read column in Input3, condition of read row in Input4 and position of the row in Input5.

 

Example:

string parameter = readvaluefromdbinpos(“databasename”, “tablename”, “parameter1”,”title = Title”, 1);

 


updatevalueindb(Input1, Input2, Input3, Input4, Input5) - used to update value in database with name of database in Input1, table name in Input2,  name of the updated column in Input3, condition of the updated row in Input4 and updated value in Input5 (if several rows fit to condition all rows values are changed)

 

Example:

updatevalueindb(“databasename”, “tablename”, “parameter1”,”title = Title”, “10”);

 


deleterowindb(Input1, Input2, Input3) - used to delete row(s) in database with name of database in Input1, table name in Input2 and condition that should fit the row(s) in Input3.

 

Example:

deleterowindb(“databasename”, “tablename”, “_id=1”);

 


readvaluefromhistorydb(Input1, Input2, Input3, Input4, Input5) - used to read value from history database with name of history database in Input1, begin time in Input2, end time in Input3 (begin and end time in milliseconds since 1 January 1970 year, Input4 database name of the parameter to read, Input5 decimal position of the read value. If several rows fit to time condition first row is read.

 

Example:

string parameter = readvaluefromhistorydb(“History DB0”, 1636367879810, 1636367979810,”pressure”, 2);

 


runsql(Input1, Input2) - used to execute SQL request with name of database in Input1 and SQL query in Input2.

 

Example:

runsql(“databasename”, “create table if not exists param (_id INTEGER PRIMARY KEY AUTOINCREMENT, temperature, pressure, humidity”);

 


runsqlquery(Input1, Input2, Input3) - used to execute SQL request with name of database in Input1 and SQL query in Input2. Input3 contains name of the Result set (table). This Result set is place into global map where key is the name of the result set from the Input3.

 

Example:

runsqlquery(“databasename”, “select * from param”, "resultname");

 


rsfirst(Input1) - used to move cursor of the result set (table) to the first row. Input1 contains name of result set. Return TRUE if the moving is successful. This function doesn't work for SQL lite database.

 

Example:

rsfirst("resultname");

 


rslast(Input1) - used to move cursor of the result set (table) to the last row. Input1 contains name of result set. Return TRUE if the moving is successful. This function doesn't work for SQL lite database.

 

Example:

rslast("resultname");

 


rsnext(Input1) - used to move cursor of the result set (table) to the next row. Input1 contains name of result set. Return TRUE if the moving is successful.

 

Example:

rsnext("resultname");

 


rsisempty(Input1) - used to check availability of the data in result set (table). Input1 contains name of result set. Return TRUE if the result set is empty. This function doesn't work for SQL lite database.

 

Example:

rsfempty("resultname");

 


rsmove(Input1, Input2) - used to move the cursor to position. Input1 contains name of result set. Input2 contains position value. Return TRUE if the moving is successful.

 

Example:

rsmove("resultname",3);

 


rsbeforefirst(Input1) - used to move cursor of the result set (table) to the position before the first row. Input1 contains name of result set. Return TRUE if the moving is successful. This function doesn't work for SQL lite database.

 

Example:

rsbeforefirst("resultname");

 


rsafterlast(Input1) - used to move cursor of the result set (table) to the position after last row. Input1 contains name of result set. Return TRUE if the moving is successful. This function doesn't work for SQL lite database.

 

Example:

rsafterlast("resultname");

 


rspos(Input1) - used to return the position of the cursor . Input1 contains name of result set. This function doesn't work for SQL lite database.

 

Example:

int pos = rspos("resultname");

 


rsreadstring(Input1, Input2) - used to read string value from the current cursor. Input1 contains name of result set. Input2 contains name of the column.

 

Example:

string name = rsreadstring("resultname","name");

 


rsreadstringnum(Input1, Input2) - used to read string value from the current cursor. Input1 contains name of result set. Input2 index of the column.

 

Example:

string name = rsreadstringnum("resultname",2);

 


rsreaddouble(Input1, Input2) - used to read double value from the current cursor. Input1 contains name of result set. Input2 contains name of the column.

 

Example:

double value = rsreaddouble("resultname","value");

 


rsreaddoublenum(Input1, Input2) - used to read double value from the current cursor. Input1 contains name of result set. Input2 index of the column.

 

Example:

double value = rsreaddoublenum("resultname",2);

 


rsreadint(Input1, Input2) - used to read int value from the current cursor. Input1 contains name of result set. Input2 contains name of the column.

 

Example:

int value = rsreadint("resultname","value");

 


rsreadintnum(Input1, Input2) - used to read int value from the current cursor. Input1 contains name of result set. Input2 index of the column.

 

Example:

int value = rsreadintnum("resultname",2);

 


rsreadbool(Input1, Input2) - used to read bool value from the current cursor. Input1 contains name of result set. Input2 contains name of the column.

 

Example:

bool value = rsreadbool("resultname","value");

 


rsreadboolnum(Input1, Input2) - used to read bool value from the current cursor. Input1 contains name of result set. Input2 index of the column.

 

Example:

bool value = rsreadboolnum("resultname",2);

 


rsgetcolnum(Input1) - used to get number of columns. Input1 contains name of result set.

 

Example:

int num = rsgetcolnum("resultname");

 


rsgetcol(Input1, Input2) - used to get column name from the result set. Input1 contains name of result set. Input2 index of the column. This function doesn't work for SQL lite database.

 

Example:

string name = rsgetcol("resultname",2);

 


rsremove(Input1) - used to remove result set from the global map memory. Input1 contains name of result set.

 

Example:

rsremove("resultname");