Android Question Connect to database from another device

Discussion in 'Android Questions' started by vecino, Jun 15, 2015.

  1. vecino

    vecino Well-Known Member Licensed User

    Hi, I can connect to the database from another device?

    esposible.png
     
    Last edited: Sep 1, 2015
  2. Peter Simpson

    Peter Simpson Well-Known Member Licensed User

  3. vecino

    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.
     
  4. DonManfred

    DonManfred Expert Licensed User

    You cannot open (and work with it) a database on another device
     
  5. vecino

    vecino Well-Known Member Licensed User

    :eek::(:confused:
    Is not there any solution?
     
  6. DonManfred

    DonManfred Expert Licensed User

    Yes. Use a Onlinedatabase to store the data and both devices should use RDC to connect to the online-db to fetch or insert data
     
    vecino likes this.
  7. Gunther

    Gunther 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: Jun 15, 2015
    vecino likes this.
  8. DonManfred

    DonManfred Expert Licensed User

    Most probably you need a rooted device to let a server software run
     
    vecino likes this.
  9. Gunther

    Gunther 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: Jun 15, 2015
    vecino likes this.
  10. vecino

    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?
     
  11. picenainformatica

    picenainformatica Active Member Licensed User

    Why you want use a tablet as server. It is a client.
     
    Last edited: Jun 15, 2015
  12. vecino

    vecino Well-Known Member Licensed User

    Not force the customer to buy a PC server.
    Although, if there is no other solution.
     
  13. DonManfred

    DonManfred Expert Licensed User

    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.
     
    KMatle and Peter Simpson like this.
  14. vecino

    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?
     
  15. DonManfred

    DonManfred Expert Licensed User

    No
    MySQL speaks mostly the same language. SQL.
    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
     
  16. KMatle

    KMatle Expert Licensed User

    1. Inhouse: Take XAMPP (php + MySql) to run in a local network. You'll need it anyway to test everything. A cheap laptop/pc will do.
    2. The world: see post of DonManfred (hoster). Can be reached from everywhere.
     
    vecino and DonManfred like this.
  17. Gunther

    Gunther 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: Jun 15, 2015
    vecino likes this.
  18. vecino

    vecino Well-Known Member Licensed User

    :D ... that's true.

    I use "normal" SQL statements.
    Examples:
    Code:
    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.

    Can you explain what that is?
     
    Last edited: Jun 15, 2015
  19. Gunther

    Gunther 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: Jun 15, 2015
    vecino likes this.
  20. vecino

    vecino Well-Known Member Licensed User

    Too complex for me. I need help with an example. Please :)
     
    Last edited: Jun 15, 2015
Loading...