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 )'' — sets the configuration field ''nm'' of the object to the value ''val''.</li>
 
<li>''bool cfgSet( string nm, ElTp val )'' — sets the configuration field ''nm'' of the object to the value ''val''.</li>
<li>''Array SQLReq( string req, bool tr = EVAL );'' — forms of the SQL-request to the DB, inside (''tr''=true), outside (''tr''=false) or no matter (''tr''=EVAL) to the transaction. 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.
 
<pre style="white-space: pre-wrap;">
 
<pre style="white-space: pre-wrap;">
 
DBTbl = SYS.BD.MySQL.GenDB.SQLReq("SELECT * from DB;");
 
DBTbl = SYS.BD.MySQL.GenDB.SQLReq("SELECT * from DB;");

Revision as of 11:37, 19 March 2018

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 )'' — 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.
<pre style="white-space: pre-wrap;">
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"]);
} </pre></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 ) — 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"]);
    }