You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
"""
|
|
Sample script to query the database directly
|
|
"""
|
|
|
|
from Net2Scripting.net2dbxs import Net2DBXS
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
with Net2DBXS() as net2db:
|
|
# Connect
|
|
net2db.connect()
|
|
# Get last log entry relating a device
|
|
dataset = net2db.query_db(
|
|
"select * from EventsEx "
|
|
"where EventID = "
|
|
"(select max(EventID) from sdk.EventsEx "
|
|
" where SerialNumber is not NULL)")
|
|
|
|
# Non result
|
|
if (not dataset
|
|
or dataset.Tables.Count < 1
|
|
or dataset.Tables[0].Rows.Count < 1):
|
|
|
|
print("Nothing relevant found")
|
|
else:
|
|
# Just to demonstrate how to get values from a dataset
|
|
|
|
# Typically Table[0]
|
|
table = dataset.Tables[0]
|
|
# In this case only interested in the first row
|
|
row = dataset.Tables[0].Rows[0]
|
|
# For each column
|
|
for col in table.Columns:
|
|
val = row.get_Item(col.ColumnName)
|
|
print("%s = %s" % (col.ColumnName, val))
|