Skip to content

Commit

Permalink
JSON types are also text
Browse files Browse the repository at this point in the history
  • Loading branch information
otoolep committed Dec 20, 2019
1 parent 47c5e80 commit 3cfb0c3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@ This release uses a new Raft consensus version, with the move to Hashicorp Raft
- [PR #601](https://github.com/rqlite/rqlite/pull/601): By default use Raft network address as node ID.
- [PR #602](https://github.com/rqlite/rqlite/pull/602): Add method to Store that returns leader ID.
- [PR #603](https://github.com/rqlite/rqlite/pull/603): Fix up status key name style.
- [PR #604](https://github.com/rqlite/rqlite/pull/604): JSON types are also text.

## 4.6.0 (November 29th 2019)
_This release adds significant new functionality to the command-line tool, including much more control over backup and restore of the database. [Visit the Releases page](https://github.com/rqlite/rqlite/releases/tag/v4.6.0) to download this release._
Expand Down
1 change: 1 addition & 0 deletions db/db.go
Expand Up @@ -526,6 +526,7 @@ func normalizeRowValues(row []driver.Value, types []string) []interface{} {
// http://www.sqlite.org/datatype3.html
func isTextType(t string) bool {
return t == "text" ||
t == "json" ||
t == "" ||
strings.HasPrefix(t, "varchar") ||
strings.HasPrefix(t, "varying character") ||
Expand Down
24 changes: 24 additions & 0 deletions db/db_test.go
Expand Up @@ -180,6 +180,30 @@ func Test_SimpleSingleStatements(t *testing.T) {
}
}

func Test_SimpleSingleJSONStatements(t *testing.T) {
db, path := mustCreateDatabase()
defer db.Close()
defer os.Remove(path)

_, err := db.Execute([]string{"CREATE TABLE foo (c0 VARCHAR(36), c1 JSON, c2 NCHAR, c3 NVARCHAR, c4 CLOB)"}, false, false)
if err != nil {
t.Fatalf("failed to create table: %s", err.Error())
}

_, err = db.Execute([]string{`INSERT INTO foo(c0, c1, c2, c3, c4) VALUES("fiona", '{"mittens": "foobar"}', "bob", "dana", "declan")`}, false, false)
if err != nil {
t.Fatalf("failed to insert record: %s", err.Error())
}

r, err := db.Query([]string{"SELECT * FROM foo"}, false, false)
if err != nil {
t.Fatalf("failed to query: %s", err.Error())
}
if exp, got := `[{"columns":["c0","c1","c2","c3","c4"],"types":["varchar(36)","json","nchar","nvarchar","clob"],"values":[["fiona","{\"mittens\": \"foobar\"}","bob","dana","declan"]]}]`, asJSON(r); exp != got {
t.Fatalf("unexpected results for query, expected %s, got %s", exp, got)
}
}

func Test_SimpleJoinStatements(t *testing.T) {
db, path := mustCreateDatabase()
defer db.Close()
Expand Down

0 comments on commit 3cfb0c3

Please sign in to comment.