Jump to content
Blank517

_SQLite_FetchData problem

Recommended Posts

Blank517

Hi, when a client sends /logout to the server i want that the server find the id of the client and set his online status to 0

Using 'default' I have no problems, but when I do this with 'blank517' gives me id 10 and then for the database remains online

Database while Blank517 logout:

id  |  username  |  password |   permissions  |  online  |

0   |  default        |    pass1      |           0             |      0       |

1   |  Blank517    |     pass       |           0              |     1       |

Server recv:

Func _Recv_From_Sockets_()
    For $0 = 1 To $max_connections
        $Recv = TCPRecv ($Socket_Data[$0][0],1024)
        If StringLeft($Recv, 1) = "/" Then
            If StringInStr($Recv, "logout") Then
                _SQLite_Query(-1, "SELECT id FROM Users WHERE username = '" & $Socket_Data[$0][1] & "' AND online = '1';", $hQuery)
                While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
                    $sMsg &= $aRow[0]; <-- $sMsg = 10 after FetchData
                WEnd
                _SQLite_Exec(-1, "UPDATE Users SET online = '0' WHERE id = '" & $sMsg & "';")
                For $000 = 1 To $max_connections
                    TCPSend($Socket_Data[$000][0], $Socket_Data[$0][1] & " ha effettuato il logout")
                Next
                TCPCloseSocket($Socket_Data[$0][0])
                $sMsg = Null
            EndIf
        Else
            _Broadcast_To_Sockets_ ($Recv)
        EndIf
    Next
EndFunc

*excuse me for my bad english >_< *

Share this post


Link to post
Share on other sites
AutoBert

run this func:

Func _Recv_From_Sockets_()
    For $0 = 1 To $max_connections
        $Recv = TCPRecv ($Socket_Data[$0][0],1024)
        If StringLeft($Recv, 1) = "/" Then
            If StringInStr($Recv, "logout") Then
                _SQLite_Query(-1, "SELECT id FROM Users WHERE username = '" & $Socket_Data[$0][1] & "' AND online = '1';", $hQuery)
                While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
                    $sMsg &= $aRow[0]; <-- $sMsg = 10 after FetchData
                WEnd
                $sMsg=StringStripWS($sMsg,3)
                ConsoleWrite($sMsg&@CRLF)
                _SQLite_Exec(-1, "UPDATE Users SET online = '0' WHERE id = '" & $sMsg & "';")
                For $000 = 1 To $max_connections
                    TCPSend($Socket_Data[$000][0], $Socket_Data[$0][1] & " ha effettuato il logout")
                Next
                TCPCloseSocket($Socket_Data[$0][0])
                $sMsg = Null
            EndIf
        Else
            _Broadcast_To_Sockets_ ($Recv)
        EndIf
    Next
EndFunc

and post the output of the console.

Share this post


Link to post
Share on other sites
AutoBert

So all records with id=11 will be set to offline.

Share this post


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

So all records with id=11 will be set to offline.

Ok, but 'Blank517' has id '1' not '11' 

Share this post


Link to post
Share on other sites
AutoBert
11 minutes ago, Blank517 said:

Ok, but 'Blank517' has id '1' not '11' 

Then are 2 records found and '1'&'1' = '11' so test this:

Func _Recv_From_Sockets_()
    For $0 = 1 To $max_connections
        $Recv = TCPRecv ($Socket_Data[$0][0],1024)
        If StringLeft($Recv, 1) = "/" Then
            If StringInStr($Recv, "logout") Then
                _SQLite_Query(-1, "SELECT id FROM Users WHERE username = '" & $Socket_Data[$0][1] & "' AND online = '1';", $hQuery)
                If _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK Then
                    $sMsg &= $aRow[0]; <-- $sMsg = 10 after FetchData
                    $sMsg=StringStripWS($sMsg,3)    ;test if needed
                    ConsoleWrite($sMsg&@CRLF)
                    _SQLite_Exec(-1, "UPDATE Users SET online = '0' WHERE id = '" & $sMsg & "';")
                EndIf
                For $000 = 1 To $max_connections
                    TCPSend($Socket_Data[$000][0], $Socket_Data[$0][1] & " ha effettuato il logout")
                Next
                TCPCloseSocket($Socket_Data[$0][0])
                $sMsg = Null
            EndIf
        Else
            _Broadcast_To_Sockets_ ($Recv)
        EndIf
    Next
EndFunc

 

Share this post


Link to post
Share on other sites
Blank517

Last help for sqlite xP

When a user login, even if it is not registered and therefore hasn't an id, the server accepts the connection

_SQLite_Query(-1, "SELECT id FROM Users WHERE username = '" & $Socket_Data[$0][1] & "' AND password = '" & $Socket_Data[$0][2] & "' AND online = 0;", $hQuery)
            If _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK Then
                $sMsg &= $aRow[0]
            EndIf
            If $sMsg = "" Then
                ConsoleWrite("[Alert] Connection refused! (" & $Socket_Data[$0][1] & ")")
                TCPSend($Socket_Data[$0][0], "Connection refused!" & @CRLF & "There is a problem with the database:" & @CRLF & " - You're not registered" & @CRLF & " - You're already online")
                TCPCloseSocket($Socket_Data[$0][0])
                Return
            EndIf

 

Share this post


Link to post
Share on other sites
kylomas

Blank517,

You are concatenating the query results to the variable $msg...try just setting $msg to the results of the query.

...on a smart phone so cant test and typing is atrocious...

Kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Blank517
25 minutes ago, kylomas said:

You are concatenating the query results to the variable $msg...try just setting $msg to the results of the query.

The result does not change it always give me a null id

Share this post


Link to post
Share on other sites
kylomas

Blank517,

Are you using a DB shell to interrogate/develop your DB?  SqliteExpert is an excellent tool if you need one.  And it has a free version.

If you do have a DB viewer/shell, verify that ID contains what you think it should.

Also, it does not make sense that you are getting a "11" from fetchdata (post #3).  I'm not sure that problem has been identified yet.

Can you supply a reproducer, DB schema?

kylomas

edit: or your entire script?

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Blank517
16 hours ago, kylomas said:

Blank517,

You are concatenating the query results to the variable $msg...try just setting $msg to the results of the query.

...on a smart phone so cant test and typing is atrocious...

Kylomas

 

16 hours ago, Blank517 said:

The result does not change it always give me a null id

 

Solved 

_SQLite_Query(-1, "SELECT id FROM Users WHERE username = '" & $Recv[1] & "' AND password = '" & $Recv[2] & "' AND online = 0;", $hQuery)
            If _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK Then
                $sMsg = $aRow[0]
            EndIf
            If $sMsg = Null Then; <-- not $sMsg = "" but = Null
                ConsoleWrite("[Alert] Connection refused! (" & $Recv[1] & ")")
                TCPSend($Socket_Data[$0][0], "Connection refused!" & @CRLF & "There is a problem with the database:" & @CRLF & " - You're not registered" & @CRLF & " - You're already online")
                TCPCloseSocket($Socket_Data[$0][0])
                Return
            EndIf

 

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

    • 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

    • ripdad
      By ripdad
      I have had several people ask for this, so I decided to work the algorithm for it and this is the result.
      What is it?
      A Gateway Proxy Sends and Receives Data Unmodified.
      https://en.wikipedia.org/wiki/Proxy_server
      What is it used for?
      You can use it as a gateway, relay or router between two known static IP addresses.
      More information is in the header of the script.
      Download: LocalGatewayProxy.au3
      You will need WSA_NBTCP.au3 from here:
      https://www.autoitscript.com/forum/topic/191954-wsa_nbtcp-v100-udf/
      If you have any questions or problems, let me know.
       
    • 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
       
×