The code is below if it helps!
Lee
Code: Select all
IncludeFile "sqlite3.pb" ; Procedures to interface with SQLite3
OpenConsole()
If SQLite3_InitLib("sqlite3.dll") = #False
PrintN("Couldn't initialize SQLite3 library.")
Else
PrintN("SQLite3 library initialized.")
; Obtain a handle to the database
Global dbHandle = SQLite3_OpenDatabase("d:\music.db")
If dbHandle = 0
PrintN("Couldn't connect to database.")
Else
PrintN("Connected to database.")
EndIf
EndIf
CloseConsole()
If InitNetwork() = 0
Debug "Can't initialize the network !"
End
EndIf
cmd.s ; String used for SQLite commands
Define.s_RecordSet RS
Port = 54321
Buffer = AllocateMemory(1000)
If CreateNetworkServer(0, Port)
Debug "Server created (Port "+Str(Port)+")."
Repeat
SEvent = NetworkServerEvent()
If SEvent
ClientID = EventClient()
Select SEvent
Case 1
Debug "A new client has connected ! "+Str(ClientID)
Case 2
Debug "Client "+Str(ClientID)+" has send a packet !"
ReceiveNetworkData(ClientID, Buffer, 1000)
Command$ = PeekS(Buffer)
Debug "Packet Reads: "+Command$
Delay(1000)
If Left(Command$, 3) = "GET"
firstDot = -1
For i = 1 To Len(Command$)
If Mid(Command$, i, 1) = "."
If firstDot = -1
firstDot=i
EndIf
EndIf
Next i
Command$ = Left(Command$, firstDot-1)
Command$ = Mid(Command$, 5, Len(Command$)-4)
SearchField$ = "SELECT path FROM tracks WHERE trackID='"+Command$+"'"
; Get number of rows
If SQLite3_GetTable(SearchField$, dbHandle, @RS)
If RS\Rows < 1
Debug "SQLite3 Error:"+SQLite3_GetLastMessage() : End
EndIf
rows = RS\Rows
SQLite3_GetTable(SearchField$, dbHandle, @RS)
If rows = 1
SQLite3_GetRowCol(1, 0, @RS): FileName$ = (RS\sValue)
Debug "Requested: "+FileName$
EndIf
EndIf
ElseIf Left(Command$, 5) = "LIST."
CopyFile("D:\music.db", GetTemporaryDirectory()+"temp.txt")
FileName$=GetTemporaryDirectory()+"temp.txt"
Debug "TempFile created."
Debug "Database requested. "+FileName$
EndIf
Delay(1000)
Debug "Sending requested file"
SendNetworkFile(ClientID, FileName$)
Debug "Requested file sent"
If Left(Command$, 5) = "LIST."
DeleteFile(GetTemporaryDirectory()+"temp.txt")
Debug "Temporary file deleted."
EndIf
Case 4
Debug "Client "+Str(ClientID)+" has closed the connection."
;Quit = 1
EndSelect
EndIf
Until Quit = 1
Debug "Server shut down!"
CloseNetworkServer(0)
Else
Debug "Can't create the server."
EndIf
End