Jump to content
Stormgrade

SQLite encryption with System.Data.SQLite.dll

Recommended Posts

Stormgrade

Hello,

I'm using Autoit 3.3.14.0.

I want to protect a SQLite db with System.Data.SQLite.dll. I've been searching over internet about it including this forum, JCHD gave a lead to resolve this problem but I can't apply it.

This was the code from jchd :

#include <SQLite.au3>   ; don't include sqlite.dll.au3 !!!
Local $path = @ScriptDir & "\mydb.sql"
_SQLite_Startup ("System.Data.SQLite.dll")
;ConsoleWrite(_SQLite_LibVersion() & @LF)
_SQLite_Open($path)
_SQLite_Exec(-1, "pragma key = 'Radu is happy!';create table if not exists test (id integer, val text);" & _
                "insert into test values (1, 'abc');")
Local $row
_SQLite_QuerySingleRow(-1, "select * from test;", $row)
;ConsoleWrite($row[1] & @LF)
_SQLite_Close()
_SQLite_Shutdown()

It don't work and I tried to use it with my code :

#include <SQLite.au3>
#include <MsgBoxConstants.au3>

Local $aManagerResult, $iManagerRows, $iManagerColumns, $iManagerRval
Local $DBName = "\mydb.sqlite"

Local $sSQliteDll = _SQLite_Startup("System.Data.SQLite.dll")
If @error Then
    MsgBox($MB_SYSTEMMODAL, "SQLite Error", "SQLite3.dll Can't be Loaded!" & @CRLF & @CRLF & _
    "Not FOUND in @SystemDir, @WindowsDir, @ScriptDir, @WorkingDir or from www.autoitscript.com")
    Exit -1
EndIf

Local $sDbName = @ScriptDir & "\" & $DBName
If FileExists($sDbName) = 1 Then
    FileCopy($sDbName,$sDbName & ".bak")
    FileDelete($sDbName)
EndIf

Local $hDskDb = _SQLite_Open($sDbName) ; Open a permanent disk database
If @error Then
    MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't open or create a permanent Database!")
    Exit -1
EndIf

If Not _SQLite_Exec(-1, "CREATE TABLE manager (ID Integer PRIMARY KEY AUTOINCREMENT, Name varchar(255) NOT NULL, Login char(50) NOT NULL,Code char(50) NOT NULL);") = $SQLITE_OK Then _
    MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg())
If Not _SQLite_Exec(-1, "pragma key = 'Radu is happy!';CREATE TABLE access (ID Integer, Login char(50) NOT NULL, Code char(50) NOT NULL);"  & _
        "INSERT INTO access VALUES (1,'admin','admin');") = $SQLITE_OK Then _
    MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg())
MsgBox($MB_SYSTEMMODAL, "SQLite","Table crée")


_SQLite_Close($hDskDb)
_SQLite_Shutdown()

Without success, I have no clue how to encrypt my SQL db without using the _Crypt_EncryptData function for my passwords.

Thank you in advance for your help.

Share this post


Link to post
Share on other sites
Stormgrade

I saw this topic :

But I'don't understand how to apply it

Share this post


Link to post
Share on other sites
jchd

There are many versions of System.Data.SQLite.dll. You must use the one compatible with your script (x86 or x64) and which is compiled as "static" and "mixed-mode" assembly. For use with AutoIt, the .Net version is irrelevant unless you intend to also use the same library with .Net features from other programs.

Also please note that you must issue the pragma key= before any use of the DB.

  • Like 2

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites
Stormgrade

There are many versions of System.Data.SQLite.dll. You must use the one compatible with your script (x86 or x64) and which is compiled as "static" and "mixed-mode" assembly. For use with AutoIt, the .Net version is irrelevant unless you intend to also use the same library with .Net features from other programs.

Also please note that you must issue the pragma key= before any use of the DB.

Have you any lead about the one I must use ?

I've downloaded this one :

Precompiled Binaries for 32-bit Windows (.NET Framework 4.0)

sqlite-netFx40-binary-Win32-2010-1.0.97.0.zip
(2.16 MiB)
 This binary package contains all the binaries for the x86 version of the System.Data.SQLite 1.0.97.0 (3.8.10.2) package. The Visual C++ 2010 SP1 runtime for x86 and the .NET Framework 4.0 are required.
(sha1: 404a5c35683d78eba1fa4de78546a8e6dd0d7f74)

Share this post


Link to post
Share on other sites
jchd

I just downloaded this version then copied the DLL in the @scriptdir from the zip file. Then this exemple works as intended:

#include <SQLite.au3>   ; don't include sqlite.dll.au3 !!!

Local $path = @ScriptDir & "\mydb.sql"
_SQLite_Startup ("System.Data.SQLite.dll")
ConsoleWrite(_SQLite_LibVersion() & @LF)
Local $row

; using encryption
_SQLite_Open($path)
_SQLite_Exec(-1, "pragma key = 'Radu is happy!';create table if not exists test (id integer, val text);" & _
                "insert into test values (1, 'abc');")
_SQLite_QuerySingleRow(-1, "select * from test;", $row)
ConsoleWrite($row[1] & @LF)
_SQLite_Close(-1)

; not using encryption over the encrypted DB gives a failure
_SQLite_Open($path)
_SQLite_QuerySingleRow(-1, "select * from test;", $row)
ConsoleWrite(_SQLite_ErrMsg(-1) & @LF)
_SQLite_Close(-1)

; changing back to no encryption
_SQLite_Open($path)
_SQLite_Exec(-1, "pragma key = 'Radu is happy!'")
_SQLite_Exec(-1, "pragma rekey = ''")
_SQLite_QuerySingleRow(-1, "select * from test;", $row)
ConsoleWrite($row[1] & @LF)
_SQLite_Close(-1)

_SQLite_Shutdown()

 

Edited by jchd
pragma is rekey to change key
  • Like 4

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites
Stormgrade

I just downloaded this version then copied the DLL in the @scriptdir from the zip file. Then this exemple works as intended:

 

I'm very sorry I don't understand, I've downloaded the zip file then I decompress "System.Data.SQLite.dll" (Later I've used all files inside the zip)

I make my au3 file in the same folder as this dll and I copy paste your code but It won't work :

"......\test2.au3" (26) : ==> Subscript used on non-accessible variable.:
ConsoleWrite($row[1] & @LF)
ConsoleWrite($row^ ERROR

It won't create the  mydb.sql file, Do you use autoit 3.3.14.0 ?

Did It work for someone else maybe I'm doing it wrong somewhere?

Share this post


Link to post
Share on other sites
Stormgrade

Works for me 3.3.12.0

Not tried of 3.3.14.0

Well it work with 3.3.12.0 ...

It return this :

3.8.10.2
abc
!   SQLite.au3 Error
--> Function: _SQLite_Query
--> Query:    select * from test;
--> Error:    file is encrypted or is not a database

file is encrypted or is not a database
abc
+>16:06:25 AutoIt3.exe ended.rc:0
+>16:06:25 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 1.244

The file was created.

I've got a similar problem with CryptEncrypt function when I have upgraded to 3.3.14.

Any idea for a workaround or I must keep my 3.3.12.0 version ?

Share this post


Link to post
Share on other sites
jchd

Work with both release 3.3.14.0 and beta 3.3.15.0, both x86.

Can you paste the Scite console output, showing SQLite error msg, if any?

Note that if the DB file exists encrypted before running the script it will fail. Just delete the file for the example to work.

For more information about how to use pragmas key and rekey and how to attach encrypted DBs, see this document under "Using the "key" PRAGMA" and "Using The ATTACH Command". The encryption offered by System.Data.SQLite is not SEE, so forget about the specifics in the official document (SEE is payware).

Edited by jchd

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites
Stormgrade

Work with both release 3.3.14.0 and beta 3.3.15.0, both x86.

Can you paste the Scite console output, showing SQLite error msg, if any?

Note that if the DB file exists encrypted before running the script it will fail. Just delete the file for the example to work.

For more information about how to use pragmas key and rekey and how to attach encrypted DBs, see this document under "Using the "key" PRAGMA" and "Using The ATTACH Command". The encryption offered by System.Data.SQLite is not SEE, so forget about the specifics in the official document (SEE is payware).

Well we'll see that tomorrow because it work well in my home but not at my office, something is wrong on my office computeur.

The output for 3.3.14.0 was :

0
"......\test2.au3" (26) : ==> Subscript used on non-accessible variable.:
ConsoleWrite($row[1] & @LF)
ConsoleWrite($row^ ERROR

I'll reinstall autoit.

Share this post


Link to post
Share on other sites
jchd

Well we'll see that tomorrow because it work well in my home but not at my office, something is wrong on my office computeur.

The output for 3.3.14.0 was :

0
"......\test2.au3" (26) : ==> Subscript used on non-accessible variable.:
ConsoleWrite($row[1] & @LF)
ConsoleWrite($row^ ERROR

I'll reinstall autoit.

The first line carrying '0' means the DLL wasn't found. Noo need to reinstal, just sort out why the DLL is not there.


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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites
Stormgrade

I've uninstalled autoit and I do a clean install.

It work now.

Thank you for your help.

Share this post


Link to post
Share on other sites
jchd

Glad to see it works for you too. There must have been something gone mad with the previous AutoIt environment/setup causing havoc.

Reading the document mentionned above, you'll see that you can use pragma hexkey = 'A40F38D5CC20E6' to use a hex password and pragma hexrekey to change it to some other hex value. If you look at a non-encrypted DB you'll see the string "SQLite format 3" at the start of file and the DB DML in plain text following the header, but once the DB is encrypted, nothing is human- readable, not even a little hint that this file is an SQLite DB.

@guinness,

Yes, the static mixed-mode assembly carries the standard C DLL interface plus the .net one (hence the mixed-mode term). This worked from day one of this library and still does now that Joe Mistachkin has taken the over .Net development as part of the official SQLite dev team. It's now unlikely that encryption support will be dropped for there are way too many users relying on it.

Edited by jchd
  • Like 1

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites
guinness

I had no clue System.Data.SQLite.dll would work. Learnt something new.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
Stormgrade

Glad to see it works for you too. There must have been something gone mad with the previous AutoIt environment/setup causing havoc.

Reading the document mentionned above, you'll see that you can use pragma hexkey = 'A40F38D5CC20E6' to use a hex password and pragma hexrekey to change it to some other hex value. If you look at a non-encrypted DB you'll see the string "SQLite format 3" at the start of file and the DB DML in plain text following the header, but once the DB is encrypted, nothing is human- readable, not even a little hint that this file is an SQLite DB.

@guinness,

Yes, the static mixed-mode assembly carries the standard C DLL interface plus the .net one (hence the mixed-mode term). This worked from day one of this library and still does now that Joe Mistachkin has taken the over .Net development as part of the official SQLite dev team. It's now unlikely that encryption support will be dropped for there are way too many users relying on it.

Thank you for the pragma hexkey tip, I'm trying to make an Internet Password keeper like Firefox Secure login, thanks for your help !!

Share this post


Link to post
Share on other sites
jchd
On 29/07/2015 at 3:28 PM, JohnOne said:

Are we talking about encryption of data here

@JohnOne,

This is plain whole DB file encryption. SQlite works with I/O blocks it calls pages inside a DB file. This encryption layer encrypts/decrypts pages on the fly when SQLite needs to write/read (resp.) pages from the file.

On 29/07/2015 at 6:26 PM, JohnOne said:

What type and level of encryption is it?

I don't know precisely, it would take reading the source code for that, but it must be a decent level like SHA2 ou something. Don't fear breaking by sister kid.

On 29/07/2015 at 3:28 PM, JohnOne said:

or just the data base having a password?

There is an SQLite add-on available in source form which allows SQLite to perform user anthentication (a completely distinct feature from encryption).

The module can be found in the source distribution, under ext\userauth and I can say it works pretty well. The caveat is that it uses the same file format as non authentication-enabled DBs, which means that if you can gain access to the DB, you can use any standard tool to read/write it without being authenticated. The feature is meant to restrict user access rights on a per-user basis, where the file is priviledge-protected inside a server or non-user area. Read user-auth.txt for details.

  • Like 1

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • Eminence
      By Eminence
      Hello,
      Using SQLite, I was trying to select a specific column with having duplicate entries removed by using the DISTINCT function. 
      Local $sQuery = "SELECT DISTINCT supervisor, COUNT(DISTINCT employee_name) FROM data_db What the above snippet does is just list only one supervisor but with the total count of unique employee names in the whole database when it should be listing out all supervisor entries from the database and list the total count of employees per each supervisors. If I remove the COUNT function, it does list out all unique entries of supervisor names from the list. Attached is a screenshot of an example database as well. 
      Any help will be much appreciated. Thank you!

    • Seminko
      By Seminko
      Hey,
      I have a script that uses SQLite. It worked without a hiccup on my W7 system.
      However, last week I bought a new machine, installed W10 and autoit, and now I'm getting an error during _SQLite_Startup.
      Can anyone advise on how to find what's wrong? Tried checking $__g_hPrintCallback_SQLite but that returns nothing.
       
      Tried downloading the latest version of the dll from the link in the function page and I also replaced the default SQLite.dll.au3 that came with AutoIt with the one that came with the latest SQLite version zip.
       
      Relevant parts of my script:
      #include <SQLite.au3> #include <SQLite.dll.au3> _SQLite_Startup(@ScriptDir & "\Config\sqlite3_x64.dll", False, 1) If @error Then MsgBox(16, "SQLite Error", "SQLite3.dll Can't be Loaded! - " & $__g_hPrintCallback_SQLite & @CRLF & @CRLF & "Exiting application / Zavolej Honzovi") Exit -1 EndIf  
      Thanks
      S.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I am building a management for the company I work with, and I just imported a real amount of rows ( about 29000 ), in my SQLite DB.
      The thing I am not understanding, is the time that the script takes to build this amount of rows in the ListView.
      I didn't measure it, but I think it took 2 minutes or so to create each ListView item...
      It is normal that it takes so much time?
      What can I do to improve the creation of the items?

      Here's the code I am using to query and to create ListView items...
      ; Articles ListView: Global $lvwArticles = GUICtrlCreateListView("ID|Fornitore|Codice|Descrizione|EU|Prezzo|Sconto Applicato|Note", 14, 87, 1507, 660, BitOR($GUI_SS_DEFAULT_LISTVIEW,$LVS_SORTASCENDING,$LVS_SORTDESCENDING), BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT)) ; Query $strQuery = "SELECT * FROM ARTICOLI;" ; Query Execution _SQLite_GetTable2d($objDatabase, $strQuery, $arrResult, $intRows, $intColumns) If @error Then ; Error Handling Else ; Cleaning the ListView _GUICtrlListView_DeleteAllItems($lvwArticles) If @error Then ; Error Handling Else ; No records in the Table If UBound($arrResult) < 2 Then ; Error Handling Else _GUICtrlListView_BeginUpdate($lvwArticles) For $intCounter = 1 To UBound($arrResult) - 1 $strListViewItem = $arrResult[$intCounter][0] & "|" & _ $arrResult[$intCounter][1] & "|" & _ $arrResult[$intCounter][2] & "|" & _ $arrResult[$intCounter][3] & "|" & _ $arrResult[$intCounter][4] & "|" & _ $arrResult[$intCounter][5] & "|" & _ $arrResult[$intCounter][6] & "|" & _ $arrResult[$intCounter][7] $objListViewItem = GUICtrlCreateListViewItem($strListViewItem, $lvwArticles) Next _GUICtrlListView_EndUpdate($lvwArticles) EndIf EndIf EndIf Thanks in advance


      Best Regards.
    • dangr82
      By dangr82
       
      I have created this function for a database, but I can not make it work. I always have two error messages: "not an error" ... and the file created, in the script directory, does not contain anything.
      Global $sDBName = "Hen.db" Func DatabaseTable() Local $sConnDB _SQLite_Startup() If @error Then MsgBox($MB_SYSTEMMODAL, "SQLite Error", "SQLite.dll Can't be Loaded!") Exit -1 EndIf $sConnDB = _SQLite_Open($sDBName) If @error Then MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Can't Load Database!") Exit -1 EndIf If Not _SQLite_Exec($sDBName, 'CREATE TABLE Animal ("Name", "Age");') = $SQLITE_OK Then MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg()) If Not _SQLite_Exec($sDBName, 'INSERT INTO Animale VALUES ("Charlie","5");') = $SQLITE_OK Then MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg()) _SQLite_Close($sConnDB) _SQLite_Shutdown() EndFunc  
    • Eminence
      By Eminence
      Hello,
      I've been searching on how to select the first row in my database which includes a time column based on the latest start_time date for today's date.
      This is my current code:
      Local $iCurrentDate = _Now() Local $sqlHandle = _dbOpen($sDbPath) Local $aResult, $iRows, $iCols _SQLite_GetTable2d($sqlHandle, "SELECT start_time FROM " & $srawDb & " ORDER BY datetime(start_time) DESC LIMIT 1", $aResult, $iRows, $iCols) _ArrayDisplay($aResult) _dbClose($sDbpath) What it does is it gets the first row entry in the database however it does not select the latest start_time entry in the database, it always select the first row. I've tried changing DESC to ASC to see if that will do it but the issue still remains. Any thoughts on this? Thanks in advance.
       
      *EDIT
      The date format in the database is by MM/DD/YYYY HH:MM:SS.
×