SQLite Server
Posted: Sun Feb 26, 2006 5:00 pm
I have created a little server based on SQLite. It communicates with it's clients using TCP sockets and the following control codes (subject to revision):
Client Control Codes
Codes Sent To Server
Chr(3) SQL Statement Separator
Chr(4) End Of Transmission
Chr(5) User Name and Password Should Precede This Code Separated By Chr(31)
Chr(20) The Buffer Contains SELECT Statements
Chr(21) The Buffer Contains DELETE, INSERT or UPDATE Statements
Codes Received From Server
Chr(3) Separator Used To Delimit The Responses To Multiple SELECT Statements
Chr(4) End Of Transmission
Chr(6) Successful Update
Chr(20) Record Separator
Chr(21) Error
Chr(31) Field Separator
Server Control Codes
Codes Sent To Client
Chr(3) Separator Used To Delimit The Responses To Multiple SELECT Statements
Chr(4) End Of Transmission
Chr(6) Successful Update
Chr(20) Record Separator
Chr(21) Error
Chr(31) Field Separator
Codes Received From Client
Chr(3) SQL Statement Separator
Chr(4) End Of Transmission
Chr(5) User Name and Password Should Precede This Code Separated By Chr(31)
Chr(20) The Buffer Contains SELECT Statements
Chr(21) The Buffer Contains DELETE, INSERT or UPDATE Statements
If you'd like a go with a free beta version (max 3 active sockets) please send me a private message and I will e-mail it to you.
Once any bugs are ironed out I plan to release a version that will avail >25 active sockets for a nominal fee.
The server does not provide any locking over and above that provided by SQLite, if it receives simultaneous requests to update it simply queues them and deals with them one at a time. Simultaneous reads are no problem.
Because the course grain locking provided by SQLite is so simplistic, i.e. the whole database, it doesn't add much overhead and updates are extremely quick. When you have a small workgroup of users this method is usually quicker than allowing multiple simultaneous updates using complicated field-level or even record-level locking algorithms.
You can also set-up the server to only accept connections from a list of IP addresses, or from a list of users with passwords or a combination of the two. If you don't set-up these lists it will accept connections from any client who sends a request on the specified port.
When you send a group of updates, separated by Chr(3) and terminated by Chr(4), they are automatically encapsulated into a transaction. If the update fails it will be rolledback you will receive the error control code Chr(21) along with the database engine error message and the sql statement that caused the exception separated by Chr(20).
You can also submit multiple select statements separated in the same way which is great for lookups.
It's been a while since I used PureBasic, but if it still has the 64K string length limit you may need to take this into consideration when requesting large recordsets.
Client Control Codes
Codes Sent To Server
Chr(3) SQL Statement Separator
Chr(4) End Of Transmission
Chr(5) User Name and Password Should Precede This Code Separated By Chr(31)
Chr(20) The Buffer Contains SELECT Statements
Chr(21) The Buffer Contains DELETE, INSERT or UPDATE Statements
Codes Received From Server
Chr(3) Separator Used To Delimit The Responses To Multiple SELECT Statements
Chr(4) End Of Transmission
Chr(6) Successful Update
Chr(20) Record Separator
Chr(21) Error
Chr(31) Field Separator
Server Control Codes
Codes Sent To Client
Chr(3) Separator Used To Delimit The Responses To Multiple SELECT Statements
Chr(4) End Of Transmission
Chr(6) Successful Update
Chr(20) Record Separator
Chr(21) Error
Chr(31) Field Separator
Codes Received From Client
Chr(3) SQL Statement Separator
Chr(4) End Of Transmission
Chr(5) User Name and Password Should Precede This Code Separated By Chr(31)
Chr(20) The Buffer Contains SELECT Statements
Chr(21) The Buffer Contains DELETE, INSERT or UPDATE Statements
If you'd like a go with a free beta version (max 3 active sockets) please send me a private message and I will e-mail it to you.
Once any bugs are ironed out I plan to release a version that will avail >25 active sockets for a nominal fee.
The server does not provide any locking over and above that provided by SQLite, if it receives simultaneous requests to update it simply queues them and deals with them one at a time. Simultaneous reads are no problem.
Because the course grain locking provided by SQLite is so simplistic, i.e. the whole database, it doesn't add much overhead and updates are extremely quick. When you have a small workgroup of users this method is usually quicker than allowing multiple simultaneous updates using complicated field-level or even record-level locking algorithms.
You can also set-up the server to only accept connections from a list of IP addresses, or from a list of users with passwords or a combination of the two. If you don't set-up these lists it will accept connections from any client who sends a request on the specified port.
When you send a group of updates, separated by Chr(3) and terminated by Chr(4), they are automatically encapsulated into a transaction. If the update fails it will be rolledback you will receive the error control code Chr(21) along with the database engine error message and the sql statement that caused the exception separated by Chr(20).
You can also submit multiple select statements separated in the same way which is great for lookups.
It's been a while since I used PureBasic, but if it still has the 64K string length limit you may need to take this into consideration when requesting large recordsets.