Send a record set via TCPsocket

Hi Everyone,
I haven’t found this question elsewhere in the Forum… sorry if I missed it. Any ideas you have would be greatly appreciated.

I have 2 computers, A and B. They have a TCPSocket connection between them that works great.

If computer A does a SQLite query like:
Dim rs as RecordSet
rs = InfoDataBase.SQLSelect( “SELECT * FROM People” )

Is there an easy way to pass that record set (rs) from computer A to B thru the TCP connection. I can break the rs down into fields (columns) and values and send them thru the TCP connection to computer B that way if I have to… However, on computer B, my programming effort is made much easier if the info arrives as a complete record set, or alternatively if it is easily re-loaded into a record set on arrival at computer B. Any ideas on how to send a complete rs thru TCP, or perhaps an easy way to break the record set down, send it, and then re-construct it?

Thank you.

Your question is one of data serialization, i.e., converting a class into a string that can be reconstructed into a class.

Since you cannot load a RecordSet yourself, you can instead create a class that emulates it, say a “MyRecordSet” class that acts just like a RecordSet. Take the data from the RecordSet on A and convert it to JSON. On B, use that data to construct your MyRecordSet class.

The complexity of the JSON is up to you, but I recommend storing the field count, record count, and type of each column along with the column names and data.

An alternative would be to use CubeSQL.

This is no problem with a TCP socket. There is an example available with MBS Plugins. Use “PacketSocket Example” in folder PacketSocket. With this example you can send whatever you want over the network.

I think Eli is pointing you in the right direction. It sounds like you most likely should be using a network capable database. There are lots of options.

That isn’t always practical or desired. For example, if you are distributing an app to clients, you wouldn’t want it to have direct access to your database. Instead, you’d go through some kind of middleware, and that’s what the OP is describing.

Thank you. You are all very insightful, and your ideas have spurred me forward. Should be no problem from here (though that sounds like famous last words).

I’ve been using Xojo (and RB) for about 9 years. I have always been impressed by how helpful the conversations are in the Forum, and by how knowledgeable the participants are. Thank you for helping me, sharing your insights, and for reminding me that I still have a lot to learn.

Have a great week.

remote access to your database is a bad idea. the “bad guys” will find and hack your database. Using a middleware is much more secure.

Yes it’s more secure for your database, but then who secures your middleware? :stuck_out_tongue_winking_eye:

It really does depend on application context. If this is something that anyone might buy or download and use over the internet then for sure you don’t want to give direct access to the db. Of course there will be lots of other concerns in that context. If this is something people are going to use in an office with their own data, then that’s pretty much a no brainer to simply connect to a lan based network db server.

There are other scenarios as well. Just depends on what you are trying to do.