Android Question Connect to database from another device

vecino

Well-Known Member
Licensed User
Hi, I can connect to the database from another device?

esposible.png
 
Last edited:

vecino

Well-Known Member
Licensed User
Hi, thanks, but I think that is for a database that is on the same device. Not in another device.
 

Gunther

Active Member
Licensed User
Well, you can, but you have to use a server application on the device with the database.
The requesting device sends its request to the server application and that fetches the data and send a reply back to the requesting device.

Actually this is the same procedure how the internet is working.

Open a listening port on the server device and send with an own protocol e.g a text string, to the server app.
Use this string (I guess a SQL string; here you can check passwords to protect the conversation) and fetch the data.
The reply goes back to the client which listening to a receiving port as well.
With WLAN actually the procedure is simple.

Greetings,

Gunther
 
Last edited:

Gunther

Active Member
Licensed User
The b4a bridge is doing it fine since long time ;o)
But I agree in case that the database is somewhere on the server device. But you may chose a good place where it sits.
The server app should have access to it!
 
Last edited:

vecino

Well-Known Member
Licensed User
Thank you all for your messages.

I need something simple. It is software for restaurants, bars, ice cream parlors, small shops, etc.
They buy the software and install it on any tablet or smartphone.

That RDC how? Is it a linux / windows server?
 

picenainformatica

Active Member
Licensed User
Why you want use a tablet as server. It is a client.
 
Last edited:

DonManfred

Expert
Licensed User
Not force the customer to buy a PC server.
You only need a webhosting (a few $/month) with the possibility for accesing a Database from outside. Then you just can use my MySQL-Library to connect to the db. My or any other mysql-connectors. There are some of them... For example i pay 10,-/Month for my webhosting with 50GB webspace and my Databases are accessible from outside so i can use them directly in my app.

All the devices from the customer just need internet to connect to the database.
 

vecino

Well-Known Member
Licensed User
Can you choose a different database than MySQL?
Do I need to change a lot in my current software?
 

DonManfred

Expert
Licensed User
Can you choose a different database than MySQL?
No
MySQL speaks mostly the same language. SQL.
Do I need to change a lot in my current software?
do i know you software? :D

The most you need to change your app working async... If it working with async methods now (RDC for example) then you dont need to change much i believe.

But it is hard to say without seeing the code
 

KMatle

Expert
Licensed User

Gunther

Active Member
Licensed User
Actually it seems to be intended to be used in house with no access to the world.

Therefore I would do it like this concept :

1)
Setup a server app on one device. This includes the database. Server app means a winsock which is listening on a port. If a client is sending a request the server app opens a new winsock for sending the reply to the client. The server sends the reply to the remote port given by the request. Authentication have to be done for any request.
2)
setup a client on a remote device. Actually almost the same but you may keep it with one winsock.
3)
Make sure that the conversation is secure by encryption.

If you don't know how to start, than try to get knowledge how chat proggies are working.
You have to insert only a sql section for fetching the data before sending the reply back.

I hope that helps.

Cheers, Gunther
 
Last edited:

vecino

Well-Known Member
Licensed User
No
MySQL speaks mostly the same language. SQL.
do i know you software? :D
:D ... that's true.

I use "normal" SQL statements.
Examples:
B4X:
cFormaPagoNom = globales.DBconex.ExecQuerySingleResult2("select nombre from tbFormasPago where codigo=?",Array As String(iFormaPagoCod))

cSql = "Select ga.codigogrupo from tbGruposArticulos ga inner join tbGrupos g on g.codigo=ga.codigogrupo order by g.orden limit 1"
cMinGrupo = globales.DBconex.ExecQuerySingleResult(cSql)

cSql = "update "&cTBcab&" set numeromesa=?, codigosalon=? where id=?"
globales.DBconex.ExecNonQuery2(cSql,Array As String(iMesa,iSalonCod, iID))

cInsert = "insert into "&cTBlin&" (idcabecera,linea,tiposerienumerocabecera,codigoempleado,codigoarticulo,"
cInsert = cInsert & "nombrearticulo,cantidad,precio,ivacod,ivapc,repc,ivaimporte,reimporte,sumalinea,"
cInsert = cInsert & "estadolinea) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
globales.DBconex.ExecNonQuery2( cInsert, Array As Object( iIIDnew, QN.GetInt("linea"), iTip&cSNnew,    _
   QN.GetInt("codigoempleado"),                                                                                 _
   QN.GetString("codigoarticulo"), QN.GetString("nombrearticulo"),            _
   QN.GetDouble("cantidad") * (-1), QN.GetDouble("precio"),                            _
   QN.GetInt("ivacod"), QN.GetDouble("ivapc"),                                                    _
   QN.GetDouble("repc"), QN.GetDouble("ivaimporte") *(-1),                            _
   QN.GetDouble("reimporte") *(-1), QN.GetDouble("sumalinea") *(-1),        _
   QN.GetInt("estadolinea")))
I also use the library flexible table.

The most you need to change your app working async... If it working with async methods now (RDC for example) then you dont need to change much i believe. But it is hard to say without seeing the code
Can you explain what that is?
 
Last edited:

Gunther

Active Member
Licensed User
Formular too complex error! - I love my C64.

Keep it simple and don't try with fancy XAMPP etc.... In the beginning.

Try to transfer the content of the cSQL variable (only) to the server app. The server app fire it to the database.

And send back the reply from the database. May be you need to convert it in a string separated with comma or other splitters.
AsyncStreams Tutorial
 
Last edited:

vecino

Well-Known Member
Licensed User
Actually it seems to be intended to be used in house with no access to the world.
Therefore I would do it like this concept :
1)Setup a server app on one device. This includes the database. Server app means a winsock which is listening on a port. If a client is sending a request the server app opens a new winsock for sending the reply to the client. The server sends the reply to the remote port given by the request. Authentication have to be done for any request.
2)setup a client on a remote device. Actually almost the same but you may keep it with one winsock.
3)Make sure that the conversation is secure by encryption.
If you don't know how to start, than try to get knowledge how chat proggies are working.
You have to insert only a sql section for fetching the data before sending the reply back.
I hope that helps.
Cheers, Gunther
Too complex for me. I need help with an example. Please :)
 
Last edited:
Top