From af13bcbfe382daf57ee8ea6dcab2293e4f86b4c3 Mon Sep 17 00:00:00 2001 From: Charlie Vieth Date: Fri, 3 Feb 2023 22:53:30 -0500 Subject: [PATCH] all: format with Go 1.19 Update Go source files to use the '//go:build' lines introduced by Go 1.17 and the doc comment formatting introduced by Go 1.19. This formatting is not changed by Go 1.20. Note: doc.go had to be changed in some places to remove double indentation. --- backup_test.go | 1 + callback.go | 8 +- callback_test.go | 1 + doc.go | 125 ++++++++++++----------- error_test.go | 1 + sqlite3.go | 149 ++++++++++++++-------------- sqlite3_go113_test.go | 1 + sqlite3_go18.go | 4 +- sqlite3_go18_test.go | 1 + sqlite3_libsqlite3.go | 1 + sqlite3_load_extension.go | 1 + sqlite3_load_extension_omit.go | 1 + sqlite3_load_extension_test.go | 1 + sqlite3_opt_allow_uri_authority.go | 1 + sqlite3_opt_app_armor.go | 4 +- sqlite3_opt_column_metadata.go | 1 + sqlite3_opt_column_metadata_test.go | 1 + sqlite3_opt_foreign_keys.go | 1 + sqlite3_opt_fts3_test.go | 1 + sqlite3_opt_fts5.go | 1 + sqlite3_opt_icu.go | 1 + sqlite3_opt_introspect.go | 1 + sqlite3_opt_math_functions.go | 1 + sqlite3_opt_math_functions_test.go | 1 + sqlite3_opt_preupdate.go | 1 + sqlite3_opt_preupdate_hook.go | 1 + sqlite3_opt_preupdate_hook_test.go | 1 + sqlite3_opt_preupdate_omit.go | 1 + sqlite3_opt_secure_delete.go | 1 + sqlite3_opt_secure_delete_fast.go | 1 + sqlite3_opt_serialize.go | 1 + sqlite3_opt_serialize_omit.go | 1 + sqlite3_opt_serialize_test.go | 1 + sqlite3_opt_stat4.go | 1 + sqlite3_opt_unlock_notify.go | 4 +- sqlite3_opt_unlock_notify_test.go | 1 + sqlite3_opt_userauth.go | 18 ++-- sqlite3_opt_userauth_omit.go | 18 ++-- sqlite3_opt_userauth_test.go | 1 + sqlite3_opt_vacuum_full.go | 1 + sqlite3_opt_vacuum_incr.go | 1 + sqlite3_opt_vtable.go | 1 + sqlite3_other.go | 1 + sqlite3_solaris.go | 1 + sqlite3_test.go | 50 +++++----- sqlite3_trace.go | 1 + sqlite3_usleep_windows.go | 1 + sqlite3_windows.go | 1 + static_mock.go | 1 + 49 files changed, 236 insertions(+), 184 deletions(-) diff --git a/backup_test.go b/backup_test.go index 6d857de5..b3ad0b58 100644 --- a/backup_test.go +++ b/backup_test.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build cgo // +build cgo package sqlite3 diff --git a/callback.go b/callback.go index d3056910..5606b5ba 100644 --- a/callback.go +++ b/callback.go @@ -360,11 +360,11 @@ func callbackRetGeneric(ctx *C.sqlite3_context, v reflect.Value) error { } cb, err := callbackRet(v.Elem().Type()) - if err != nil { - return err - } + if err != nil { + return err + } - return cb(ctx, v.Elem()) + return cb(ctx, v.Elem()) } func callbackRet(typ reflect.Type) (callbackRetConverter, error) { diff --git a/callback_test.go b/callback_test.go index b09122ae..e1447b32 100644 --- a/callback_test.go +++ b/callback_test.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build cgo // +build cgo package sqlite3 diff --git a/doc.go b/doc.go index ac27633b..c78e4437 100644 --- a/doc.go +++ b/doc.go @@ -5,63 +5,63 @@ This works as a driver for database/sql. Installation - go get github.com/mattn/go-sqlite3 + go get github.com/mattn/go-sqlite3 -Supported Types +# Supported Types Currently, go-sqlite3 supports the following data types. - +------------------------------+ - |go | sqlite3 | - |----------|-------------------| - |nil | null | - |int | integer | - |int64 | integer | - |float64 | float | - |bool | integer | - |[]byte | blob | - |string | text | - |time.Time | timestamp/datetime| - +------------------------------+ - -SQLite3 Extension + +------------------------------+ + |go | sqlite3 | + |----------|-------------------| + |nil | null | + |int | integer | + |int64 | integer | + |float64 | float | + |bool | integer | + |[]byte | blob | + |string | text | + |time.Time | timestamp/datetime| + +------------------------------+ + +# SQLite3 Extension You can write your own extension module for sqlite3. For example, below is an extension for a Regexp matcher operation. - #include - #include - #include - #include - - SQLITE_EXTENSION_INIT1 - static void regexp_func(sqlite3_context *context, int argc, sqlite3_value **argv) { - if (argc >= 2) { - const char *target = (const char *)sqlite3_value_text(argv[1]); - const char *pattern = (const char *)sqlite3_value_text(argv[0]); - const char* errstr = NULL; - int erroff = 0; - int vec[500]; - int n, rc; - pcre* re = pcre_compile(pattern, 0, &errstr, &erroff, NULL); - rc = pcre_exec(re, NULL, target, strlen(target), 0, 0, vec, 500); - if (rc <= 0) { - sqlite3_result_error(context, errstr, 0); - return; - } - sqlite3_result_int(context, 1); - } - } - - #ifdef _WIN32 - __declspec(dllexport) - #endif - int sqlite3_extension_init(sqlite3 *db, char **errmsg, - const sqlite3_api_routines *api) { - SQLITE_EXTENSION_INIT2(api); - return sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8, - (void*)db, regexp_func, NULL, NULL); - } + #include + #include + #include + #include + + SQLITE_EXTENSION_INIT1 + static void regexp_func(sqlite3_context *context, int argc, sqlite3_value **argv) { + if (argc >= 2) { + const char *target = (const char *)sqlite3_value_text(argv[1]); + const char *pattern = (const char *)sqlite3_value_text(argv[0]); + const char* errstr = NULL; + int erroff = 0; + int vec[500]; + int n, rc; + pcre* re = pcre_compile(pattern, 0, &errstr, &erroff, NULL); + rc = pcre_exec(re, NULL, target, strlen(target), 0, 0, vec, 500); + if (rc <= 0) { + sqlite3_result_error(context, errstr, 0); + return; + } + sqlite3_result_int(context, 1); + } + } + + #ifdef _WIN32 + __declspec(dllexport) + #endif + int sqlite3_extension_init(sqlite3 *db, char **errmsg, + const sqlite3_api_routines *api) { + SQLITE_EXTENSION_INIT2(api); + return sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8, + (void*)db, regexp_func, NULL, NULL); + } It needs to be built as a so/dll shared library. And you need to register the extension module like below. @@ -77,18 +77,18 @@ Then, you can use this extension. rows, err := db.Query("select text from mytable where name regexp '^golang'") -Connection Hook +# Connection Hook You can hook and inject your code when the connection is established by setting ConnectHook to get the SQLiteConn. sql.Register("sqlite3_with_hook_example", - &sqlite3.SQLiteDriver{ - ConnectHook: func(conn *sqlite3.SQLiteConn) error { - sqlite3conn = append(sqlite3conn, conn) - return nil - }, - }) + &sqlite3.SQLiteDriver{ + ConnectHook: func(conn *sqlite3.SQLiteConn) error { + sqlite3conn = append(sqlite3conn, conn) + return nil + }, + }) You can also use database/sql.Conn.Raw (Go >= 1.13): @@ -101,7 +101,7 @@ You can also use database/sql.Conn.Raw (Go >= 1.13): }) // if err != nil { ... } -Go SQlite3 Extensions +# Go SQlite3 Extensions If you want to register Go functions as SQLite extension functions you can make a custom driver by calling RegisterFunction from @@ -111,11 +111,11 @@ ConnectHook. return regexp.MatchString(re, s) } sql.Register("sqlite3_extended", - &sqlite3.SQLiteDriver{ - ConnectHook: func(conn *sqlite3.SQLiteConn) error { - return conn.RegisterFunc("regexp", regex, true) - }, - }) + &sqlite3.SQLiteDriver{ + ConnectHook: func(conn *sqlite3.SQLiteConn) error { + return conn.RegisterFunc("regexp", regex, true) + }, + }) You can then use the custom driver by passing its name to sql.Open. @@ -130,6 +130,5 @@ You can then use the custom driver by passing its name to sql.Open. } See the documentation of RegisterFunc for more details. - */ package sqlite3 diff --git a/error_test.go b/error_test.go index 3cfad061..0ff14c18 100644 --- a/error_test.go +++ b/error_test.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build cgo // +build cgo package sqlite3 diff --git a/sqlite3.go b/sqlite3.go index 9c0f4d89..8aaef766 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -971,103 +971,104 @@ func (c *SQLiteConn) begin(ctx context.Context) (driver.Tx, error) { // The argument is may be either in parentheses or it may be separated from // the pragma name by an equal sign. The two syntaxes yield identical results. // In many pragmas, the argument is a boolean. The boolean can be one of: -// 1 yes true on -// 0 no false off +// +// 1 yes true on +// 0 no false off // // You can specify a DSN string using a URI as the filename. -// test.db -// file:test.db?cache=shared&mode=memory -// :memory: -// file::memory: // -// mode -// Access mode of the database. -// https://www.sqlite.org/c3ref/open.html -// Values: -// - ro -// - rw -// - rwc -// - memory +// test.db +// file:test.db?cache=shared&mode=memory +// :memory: +// file::memory: // -// cache -// SQLite Shared-Cache Mode -// https://www.sqlite.org/sharedcache.html -// Values: -// - shared -// - private +// mode +// Access mode of the database. +// https://www.sqlite.org/c3ref/open.html +// Values: +// - ro +// - rw +// - rwc +// - memory // -// immutable=Boolean -// The immutable parameter is a boolean query parameter that indicates -// that the database file is stored on read-only media. When immutable is set, -// SQLite assumes that the database file cannot be changed, -// even by a process with higher privilege, -// and so the database is opened read-only and all locking and change detection is disabled. -// Caution: Setting the immutable property on a database file that -// does in fact change can result in incorrect query results and/or SQLITE_CORRUPT errors. +// cache +// SQLite Shared-Cache Mode +// https://www.sqlite.org/sharedcache.html +// Values: +// - shared +// - private // -// go-sqlite3 adds the following query parameters to those used by SQLite: -// _loc=XXX -// Specify location of time format. It's possible to specify "auto". +// immutable=Boolean +// The immutable parameter is a boolean query parameter that indicates +// that the database file is stored on read-only media. When immutable is set, +// SQLite assumes that the database file cannot be changed, +// even by a process with higher privilege, +// and so the database is opened read-only and all locking and change detection is disabled. +// Caution: Setting the immutable property on a database file that +// does in fact change can result in incorrect query results and/or SQLITE_CORRUPT errors. // -// _mutex=XXX -// Specify mutex mode. XXX can be "no", "full". +// go-sqlite3 adds the following query parameters to those used by SQLite: // -// _txlock=XXX -// Specify locking behavior for transactions. XXX can be "immediate", -// "deferred", "exclusive". +// _loc=XXX +// Specify location of time format. It's possible to specify "auto". // -// _auto_vacuum=X | _vacuum=X -// 0 | none - Auto Vacuum disabled -// 1 | full - Auto Vacuum FULL -// 2 | incremental - Auto Vacuum Incremental +// _mutex=XXX +// Specify mutex mode. XXX can be "no", "full". // -// _busy_timeout=XXX"| _timeout=XXX -// Specify value for sqlite3_busy_timeout. +// _txlock=XXX +// Specify locking behavior for transactions. XXX can be "immediate", +// "deferred", "exclusive". // -// _case_sensitive_like=Boolean | _cslike=Boolean -// https://www.sqlite.org/pragma.html#pragma_case_sensitive_like -// Default or disabled the LIKE operation is case-insensitive. -// When enabling this options behaviour of LIKE will become case-sensitive. +// _auto_vacuum=X | _vacuum=X +// 0 | none - Auto Vacuum disabled +// 1 | full - Auto Vacuum FULL +// 2 | incremental - Auto Vacuum Incremental // -// _defer_foreign_keys=Boolean | _defer_fk=Boolean -// Defer Foreign Keys until outermost transaction is committed. +// _busy_timeout=XXX"| _timeout=XXX +// Specify value for sqlite3_busy_timeout. // -// _foreign_keys=Boolean | _fk=Boolean -// Enable or disable enforcement of foreign keys. +// _case_sensitive_like=Boolean | _cslike=Boolean +// https://www.sqlite.org/pragma.html#pragma_case_sensitive_like +// Default or disabled the LIKE operation is case-insensitive. +// When enabling this options behaviour of LIKE will become case-sensitive. // -// _ignore_check_constraints=Boolean -// This pragma enables or disables the enforcement of CHECK constraints. -// The default setting is off, meaning that CHECK constraints are enforced by default. +// _defer_foreign_keys=Boolean | _defer_fk=Boolean +// Defer Foreign Keys until outermost transaction is committed. // -// _journal_mode=MODE | _journal=MODE -// Set journal mode for the databases associated with the current connection. -// https://www.sqlite.org/pragma.html#pragma_journal_mode +// _foreign_keys=Boolean | _fk=Boolean +// Enable or disable enforcement of foreign keys. // -// _locking_mode=X | _locking=X -// Sets the database connection locking-mode. -// The locking-mode is either NORMAL or EXCLUSIVE. -// https://www.sqlite.org/pragma.html#pragma_locking_mode +// _ignore_check_constraints=Boolean +// This pragma enables or disables the enforcement of CHECK constraints. +// The default setting is off, meaning that CHECK constraints are enforced by default. // -// _query_only=Boolean -// The query_only pragma prevents all changes to database files when enabled. +// _journal_mode=MODE | _journal=MODE +// Set journal mode for the databases associated with the current connection. +// https://www.sqlite.org/pragma.html#pragma_journal_mode // -// _recursive_triggers=Boolean | _rt=Boolean -// Enable or disable recursive triggers. +// _locking_mode=X | _locking=X +// Sets the database connection locking-mode. +// The locking-mode is either NORMAL or EXCLUSIVE. +// https://www.sqlite.org/pragma.html#pragma_locking_mode // -// _secure_delete=Boolean|FAST -// When secure_delete is on, SQLite overwrites deleted content with zeros. -// https://www.sqlite.org/pragma.html#pragma_secure_delete +// _query_only=Boolean +// The query_only pragma prevents all changes to database files when enabled. // -// _synchronous=X | _sync=X -// Change the setting of the "synchronous" flag. -// https://www.sqlite.org/pragma.html#pragma_synchronous +// _recursive_triggers=Boolean | _rt=Boolean +// Enable or disable recursive triggers. // -// _writable_schema=Boolean -// When this pragma is on, the SQLITE_MASTER tables in which database -// can be changed using ordinary UPDATE, INSERT, and DELETE statements. -// Warning: misuse of this pragma can easily result in a corrupt database file. +// _secure_delete=Boolean|FAST +// When secure_delete is on, SQLite overwrites deleted content with zeros. +// https://www.sqlite.org/pragma.html#pragma_secure_delete // +// _synchronous=X | _sync=X +// Change the setting of the "synchronous" flag. +// https://www.sqlite.org/pragma.html#pragma_synchronous // +// _writable_schema=Boolean +// When this pragma is on, the SQLITE_MASTER tables in which database +// can be changed using ordinary UPDATE, INSERT, and DELETE statements. +// Warning: misuse of this pragma can easily result in a corrupt database file. func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { if C.sqlite3_threadsafe() == 0 { return nil, errors.New("sqlite library was not compiled for thread-safe operation") diff --git a/sqlite3_go113_test.go b/sqlite3_go113_test.go index a010cb7a..3f2f0f58 100644 --- a/sqlite3_go113_test.go +++ b/sqlite3_go113_test.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build go1.13 && cgo // +build go1.13,cgo package sqlite3 diff --git a/sqlite3_go18.go b/sqlite3_go18.go index bd97cb87..5954d9b5 100644 --- a/sqlite3_go18.go +++ b/sqlite3_go18.go @@ -3,8 +3,8 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build cgo -// +build go1.8 +//go:build cgo && go1.8 +// +build cgo,go1.8 package sqlite3 diff --git a/sqlite3_go18_test.go b/sqlite3_go18_test.go index 8c8c4515..eec7479d 100644 --- a/sqlite3_go18_test.go +++ b/sqlite3_go18_test.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build go1.8 && cgo // +build go1.8,cgo package sqlite3 diff --git a/sqlite3_libsqlite3.go b/sqlite3_libsqlite3.go index e428fe67..d58576c1 100644 --- a/sqlite3_libsqlite3.go +++ b/sqlite3_libsqlite3.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build libsqlite3 // +build libsqlite3 package sqlite3 diff --git a/sqlite3_load_extension.go b/sqlite3_load_extension.go index 9433fea8..03cbc8b6 100644 --- a/sqlite3_load_extension.go +++ b/sqlite3_load_extension.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build !sqlite_omit_load_extension // +build !sqlite_omit_load_extension package sqlite3 diff --git a/sqlite3_load_extension_omit.go b/sqlite3_load_extension_omit.go index 8c75f9bd..d4f8ce65 100644 --- a/sqlite3_load_extension_omit.go +++ b/sqlite3_load_extension_omit.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_omit_load_extension // +build sqlite_omit_load_extension package sqlite3 diff --git a/sqlite3_load_extension_test.go b/sqlite3_load_extension_test.go index 97b11233..c6c03bb2 100644 --- a/sqlite3_load_extension_test.go +++ b/sqlite3_load_extension_test.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build !sqlite_omit_load_extension // +build !sqlite_omit_load_extension package sqlite3 diff --git a/sqlite3_opt_allow_uri_authority.go b/sqlite3_opt_allow_uri_authority.go index 8c4d4d20..51240cbf 100644 --- a/sqlite3_opt_allow_uri_authority.go +++ b/sqlite3_opt_allow_uri_authority.go @@ -4,6 +4,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_allow_uri_authority // +build sqlite_allow_uri_authority package sqlite3 diff --git a/sqlite3_opt_app_armor.go b/sqlite3_opt_app_armor.go index 63c80cfe..565dbc29 100644 --- a/sqlite3_opt_app_armor.go +++ b/sqlite3_opt_app_armor.go @@ -4,8 +4,8 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build !windows -// +build sqlite_app_armor +//go:build !windows && sqlite_app_armor +// +build !windows,sqlite_app_armor package sqlite3 diff --git a/sqlite3_opt_column_metadata.go b/sqlite3_opt_column_metadata.go index c67fa82b..63659b46 100644 --- a/sqlite3_opt_column_metadata.go +++ b/sqlite3_opt_column_metadata.go @@ -1,3 +1,4 @@ +//go:build sqlite_column_metadata // +build sqlite_column_metadata package sqlite3 diff --git a/sqlite3_opt_column_metadata_test.go b/sqlite3_opt_column_metadata_test.go index 28767f1e..0a9eec6e 100644 --- a/sqlite3_opt_column_metadata_test.go +++ b/sqlite3_opt_column_metadata_test.go @@ -1,3 +1,4 @@ +//go:build sqlite_column_metadata // +build sqlite_column_metadata package sqlite3 diff --git a/sqlite3_opt_foreign_keys.go b/sqlite3_opt_foreign_keys.go index a676e097..82c944e1 100644 --- a/sqlite3_opt_foreign_keys.go +++ b/sqlite3_opt_foreign_keys.go @@ -4,6 +4,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_foreign_keys // +build sqlite_foreign_keys package sqlite3 diff --git a/sqlite3_opt_fts3_test.go b/sqlite3_opt_fts3_test.go index ce44474c..a7b31a71 100644 --- a/sqlite3_opt_fts3_test.go +++ b/sqlite3_opt_fts3_test.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build cgo // +build cgo package sqlite3 diff --git a/sqlite3_opt_fts5.go b/sqlite3_opt_fts5.go index 0f38df75..2645f284 100644 --- a/sqlite3_opt_fts5.go +++ b/sqlite3_opt_fts5.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_fts5 || fts5 // +build sqlite_fts5 fts5 package sqlite3 diff --git a/sqlite3_opt_icu.go b/sqlite3_opt_icu.go index 8257a75b..7c43e574 100644 --- a/sqlite3_opt_icu.go +++ b/sqlite3_opt_icu.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_icu || icu // +build sqlite_icu icu package sqlite3 diff --git a/sqlite3_opt_introspect.go b/sqlite3_opt_introspect.go index 6512b2b3..cd2e5401 100644 --- a/sqlite3_opt_introspect.go +++ b/sqlite3_opt_introspect.go @@ -4,6 +4,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_introspect // +build sqlite_introspect package sqlite3 diff --git a/sqlite3_opt_math_functions.go b/sqlite3_opt_math_functions.go index 7cd68d3f..bd62d9a2 100644 --- a/sqlite3_opt_math_functions.go +++ b/sqlite3_opt_math_functions.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_math_functions // +build sqlite_math_functions package sqlite3 diff --git a/sqlite3_opt_math_functions_test.go b/sqlite3_opt_math_functions_test.go index 6ff076b4..09dbd8db 100644 --- a/sqlite3_opt_math_functions_test.go +++ b/sqlite3_opt_math_functions_test.go @@ -1,3 +1,4 @@ +//go:build sqlite_math_functions // +build sqlite_math_functions package sqlite3 diff --git a/sqlite3_opt_preupdate.go b/sqlite3_opt_preupdate.go index cea032e3..ed725eeb 100644 --- a/sqlite3_opt_preupdate.go +++ b/sqlite3_opt_preupdate.go @@ -4,6 +4,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build cgo // +build cgo package sqlite3 diff --git a/sqlite3_opt_preupdate_hook.go b/sqlite3_opt_preupdate_hook.go index b43e4821..bcf989ac 100644 --- a/sqlite3_opt_preupdate_hook.go +++ b/sqlite3_opt_preupdate_hook.go @@ -4,6 +4,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_preupdate_hook // +build sqlite_preupdate_hook package sqlite3 diff --git a/sqlite3_opt_preupdate_hook_test.go b/sqlite3_opt_preupdate_hook_test.go index 20c87665..b8f1f734 100644 --- a/sqlite3_opt_preupdate_hook_test.go +++ b/sqlite3_opt_preupdate_hook_test.go @@ -4,6 +4,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_preupdate_hook // +build sqlite_preupdate_hook package sqlite3 diff --git a/sqlite3_opt_preupdate_omit.go b/sqlite3_opt_preupdate_omit.go index c510a15b..f60da6c1 100644 --- a/sqlite3_opt_preupdate_omit.go +++ b/sqlite3_opt_preupdate_omit.go @@ -4,6 +4,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build !sqlite_preupdate_hook && cgo // +build !sqlite_preupdate_hook,cgo package sqlite3 diff --git a/sqlite3_opt_secure_delete.go b/sqlite3_opt_secure_delete.go index 934fa6b8..6bb05b84 100644 --- a/sqlite3_opt_secure_delete.go +++ b/sqlite3_opt_secure_delete.go @@ -4,6 +4,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_secure_delete // +build sqlite_secure_delete package sqlite3 diff --git a/sqlite3_opt_secure_delete_fast.go b/sqlite3_opt_secure_delete_fast.go index b0de130f..982020ae 100644 --- a/sqlite3_opt_secure_delete_fast.go +++ b/sqlite3_opt_secure_delete_fast.go @@ -4,6 +4,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_secure_delete_fast // +build sqlite_secure_delete_fast package sqlite3 diff --git a/sqlite3_opt_serialize.go b/sqlite3_opt_serialize.go index 2560c43a..f1710c1c 100644 --- a/sqlite3_opt_serialize.go +++ b/sqlite3_opt_serialize.go @@ -1,3 +1,4 @@ +//go:build !libsqlite3 || sqlite_serialize // +build !libsqlite3 sqlite_serialize package sqlite3 diff --git a/sqlite3_opt_serialize_omit.go b/sqlite3_opt_serialize_omit.go index b154dd34..d00ead0b 100644 --- a/sqlite3_opt_serialize_omit.go +++ b/sqlite3_opt_serialize_omit.go @@ -1,3 +1,4 @@ +//go:build libsqlite3 && !sqlite_serialize // +build libsqlite3,!sqlite_serialize package sqlite3 diff --git a/sqlite3_opt_serialize_test.go b/sqlite3_opt_serialize_test.go index 624c5a94..09991ed8 100644 --- a/sqlite3_opt_serialize_test.go +++ b/sqlite3_opt_serialize_test.go @@ -1,3 +1,4 @@ +//go:build !libsqlite3 || sqlite_serialize // +build !libsqlite3 sqlite_serialize package sqlite3 diff --git a/sqlite3_opt_stat4.go b/sqlite3_opt_stat4.go index d4d30f0d..799fbb0f 100644 --- a/sqlite3_opt_stat4.go +++ b/sqlite3_opt_stat4.go @@ -4,6 +4,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_stat4 // +build sqlite_stat4 package sqlite3 diff --git a/sqlite3_opt_unlock_notify.go b/sqlite3_opt_unlock_notify.go index adfa26c5..76f7bbfb 100644 --- a/sqlite3_opt_unlock_notify.go +++ b/sqlite3_opt_unlock_notify.go @@ -3,8 +3,8 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build cgo -// +build sqlite_unlock_notify +//go:build cgo && sqlite_unlock_notify +// +build cgo,sqlite_unlock_notify package sqlite3 diff --git a/sqlite3_opt_unlock_notify_test.go b/sqlite3_opt_unlock_notify_test.go index 95db9387..3a9168cd 100644 --- a/sqlite3_opt_unlock_notify_test.go +++ b/sqlite3_opt_unlock_notify_test.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_unlock_notify // +build sqlite_unlock_notify package sqlite3 diff --git a/sqlite3_opt_userauth.go b/sqlite3_opt_userauth.go index b62b6084..78fa6837 100644 --- a/sqlite3_opt_userauth.go +++ b/sqlite3_opt_userauth.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_userauth // +build sqlite_userauth package sqlite3 @@ -79,7 +80,7 @@ var ( // If a database contains the SQLITE_USER table, then the // call to Authenticate must be invoked with an // appropriate username and password prior to enable read and write -//access to the database. +// access to the database. // // Return SQLITE_OK on success or SQLITE_ERROR if the username/password // combination is incorrect or unknown. @@ -103,9 +104,10 @@ func (c *SQLiteConn) Authenticate(username, password string) error { // It is however exported for usage within SQL by the user. // // Returns: +// // C.SQLITE_OK (0) // C.SQLITE_ERROR (1) -// C.SQLITE_AUTH (23) +// C.SQLITE_AUTH (23) func (c *SQLiteConn) authenticate(username, password string) int { // Allocate C Variables cuser := C.CString(username) @@ -155,9 +157,10 @@ func (c *SQLiteConn) AuthUserAdd(username, password string, admin bool) error { // It is however exported for usage within SQL by the user. // // Returns: +// // C.SQLITE_OK (0) // C.SQLITE_ERROR (1) -// C.SQLITE_AUTH (23) +// C.SQLITE_AUTH (23) func (c *SQLiteConn) authUserAdd(username, password string, admin int) int { // Allocate C Variables cuser := C.CString(username) @@ -207,9 +210,10 @@ func (c *SQLiteConn) AuthUserChange(username, password string, admin bool) error // It is however exported for usage within SQL by the user. // // Returns: +// // C.SQLITE_OK (0) // C.SQLITE_ERROR (1) -// C.SQLITE_AUTH (23) +// C.SQLITE_AUTH (23) func (c *SQLiteConn) authUserChange(username, password string, admin int) int { // Allocate C Variables cuser := C.CString(username) @@ -249,9 +253,10 @@ func (c *SQLiteConn) AuthUserDelete(username string) error { // It is however exported for usage within SQL by the user. // // Returns: +// // C.SQLITE_OK (0) // C.SQLITE_ERROR (1) -// C.SQLITE_AUTH (23) +// C.SQLITE_AUTH (23) func (c *SQLiteConn) authUserDelete(username string) int { // Allocate C Variables cuser := C.CString(username) @@ -280,8 +285,9 @@ func (c *SQLiteConn) AuthEnabled() (exists bool) { // It is however exported for usage within SQL by the user. // // Returns: +// // 0 - Disabled -// 1 - Enabled +// 1 - Enabled func (c *SQLiteConn) authEnabled() int { return int(C._sqlite3_auth_enabled(c.db)) } diff --git a/sqlite3_opt_userauth_omit.go b/sqlite3_opt_userauth_omit.go index 302cd57a..3112b65d 100644 --- a/sqlite3_opt_userauth_omit.go +++ b/sqlite3_opt_userauth_omit.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build !sqlite_userauth // +build !sqlite_userauth package sqlite3 @@ -17,7 +18,7 @@ import ( // If a database contains the SQLITE_USER table, then the // call to Authenticate must be invoked with an // appropriate username and password prior to enable read and write -//access to the database. +// access to the database. // // Return SQLITE_OK on success or SQLITE_ERROR if the username/password // combination is incorrect or unknown. @@ -34,9 +35,10 @@ func (c *SQLiteConn) Authenticate(username, password string) error { // It is however exported for usage within SQL by the user. // // Returns: +// // C.SQLITE_OK (0) // C.SQLITE_ERROR (1) -// C.SQLITE_AUTH (23) +// C.SQLITE_AUTH (23) func (c *SQLiteConn) authenticate(username, password string) int { // NOOP return 0 @@ -65,9 +67,10 @@ func (c *SQLiteConn) AuthUserAdd(username, password string, admin bool) error { // It is however exported for usage within SQL by the user. // // Returns: +// // C.SQLITE_OK (0) // C.SQLITE_ERROR (1) -// C.SQLITE_AUTH (23) +// C.SQLITE_AUTH (23) func (c *SQLiteConn) authUserAdd(username, password string, admin int) int { // NOOP return 0 @@ -96,9 +99,10 @@ func (c *SQLiteConn) AuthUserChange(username, password string, admin bool) error // It is however exported for usage within SQL by the user. // // Returns: +// // C.SQLITE_OK (0) // C.SQLITE_ERROR (1) -// C.SQLITE_AUTH (23) +// C.SQLITE_AUTH (23) func (c *SQLiteConn) authUserChange(username, password string, admin int) int { // NOOP return 0 @@ -122,9 +126,10 @@ func (c *SQLiteConn) AuthUserDelete(username string) error { // It is however exported for usage within SQL by the user. // // Returns: +// // C.SQLITE_OK (0) // C.SQLITE_ERROR (1) -// C.SQLITE_AUTH (23) +// C.SQLITE_AUTH (23) func (c *SQLiteConn) authUserDelete(username string) int { // NOOP return 0 @@ -142,8 +147,9 @@ func (c *SQLiteConn) AuthEnabled() (exists bool) { // It is however exported for usage within SQL by the user. // // Returns: +// // 0 - Disabled -// 1 - Enabled +// 1 - Enabled func (c *SQLiteConn) authEnabled() int { // NOOP return 0 diff --git a/sqlite3_opt_userauth_test.go b/sqlite3_opt_userauth_test.go index 543f48e8..12e11510 100644 --- a/sqlite3_opt_userauth_test.go +++ b/sqlite3_opt_userauth_test.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_userauth // +build sqlite_userauth package sqlite3 diff --git a/sqlite3_opt_vacuum_full.go b/sqlite3_opt_vacuum_full.go index 5185a96d..df13c9d2 100644 --- a/sqlite3_opt_vacuum_full.go +++ b/sqlite3_opt_vacuum_full.go @@ -4,6 +4,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_vacuum_full // +build sqlite_vacuum_full package sqlite3 diff --git a/sqlite3_opt_vacuum_incr.go b/sqlite3_opt_vacuum_incr.go index a9d8a185..a2e48814 100644 --- a/sqlite3_opt_vacuum_incr.go +++ b/sqlite3_opt_vacuum_incr.go @@ -4,6 +4,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_vacuum_incr // +build sqlite_vacuum_incr package sqlite3 diff --git a/sqlite3_opt_vtable.go b/sqlite3_opt_vtable.go index 4a93c465..4499e896 100644 --- a/sqlite3_opt_vtable.go +++ b/sqlite3_opt_vtable.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_vtable || vtable // +build sqlite_vtable vtable package sqlite3 diff --git a/sqlite3_other.go b/sqlite3_other.go index 077d3c64..1f9a7550 100644 --- a/sqlite3_other.go +++ b/sqlite3_other.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build !windows // +build !windows package sqlite3 diff --git a/sqlite3_solaris.go b/sqlite3_solaris.go index 102f90c9..fb4d3251 100644 --- a/sqlite3_solaris.go +++ b/sqlite3_solaris.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build solaris // +build solaris package sqlite3 diff --git a/sqlite3_test.go b/sqlite3_test.go index 326361ec..c990ae1d 100644 --- a/sqlite3_test.go +++ b/sqlite3_test.go @@ -1128,7 +1128,7 @@ func TestQueryer(t *testing.T) { if err != nil { t.Error("Failed to db.Query:", err) } - if id != n + 1 { + if id != n+1 { t.Error("Failed to db.Query: not matched results") } n = n + 1 @@ -1497,28 +1497,28 @@ func TestAggregatorRegistration(t *testing.T) { } type mode struct { - counts map[interface{}]int - top interface{} - topCount int + counts map[interface{}]int + top interface{} + topCount int } func newMode() *mode { - return &mode{ - counts: map[interface{}]int{}, - } + return &mode{ + counts: map[interface{}]int{}, + } } func (m *mode) Step(x interface{}) { - m.counts[x]++ - c := m.counts[x] - if c > m.topCount { - m.top = x - m.topCount = c - } + m.counts[x]++ + c := m.counts[x] + if c > m.topCount { + m.top = x + m.topCount = c + } } func (m *mode) Done() interface{} { - return m.top + return m.top } func TestAggregatorRegistration_GenericReturn(t *testing.T) { @@ -1534,19 +1534,19 @@ func TestAggregatorRegistration_GenericReturn(t *testing.T) { defer db.Close() _, err = db.Exec("create table foo (department integer, profits integer)") - if err != nil { - t.Fatal("Failed to create table:", err) - } - _, err = db.Exec("insert into foo values (1, 10), (1, 20), (1, 45), (2, 42), (2, 115), (2, 20)") - if err != nil { - t.Fatal("Failed to insert records:", err) - } + if err != nil { + t.Fatal("Failed to create table:", err) + } + _, err = db.Exec("insert into foo values (1, 10), (1, 20), (1, 45), (2, 42), (2, 115), (2, 20)") + if err != nil { + t.Fatal("Failed to insert records:", err) + } var mode int - err = db.QueryRow("select mode(profits) from foo").Scan(&mode) - if err != nil { - t.Fatal("MODE query error:", err) - } + err = db.QueryRow("select mode(profits) from foo").Scan(&mode) + if err != nil { + t.Fatal("MODE query error:", err) + } if mode != 20 { t.Fatal("Got incorrect mode. Wanted 20, got: ", mode) diff --git a/sqlite3_trace.go b/sqlite3_trace.go index 56bb9149..6c47cce1 100644 --- a/sqlite3_trace.go +++ b/sqlite3_trace.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build sqlite_trace || trace // +build sqlite_trace trace package sqlite3 diff --git a/sqlite3_usleep_windows.go b/sqlite3_usleep_windows.go index b6739bf6..6527f6fd 100644 --- a/sqlite3_usleep_windows.go +++ b/sqlite3_usleep_windows.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build cgo // +build cgo package sqlite3 diff --git a/sqlite3_windows.go b/sqlite3_windows.go index 81aa2abd..f863bcd3 100644 --- a/sqlite3_windows.go +++ b/sqlite3_windows.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build windows // +build windows package sqlite3 diff --git a/static_mock.go b/static_mock.go index f19e842f..506efc8e 100644 --- a/static_mock.go +++ b/static_mock.go @@ -3,6 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. +//go:build !cgo // +build !cgo package sqlite3