Skip to content

Commit 7bc5411

Browse files
committed
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.
1 parent 1603038 commit 7bc5411

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+237
-185
lines changed

backup_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build cgo
67
// +build cgo
78

89
package sqlite3

callback.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,11 @@ func callbackRetGeneric(ctx *C.sqlite3_context, v reflect.Value) error {
360360
}
361361

362362
cb, err := callbackRet(v.Elem().Type())
363-
if err != nil {
364-
return err
365-
}
363+
if err != nil {
364+
return err
365+
}
366366

367-
return cb(ctx, v.Elem())
367+
return cb(ctx, v.Elem())
368368
}
369369

370370
func callbackRet(typ reflect.Type) (callbackRetConverter, error) {

callback_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build cgo
67
// +build cgo
78

89
package sqlite3

doc.go

Lines changed: 62 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,63 @@ This works as a driver for database/sql.
55
66
Installation
77
8-
go get github.com/mattn/go-sqlite3
8+
go get github.com/mattn/go-sqlite3
99
10-
Supported Types
10+
# Supported Types
1111
1212
Currently, go-sqlite3 supports the following data types.
1313
14-
+------------------------------+
15-
|go | sqlite3 |
16-
|----------|-------------------|
17-
|nil | null |
18-
|int | integer |
19-
|int64 | integer |
20-
|float64 | float |
21-
|bool | integer |
22-
|[]byte | blob |
23-
|string | text |
24-
|time.Time | timestamp/datetime|
25-
+------------------------------+
26-
27-
SQLite3 Extension
14+
+------------------------------+
15+
|go | sqlite3 |
16+
|----------|-------------------|
17+
|nil | null |
18+
|int | integer |
19+
|int64 | integer |
20+
|float64 | float |
21+
|bool | integer |
22+
|[]byte | blob |
23+
|string | text |
24+
|time.Time | timestamp/datetime|
25+
+------------------------------+
26+
27+
# SQLite3 Extension
2828
2929
You can write your own extension module for sqlite3. For example, below is an
3030
extension for a Regexp matcher operation.
3131
32-
#include <pcre.h>
33-
#include <string.h>
34-
#include <stdio.h>
35-
#include <sqlite3ext.h>
36-
37-
SQLITE_EXTENSION_INIT1
38-
static void regexp_func(sqlite3_context *context, int argc, sqlite3_value **argv) {
39-
if (argc >= 2) {
40-
const char *target = (const char *)sqlite3_value_text(argv[1]);
41-
const char *pattern = (const char *)sqlite3_value_text(argv[0]);
42-
const char* errstr = NULL;
43-
int erroff = 0;
44-
int vec[500];
45-
int n, rc;
46-
pcre* re = pcre_compile(pattern, 0, &errstr, &erroff, NULL);
47-
rc = pcre_exec(re, NULL, target, strlen(target), 0, 0, vec, 500);
48-
if (rc <= 0) {
49-
sqlite3_result_error(context, errstr, 0);
50-
return;
51-
}
52-
sqlite3_result_int(context, 1);
53-
}
54-
}
55-
56-
#ifdef _WIN32
57-
__declspec(dllexport)
58-
#endif
59-
int sqlite3_extension_init(sqlite3 *db, char **errmsg,
60-
const sqlite3_api_routines *api) {
61-
SQLITE_EXTENSION_INIT2(api);
62-
return sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8,
63-
(void*)db, regexp_func, NULL, NULL);
64-
}
32+
#include <pcre.h>
33+
#include <string.h>
34+
#include <stdio.h>
35+
#include <sqlite3ext.h>
36+
37+
SQLITE_EXTENSION_INIT1
38+
static void regexp_func(sqlite3_context *context, int argc, sqlite3_value **argv) {
39+
if (argc >= 2) {
40+
const char *target = (const char *)sqlite3_value_text(argv[1]);
41+
const char *pattern = (const char *)sqlite3_value_text(argv[0]);
42+
const char* errstr = NULL;
43+
int erroff = 0;
44+
int vec[500];
45+
int n, rc;
46+
pcre* re = pcre_compile(pattern, 0, &errstr, &erroff, NULL);
47+
rc = pcre_exec(re, NULL, target, strlen(target), 0, 0, vec, 500);
48+
if (rc <= 0) {
49+
sqlite3_result_error(context, errstr, 0);
50+
return;
51+
}
52+
sqlite3_result_int(context, 1);
53+
}
54+
}
55+
56+
#ifdef _WIN32
57+
__declspec(dllexport)
58+
#endif
59+
int sqlite3_extension_init(sqlite3 *db, char **errmsg,
60+
const sqlite3_api_routines *api) {
61+
SQLITE_EXTENSION_INIT2(api);
62+
return sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8,
63+
(void*)db, regexp_func, NULL, NULL);
64+
}
6565
6666
It needs to be built as a so/dll shared library. And you need to register
6767
the extension module like below.
@@ -77,18 +77,18 @@ Then, you can use this extension.
7777
7878
rows, err := db.Query("select text from mytable where name regexp '^golang'")
7979
80-
Connection Hook
80+
# Connection Hook
8181
8282
You can hook and inject your code when the connection is established by setting
8383
ConnectHook to get the SQLiteConn.
8484
8585
sql.Register("sqlite3_with_hook_example",
86-
&sqlite3.SQLiteDriver{
87-
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
88-
sqlite3conn = append(sqlite3conn, conn)
89-
return nil
90-
},
91-
})
86+
&sqlite3.SQLiteDriver{
87+
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
88+
sqlite3conn = append(sqlite3conn, conn)
89+
return nil
90+
},
91+
})
9292
9393
You can also use database/sql.Conn.Raw (Go >= 1.13):
9494
@@ -101,7 +101,7 @@ You can also use database/sql.Conn.Raw (Go >= 1.13):
101101
})
102102
// if err != nil { ... }
103103
104-
Go SQlite3 Extensions
104+
# Go SQlite3 Extensions
105105
106106
If you want to register Go functions as SQLite extension functions
107107
you can make a custom driver by calling RegisterFunction from
@@ -111,11 +111,11 @@ ConnectHook.
111111
return regexp.MatchString(re, s)
112112
}
113113
sql.Register("sqlite3_extended",
114-
&sqlite3.SQLiteDriver{
115-
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
116-
return conn.RegisterFunc("regexp", regex, true)
117-
},
118-
})
114+
&sqlite3.SQLiteDriver{
115+
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
116+
return conn.RegisterFunc("regexp", regex, true)
117+
},
118+
})
119119
120120
You can then use the custom driver by passing its name to sql.Open.
121121
@@ -130,6 +130,5 @@ You can then use the custom driver by passing its name to sql.Open.
130130
}
131131
132132
See the documentation of RegisterFunc for more details.
133-
134133
*/
135134
package sqlite3

error_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build cgo
67
// +build cgo
78

89
package sqlite3

sqlite3.go

Lines changed: 75 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -971,103 +971,104 @@ func (c *SQLiteConn) begin(ctx context.Context) (driver.Tx, error) {
971971
// The argument is may be either in parentheses or it may be separated from
972972
// the pragma name by an equal sign. The two syntaxes yield identical results.
973973
// In many pragmas, the argument is a boolean. The boolean can be one of:
974-
// 1 yes true on
975-
// 0 no false off
974+
//
975+
// 1 yes true on
976+
// 0 no false off
976977
//
977978
// You can specify a DSN string using a URI as the filename.
978-
// test.db
979-
// file:test.db?cache=shared&mode=memory
980-
// :memory:
981-
// file::memory:
982979
//
983-
// mode
984-
// Access mode of the database.
985-
// https://www.sqlite.org/c3ref/open.html
986-
// Values:
987-
// - ro
988-
// - rw
989-
// - rwc
990-
// - memory
980+
// test.db
981+
// file:test.db?cache=shared&mode=memory
982+
// :memory:
983+
// file::memory:
991984
//
992-
// cache
993-
// SQLite Shared-Cache Mode
994-
// https://www.sqlite.org/sharedcache.html
995-
// Values:
996-
// - shared
997-
// - private
985+
// mode
986+
// Access mode of the database.
987+
// https://www.sqlite.org/c3ref/open.html
988+
// Values:
989+
// - ro
990+
// - rw
991+
// - rwc
992+
// - memory
998993
//
999-
// immutable=Boolean
1000-
// The immutable parameter is a boolean query parameter that indicates
1001-
// that the database file is stored on read-only media. When immutable is set,
1002-
// SQLite assumes that the database file cannot be changed,
1003-
// even by a process with higher privilege,
1004-
// and so the database is opened read-only and all locking and change detection is disabled.
1005-
// Caution: Setting the immutable property on a database file that
1006-
// does in fact change can result in incorrect query results and/or SQLITE_CORRUPT errors.
994+
// cache
995+
// SQLite Shared-Cache Mode
996+
// https://www.sqlite.org/sharedcache.html
997+
// Values:
998+
// - shared
999+
// - private
10071000
//
1008-
// go-sqlite3 adds the following query parameters to those used by SQLite:
1009-
// _loc=XXX
1010-
// Specify location of time format. It's possible to specify "auto".
1001+
// immutable=Boolean
1002+
// The immutable parameter is a boolean query parameter that indicates
1003+
// that the database file is stored on read-only media. When immutable is set,
1004+
// SQLite assumes that the database file cannot be changed,
1005+
// even by a process with higher privilege,
1006+
// and so the database is opened read-only and all locking and change detection is disabled.
1007+
// Caution: Setting the immutable property on a database file that
1008+
// does in fact change can result in incorrect query results and/or SQLITE_CORRUPT errors.
10111009
//
1012-
// _mutex=XXX
1013-
// Specify mutex mode. XXX can be "no", "full".
1010+
// go-sqlite3 adds the following query parameters to those used by SQLite:
10141011
//
1015-
// _txlock=XXX
1016-
// Specify locking behavior for transactions. XXX can be "immediate",
1017-
// "deferred", "exclusive".
1012+
// _loc=XXX
1013+
// Specify location of time format. It's possible to specify "auto".
10181014
//
1019-
// _auto_vacuum=X | _vacuum=X
1020-
// 0 | none - Auto Vacuum disabled
1021-
// 1 | full - Auto Vacuum FULL
1022-
// 2 | incremental - Auto Vacuum Incremental
1015+
// _mutex=XXX
1016+
// Specify mutex mode. XXX can be "no", "full".
10231017
//
1024-
// _busy_timeout=XXX"| _timeout=XXX
1025-
// Specify value for sqlite3_busy_timeout.
1018+
// _txlock=XXX
1019+
// Specify locking behavior for transactions. XXX can be "immediate",
1020+
// "deferred", "exclusive".
10261021
//
1027-
// _case_sensitive_like=Boolean | _cslike=Boolean
1028-
// https://www.sqlite.org/pragma.html#pragma_case_sensitive_like
1029-
// Default or disabled the LIKE operation is case-insensitive.
1030-
// When enabling this options behaviour of LIKE will become case-sensitive.
1022+
// _auto_vacuum=X | _vacuum=X
1023+
// 0 | none - Auto Vacuum disabled
1024+
// 1 | full - Auto Vacuum FULL
1025+
// 2 | incremental - Auto Vacuum Incremental
10311026
//
1032-
// _defer_foreign_keys=Boolean | _defer_fk=Boolean
1033-
// Defer Foreign Keys until outermost transaction is committed.
1027+
// _busy_timeout=XXX"| _timeout=XXX
1028+
// Specify value for sqlite3_busy_timeout.
10341029
//
1035-
// _foreign_keys=Boolean | _fk=Boolean
1036-
// Enable or disable enforcement of foreign keys.
1030+
// _case_sensitive_like=Boolean | _cslike=Boolean
1031+
// https://www.sqlite.org/pragma.html#pragma_case_sensitive_like
1032+
// Default or disabled the LIKE operation is case-insensitive.
1033+
// When enabling this options behaviour of LIKE will become case-sensitive.
10371034
//
1038-
// _ignore_check_constraints=Boolean
1039-
// This pragma enables or disables the enforcement of CHECK constraints.
1040-
// The default setting is off, meaning that CHECK constraints are enforced by default.
1035+
// _defer_foreign_keys=Boolean | _defer_fk=Boolean
1036+
// Defer Foreign Keys until outermost transaction is committed.
10411037
//
1042-
// _journal_mode=MODE | _journal=MODE
1043-
// Set journal mode for the databases associated with the current connection.
1044-
// https://www.sqlite.org/pragma.html#pragma_journal_mode
1038+
// _foreign_keys=Boolean | _fk=Boolean
1039+
// Enable or disable enforcement of foreign keys.
10451040
//
1046-
// _locking_mode=X | _locking=X
1047-
// Sets the database connection locking-mode.
1048-
// The locking-mode is either NORMAL or EXCLUSIVE.
1049-
// https://www.sqlite.org/pragma.html#pragma_locking_mode
1041+
// _ignore_check_constraints=Boolean
1042+
// This pragma enables or disables the enforcement of CHECK constraints.
1043+
// The default setting is off, meaning that CHECK constraints are enforced by default.
10501044
//
1051-
// _query_only=Boolean
1052-
// The query_only pragma prevents all changes to database files when enabled.
1045+
// _journal_mode=MODE | _journal=MODE
1046+
// Set journal mode for the databases associated with the current connection.
1047+
// https://www.sqlite.org/pragma.html#pragma_journal_mode
10531048
//
1054-
// _recursive_triggers=Boolean | _rt=Boolean
1055-
// Enable or disable recursive triggers.
1049+
// _locking_mode=X | _locking=X
1050+
// Sets the database connection locking-mode.
1051+
// The locking-mode is either NORMAL or EXCLUSIVE.
1052+
// https://www.sqlite.org/pragma.html#pragma_locking_mode
10561053
//
1057-
// _secure_delete=Boolean|FAST
1058-
// When secure_delete is on, SQLite overwrites deleted content with zeros.
1059-
// https://www.sqlite.org/pragma.html#pragma_secure_delete
1054+
// _query_only=Boolean
1055+
// The query_only pragma prevents all changes to database files when enabled.
10601056
//
1061-
// _synchronous=X | _sync=X
1062-
// Change the setting of the "synchronous" flag.
1063-
// https://www.sqlite.org/pragma.html#pragma_synchronous
1057+
// _recursive_triggers=Boolean | _rt=Boolean
1058+
// Enable or disable recursive triggers.
10641059
//
1065-
// _writable_schema=Boolean
1066-
// When this pragma is on, the SQLITE_MASTER tables in which database
1067-
// can be changed using ordinary UPDATE, INSERT, and DELETE statements.
1068-
// Warning: misuse of this pragma can easily result in a corrupt database file.
1060+
// _secure_delete=Boolean|FAST
1061+
// When secure_delete is on, SQLite overwrites deleted content with zeros.
1062+
// https://www.sqlite.org/pragma.html#pragma_secure_delete
10691063
//
1064+
// _synchronous=X | _sync=X
1065+
// Change the setting of the "synchronous" flag.
1066+
// https://www.sqlite.org/pragma.html#pragma_synchronous
10701067
//
1068+
// _writable_schema=Boolean
1069+
// When this pragma is on, the SQLITE_MASTER tables in which database
1070+
// can be changed using ordinary UPDATE, INSERT, and DELETE statements.
1071+
// Warning: misuse of this pragma can easily result in a corrupt database file.
10711072
func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
10721073
if C.sqlite3_threadsafe() == 0 {
10731074
return nil, errors.New("sqlite library was not compiled for thread-safe operation")

sqlite3_go113_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build go1.13 && cgo
67
// +build go1.13,cgo
78

89
package sqlite3

0 commit comments

Comments
 (0)