SHARE
TWEET

Untitled

a guest Feb 15th, 2019 170 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. define class REST::myRestAPI
  2.  
  3. 'GET getOMevents----------------------------------------------------------
  4. function getOMevents as p (Node_ID as N, Limit as N, SensorType as C )
  5. dim ops as p
  6. ops.connectionString = "::Name::om_ev"
  7. dim ops.sql as c
  8. ops.json = .t.
  9. 'define the nested sql queries and query properties. each level of indentation denotes a parent-child relationship
  10. ops.sql = <<%xstr%
  11. {sql: 'SELECT Node_ID, Location, SensorType, Value, Units, Comment, Zone, DateTime FROM OMevents WHERE Node_ID = :Node_ID AND SensorType = :SensorType LIMIT :LIMIT',name: 'Top',sqlSecurityJSON: ''}
  12. %xstr%
  13. dim args as sql::arguments
  14. args.add("Node_ID", Node_ID)
  15. args.add("SensorType", SensorType)
  16. args.add("Limit", LIMIT)
  17. dim p as p
  18. 'execute the definition to get the JSON data
  19. p = a5_sql_nested_query_to_json_document(ops,args)
  20. if p.hasError = .f. then
  21.     dim json as c
  22.     json = p.json
  23.    
  24.     getOMevents = json_parse(json)
  25.    
  26. else
  27.     'there was an error
  28.     dim errorText as c
  29.     errorText = p.errortext
  30.     dim pout as p
  31.     pout.error = .t.
  32.     pout.errorText = errorText
  33.     getOMevents = pout
  34. end if
  35.        
  36. end function
  37.  
  38. 'GET getOMnodes----------------------------------------------------------
  39. function getOMnodes as p (Node_ID as N)
  40.    
  41.  
  42. dim ops as p
  43. ops.connectionString = "::Name::om_main"
  44. dim ops.sql as c
  45. ops.json = .t.
  46. 'define the nested sql queries and query properties. each level of indentation denotes a parent-child relationship
  47. ops.sql = <<%xstr%
  48. {sql: 'SELECT * FROM OMnodes ',name: 'Top',sqlSecurityJSON: ''}
  49. %xstr%
  50. dim args as sql::arguments
  51. args.add("Node_ID",Node_ID)
  52. dim p as p
  53. 'execute the definition to get the JSON data
  54. p = a5_sql_nested_query_to_json_document(ops,args)
  55. if p.hasError = .f. then
  56.     dim json as c
  57.     json = p.json
  58.    
  59.     getOMnodes = json_parse(json)
  60.    
  61. else
  62.     'there was an error
  63.     dim errorText as c
  64.     errorText = p.errortext
  65.     dim pout as p
  66.     pout.error = .t.
  67.     pout.errorText = errorText
  68.     getOMnodes = pout
  69. end if
  70.        
  71. end function
  72.  
  73. 'GET getOMcurrstatus----------------------------------------------------------
  74. function getOMcurrstatus as p (Node_ID as N)
  75. dim ops as p
  76. ops.connectionString = "::Name::om_main"
  77. dim ops.sql as c
  78. ops.json = .t.
  79. 'define the nested sql queries and query properties. each level of indentation denotes a parent-child relationship
  80. ops.sql = <<%xstr%
  81. {sql: 'SELECT * FROM OMcurrstatus WHERE Node_ID = :Node_ID',name: 'Top',sqlSecurityJSON: ''}
  82. %xstr%
  83. dim args as sql::arguments
  84. args.add("Node_ID",Node_ID)
  85. dim p as p
  86. 'execute the definition to get the JSON data
  87. p = a5_sql_nested_query_to_json_document(ops,args)
  88. if p.hasError = .f. then
  89.     dim json as c
  90.     json = p.json
  91.    
  92.     getOMcurrstatus = json_parse(json)
  93.    
  94. else
  95.     'there was an error
  96.     dim errorText as c
  97.     errorText = p.errortext
  98.     dim pout as p
  99.     pout.error = .t.
  100.     pout.errorText = errorText
  101.     getOMcurrstatus = pout
  102. end if
  103.        
  104. end function
  105.  
  106. 'GET getOMcurrstatusSensorType----------------------------------------------------------
  107. function getOMcurrstatusSensorType as p (SensorType as C)
  108.    
  109.  
  110. dim ops as p
  111. ops.connectionString = "::Name::om_main"
  112. dim ops.sql as c
  113. ops.json = .t.
  114. 'define the nested sql queries and query properties. each level of indentation denotes a parent-child relationship
  115. ops.sql = <<%xstr%
  116. {sql: 'SELECT * FROM OMcurrstatus WHERE SensorType = :SensorType',name: 'Top',sqlSecurityJSON: ''}
  117. %xstr%
  118. dim args as sql::arguments
  119. args.add("SensorType",SensorType)
  120. dim p as p
  121. 'execute the definition to get the JSON data
  122. p = a5_sql_nested_query_to_json_document(ops,args)
  123. if p.hasError = .f. then
  124.     dim json as c
  125.     json = p.json
  126.    
  127.     getOMcurrstatusSensorType = json_parse(json)
  128.    
  129. else
  130.     'there was an error
  131.     dim errorText as c
  132.     errorText = p.errortext
  133.     dim pout as p
  134.     pout.error = .t.
  135.     pout.errorText = errorText
  136.     getOMcurrstatusSensorType = pout
  137. end if
  138. end function
  139.  
  140.  
  141. 'UPDATE updateNode ----------------------------------------------------------  
  142. function updateNode as p (updateNode as REST::myRestAPI::updatePnode)
  143.     dim NodeID as c = updateNode.NodeID
  144.     dim NodeName as c  = updateNode.NodeName
  145.     dim SensorID as c  = updateNode.SensorID
  146.     dim Location as c  = updateNode.Location
  147.     dim ProductName as c  = updateNode.ProductName
  148.     dim Parent as c  = updateNode.Parent
  149.     dim Zone as c  = updateNode.Zone
  150.     dim Status as c  = updateNode.Status
  151.     dim LastUpdate as c  = updateNode.LastUpdate
  152.    
  153.     dim cn as sql::connection
  154.     dim flag as l
  155.     flag = cn.open("::Name::om_main")
  156.     if flag = .f. then
  157.     'there was an error
  158.     dim errorText as c
  159.     errorText = cn.callresult.text
  160.     end
  161.     end if
  162.     'turn on portable SQL
  163.     cn.PortableSQLEnabled = .t.
  164.     dim SQL as c
  165.  
  166.  
  167.  
  168.     cn = "::name::Koneksine"
  169.     table = "tabele"
  170.     filter = "idne = '"+NodeID+"'"
  171.     results = "idne"
  172.  
  173.     dim checkID as c
  174.     checkID = sql_lookup(cn, table, filter, results)
  175.  
  176.     if checkID <> ""
  177.         sql = "UPDATE OMnodes SET Node_Name= :NodeName, Sensor_ID= :SensorID, Location= :Location, Product_Name= :ProductName, Parent= :Parent, Zone= :Zone, SensorTypeatus= :Status, LastUpdate= :LastUpdate WHERE Node_ID= :NodeID"
  178.     else
  179.         sql = "INSERT OMnodes SET Node_Name= :NodeName, Sensor_ID= :SensorID, Location= :Location, Product_Name= :ProductName, Parent= :Parent, Zone= :Zone, SensorTypeatus= :Status, LastUpdate= :LastUpdate WHERE Node_ID= :NodeID"
  180.     end if
  181.  
  182.  
  183.    
  184.     dim args as sql::arguments
  185.     args.add("NodeID", NodeID)
  186.     args.add("NodeName", NodeName)
  187.     args.add("SensorID", SensorID)
  188.     args.add("Location", Location)
  189.     args.add("ProductName", ProductName)
  190.     args.add("Parent", Parent)
  191.     args.add("Zone", Zone)
  192.     args.add("Status", Status)
  193.     args.add("LastUpdate", LastUpdate)
  194.  
  195.    
  196.     'execute the SQL
  197.     flag = cn.execute(sql,args)
  198.    
  199.     if flag = .f. then
  200.     'there was an error
  201.    
  202.     dim errorText as c
  203.     errorText = cn.callresult.text
  204.     cn.close()
  205.     end
  206.     end if
  207.    
  208.     dim rowsInserted as n
  209.     'get the number of rows that were inserted
  210.     rowsInserted = cn.CallResult.rowsaffected
  211.     cn.close()
  212.    
  213. end function
  214.  
  215. end class
  216.  
  217. define class REST::myRestAPI::updatePnode
  218.     dim NodeID as c
  219.     dim NodeName as c
  220.     dim SensorID as c
  221.     dim Location as c
  222.     dim ProductName as c
  223.     dim Parent as c
  224.     dim Zone as c
  225.     dim Status as c
  226.     dim LastUpdate as c
  227. end class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top