Skip to content

Commit 9bd2002

Browse files
committed
Merge remote-tracking branch 'mattn/master' into merge-upstream
2 parents 2f0d1da + 8bf7a8a commit 9bd2002

File tree

6 files changed

+63
-729
lines changed

6 files changed

+63
-729
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ go-sqlite3
33

44
[![Circle CI](https://circleci.com/gh/rqlite/go-sqlite3/tree/master.svg?style=svg)](https://circleci.com/gh/rqlite/go-sqlite3/tree/master)
55

6-
See upstream for README.

error_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ func TestCorruptDbErrors(t *testing.T) {
4343
_, err = db.Exec("drop table foo")
4444
}
4545

46-
sqliteErr := err.(Error)
46+
sqliteErr, ok := err.(Error)
47+
if !ok {
48+
t.Fatal(err)
49+
}
4750
if sqliteErr.Code != ErrNotADB {
4851
t.Error("wrong error code for corrupted DB")
4952
}

sqlite3-binding.c

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef USE_LIBSQLITE3
22
/******************************************************************************
33
** This file is an amalgamation of many separate C source files from SQLite
4-
** version 3.50.3. By combining all the individual C code files into this
4+
** version 3.50.4. By combining all the individual C code files into this
55
** single large file, the entire code can be compiled as a single translation
66
** unit. This allows many compilers to do optimizations that would not be
77
** possible if the files were compiled separately. Performance improvements
@@ -19,7 +19,7 @@
1919
** separate file. This file contains only code for the core SQLite library.
2020
**
2121
** The content in this amalgamation comes from Fossil check-in
22-
** 3ce993b8657d6d9deda380a93cdd6404a8c8 with changes in files:
22+
** 4d8adfb30e03f9cf27f800a2c1ba3c48fb4c with changes in files:
2323
**
2424
**
2525
*/
@@ -466,9 +466,9 @@ extern "C" {
466466
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
467467
** [sqlite_version()] and [sqlite_source_id()].
468468
*/
469-
#define SQLITE_VERSION "3.50.3"
470-
#define SQLITE_VERSION_NUMBER 3050003
471-
#define SQLITE_SOURCE_ID "2025-07-17 13:25:10 3ce993b8657d6d9deda380a93cdd6404a8c8ba1b185b2bc423703e41ae5f2543"
469+
#define SQLITE_VERSION "3.50.4"
470+
#define SQLITE_VERSION_NUMBER 3050004
471+
#define SQLITE_SOURCE_ID "2025-07-30 19:33:53 4d8adfb30e03f9cf27f800a2c1ba3c48fb4ca1b08b0f5ed59a4d5ecbf45e20a3"
472472

473473
/*
474474
** CAPI3REF: Run-Time Library Version Numbers
@@ -19441,6 +19441,7 @@ struct Expr {
1944119441
Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL
1944219442
** for a column of an index on an expression */
1944319443
Window *pWin; /* EP_WinFunc: Window/Filter defn for a function */
19444+
int nReg; /* TK_NULLS: Number of registers to NULL out */
1944419445
struct { /* TK_IN, TK_SELECT, and TK_EXISTS */
1944519446
int iAddr; /* Subroutine entry address */
1944619447
int regReturn; /* Register used to hold return address */
@@ -21475,6 +21476,7 @@ SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(Parse*, Table*, Column*, int)
2147521476
SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int);
2147621477
SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
2147721478
SQLITE_PRIVATE int sqlite3ExprCodeRunJustOnce(Parse*, Expr*, int);
21479+
SQLITE_PRIVATE void sqlite3ExprNullRegisterRange(Parse*, int, int);
2147821480
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
2147921481
SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
2148021482
SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8);
@@ -115242,6 +115244,12 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target)
115242115244
sqlite3VdbeLoadString(v, target, pExpr->u.zToken);
115243115245
return target;
115244115246
}
115247+
case TK_NULLS: {
115248+
/* Set a range of registers to NULL. pExpr->y.nReg registers starting
115249+
** with target */
115250+
sqlite3VdbeAddOp3(v, OP_Null, 0, target, target + pExpr->y.nReg - 1);
115251+
return target;
115252+
}
115245115253
default: {
115246115254
/* Make NULL the default case so that if a bug causes an illegal
115247115255
** Expr node to be passed into this function, it will be handled
@@ -115926,6 +115934,25 @@ SQLITE_PRIVATE int sqlite3ExprCodeRunJustOnce(
115926115934
return regDest;
115927115935
}
115928115936

115937+
/*
115938+
** Make arrangements to invoke OP_Null on a range of registers
115939+
** during initialization.
115940+
*/
115941+
SQLITE_PRIVATE SQLITE_NOINLINE void sqlite3ExprNullRegisterRange(
115942+
Parse *pParse, /* Parsing context */
115943+
int iReg, /* First register to set to NULL */
115944+
int nReg /* Number of sequential registers to NULL out */
115945+
){
115946+
u8 okConstFactor = pParse->okConstFactor;
115947+
Expr t;
115948+
memset(&t, 0, sizeof(t));
115949+
t.op = TK_NULLS;
115950+
t.y.nReg = nReg;
115951+
pParse->okConstFactor = 1;
115952+
sqlite3ExprCodeRunJustOnce(pParse, &t, iReg);
115953+
pParse->okConstFactor = okConstFactor;
115954+
}
115955+
115929115956
/*
115930115957
** Generate code to evaluate an expression and store the results
115931115958
** into a register. Return the register number where the results
@@ -153176,6 +153203,7 @@ SQLITE_PRIVATE int sqlite3Select(
153176153203
sqlite3VdbeAddOp2(v, OP_Integer, 0, iAbortFlag);
153177153204
VdbeComment((v, "clear abort flag"));
153178153205
sqlite3VdbeAddOp3(v, OP_Null, 0, iAMem, iAMem+pGroupBy->nExpr-1);
153206+
sqlite3ExprNullRegisterRange(pParse, iAMem, pGroupBy->nExpr);
153179153207

153180153208
/* Begin a loop that will extract all source rows in GROUP BY order.
153181153209
** This might involve two separate loops with an OP_Sort in between, or
@@ -168471,6 +168499,7 @@ static int whereLoopAddBtree(
168471168499
pNew->u.btree.nEq = 0;
168472168500
pNew->u.btree.nBtm = 0;
168473168501
pNew->u.btree.nTop = 0;
168502+
pNew->u.btree.nDistinctCol = 0;
168474168503
pNew->nSkip = 0;
168475168504
pNew->nLTerm = 0;
168476168505
pNew->iSortIdx = 0;
@@ -169539,8 +169568,6 @@ static i8 wherePathSatisfiesOrderBy(
169539169568
obSat = obDone;
169540169569
}
169541169570
break;
169542-
}else if( wctrlFlags & WHERE_DISTINCTBY ){
169543-
pLoop->u.btree.nDistinctCol = 0;
169544169571
}
169545169572
iCur = pWInfo->pTabList->a[pLoop->iTab].iCursor;
169546169573

@@ -257281,7 +257308,7 @@ static void fts5SourceIdFunc(
257281257308
){
257282257309
assert( nArg==0 );
257283257310
UNUSED_PARAM2(nArg, apUnused);
257284-
sqlite3_result_text(pCtx, "fts5: 2025-07-17 13:25:10 3ce993b8657d6d9deda380a93cdd6404a8c8ba1b185b2bc423703e41ae5f2543", -1, SQLITE_TRANSIENT);
257311+
sqlite3_result_text(pCtx, "fts5: 2025-07-30 19:33:53 4d8adfb30e03f9cf27f800a2c1ba3c48fb4ca1b08b0f5ed59a4d5ecbf45e20a3", -1, SQLITE_TRANSIENT);
257285257312
}
257286257313

257287257314
/*

sqlite3-binding.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ extern "C" {
147147
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
148148
** [sqlite_version()] and [sqlite_source_id()].
149149
*/
150-
#define SQLITE_VERSION "3.50.3"
151-
#define SQLITE_VERSION_NUMBER 3050003
152-
#define SQLITE_SOURCE_ID "2025-07-17 13:25:10 3ce993b8657d6d9deda380a93cdd6404a8c8ba1b185b2bc423703e41ae5f2543"
150+
#define SQLITE_VERSION "3.50.4"
151+
#define SQLITE_VERSION_NUMBER 3050004
152+
#define SQLITE_SOURCE_ID "2025-07-30 19:33:53 4d8adfb30e03f9cf27f800a2c1ba3c48fb4ca1b08b0f5ed59a4d5ecbf45e20a3"
153153

154154
/*
155155
** CAPI3REF: Run-Time Library Version Numbers

sqlite3_opt_userauth.go

Lines changed: 13 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -16,62 +16,20 @@ package sqlite3
1616
#else
1717
#include <sqlite3.h>
1818
#endif
19-
#include <stdlib.h>
20-
21-
static int
22-
_sqlite3_user_authenticate(sqlite3* db, const char* zUsername, const char* aPW, int nPW)
23-
{
24-
return sqlite3_user_authenticate(db, zUsername, aPW, nPW);
25-
}
26-
27-
static int
28-
_sqlite3_user_add(sqlite3* db, const char* zUsername, const char* aPW, int nPW, int isAdmin)
29-
{
30-
return sqlite3_user_add(db, zUsername, aPW, nPW, isAdmin);
31-
}
32-
33-
static int
34-
_sqlite3_user_change(sqlite3* db, const char* zUsername, const char* aPW, int nPW, int isAdmin)
35-
{
36-
return sqlite3_user_change(db, zUsername, aPW, nPW, isAdmin);
37-
}
38-
39-
static int
40-
_sqlite3_user_delete(sqlite3* db, const char* zUsername)
41-
{
42-
return sqlite3_user_delete(db, zUsername);
43-
}
44-
45-
static int
46-
_sqlite3_auth_enabled(sqlite3* db)
47-
{
48-
int exists = -1;
49-
50-
sqlite3_stmt *stmt;
51-
sqlite3_prepare_v2(db, "select count(type) from sqlite_master WHERE type='table' and name='sqlite_user';", -1, &stmt, NULL);
52-
53-
while ( sqlite3_step(stmt) == SQLITE_ROW) {
54-
exists = sqlite3_column_int(stmt, 0);
55-
}
56-
57-
sqlite3_finalize(stmt);
58-
59-
return exists;
60-
}
6119
*/
6220
import "C"
6321
import (
6422
"errors"
65-
"unsafe"
6623
)
6724

6825
const (
6926
SQLITE_AUTH = C.SQLITE_AUTH
7027
)
7128

7229
var (
73-
ErrUnauthorized = errors.New("SQLITE_AUTH: Unauthorized")
74-
ErrAdminRequired = errors.New("SQLITE_AUTH: Unauthorized; Admin Privileges Required")
30+
ErrUnauthorized = errors.New("SQLITE_AUTH: Unauthorized")
31+
ErrAdminRequired = errors.New("SQLITE_AUTH: Unauthorized; Admin Privileges Required")
32+
errUserAuthNoLongerSupported = errors.New("sqlite3: the sqlite_userauth tag is no longer supported as the userauth extension is no longer supported by the SQLite authors, see https://github.com/mattn/go-sqlite3/issues/1341")
7533
)
7634

7735
// Authenticate will perform an authentication of the provided username
@@ -88,15 +46,7 @@ var (
8846
// If the SQLITE_USER table is not present in the database file, then
8947
// this interface is a harmless no-op returning SQLITE_OK.
9048
func (c *SQLiteConn) Authenticate(username, password string) error {
91-
rv := c.authenticate(username, password)
92-
switch rv {
93-
case C.SQLITE_ERROR, C.SQLITE_AUTH:
94-
return ErrUnauthorized
95-
case C.SQLITE_OK:
96-
return nil
97-
default:
98-
return c.lastError()
99-
}
49+
return errUserAuthNoLongerSupported
10050
}
10151

10252
// authenticate provides the actual authentication to SQLite.
@@ -109,17 +59,7 @@ func (c *SQLiteConn) Authenticate(username, password string) error {
10959
// C.SQLITE_ERROR (1)
11060
// C.SQLITE_AUTH (23)
11161
func (c *SQLiteConn) authenticate(username, password string) int {
112-
// Allocate C Variables
113-
cuser := C.CString(username)
114-
cpass := C.CString(password)
115-
116-
// Free C Variables
117-
defer func() {
118-
C.free(unsafe.Pointer(cuser))
119-
C.free(unsafe.Pointer(cpass))
120-
}()
121-
122-
return int(C._sqlite3_user_authenticate(c.db, cuser, cpass, C.int(len(password))))
62+
return 1
12363
}
12464

12565
// AuthUserAdd can be used (by an admin user only)
@@ -131,20 +71,7 @@ func (c *SQLiteConn) authenticate(username, password string) int {
13171
// for any ATTACH-ed databases. Any call to AuthUserAdd by a
13272
// non-admin user results in an error.
13373
func (c *SQLiteConn) AuthUserAdd(username, password string, admin bool) error {
134-
isAdmin := 0
135-
if admin {
136-
isAdmin = 1
137-
}
138-
139-
rv := c.authUserAdd(username, password, isAdmin)
140-
switch rv {
141-
case C.SQLITE_ERROR, C.SQLITE_AUTH:
142-
return ErrAdminRequired
143-
case C.SQLITE_OK:
144-
return nil
145-
default:
146-
return c.lastError()
147-
}
74+
return errUserAuthNoLongerSupported
14875
}
14976

15077
// authUserAdd enables the User Authentication if not enabled.
@@ -162,17 +89,7 @@ func (c *SQLiteConn) AuthUserAdd(username, password string, admin bool) error {
16289
// C.SQLITE_ERROR (1)
16390
// C.SQLITE_AUTH (23)
16491
func (c *SQLiteConn) authUserAdd(username, password string, admin int) int {
165-
// Allocate C Variables
166-
cuser := C.CString(username)
167-
cpass := C.CString(password)
168-
169-
// Free C Variables
170-
defer func() {
171-
C.free(unsafe.Pointer(cuser))
172-
C.free(unsafe.Pointer(cpass))
173-
}()
174-
175-
return int(C._sqlite3_user_add(c.db, cuser, cpass, C.int(len(password)), C.int(admin)))
92+
return 1
17693
}
17794

17895
// AuthUserChange can be used to change a users
@@ -181,20 +98,7 @@ func (c *SQLiteConn) authUserAdd(username, password string, admin int) int {
18198
// credentials or admin privilege setting. No user may change their own
18299
// admin privilege setting.
183100
func (c *SQLiteConn) AuthUserChange(username, password string, admin bool) error {
184-
isAdmin := 0
185-
if admin {
186-
isAdmin = 1
187-
}
188-
189-
rv := c.authUserChange(username, password, isAdmin)
190-
switch rv {
191-
case C.SQLITE_ERROR, C.SQLITE_AUTH:
192-
return ErrAdminRequired
193-
case C.SQLITE_OK:
194-
return nil
195-
default:
196-
return c.lastError()
197-
}
101+
return errUserAuthNoLongerSupported
198102
}
199103

200104
// authUserChange allows to modify a user.
@@ -215,17 +119,7 @@ func (c *SQLiteConn) AuthUserChange(username, password string, admin bool) error
215119
// C.SQLITE_ERROR (1)
216120
// C.SQLITE_AUTH (23)
217121
func (c *SQLiteConn) authUserChange(username, password string, admin int) int {
218-
// Allocate C Variables
219-
cuser := C.CString(username)
220-
cpass := C.CString(password)
221-
222-
// Free C Variables
223-
defer func() {
224-
C.free(unsafe.Pointer(cuser))
225-
C.free(unsafe.Pointer(cpass))
226-
}()
227-
228-
return int(C._sqlite3_user_change(c.db, cuser, cpass, C.int(len(password)), C.int(admin)))
122+
return 1
229123
}
230124

231125
// AuthUserDelete can be used (by an admin user only)
@@ -234,15 +128,7 @@ func (c *SQLiteConn) authUserChange(username, password string, admin int) int {
234128
// the database cannot be converted into a no-authentication-required
235129
// database.
236130
func (c *SQLiteConn) AuthUserDelete(username string) error {
237-
rv := c.authUserDelete(username)
238-
switch rv {
239-
case C.SQLITE_ERROR, C.SQLITE_AUTH:
240-
return ErrAdminRequired
241-
case C.SQLITE_OK:
242-
return nil
243-
default:
244-
return c.lastError()
245-
}
131+
return errUserAuthNoLongerSupported
246132
}
247133

248134
// authUserDelete can be used to delete a user.
@@ -258,25 +144,12 @@ func (c *SQLiteConn) AuthUserDelete(username string) error {
258144
// C.SQLITE_ERROR (1)
259145
// C.SQLITE_AUTH (23)
260146
func (c *SQLiteConn) authUserDelete(username string) int {
261-
// Allocate C Variables
262-
cuser := C.CString(username)
263-
264-
// Free C Variables
265-
defer func() {
266-
C.free(unsafe.Pointer(cuser))
267-
}()
268-
269-
return int(C._sqlite3_user_delete(c.db, cuser))
147+
return 1
270148
}
271149

272150
// AuthEnabled checks if the database is protected by user authentication
273151
func (c *SQLiteConn) AuthEnabled() (exists bool) {
274-
rv := c.authEnabled()
275-
if rv == 1 {
276-
exists = true
277-
}
278-
279-
return
152+
return false
280153
}
281154

282155
// authEnabled perform the actual check for user authentication.
@@ -289,7 +162,7 @@ func (c *SQLiteConn) AuthEnabled() (exists bool) {
289162
// 0 - Disabled
290163
// 1 - Enabled
291164
func (c *SQLiteConn) authEnabled() int {
292-
return int(C._sqlite3_auth_enabled(c.db))
165+
return 0
293166
}
294167

295168
// EOF

0 commit comments

Comments
 (0)