Hi there,
With the shared-cache enabled, attaching a database to a second instance of the 
database connection throws an error : "database is already attached".
Why does this happen? is it by design or is it a bug?

Here is how to replicate the error:

#include <stdio.h>
#include "sqlite3.h"

int main(int argc, char **argv){
  sqlite3 *dbCon1;
  sqlite3 *dbCon2;
  int rc = SQLITE_OK;
  char *err;

  sqlite3_enable_shared_cache(1); // enable shared cache
  sqlite3_open("c:\\temp\\Database.sqlite", &dbCon1);
  if((rc = sqlite3_exec(dbCon1, "attach 'c:\\temp\\Database.sqlite' as db;", 0, 
0, &err)) != SQLITE_OK){
    printf("Error attaching: %s\n", err)
    sqlite3_close(dbCon1);
    return rc;
  }

  sqlite3_open("c:\\temp\\Database.sqlite", &dbCon2);
  if((rc = sqlite3_exec(dbCon2, "attach 'c:\\temp\\Database.sqlite' as db;", 0, 
0, &err)) != SQLITE_OK){
    printf("Error attaching: %s\n", err);
    sqlite3_close(dbCon2);
    return rc;
  }

  printf("attached on both connections\n");
  sqlite3_close(dbCon1);
  sqlite3_close(dbCon2);
}

Grace Batumbya
Research Assistant | Seneca CDOT
Phone: 416-491-5050 x3548
cdot.senecac.on.ca<http://cdot.senecac.on.ca/>



_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to