Jump to content

Display an Array from a SQLite DB in an existing GUI


dimmyr
 Share

Recommended Posts

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!

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...