Skip to content

Commit 1f0dc0a

Browse files
committed
go fmt ./...
1 parent c91bca4 commit 1f0dc0a

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

+245
-193
lines changed

backup_test.go

+1
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

+4-4
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

+1
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

+51-52
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,7 +77,7 @@ 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.
@@ -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
@@ -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

+1
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

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

sqlite3_go113_test.go

+1
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

sqlite3_go18.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file.
55

6-
// +build cgo
7-
// +build go1.8
6+
//go:build cgo && go1.8
7+
// +build cgo,go1.8
88

99
package sqlite3
1010

sqlite3_go18_test.go

+1
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.8 && cgo
67
// +build go1.8,cgo
78

89
package sqlite3

sqlite3_libsqlite3.go

+1
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 libsqlite3
67
// +build libsqlite3
78

89
package sqlite3

sqlite3_load_extension.go

+1
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 !sqlite_omit_load_extension
67
// +build !sqlite_omit_load_extension
78

89
package sqlite3

0 commit comments

Comments
 (0)