From OpenSCADAWiki
Jump to: navigation, search
(Importing a new version from external source)
(Importing a new version from external source)
 
Line 4: Line 4:
 
<li>''ElTp cfg( string nm )'' — gets the value of the configuration field ''nm'' of the object.</li>
 
<li>''ElTp cfg( string nm )'' — gets the value of the configuration field ''nm'' of the object.</li>
 
<li>''bool cfgSet( string nm, ElTp val )'' [<span style='color:red'>access to the appropriate subsystem</span>] — sets the configuration field ''nm'' of the object to the value ''val''.</li>
 
<li>''bool cfgSet( string nm, ElTp val )'' [<span style='color:red'>access to the appropriate subsystem</span>] — sets the configuration field ''nm'' of the object to the value ''val''.</li>
<li>''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.
+
<li>''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.
 
<syntaxhighlight lang="JavaScript">
 
<syntaxhighlight lang="JavaScript">
 
DBTbl = SYS.BD.MySQL.GenDB.SQLReq("SELECT * from DB;");
 
DBTbl = SYS.BD.MySQL.GenDB.SQLReq("SELECT * from DB;");

Latest revision as of 17:14, 11 May 2025

Information about message (contribute)
This message has no documentation. If you know where or how this message is used, you can help other translators by adding documentation to this message.
Message definition (Documents/User API)
== {{Anch|SYS.BD|Subsystem "DB" (SYS.BD)}} ==
Functions of the database object (SYS.BD["TypeDB"]["DB"]):
<ul>
<li>''ElTp cfg( string nm )'' — gets the value of the configuration field ''nm'' of the object.</li>
<li>''bool cfgSet( string nm, ElTp val )'' [<span style='color:red'>access to the appropriate subsystem</span>] — sets the configuration field ''nm'' of the object to the value ''val''.</li>
<li>''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.
<syntaxhighlight lang="JavaScript">
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"]);
} </syntaxhighlight></li>
</ul>
Translation== {{Anch|SYS.BD|Subsystem "DB" (SYS.BD)}} ==
Functions of the database object (SYS.BD["TypeDB"]["DB"]):
<ul>
<li>''ElTp cfg( string nm )'' — gets the value of the configuration field ''nm'' of the object.</li>
<li>''bool cfgSet( string nm, ElTp val )'' [<span style='color:red'>access to the appropriate subsystem</span>] — sets the configuration field ''nm'' of the object to the value ''val''.</li>
<li>''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.
<syntaxhighlight lang="JavaScript">
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"]);
} </syntaxhighlight></li>
</ul>

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"]);
    }