Skip to content

sess.InsertInto with multicolumn only last column set value  #261

Description

@tablecell

main.go

package main

import (
_ "github.com/mattn/go-sqlite3"
"github.com/gocraft/dbr/v2"
 
)

type User struct {
	ID        int64
	Name      string
	Age       int

}


func main(){

conn, err:= dbr.Open("sqlite3", "test.db", nil)
// CREATE TABLE `user` ( `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, `name` text , age integer)
//conn.SetMaxOpenConns(10)

if nil != err {

		panic(err)
	}
 
sess := conn.NewSession(nil)

     user := &User{Name:"ooo",Age:11}

 
 sess.InsertInto("user").
 	Columns("name").
 		Columns("age").
	Record(user).
	Exec()
}

only field "age" has value but field "name" is NULL

 sess.InsertInto("user").
	Columns("age").
Columns("name").
	Record(user).
	Exec()

only field "name" has value but field "age" is NULL

sess.InsertInto("user").
        Record(user).
	Exec()

and

sess.InsertInto("user").
 	Columns("*").
        Record(user).
	Exec()

and

 sess.InsertInto("user").
	Columns("name,age").
	Record(user).
	Exec()

all fail

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions