Access sqlite from a remote server

2019-01-15 16:06发布

I am wondering how i can access an sqlite database that is sitting a remote server.I have read threads discouraging it but i need to do it if its possible.

     /*
QUrlOperator xc("http://example.com");
xc.get("testdatabase.db");
*/

QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE" );

  db.setDatabaseName(xc.get("testdatabase.db"));
  //idea

  if( !db.open() )
  {
    qDebug() << db.lastError();
    qFatal( "Failed to connect." );
  }

标签: qt sqlite3
7条回答
混吃等死
2楼-- · 2019-01-15 16:50

you can consider switching to PostgreSQL instead of SQLite, the database manipulation is very similar. The little differences in handling primary keys etc you can google. For example in the INSERT statement you'd pass a NULL in SQLite, as a primary key and in Postgre you'd pass it as DEFAULT (given you want the database to create the key for you).

In Python3 for example, the code difference I know of is that PostgreSQL allows remote connection and that avoiding SQL injection syntax is slightly different, as SQLite3 way would be with ? and PostgreSQL9.5 would be with %s

Switching to Postgre would provide you a remote connection possibility and it is a definite step up from using a local database (which is only designed for small to medium bandwidth applications).

查看更多
登录 后发表回答