go-dqlite: Using returning clause causes errors

Hi, I noticed different types of errors when using the returning clause.

Sometimes I see this:

server: src/vfs.c:1701: vfsFileShmLock: Assertion `wal->n_tx == 0' failed

And sometimes this:

error: another row available

These errors happen with the below code after the app is ready and the DB has been created.

if _, err := db.ExecContext(ctx, "create table if not exists test (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, value TEXT NOT NULL)"); err != nil {
	return err
}

for i := 0; i < 10; i++ {
	result, err :=  db.ExecContext(ctx, "INSERT INTO test (value) VALUES (?) RETURNING *",  i)
	if err != nil {
		return err
	}
	id, err := result.LastInsertId()
	if err != nil {
		return err
	}
	log.Printf("inserted %d", id)
}

It works OK, when removing the returning clause.

I have installed the c libraries with this script: https://gist.github.com/bluebrown/85e1b39980f50c66682743afe0d8b316.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 18 (13 by maintainers)

Most upvoted comments

Actually @cole-miller’s PR https://github.com/canonical/dqlite/pull/477 should be a good first step for solving this. I believe what we’d need is to also return rows for non read-only statements submitted using the QUERY or QUERY_SQL protocol method. So actually we may not need a protocol change.