From OpenSCADAWiki
Subsystem "DB" (SYS.BD)
Functions of the database object (SYS.BD["TypeDB"]["DB"]):
- ElTp cfg( string nm ) — gets the value of the configuration field nm of the object.
- bool cfgSet( string nm, ElTp val ) [access to the appropriate subsystem] — sets the configuration field nm of the object to the value val.
- Array SQLReq( string req, bool tr = EVAL ); — performs the SQL-request req to the DB, inside (tr=true), outside (tr=false) or no matter (tr=EVAL) to the transaction. Returns an array of rows of the result table with the fields both per indexes and column names. At an error the result property "err" sets to the error value.
DBTbl = SYS.BD.MySQL.GenDB.SQLReq("SELECT * from DB;"); if(DBTbl.err.length) SYS.messInfo("TEST DB","Error: "+DBTbl.err); else for(var iRw = 0; iRw < DBTbl.length; iRw++) { var rec = ""; for(var iFld = 0; iFld < DBTbl[iRw].length; iFld++) rec += DBTbl[iRw][iFld] + "\t"; SYS.messInfo("TEST DB", "Row "+iRw+": "+rec); //Get column value by the name if(iRw) SYS.messInfo("TEST DB", "Row "+iRw+": 'NAME'"+DBTbl[iRw]["NAME"]); }