Skip to content

Commit

Permalink
fix(sql): Allow sqlite on Windows
Browse files Browse the repository at this point in the history
fixes: #13859
  • Loading branch information
powersj committed Sep 7, 2023
1 parent 3607519 commit 9f81dc8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion plugins/inputs/sql/drivers_sqlite.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build linux && freebsd && darwin && (!mips || !mips64)
//go:build !mips && !mipsle && !mips64 && !mips64le

package sql

Expand Down
4 changes: 1 addition & 3 deletions plugins/outputs/sql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ docs](https://github.com/jackc/pgx) for more details.

### modernc.org/sqlite

This driver is not available on all operating systems and architectures. It is
only included in Linux builds on amd64, 386, arm64, arm, and Darwin on amd64. It
is not available for Windows, FreeBSD, and other Linux and Darwin platforms.
It is not supported on mips and mips64 platforms.

The DSN is a filename or url with scheme "file:". See the [driver
docs](https://modernc.org/sqlite) for details.
Expand Down
2 changes: 1 addition & 1 deletion plugins/outputs/sql/sqlite.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build linux && freebsd && darwin && (!mips || !mips64)
//go:build !mips && !mipsle && !mips64 && !mips64le

package sql

Expand Down
13 changes: 7 additions & 6 deletions plugins/outputs/sql/sqlite_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build linux && freebsd && (!mips || !mips64)
//go:build !mips && !mipsle && !mips64 && !mips64le

package sql

Expand Down Expand Up @@ -49,11 +49,13 @@ func TestSqlite(t *testing.T) {
// Check that tables were created as expected
rows, err = db.Query("select sql from sqlite_master")
require.NoError(t, err)
defer rows.Close()
var sql string
require.True(t, rows.Next())
require.NoError(t, rows.Scan(&sql))
require.Equal(t,
`CREATE TABLE "metric_one"("timestamp" TIMESTAMP,"tag_one" TEXT,"tag_two" TEXT,"int64_one" INT,"int64_two" INT)`,
`CREATE TABLE "metric_one"("timestamp" TIMESTAMP,"tag_one" TEXT,"tag_two" TEXT,"int64_one" INT,`+
`"int64_two" INT,"bool_one" BOOL,"bool_two" BOOL,"uint64_one" INT UNSIGNED,"float64_one" DOUBLE)`,
sql,
)
require.True(t, rows.Next())
Expand All @@ -69,7 +71,6 @@ func TestSqlite(t *testing.T) {
sql,
)
require.False(t, rows.Next())
require.NoError(t, rows.Close())

// sqlite stores dates as strings. They may be in the local
// timezone. The test needs to parse them back into a time.Time to
Expand All @@ -81,6 +82,7 @@ func TestSqlite(t *testing.T) {
// Check contents of tables
rows, err = db.Query("select timestamp, tag_one, tag_two, int64_one, int64_two from metric_one")
require.NoError(t, err)
defer rows.Close()
require.True(t, rows.Next())
var (
a string
Expand All @@ -96,10 +98,10 @@ func TestSqlite(t *testing.T) {
require.Equal(t, int64(1234), d)
require.Equal(t, int64(2345), e)
require.False(t, rows.Next())
require.NoError(t, rows.Close())

rows, err = db.Query("select timestamp, tag_three, string_one from metric_two")
require.NoError(t, err)
defer rows.Close()
require.True(t, rows.Next())
var (
f, g, h string
Expand All @@ -111,10 +113,10 @@ func TestSqlite(t *testing.T) {
require.Equal(t, "tag3", g)
require.Equal(t, "string1", h)
require.False(t, rows.Next())
require.NoError(t, rows.Close())

rows, err = db.Query(`select timestamp, "tag four", "string two" from "metric three"`)
require.NoError(t, err)
defer rows.Close()
require.True(t, rows.Next())
var (
i, j, k string
Expand All @@ -126,5 +128,4 @@ func TestSqlite(t *testing.T) {
require.Equal(t, "tag4", j)
require.Equal(t, "string2", k)
require.False(t, rows.Next())
require.NoError(t, rows.Close())
}

0 comments on commit 9f81dc8

Please sign in to comment.