volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

Unable to parse INTEGER PRIMARY KEY from Bind() (SQLite) #241

Closed xahon closed 5 years ago

xahon commented 6 years ago

What version of SQLBoiler are you using (sqlboiler --version)?

SQLBoiler v2.6.0

Minimal code to reproduce

package main

import (
  "database/sql"
  _ "github.com/mattn/go-sqlite3"
  "github.com/volatiletech/sqlboiler/boil"
  "github.com/volatiletech/sqlboiler/queries"
  "encoding/json"
  "fmt"
)

func main() {
  db, err := sql.Open("sqlite3", "test.db")
  if err != nil {
    panic("failed to connect database")
  }
  defer db.Close()
  boil.SetDB(db)

  type Test struct {
    Id            uint64 `json:"id" db:"id"` // Tried int int16 int32 uint uint32 uint16 string
    SomethingElse string `json:"something" db:"something_else"`
  }
  queries.Raw(db, `--
DROP TABLE IF EXISTS test;
CREATE TABLE test (id INTEGER PRIMARY KEY, something_else TEXT)`).ExecP()

  queries.Raw(db, `--
INSERT INTO test (something_else) VALUES ("Hello"), ("World")`).ExecP()

  testable := new([]Test)
  queries.Raw(db, `SELECT * FROM test`).Bind(testable)

  j, _ := json.MarshalIndent(*testable, "", "  ")
  fmt.Println(string(j))
}

Ouput of GO:

[
   {
     "id": 0,
     "something": "Hello"
   },
   {
     "id": 0,
     "something": "World"
   }
]

Output of sqliteBrowser: image

P.S. If you change table fieldname id to idd and struct name Id to Idd it works like a charm P.P.S Problem occurs if you will use uid and Uid fields P.P.P.S Problem occurs if you will use guid and Guid fields

xahon commented 6 years ago

Problem didn't happened when i used ID (Uppercase) field in my struct

aarondl commented 6 years ago

Hm, I'll tag this as a bug and maybe be able to tackle it when I port over the sqlite3 support to v3.

aarondl commented 5 years ago

Stale. Not sure if this problem reproduces itself on v3 with latest sqlite3