go-sqlite3 で json1 extension が no such function と言われる時

現象

以下のような SQL を実行すると

func dbSQLiteRestoreFromFireBase() (err error) {
	defer erapse.ShowErapsedTIme(time.Now())

	_, err = dbSQLiteptr.Exec(`CREATE TABLE IF NOT EXISTS hyphas (
		id				VARCHAR(5) PRIMARY KEY,
		services,	JSON,
		attr			JSON,
		CHECK (JSON_VALID(services)),
		CHECK (JSON_VALID(attr))
		) WITHOUT ROWID`)

	return
}

no such function といわれてしまいました

no such function: JSON_VALID

結論

#cgo CFLAGS: -DSQLITE_ENABLE_JSON1 を sqlite3.go に追加して go-sqlite3 をリビルドします

ステップ

1. sqlite3.go を編集

~/go/src/github.com/mattn/go-sqlite3/sqlite3.go を開いて #cgo CFLAGS: -DSQLITE_ENABLE_JSON1 を追加します
























 

// Copyright (C) 2019 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
// Copyright (C) 2018 G.J.R. Timmer <gjr.timmer@gmail.com>.
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.

// +build cgo

package sqlite3

/*
#cgo CFLAGS: -std=gnu99
#cgo CFLAGS: -DSQLITE_ENABLE_RTREE
#cgo CFLAGS: -DSQLITE_THREADSAFE=1
#cgo CFLAGS: -DHAVE_USLEEP=1
#cgo CFLAGS: -DSQLITE_ENABLE_FTS3
#cgo CFLAGS: -DSQLITE_ENABLE_FTS3_PARENTHESIS
#cgo CFLAGS: -DSQLITE_ENABLE_FTS4_UNICODE61
#cgo CFLAGS: -DSQLITE_TRACE_SIZE_LIMIT=15
#cgo CFLAGS: -DSQLITE_OMIT_DEPRECATED
#cgo CFLAGS: -DSQLITE_DISABLE_INTRINSIC
#cgo CFLAGS: -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1
#cgo CFLAGS: -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT
#cgo CFLAGS: -DSQLITE_ENABLE_JSON1

2.build

go build github.com/mattn/go-sqlite3

3. install

go install build github.com/mattn/go-sqlite3

references


Last Updated: 2/8/2021, 1:56:06 PM