On 02/07/2017 05:14 PM, Jake Thaw wrote:
Hello Richard,

Is the following enhancement included as part of this pre-release snapshot?

- Enhance the session extension to support WITHOUT ROWID tables.

The draft documentation still says that this support does not yet exist,
and my test below also demonstrates this. Please let me know if I am
missing something.

Hi Jake,

Maybe you accidentally linked against the wrong version of SQLite or something. It's working here. The code I used is below. It is the same as yours except that:

  * prints the SQLite version to stdout, and
* includes a dummy conflict handler. Technically the conflict handler argument to sqlite3changeset_apply may not be NULL, although it wouldn't cause your test to fail.

Dan.

/****************************************************************/

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

static int xConflict(
  void *pCtx,
  int eConf,
  sqlite3_changeset_iter *pIter
){
  return SQLITE_CHANGESET_ABORT;
}

/*
** The following function will print an error as expected: "UNIQUE
** constraint failed: a.x".
**
** If table a is WITHOUT ROWID, then there will be no error.
*/
void fn(void){
  sqlite3 *db;
  sqlite3_session *pSession = 0;
  int nChangeset;
  void *pChangeset;
  char *sql;
  char *zMsg;

  printf("Using SQLite %s\n", sqlite3_libversion());

  sqlite3_open(":memory:", &db);

  sql = "CREATE TABLE a(x PRIMARY KEY) --WITHOUT ROWID";
  sqlite3_exec(db, sql, NULL, NULL, NULL);

  sqlite3session_create(db, "main", &pSession);
  sqlite3session_attach(pSession, "a");

  sql = "INSERT INTO a VALUES (1)";
  sqlite3_exec(db, sql, NULL, NULL, NULL);

  sqlite3session_changeset(pSession, &nChangeset, &pChangeset);

  sql = "DELETE FROM a WHERE x=1";
  sqlite3_exec(db, sql, NULL, NULL, NULL);

  sqlite3changeset_apply(db, nChangeset, pChangeset, 0, xConflict, 0);

  sql = "INSERT INTO a VALUES (1)";
  sqlite3_exec(db, sql, NULL, NULL, &zMsg);
  if( zMsg ) printf("%s\n", zMsg);
}

int main(int argc, char **argv){
  fn();
  return 0;
}

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

Reply via email to