fly Posted February 22, 2011 Posted February 22, 2011 So, I'm trying to use SQLite and I'm running into some issues... Full disclosure: I'm a total SQL greenhorn I have a SQL table. Once column is logging the time data was written to the table (in Ticks). I'm then trying to run a query that counts all rows written in the last 60 seconds. That gives me this: $sTime = _TimeToTicks(@HOUR, @MIN, @SEC) - 60000 _SQlite_Query(-1, "SELECT count(Time) FROM Info WHERE Time < '" & $sTime & "';", $hQuery) _SQLite_FetchData ($hQuery, $aOut) ConsoleWrite("Less than 60s = " & $aOut[0]& @CRLF) My ConsoleWrite output is constantly ZERO. What am I doing wrong?
water Posted February 22, 2011 Posted February 22, 2011 Add some debugging code into your script: $sTime = _TimeToTicks(@HOUR, @MIN, @SEC) - 60000 _SQlite_Query(-1, "SELECT count(Time) FROM Info WHERE Time < '" & $sTime & "';", $hQuery) ConsoleWrite("Query: " & @error & @CRLF) _SQLite_FetchData ($hQuery, $aOut) ConsoleWrite("Fetch: " & @error & @CRLF) ConsoleWrite("Less than 60s = " & $aOut[0]& @CRLF) My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Xenobiologist Posted February 22, 2011 Posted February 22, 2011 Try using Squirrel or Toad or DataStudio to firstly get your statement working outside from Autoit. Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
fly Posted February 22, 2011 Author Posted February 22, 2011 Add some debugging code into your script: $sTime = _TimeToTicks(@HOUR, @MIN, @SEC) - 60000 _SQlite_Query(-1, "SELECT count(Time) FROM Info WHERE Time < '" & $sTime & "';", $hQuery) ConsoleWrite("Query: " & @error & @CRLF) _SQLite_FetchData ($hQuery, $aOut) ConsoleWrite("Fetch: " & @error & @CRLF) ConsoleWrite("Less than 60s = " & $aOut[0]& @CRLF) Here is what I get: Query: 0 Fetch: 0 Less than 60s = 0 Try using Squirrel or Toad or DataStudio to firstly get your statement working outside from Autoit. Are any of these free and easy to setup? I'm really a terrible SQL guy. I guess the good news is that neither of you found something obviously wrong with my statement.
saywell Posted February 22, 2011 Posted February 22, 2011 I use SQLite manager add-on for FireFox - free. You can look at the data to eyeball the expected results, and enter SQL code to see the results of the query. William
fly Posted February 22, 2011 Author Posted February 22, 2011 I use SQLite manager add-on for FireFox - free. You can look at the data to eyeball the expected results, and enter SQL code to see the results of the query.WilliamThis is probably a really dumb question, but is my AutoIt database stored on the system somewhere as a file? If so, where is it so I point this Firefox addon to it?
saywell Posted February 22, 2011 Posted February 22, 2011 Maybe, maybe not! SQLite can create in-memory databases, or files. If you use a file it might be easier to experiment/learn with. The FF extension will create a file [ .SQlite ] for you. William
fly Posted February 22, 2011 Author Posted February 22, 2011 Maybe, maybe not! SQLite can create in-memory databases, or files. If you use a file it might be easier to experiment/learn with. The FF extension will create a file [ .SQlite ] for you. William Ah! I see that I can specify a file with _SQLite_Open(). Okay, thanks I'll try this...
fly Posted February 22, 2011 Author Posted February 22, 2011 I figured it out, sorta. The only thing worse than my SQL is my logic. The SQL query needs to see if Time is in between the current time (in ticks) and the current time - 60000 ticks. Now to figure out how to do that in the WHERE part of the SQL query...
wolf9228 Posted February 23, 2011 Posted February 23, 2011 (edited) So, I'm trying to use SQLite and I'm running into some issues... Full disclosure: I'm a total SQL greenhorn I have a SQL table. Once column is logging the time data was written to the table (in Ticks). I'm then trying to run a query that counts all rows written in the last 60 seconds. That gives me this: $sTime = _TimeToTicks(@HOUR, @MIN, @SEC) - 60000 _SQlite_Query(-1, "SELECT count(Time) FROM Info WHERE Time < '" & $sTime & "';", $hQuery) _SQLite_FetchData ($hQuery, $aOut) ConsoleWrite("Less than 60s = " & $aOut[0]& @CRLF) My ConsoleWrite output is constantly ZERO. What am I doing wrong? #Include <Date.au3> #include <SQLite.au3> #include <SQLite.dll.au3> FileDelete("Database.db") Dim $hQuery , $aOut , $count = 0 _SQLite_Startup () $DbHandle = _SQLite_Open("Database.db") _SQLite_Exec(-1,"CREATE TABLE Info (Time,count);") $count += 1 $sTime = _TimeToTicks(@HOUR, @MIN, @SEC) _SQLite_Exec (-1, "INSERT INTO Info(Time,count) VALUES ('" & $sTime & "' , '" & $count & "');") Sleep(1000) $count += 1 $sTime = _TimeToTicks(@HOUR, @MIN, @SEC) _SQLite_Exec (-1, "INSERT INTO Info(Time,count) VALUES ('" & $sTime & "' , '" & $count & "');") Sleep(1000) $count += 1 $sTime = _TimeToTicks(@HOUR, @MIN, @SEC) _SQLite_Exec (-1, "INSERT INTO Info(Time,count) VALUES ('" & $sTime & "' , '" & $count & "');") Sleep(1000) $count += 1 $sTime = _TimeToTicks(@HOUR, @MIN, @SEC) _SQLite_Exec (-1, "INSERT INTO Info(Time,count) VALUES ('" & $sTime & "' , '" & $count & "');") Sleep(1000) $count += 1 $sTime = _TimeToTicks(@HOUR, @MIN, @SEC) _SQLite_Exec (-1, "INSERT INTO Info(Time,count) VALUES ('" & $sTime & "' , '" & $count & "');") _SQlite_Query(-1, "SELECT Time FROM Info WHERE Time > '" & $sTime - 60000 & "';", $hQuery) While 1 _SQLite_FetchData ($hQuery, $aOut) if @error Then ExitLoop ConsoleWrite("Less than 60s = " & $aOut[0]& @CRLF) WEnd Edited February 23, 2011 by wolf9228 صرح السماء كان هنا
Skysnake Posted May 7, 2015 Posted May 7, 2015 (edited) https://www.sqlite.org/lang_aggfunc.htmlSQLite query works. I keep on getting a [0]0 array in Autoit.Expecting [0]2 on my data... Edited May 7, 2015 by Skysnake Skysnake Why is the snake in the sky?
jchd Posted May 7, 2015 Posted May 7, 2015 This one is 4-year old! This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now