0

Don't know if someone here knows Tasker Android app, but I think everyone could globally understand what I'm looking to accomplish, because I will basically talk about "raw" SQL code, as it's written on most common languages.

First, this is what I want, roughly:

IF (SELECT * FROM ("january") WHERE ("day") = (19)) MATCHES [%records(#) = 1] END

ELSE

SELECT * FROM ("january") WHERE ("day") = (19)  ORDER BY ("timea") DESC END

What I want to say above is: If in the first part of the code (IF ... END) the number of the resulting records, matching the number 19 on 'day' column, is just one, end execution here; but if more than one record is found, jump to the next part, after ELSE.

And if you are a Tasker user, you will understand the next (my current) setup:

A1: SQL Query [ Mode:Raw File:Tasker/Resources/Calendar Express/calendar_db Table:january Columns:day Query:SELECT * FROM ("january") WHERE ("day") = (19) Selection Parameters: Order By: Output Column Divider: Variable Array:%records Use Root:Off ] 
A2: SQL Query [ Mode:Raw File:Tasker/Resources/Calendar Express/calendar_db Table:january Columns:day Query:SELECT * FROM ("january") WHERE ("day") = (19)  ORDER BY ("timea") DESC Selection Parameters: Order By: Output Column Divider: Variable Array:%records Use Root:Off ] If [ %records(#) > 1 ]
An:...

So, as you can see, A1 will run always, without exceptions, getting the result in the variable array '%records()' (% is how Tasker identifies vars, as $ in other langs; and the use of parenthesis rather than brackets). Then, if the number of entries inside the array is just one, A2 will be jumped (if %records(#) > 1), and following actions are executed.

But, if after running A1 the %records() array contains 3, A2 action will be executed overwritting the content of %records() array, previoulsy set. But this time will contain same number of records (3), but reordered.

Is possible to do so, in just one code line? Thanks ;)

  • Both queries look almost the same, just the first has no `ORDER BY` clause. But if it only returns one record the `ORDER BY` won't change anything in the result. So I wonder, why can't you just use the second query? – sticky bit Aug 15 '18 at 16:10
  • Ohhh, my god. Thank you for opening me eyes. I didn't realize how obvious it is, it's true. My fault. Thanks! ;) – SmartPhoneLover Aug 15 '18 at 16:45
  • This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting. – sɐunıɔןɐqɐp Aug 15 '18 at 18:16

1 Answers1

0

As 'sticky bit' replied on a comment before, I can just still using the second action, as it won't affect the output if it's only a single record. Solved!