Jump to content
dimmyr

Display an Array from a SQLite DB in an existing GUI

Recommended Posts

dimmyr

I would like to be able to display a table from a SQLite file inside an existing GUI, by clicking a button to get the most updated info.  Is that possible?  Eventually, I'd like to display a simple chart based on that table as well.

I have only dabbled with AutoIT and don't have enough functional knowledge to discern the various suggestions that this forum is awash with, so I would appreciate if someone was able to at least direct me towards the right path.

Thank you so much!

Share this post


Link to post
Share on other sites
JLogan3o13

Here is a rudimentary example, taken from the help file's _SQLite_ functions. It should serve as a starting point: try your hand at modifying to your needs, and look up the functions listed in the help file to learn more about them.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>

Local $aResult, $iRows, $iColumns, $iRval

_SQLite_Startup()
_SQLite_Open()

; The lines below create an Example Table
;   Name        | Age
;   -----------------------
;   Alice       | 43
;   Bob         | 28
;   Cindy       | 21

If Not _SQLite_Exec(-1, "CREATE TEMP TABLE persons (Name, Age);") = $SQLITE_OK Then _
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg())
If Not _SQLite_Exec(-1, "INSERT INTO persons VALUES ('Billy','18');") = $SQLITE_OK Then _
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg())
If Not _SQLite_Exec(-1, "INSERT INTO persons VALUES ('Joe','20');") = $SQLITE_OK Then _
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg())
If Not _SQLite_Exec(-1, "INSERT INTO persons VALUES ('Jim','75');") = $SQLITE_OK Then _
        MsgBox($MB_SYSTEMMODAL, "SQLite Error", _SQLite_ErrMsg())

$iRval = _SQLite_GetTable2d(-1, "SELECT * FROM persons;", $aResult, $iRows, $iColumns)
    If $iRval = $SQLITE_OK Then
        GUICreate("Show my SQLite Data", 300, 300)
        $sListView = GUICtrlCreateListView("Names|Ages", 10, 10, 280, 280)
            For $i = 1 To UBound($aResult) - 1
                GUICtrlCreateListViewItem($aResult[$i][0] & "|" & $aResult[$i][1], $sListView)
            Next


        GUISetState(@SW_SHOW)

            While 1
                Switch GUIGetMsg()
                    Case $GUI_EVENT_CLOSE
                        ExitLoop
                EndSwitch
            WEnd

        GUIDelete()

    Else
        MsgBox($MB_SYSTEMMODAL, "SQLite Error: " & $iRval, _SQLite_ErrMsg())
    EndIf

_SQLite_Close()
_SQLite_Shutdown()
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
JLogan3o13

Grr! Permanent ban on anyone posting the same question in multiple forums, I say. :angry:


√-1 2^3 ∑ π, and it was delicious!

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

×