Search code examples
swiftxcodesqlitesqlite.swift

Xcode Can't connect to SQLITE Database


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


Solution

  • 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()