-4

I am trying to connect to SQLITE DB hosted at "http://server/apr/mysqlite.db" using sqlite3_open() but failing to achieve the connection. I can see the database file via browser explorer.

I am able to setup connection with database available at my local machine but didn't find any documentation to setup connection to http:// database.

Could anyone please help me accomplish the SQLITE connection in my XCODE

Partha Das
  • 17
  • 1
  • 6
  • Are you sure it is possible, sqlite isn't a server as far as I am concerned? – Joakim Danielson Dec 03 '19 at 12:43
  • Hi Joakim, I am new to Xcode and Swift programming. Here the SQLITE database is kept at the server which i am trying to access via SQLITE3_OPEN() – Partha Das Dec 03 '19 at 12:44
  • Well I still think SQLite is for local use and that this is what you need to research first. Maybe start by reading [this](https://www.sqlite.org/whentouse.html) – Joakim Danielson Dec 03 '19 at 12:58

1 Answers1

0

sqlite3_open() can't open a URL, it can only open a local file.

In order for sqlite3_open() to do what you want, the following needs to be true:

  • The sqlite3 library needs to have an HTTP client embedded in it (it doesn't).
  • The server at the other end needs to run a service to accept HTTP requests and pass commands on to the requested database (I am not aware of anybody having made such a service).

It's possible that somebody has created the service in the second bullet point but, if they have, you'd need a different sqlite3 library that implements the same API but sends your requests to the server instead of reading and writing a local file.

If your use-case is compatible and there is a sqlite3 database at that URL, you could download it to a local file and then open it using the normal sqlite3 library. You would not be able to re-upload any changes you make, though.

ETA

Joakim Danielson is correct. Sqlite3 is intended to be embedded in end user applications, not as a client server database manager. It's worth reading the Appropriate Uses page where it says:

SQLite does not compete with client/server databases. SQLite competes with fopen()

JeremyP
  • 84,577
  • 15
  • 123
  • 161
  • Thanks JeremyP :) for more insight into it. Could you also please help me as how should i proceed to setup the connection with remote database using Xcode and Swift, (and which database to use) so that the iOS app which i am developing makes connectivity to the remote database, once deployed on iphone. – Partha Das Dec 03 '19 at 14:33
  • @ParthaDas That's a big topic. I don't think it's something that can easily be answered in the context of Stack Overflow.As a starting point read [this](https://codewithchris.com/iphone-app-connect-to-mysql-database/). It leads you through the steps you need to do. Note that I am not endorsing MySql or PHP but it will give you some idea of how involved what you are asking is. – JeremyP Dec 03 '19 at 15:26
  • great ! Thanks a lot JeremyP :) – Partha Das Dec 03 '19 at 16:00