diff options
author | Martin Tournoij <martin@arp242.net> | 2020-12-28 07:52:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-28 08:52:08 +0900 |
commit | 3cbdae750e52afa881060732446298f98131e834 (patch) | |
tree | c181c1cdeb093cfe1b4d74c8ece55a5fdcd303ee /sqlite3.go | |
parent | Update amalgamation code (#896) (diff) | |
download | golite-3cbdae750e52afa881060732446298f98131e834.tar.gz golite-3cbdae750e52afa881060732446298f98131e834.tar.xz |
Export sqlite3_stmt_readonly() via SQLiteStmt.Readonly() (#895)
This can be used like in the test; I wrote a little wrapper around
sql.DB which uses this, and allows concurrent reads but just one single
write. This is perhaps a better generic "table locked"-solution than
setting the connections to 1 and/or cache=shared (although even better
would be to design your app in such a way that this doesn't happpen in
the first place, but even then a little seat belt isn't a bad thing).
The parsing adds about 0.1ms to 0.2ms of overhead in the wrapper, which
isn't too bad (and it caches the results, so only needs to do this
once).
At any rate, I can't really access functions from sqlite3-binding.c from
my application, so expose it via SQLiteStmt.
Diffstat (limited to 'sqlite3.go')
-rw-r--r-- | sqlite3.go | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -2007,6 +2007,13 @@ func (s *SQLiteStmt) execSync(args []namedValue) (driver.Result, error) { return &SQLiteResult{id: int64(rowid), changes: int64(changes)}, nil } +// Readonly reports if this statement is considered readonly by SQLite. +// +// See: https://sqlite.org/c3ref/stmt_readonly.html +func (s *SQLiteStmt) Readonly() bool { + return C.sqlite3_stmt_readonly(s.s) == 1 +} + // Close the rows. func (rc *SQLiteRows) Close() error { rc.s.mu.Lock() |