sqlite 测试
This commit is contained in:
parent
fce779dfb6
commit
a7069fe9b7
@ -4,6 +4,7 @@ go 1.18
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gen2brain/beeep v0.0.0-20230602101333-f384c29b62dd
|
github.com/gen2brain/beeep v0.0.0-20230602101333-f384c29b62dd
|
||||||
|
github.com/mutecomm/go-sqlcipher/v4 v4.4.2
|
||||||
github.com/wailsapp/wails/v2 v2.5.1
|
github.com/wailsapp/wails/v2 v2.5.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,6 +33,8 @@ github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHR
|
|||||||
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||||
|
github.com/mutecomm/go-sqlcipher/v4 v4.4.2 h1:eM10bFtI4UvibIsKr10/QT7Yfz+NADfjZYh0GKrXUNc=
|
||||||
|
github.com/mutecomm/go-sqlcipher/v4 v4.4.2/go.mod h1:mF2UmIpBnzFeBdu/ypTDb/LdbS0nk0dfSN1WUsWTjMA=
|
||||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
|
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
|
||||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
|
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
|
||||||
github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2 h1:acNfDZXmm28D2Yg/c3ALnZStzNaZMSagpbr96vY6Zjc=
|
github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2 h1:acNfDZXmm28D2Yg/c3ALnZStzNaZMSagpbr96vY6Zjc=
|
||||||
@ -44,6 +46,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
|
|||||||
github.com/samber/lo v1.27.1 h1:sTXwkRiIFIQG+G0HeAvOEnGjqWeWtI9cg5/n51KrxPg=
|
github.com/samber/lo v1.27.1 h1:sTXwkRiIFIQG+G0HeAvOEnGjqWeWtI9cg5/n51KrxPg=
|
||||||
github.com/samber/lo v1.27.1/go.mod h1:it33p9UtPMS7z72fP4gw/EIfQB2eI8ke7GR2wc6+Rhg=
|
github.com/samber/lo v1.27.1/go.mod h1:it33p9UtPMS7z72fP4gw/EIfQB2eI8ke7GR2wc6+Rhg=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||||
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
|
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
|
||||||
|
@ -2,13 +2,17 @@ package lib
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gen2brain/beeep"
|
"github.com/gen2brain/beeep"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
_ "github.com/mutecomm/go-sqlcipher/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestName(t *testing.T) {
|
func TestName(t *testing.T) {
|
||||||
@ -57,3 +61,61 @@ func TestJavaEnv(t *testing.T) {
|
|||||||
fmt.Println(os.Getenv("java_home"))
|
fmt.Println(os.Getenv("java_home"))
|
||||||
fmt.Println(os.Getenv("JAVA_HOME"))
|
fmt.Println(os.Getenv("JAVA_HOME"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSqlite(t *testing.T) {
|
||||||
|
fmt.Println(os.Args[0])
|
||||||
|
fmt.Println(os.Getwd())
|
||||||
|
|
||||||
|
dbPath := filepath.Join(filepath.Dir(os.Args[0]), "test.db")
|
||||||
|
fmt.Printf("dbPath => %v\n", dbPath)
|
||||||
|
|
||||||
|
// 加密
|
||||||
|
//dataSourceName := fmt.Sprintf("file:%s?_pragma_key=%s", dbPath, "shikong")
|
||||||
|
// 不加密
|
||||||
|
dataSourceName := fmt.Sprintf("file:%s?", dbPath)
|
||||||
|
db, err := sql.Open("sqlite3", dataSourceName)
|
||||||
|
_, _ = db.Exec("PRAGMA cipher_use_hmac = OFF;")
|
||||||
|
_, _ = db.Exec("PRAGMA cipher_page_size = 1024;")
|
||||||
|
_, _ = db.Exec("PRAGMA kdf_iter = 4000;")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
_ = db.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
|
err = db.Ping()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
//_, err = db.Exec("PRAGMA key = shikong;")
|
||||||
|
//if err != nil {
|
||||||
|
// t.Fatal(err)
|
||||||
|
// return
|
||||||
|
//}
|
||||||
|
|
||||||
|
sql := `
|
||||||
|
DROP TABLE IF EXISTS cars;
|
||||||
|
CREATE TABLE cars(id INTEGER PRIMARY KEY, name TEXT, price INT);
|
||||||
|
INSERT INTO cars(name, price) VALUES('Audi',52642);
|
||||||
|
INSERT INTO cars(name, price) VALUES('Mercedes',57127);
|
||||||
|
INSERT INTO cars(name, price) VALUES('Skoda',9000);
|
||||||
|
INSERT INTO cars(name, price) VALUES('Volvo',29000);
|
||||||
|
INSERT INTO cars(name, price) VALUES('Bentley',350000);
|
||||||
|
INSERT INTO cars(name, price) VALUES('Citroen',21000);
|
||||||
|
INSERT INTO cars(name, price) VALUES('Hummer',41400);
|
||||||
|
INSERT INTO cars(name, price) VALUES('Volkswagen',21600);
|
||||||
|
`
|
||||||
|
_, _ = db.Exec(sql)
|
||||||
|
|
||||||
|
result, err := db.Exec("select * from sqlite_master;")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Printf("%+v\n", result)
|
||||||
|
|
||||||
|
fmt.Println("数据库连接成功")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user