Can't do XTDB queries from xTension?
Jeffrey Lomicka
JeffreyLomicka at comcast.net
Mon Sep 5 10:07:12 EDT 2022
I'm up and running again.
Here is my workaround for the XTDB query problem. "QueryXTDBForValueOld"
doesnt' work, "QueryXTDBForValue" works by performing the same query in
another process via shell script.
on QueryXTDBForValueOld(unitName, timeInterval)
set endTime to current date
set startTime to endTime - timeInterval
set newEndTime to startTime + 3 * minutes
tell application "XTdb" to set queryResult to query unitName
starting at startTime ending at newEndTime
return second item of first item of queryResult
end QueryXTDBForValueOld
on QueryXTDBForValue(unitName, timeInterval)
set endTime to current date
set startTime to endTime - timeInterval
set newEndTime to startTime + 3 * minutes
set queryString to (("osascript -e 'tell application \"XTDB\" to
query \"" & unitName & "\" starting at date \"" & startTime as text) &
"\" ending at date \"" & newEndTime as text) & "\"'"
set queryResult to do shell script of queryString
set retval to (word 11 of queryResult) as number
return retval
end QueryXTDBForValue
On 9/5/22 8:19 25AM, Jeffrey Lomicka wrote:
> I updated to the latest xTension yesterday after waiting several years
> (in order to get the latest Kasa plug-in), and it went smoother than I
> expected. The only broken thing so far is my script for reporting
> rainfall, because queries to XTDB seem to have stopped working.
>
> Note that (at first) I didn't update XTDB, only XTension, so XTDB
> didn't change. As part of my diagnostics, I did upgrade XTDB as well,
> but no change in behavior.
>
> The script in question is reduced to this:
>
> set unitName to "New Rain Gauge-Total"
> set endTime to current date
> set startTime to endTime - 24 * 60 * minutes
> set newEndTime to startTime + 3 * minutes
> tell application "XTdb"
> set queryResult to query unitName starting at startTime ending at
> newEndTime
> end tell
> write log result
>
> This works flawlessly from the script editor, but when run inside
> XTension it hangs until the Apple event times out or I exit XTDB.
>
> This is running MacOS Sierra. XTension 9.4.47.
>
> I'm working on a workaround to perform the query in another thread
> with a shell command "osascript -e", that's looking promising.
>
> _______________________________________________
> XTensionList mailing list
> XTensionList at machomeautomation.com
> http://mail.machomeautomation.com/mailman/listinfo/xtensionlist
More information about the XTensionList
mailing list