Jump to content
Blank517

SQLite login

Recommended Posts

Blank517

Hi, I would like to make a login script with SQLite. The database looks like this:

_SQLite_Exec(-1, "CREATE TABLE Users (id INT(8) NOT NULL, username VARCHAR(30) NOT NULL, password VARCHAR(255) NOT NULL, permission INT(8) NOT NULL, PRIMARY KEY (id)); CREATE UNIQUE INDEX 'user_name_unique' ON 'Users' ('username' );")
_SQLite_Exec(-1, "INSERT INTO Users(id, username, password, permission) VALUES ('0', 'default', 'password', '0');")


theoretically I should make a query in this way, right?

_SQLite_Query (-1, "SELECT id FROM Users WHERE username = '" & $ Recv [1] & "' AND password = '" & $ Recv [2] & "';", $ hQuery)


but then I do not know how to know if you have found the 'id'

Share this post


Link to post
Share on other sites
JLogan3o13

Are you checking against $SQLITE_OK? Look at the example for _SQLite_Query in the help file.


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

Share this post


Link to post
Share on other sites
Blank517
Just now, JLogan3o13 said:

Are you checking against $SQLITE_OK? Look at the example for _SQLite_Query in the help file.

I already tried but i think that $SQLITE_OK checks only if command was successful

Share this post


Link to post
Share on other sites
JLogan3o13

I guess I'm not understanding what you are asking then, it might be helpful to post all of your code. If I create a table based on the inputs you're looking for, like so:

#include <SQLite.au3>
#include <SQLite.dll.au3>

Local $hDB, $myDBase = @TempDir & "\Test.tmp", $dllSQLite = @TempDir & "\sqlite.dll"

Local $sDLL = _SQLite_Startup($dllSQLite, False, 1)
    If @error Then
        ConsoleWrite("Failed with error: " & @error & @CRLF)
        Exit(-1)
    EndIf

$hDB = _SQLite_Open($myDBase)
    If $hDB = -1 Then Exit(MsgBox(0, "", "Error"))

    If $SQLITE_OK <> _SQLite_Exec($hDB, "CREATE TABLE Test ('ID', 'Username', 'Password', 'Permission');") Then
        MsgBox(0, "", "Error from TableCreate: " & _SQLite_ErrCode() & ". " & _SQLite_ErrMsg())
        Exit (-1)
    Else
        _SQLite_Exec($hDB, "INSERT INTO Test VALUES ('20418','Billy', 'Password1!', 'Administrator');")
        _SQLite_Exec($hDB, "INSERT INTO Test VALUES ('20419','Joe', 'Password2!', 'Operator');")
        _SQLite_Exec($hDB, "INSERT INTO Test VALUES ('20420','Jim', 'Password3!', 'User');")
        _SQLite_Exec($hDB, "INSERT INTO Test VALUES ('20421','Bob', 'Password4!', 'CEO');")
        _SQLite_Exec($hDB, "INSERT INTO Test VALUES ('20422','Sally', 'Password5!', 'Manager');")
        _SQLite_Exec($hDB, "INSERT INTO Test VALUES ('20423','Susie', 'Password6!', 'Mailroom');")
        _SQLite_Exec($hDB, "INSERT INTO Test VALUES ('20424','Sandra', 'Password7!', 'Secretary');")
    EndIf

_SQLite_Close()
_SQLite_Shutdown()

and then run a query against the values I've inserted, like this:

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

Local $Recv[2] = ["Jimmy", "Password1!"], $hQuery, $aRow, $sMsg
Local $hDB, $myDBase = @TempDir & "\test.tmp", $dllSQLite = @TempDir & "\sqlite.dll"

Local $sDLL = _SQLite_Startup($dllSQLite, False, 1)
    If @error Then
        ConsoleWrite("Failed with error: " & @error & @CRLF)
        Exit(-1)
    EndIf

$hDB = _SQLite_Open($myDBase)
    If $hDB = -1 Then Exit(MsgBox(0, "", "Error"))

_SQLite_Query ($hDB, "SELECT id FROM Test WHERE username = '" & $Recv [0] & "' AND password = '" & $Recv [1] & "';", $hQuery)
    While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
        $sMsg &= $aRow[0]
    WEnd

    MsgBox($MB_SYSTEMMODAL, "SQL Query", (($sMsg = "") ? "Failed to return ID" : $sMsg))

_SQLite_Close()
_SQLite_Shutdown()

It will tell me if the ID is not found.


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

Share this post


Link to post
Share on other sites
Blank517

@JLogan3o13 I love youuuu <3

You solved my problem, I didn't understand how to correctly use _SQLite_Query with _SQLite_FetchData...

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

    • 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.
    • Seminko
      By Seminko
      In my recent project I'm downloading a bunch of data, so I decided to store it in a SQLite database. NOTE: I'm using sqlite3_x64.dll
      Everything is working just fine but I'm struggling with getting the Median value. SQLite has an Average function but not a Median one.
      I googled but all of the provided solutions are way above my pay-grade. After some more searching I found 'extension-functions.c' on the SQLite site where Median is included. After almost an hour of struggling I was able to successfully compile it into a DLL.
      So I downloaded @jchd's SQLiteExtLoad.au3 as seen here:
      But I'm getting these errors:
      "Path\SQLiteExtLoad.au3"(21,40) : warning: $g_hDll_SQLite: possibly used before declaration. Local $RetVal = DllCall($g_hDll_SQLite, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ "Path\SQLiteExtLoad.au3"(21,40) : error: $g_hDll_SQLite: undeclared global variable. Local $RetVal = DllCall($g_hDll_SQLite, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ So I tried, copying the function to my file and changing the DLL variable ($g_hDll_SQLite) directly to the DLL location (C:\...\.. .dll), but now this error fires
      If __SQLite_hChk($hConn, 1) Then Return SetError(@error, 0, $SQLITE_MISUSE) To be honest, I don't know what to use as the $hConn - handle of connection.
      I would appreciate any help, be it getting the median using SQLite queries or getting the DLL extension loaded using AutoIt.
      Thanks, S.
       
      EDIT: well, I suspect the $hConn variable refers to the return value of the _SQLite_Open function. Well, at least now _SQLite_EnableExtensions doesn't give errors. Now I run into problems with _SQLite_LoadExtension, which gives error -1, and extended 1. Apparently the 1 constant is a generic error where other error do not apply.
      BTW, anybody knows whether I need to compile the extension DLL "into" x64 when I use a x64 SQLite? That might be the problem...
       
      EDIT2: I recompiled the dll and tried it using the SQLite3.exe and it works, so I'm confident the extension DLL has been created correctly

    • AdamUL
      By AdamUL
      I have been testing AutoIt 3.3.14.3 with SQLite, and the Help File examples.  The examples that I have tested are throwing errors or not doing anything.  I have sqlite3.dll, sqlite3_x64.dll, and sqlite3.exe in the directories with the testing script.  I am copying the examples directly from the help file into a test script for testing with no edits.  The _SQLite_GetTable2d example is returning an error ("Library used incorrectly") with each _SQLite_Exec command.  The _SQLite_FastEncode example returns an empty dialog box.  The _SQLite_Exec example only prints out the SQLite version, and nothing else in the SciTE console.  Currently, I'm still searching for what is causing this issue.  I'm on Windows 7 Enterprise 64-bit.  Is anyone else having this issue?  
       
      Adam
       
×