• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    SQL data source to query MangoES H2

    Scheduled Pinned Locked Moved User help
    5 Posts 3 Posters 2.6k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • jeremyhJ Offline
      jeremyh
      last edited by

      I thought I would create a SQL datasource on a MangoES so that I could keep tabs on the number of points in the system.

      I configured my SQL data source like this and when I run the statement test I get the correct value of 535:

      Screen Shot 2015-09-10 at 12.33.57 pm.png

      But when I go to configure an actual point for that column it never updates:

      Screen Shot 2015-09-10 at 12.33.41 pm.png

      Any idea what I'm doing wrong?

      1 Reply Last reply Reply Quote 0
      • JoelHaggarJ Offline
        JoelHaggar
        last edited by

        I was also able to duplicate this and not sure why it didn't work. I was able to get it to work as a row based query. Check the box for row based query and then use this statement"

        select 'count' as count, count(*) from datapoints
        

        You'll probably need to delete your data point and then create a new one with count as the row identifier.

        1 Reply Last reply Reply Quote 0
        • jeremyhJ Offline
          jeremyh
          last edited by jeremyh

          Thanks Joel, that works.

          Here is the JSON if anyone would like it (sorry, can't figure out how to make all this code):

          {
          "dataSources":[
          {
          "xid":"DS_652957",
          "name":"SQL",
          "enabled":true,
          "type":"SQL",
          "alarmLevels":{
          "POLL_ABORTED":"NONE",
          "STATEMENT_EXCEPTION":"NONE",
          "DATA_SOURCE_EXCEPTION":"NONE"
          },
          "purgeType":"YEARS",
          "updatePeriodType":"MINUTES",
          "connectionUrl":"jdbc:h2:/opt/mango/databases/mah2",
          "driverClassname":"org.h2.Driver",
          "password":"password-here",
          "rowBasedQuery":true,
          "selectStatement":"select 'count' as count, count(*) from datapoints",
          "updatePeriods":5,
          "username":"mango",
          "purgeOverride":false,
          "purgePeriod":1
          }
          ],
          "dataPoints":[
          {
          "xid":"DP_262803",
          "name":"Point Count",
          "enabled":true,
          "loggingType":"ON_CHANGE",
          "intervalLoggingPeriodType":"MINUTES",
          "intervalLoggingType":"INSTANT",
          "purgeType":"YEARS",
          "pointLocator":{
          "dataType":"NUMERIC",
          "dateParameterFormat":"yyyy-MM-dd'T'HH:mm:ss",
          "fieldName":"Count",
          "parameters":[
          ],
          "tableModifier":false,
          "timeOverrideName":"",
          "updateStatement":""
          },
          "eventDetectors":[
          ],
          "plotType":"STEP",
          "unit":"",
          "chartColour":"",
          "chartRenderer":null,
          "dataSourceXid":"DS_652957",
          "defaultCacheSize":1,
          "deviceName":"MangoES",
          "discardExtremeValues":false,
          "discardHighLimit":0.0,
          "discardLowLimit":0.0,
          "intervalLoggingPeriod":15,
          "intervalLoggingSampleWindowSize":0,
          "overrideIntervalLoggingSamples":false,
          "purgeOverride":false,
          "purgePeriod":1,
          "textRenderer":{
          "type":"ANALOG",
          "useUnitAsSuffix":false,
          "unit":"",
          "renderedUnit":"",
          "suffix":" points",
          "format":"####"
          },
          "tolerance":0.0
          }
          ]
          }

          1 Reply Last reply Reply Quote 0
          • jeremyhJ Offline
            jeremyh
            last edited by

            Hey Joel,

            For bonus points - what SQL statement could I use to return values for number of data sources, number of events, number of event handlers, number of users as well as number of data points?

            Then in that data source I'd like to have data points to log each of the above.

            This way I can set up easy alerts in case anyone adds or deletes a data source, point, user, etc.

            1 Reply Last reply Reply Quote 0
            • terrypackerT Offline
              terrypacker
              last edited by terrypacker

              I was just playing around with this and found that if you want to use the query 'select count() from datapoints' you need to use the data source as a 'non row based query' and then set the column name to 'Count()'. You can see this in the test utility if you look at the Column name, its shown as COUNT(*) when you test the query.

              You could also use this query if you want to have a specific column name:

              select count(*) as pointcount from datapoints;
              

              As for your last question you can put this all together like this:

              SELECT  (
                  SELECT COUNT(*)
                  FROM   datapoints
                  ) AS pointCount,
                  (
                  SELECT COUNT(*)
                  FROM   datasources
                  ) AS datasourceCount,
                  (
                  SELECT COUNT(*)
                  FROM   events
                  ) AS eventCount,
                  (
                  SELECT COUNT(*)
                  FROM   eventHandlers
                  ) AS eventHandlerCount,
                  (
                  SELECT COUNT(*)
                  FROM   users
                  ) AS userCount
              FROM    dual
              

              The thing to notice here is the keyword 'dual' at the end, this is required as you cannot perform a select without a from clause and the dual table that all accounts can access for common needs and it has one record.

              Just make sure you change the data source back to not use the row based query.

              FYI To format as code just make sure your lines are all indented by a tab or 4 spaces and has whitespace lines above and below.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post