I'm having an embedded device which keeps a list of inner tables. I would like it to synchronize this table's state with some outside database for debugging purposes. That is whenever I add an element to a certain struct array I wish the device to issue an "INSERT INTO ..." command.
However I'm sending the data over an RS232 serial cable, which makes the overhead of sending explicit SQL unacceptable.
Since there are only 3 types of SQL commands I use a lot, I can only serialize these few. Namely INSERT INTO
,DELETE FROM
, and UPDATE
.
The general idea I had in mind is to send data with a "compressed/serializable" SQL protocol. We won't send commands directly to SQL server but to a custom serialized-SQL server I'll write:
- We'll assign a number to each database-changing simple action (ie INSERT, DELETE, UPDATE). The only available serializable-SQL commands are
INSERT INTO x ()
,DELETE FROM x WHERE id=y
. Where we can only changex
andy
. - At first create all necessary tables on the server once. Keep a hash table on the server that maps each table to a number. This can be done in plain SQL as this is only done once.
- Then assign a number to each table, make sure the server knows about this number
- Finally whenever we wish to execute an SQL command, we'll send command number, followed by table number, followed by data length followed by data. The server would figure out the layout of the actual data by table's description.
For example
INSERT INTO temperature(temperature,location)
VALUES ((108,"chille"),(120,"usa"))
Would be translated to
[INSERT INTO id][2 data to send]
[byte of 108][6 bytes string "chille"]
[byte of 120][3 bytes "usa"]
and
DELETE FROM people (id,"bob") WHERE id=1 or id=2
Would be translated to
[DELETE id][2 data to send][byte of 1][byte 2]
Since id is defined as a single byte integer.
Is there any known protocol/implementation in this spirit?
Does anyone have a better idea?