If you're keen on learning more sql, here's a few tips.
Sqlite3 can do a lot with strings, so you can do something like:
select substr(colA, 2, 6)||' something something '||substr(colB, 4, 8) from table1 where blah=foo
See more details: http://www.sqlite.org/lang_corefunc.html
If I am using a query that spans several tables, like your statement:
select a.col1, b.col3, c.col6 from table1 a, table2 b, table3 c where a.col2=b.col4 and b.col7=c.col2 and a.col4='whatever'
... I prefer to write it like this instead:
select a.col1, b.col3, c.col6 from table1 a join table2 b on a.col2=b.col4 join table3 c on b.col7=c.col2 where a.col4='whatever'
Exactly same results, but it'll be clearer to yourself (and others) which equality clause is meant for joining tables together and which equality clause is acting as a filter.
Sql is a very useful skill to learn, I highly recommend it.
Tom
sqlite3 -list /data/data/com.android.providers.calendar/databases/calendar.db "SELECT Instances.begin, Events.title FROM Instances JOIN Events ON Instances.event_id = Events._id WHERE begin > %TIMEMS ORDER BY Instances.begin ASC LIMIT 5;" | awk -F "|" '{printf strftime("%a %H:%M",$1/1000)}{print " -",$2}'
One odd thing I found was that although my command worked perfectly from the "adb shell", when I added the "awk" section to the end it stopped working from the Tasker shell command. Not sure why, whether it was a size thing or limitation on the way tasker deals with the shell command but I did get it to work perfectly using "Sceure Settings" command option instead!
The problem I had was that I wanted the weekday to be a 3 letter abbreviated day name and the "strftime" function in sqlite3 does not support that option only the weekday number.
Matt
Hi everybody!
I found the discussion here really useful. I'm having an issue and was wondering if someone could point me in the right direction. I'm trying to pull the end time from a calendar appointment and set it aso a tasker variable.Here's what I got so far:sqlite3/data/data/com.android.providers.calendar/databases/calendar.dbSELECT c.endFROM Calendars a, Events b, Instances c
WHERE a._id=b.calendar_id
AND b._id=c.Event_id
AND a.name='Main'
AND b.title='Sleep'
AND date(datetime(end / 1000 , 'unixepoch')) > date('now')
GROUP BY a.name,b.titleI'd like the output to be in 24 hour HH:MM format if possibleAny help would be greatly appreciated.
The debugger allows selecting the row and showing different views
When using your second query it generates an error:
Tom
The info you're looking for is basically here:
APS.compilespeech (114)
A1: If [ %APSEVENTS Is Set ]
A2: Variable Set [ Name:%newline To:
Do Maths:Off Append:Off ]
A3: Variable Set [ Name:%APSSPEECH To:Morning sir, hope you slept well. Today you have Do Maths:Off Append:Off ]
A4: Variable Split [ Name:%APSEVENTS Splitter:%newline Delete Base:Off ]
A5: For [ Variable:%apsevent Items:%APSEVENTS() ]
A6: Variable Split [ Name:%apsevent Splitter:| Delete Base:Off ]
A7: Variable Set [ Name:%APSSPEECH To:%apsevent4 at %apsevent1 and then Do Maths:Off Append:On ]
A8: End For
A9: Variable Set [ Name:%APSSPEECH To: You're done. Have a good day. Do Maths:Off Append:On ]
A10: Else
A11: Variable Set [ Name:%APSSPEECH To:Good morning sir, glad to see you got up okay. Just to let you know, you have nothing scheduled for today. Do Maths:Off Append:Off ]
A12: End If
--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/BecVXt-Yuks/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Paul,
I'm running your shell
sqlite3 /data/data/com.android. providers.calendar/databases/calendar.db "SELECT strftime('%H:%M', Instances.begin/1000, 'unixepoch'), calendar_displayname, calendar_id, title FROM Instances, Events, Calendars WHERE Instances.event_id = Events._id AND date(datetime(begin / 1000 , 'unixepoch')) = date('now') AND Events.Calendar_id = Calendars._id AND Calendar_id NOT IN(4,6) ORDER BY Instances.begin ASC;"
through a Secure Settings 'run command' using root and trying to output to a variable.It wasn't working so I checked 'show output' in the secure settings configuration. It outputs this as an error
sqlite3: Error: too many options: "SELECT strftime... Then the rest of the shell all the way to ASC;"I'm trying to work out to what 'too many options' refers. Could it be too many calendars to query and it doesn't know which one I want? I have three on my phone.
I'm really new to databases & sql and have been trying to learn by studying other people's shells etc. I've reached the limits of my understanding on this one though!
Ta,
Martin
*ALMIGHTY FACEPALM*
I swear a typo will one day destroy the world. In my defence maybe the two words were straddling a line & I couldn't see the space. Well that's my story at least and I'm sticking to it!
Sorry, didn't notice that Tasker didn't output the new line variable very clearly. But I'm glad you have everything working properly. Enjoy :-)
hi Paul,
that's awesome! thank you very very much for your help.
just found out there's a variable: %newline
beside, I'm too stupid for programming & logic :-D
and now I have a personal assistant that speaks my agenda in the morning :)
thanks again.
On Monday, May 20, 2013 1:08:44 PM UTC+7, Paul [sabret00the] wrote:
--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/BecVXt-Yuks/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/groups/opt_out.
Error: unable to open database "//Cal/calendar.db": unable to open database file
--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/BecVXt-Yuks/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/groups/opt_out.
you're welome. being able to explorer the innards of Android is awesome. I can't imagine not being able to pop the hood up and taking a look inside.
--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/BecVXt-Yuks/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/groups/opt_out.
On Wednesday, March 20, 2013 5:35:13 AM UTC-4, Nigel Roy wrote:sqlite3 -list /data/data/com.android.providers.calendar/databases/calendar.db "SELECT Instances.begin, Events.title FROM Instances JOIN Events ON Instances.event_id = Events._id WHERE begin > %TIMEMS ORDER BY Instances.begin ASC LIMIT 5;" | awk -F "|" '{printf strftime("%a %H:%M",$1/1000)}{print " -",$2}'
One odd thing I found was that although my command worked perfectly from the "adb shell", when I added the "awk" section to the end it stopped working from the Tasker shell command. Not sure why, whether it was a size thing or limitation on the way tasker deals with the shell command but I did get it to work perfectly using "Sceure Settings" command option instead!I wonder if maybe Tasker was confused by the %a %H %M in the awk cmd and tried to treat them as Tasker vars?I usually do my shell cmd authoring in a shell script:/data/local/scripts/example.sh=============#!/system/bin/shsqlite3 something.db "select blah from foo" | awk '/something/ {print $1}';exit;=============... and try it out from a terminal emulator on my phone. Once the script is perfected, I then call that script in Tasker's RunShell:Action > Script > RunShell > /data/local/scripts/example.shA few advantages to this approach:1. I don't have to worry about a huge command inside of the RunShell command field.2. I can always run the shell script manually from a terminal emulator.3. Most importantly, I can reuse the functionality of that shell script by calling it from other shell scripts.It's all a matter of personal taste, so it's all good.Tom
--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/BecVXt-Yuks/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/groups/opt_out.
Matt
Works perfectly! Thanks heaps guys
--
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+un...@googlegroups.com.
Matt
Tasker variable %TIMES is the current time in unix epoch time. To add two days, add 2*24*60*60 seconds.
Matt
I saw this article: http://www.pocketables.com/2012/07/tasker-google-calendar-event-announcer-task-download.html about Tasker and calendar events. I wanted to use Tasker to announce my calendar events but, as my other posts have noted, I'm not a fan of constantly grabbing data from HTTP get and chopping up with variable split, namely because of the added layer of connecting to a web server and all the issues that can crop up with that. Also my issue is/was I have calendars in my phone that don't come from Google - like my work calendar. So I started digging around the calendar database on the phone and pleasingly found the data.After a quick self taught crash course in sqlite3 (which is so pleasant to use) I found a clean, efficient way to grab exactly the data you want from one Tasker action:- Run Shell- Command:sqlite3/data/data/com.android.providers.calendar/databases/calendar.db
SELECT begin, calendar_displayname, title FROM Instances, Events, Calendars WHERE Instances.event_id = Events._id ANDdate(datetime(begin / 1000 , 'unixepoch')) = date('now') AND Events.Calendar_id = Calendars._id ORDER BY Instances.begin ASC;
su
sqlite3 /data/data/com.android.providers.calendar/databases/calendar.db
SELECT Calendars.calendar_displayName, datetime(Instances.begin/1000, 'unixepoch', 'localtime'), Events.title FROM Calendars, Instances, Events WHERE Instances.event_id = Events._id AND Events.calendar_id = Calendars._id ORDER BY Instances.begin ASC;
Matt
You don't need the su command (just check the use root option. And I believe you need the sqlite command in double quotes (starting at SELECT...).
Thanks, like this?
Test (89)
A1: Run Shell [ Command:sqlite3 /data/data/com.android.providers.calendar/databases/calendar.db
"SELECT Calendars.calendar_displayName, datetime(Instances.begin/1000, 'unixepoch', 'localtime'), Events.title FROM Calendars, Instances, Events WHERE Instances.event_id = Events._id AND Events.calendar_id = Calendars._id ORDER BY Instances.begin ASC"; Timeout (Seconds):0 Use Root:On Store Output In:%SchedOutput Store Errors In:%SchedError Store Result In:%SchedResult ]
I get the error in the pic:
You don't need the su command (just check the use root option. And I believe you need the sqlite command in double quotes (starting at SELECT...).
Matt
--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/BecVXt-Yuks/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/tasker.
For more options, visit https://groups.google.com/d/optout.
I figured it out, I think. I can get Tasker to run the task by filtering the sql a little bit more...I guess I had too many results before?
Does Tasker have any sort of limitation to the number of results?
But, then I discovered that project that Brandon mentioned a few posts up. It is so much better, that I completely replaced my old sql calendar tasks. Since you can import as a project, you can also tweak it to your liking relatively easily.
I will check out the project Brandon recommend. Thanks for your help.
Do that, for sure.
Also, I forgot that I do actually have a workaround for this problem! It's been a while since I've looked at it, but I am still using sql in 3 profiles that search for calendar events, like "When is Vanessa's birthday?" Or "When was my last sales meeting?" Or "When are my profit projections due?" etc...
I ran into the problem with birthdays because they are all day events. I never did find a solution to fix the dates with sql, but I did successfully manipulate the date with tasker, after the sql is run...
In your sql run shell command, you need to include the column "allDay" from the table "Events" and then set a variable %AllDay to 1 if that column indicates so, after splitting the output. Then I created this separate Date Conversion task that I run with a Perform Task action:
Date Conversion (659)
A1: Variable Split [ Name:%Scheduletext121 Splitter:- Delete Base:Off ]
A2: Variable Set [ Name:%Year To:%Scheduletext1211 Do Maths:Off Append:Off ]
A3: Variable Set [ Name:%Month To:%Scheduletext1212 Do Maths:Off Append:Off ]
A4: Variable Set [ Name:%Date To:%Scheduletext1213 Do Maths:On Append:Off ]
A5: If [ %AllDay ~ 1 ]
A6: Variable Set [ Name:%Date To:%Date + 1 Do Maths:On Append:Off ]
A7: End If
A8: Variable Set [ Name:%FormattedDate To:%Month/%Date/%Year Do Maths:Off Append:Off ]
If you try it, let me know if it works for you or if you have questions! Is relatively easy.
Sorry I forgot about this solution!
I will check out the project Brandon recommend. Thanks for your help.
How weird, I have been working on a similar thing myself on and off over the past few days.
I found you definitely need to be on a rooted phone, if my understanding is correct the Android system will not allow one application to access another’s data so root is required to read the database.
I agree that the sqlite3 command is an excellent way to get data from the calendar, I used "adb shell" from my laptop to perfect my query but a slightly different method to you, in order to set the time I used a a Tasker variable substitution in the query. I also initially went down the lines of splitting variables but it ended up being quite a long and painful task so I found that I could use "awk" to manipulate the results.
My shell command pipes the sqlite3 result through "awk" to give me a formatted output list of the next 5 reminders which I have just used to populate the field of a Minimalistic Text widget!
Here is the command:
sqlite3 -list /data/data/com.android.providers.calendar/databases/calendar.db "SELECT Instances.begin, Events.title FROM Instances JOIN Events ON Instances.event_id = Events._id WHERE begin > %TIMEMS ORDER BY Instances.begin ASC LIMIT 5;" | awk -F "|" '{printf strftime("%a %H:%M",$1/1000)}{print " -",$2}'
Your success with awk may depend on the version of busybox you have installed but you can test this via adb shell which I find is a lot easier than testing it out directly on the phone..
The "awk -F "|"" tells awk that the delimiter is the pipe symbol instead of the default "space".
The "printf strftime" section reformats the time (in awk $1 refers to the first column or field) in seconds to give the 3 letter day followed by 24 hour clock in hours and minutes. Using "printf" means there is no carriage return after the date and time. The second "print" section prints the second column (in my case the event description) after a " -".
The output looks something like this:
Tue 13:00 - Call Someone
Tue 19:00 - Spare key
Wed 08:00 - Someone on holiday
Thu 17:00 - Rubbish
Fri 08:30 - Parking permit
Depending on how you are displaying the information you may find some of it is wrapped but like you I was very pleased with myself for managing to fight my way through the various database tables and SQL options.
I am quite sure there is a lot more potential waiting in there to be unlocked.
One odd thing I found was that although my command worked perfectly from the "adb shell", when I added the "awk" section to the end it stopped working from the Tasker shell command. Not sure why, whether it was a size thing or limitation on the way tasker deals with the shell command but I did get it to work perfectly using "Sceure Settings" command option instead!