Difference between revisions of "Accessing the Database Using Scripts"
From Observer GigaFlow Support | VIAVI Solutions Inc.
Kevin Wilkie (Talk | contribs) (Created page with " Get a numeric result from the database and output it to the log log.warn(actions.getDatabaseManager().getLongFromDB("select count(*) from devices",0)) Get a result set from...") |
|||
Line 1: | Line 1: | ||
− | + | [[Category:Databasing Notes]] | |
+ | [[Category:Scripting Notes]] | ||
+ | [[Category:Technical Notes]] | ||
Get a numeric result from the database and output it to the log | Get a numeric result from the database and output it to the log | ||
log.warn(actions.getDatabaseManager().getLongFromDB("select count(*) from devices",0)) | log.warn(actions.getDatabaseManager().getLongFromDB("select count(*) from devices",0)) |
Revision as of 15:24, 12 October 2018
Get a numeric result from the database and output it to the log
log.warn(actions.getDatabaseManager().getLongFromDB("select count(*) from devices",0))
Get a result set from the database and iterate over it.
//Select uniquedeviceid,device,ip from the devices table and return an array. //The array at the end is the prepared elements you may want to pass into the statement var devices = actions.getDatabaseManager().getVectorFromDBprepared("select uniquedeviceid,device,ip from devices",[]) //Iterate over elements, devices.length= the number of elements returned in the previous query for (var i=0;i<devices.length;i++){ //Print out each element devices[i] and the values for the fields in that element //i.e. // devices[i][0] = uniquedeviceid //devices[i][1] = device //devices[i][2] = ip log.warn(devices[i][0]+" "+devices[i][1]+" "+devices[i][2]); }
Get a filtered result set from the database and iterate over it.
//Select uniquedeviceid,device,ip from the devices table where uniquedeviceid> 10 the and return an array. //The array at the end is the prepared elements you may want to pass into the statement var devices = actions.getDatabaseManager().getVectorFromDBprepared("select uniquedeviceid,device,ip from devices where uniquedeviceid >?",[10]) //Iterate over elements, devices.length= the number of elements returned in the previous query for (var i=0;i<devices.length;i++){ //Print out each element devices[i] and the values for the fields in that element log.warn(devices[i][0]+" "+devices[i][1]+" "+devices[i][2]); }