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

sql: converting Exec argument $2 type: non-Value type uint64 returned from Value #197

Closed dtrehas closed 7 years ago

dtrehas commented 7 years ago

Hello and thanks for your time to check this issue

If you're having a generation problem please answer these questions before submitting your issue. Thanks!

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

2.5.1

If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)

If this happened at runtime what code produced the issue? (if not applicable leave blank)

Definition of container..

type Container struct {
    ContainerID     uint        `boil:"container_id" json:"container_id" toml:"container_id" yaml:"container_id"`
    ContainerType   null.String `boil:"container_type" json:"container_type,omitempty" toml:"container_type" yaml:"container_type,omitempty"`
    ContainerWeight null.Uint32 `boil:"container_weight" json:"container_weight,omitempty" toml:"container_weight" yaml:"container_weight,omitempty"`
    ContainerVol    null.Uint32 `boil:"container_vol" json:"container_vol,omitempty" toml:"container_vol" yaml:"container_vol,omitempty"`
    ContainerNum    null.Uint16 `boil:"container_num" json:"container_num,omitempty" toml:"container_num" yaml:"container_num,omitempty"`
    RFQID           uint        `boil:"rfq_id" json:"rfq_id" toml:"rfq_id" yaml:"rfq_id"`

    R *containerR `boil:"-" json:"-" toml:"-" yaml:"-"`
    L containerL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}

//Actual code 

container:= models.Container{
        ContainerType: StringFrom("40ft"), 
        ContainerWeight: Uint32From(10000), *
        ContainerVol:Uint32From(100) , 
        ContainerNum: Uint16From(2), 

        RFQID:4 ,
    }

    if err:= container.Insert(db); err != nil {
        fmt.Fprintf(boil.DebugWriter,"%s\n", err)
        if driverErr, ok := err.(*mysql.MySQLError); ok { // Now the error number is accessible directly

                fmt.Fprintf(boil.DebugWriter,"%v, %s\n", driverErr.Number, driverErr.Message)

        }
    }

What is the output of the command above with the -d flag added to it? (Provided you are comfortable sharing this, it contains a blueprint of your schema)

INSERT INTO containers (container_type,container_weight,container_vol,container_num,rfq_id) VALUES (?,?,?,?,?) [{40ft true} {10000 true} {100 true} {2 true} 4] models: unable to insert into containers: sql: converting Exec argument $2 type: non-Value type uint64 returned from Value

Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)

CREATE TABLE containers (

    container_id INTEGER UNSIGNED PRIMARY KEY AUTO_INCREMENT,
    -- Container type
    container_type VARCHAR(50) NULL,

    -- Container (Kg)
    container_weight MEDIUMINT UNSIGNED NULL,

    -- Container Volume (m3)
    container_vol MEDIUMINT UNSIGNED NULL,

    --  Container number
    container_num SMALLINT UNSIGNED NULL,

    rfq_id INTEGER UNSIGNED NOT NULL,

    CONSTRAINT fk_containers_rfq_id
    FOREIGN KEY (rfq_id) REFERENCES rfqs(rfq_id)
);

Further information. What did you do, what did you expect?

I was trying to insert this struct in the database.

Is it any problem with MEDIUMINT or SMALLINT binding? Thank you in advance, Dimitris

aarondl commented 7 years ago

This was caused by an issue in the null package when using Uint32. I've corrected it and released v6.4, Please test it :)

dtrehas commented 7 years ago

Thank you for the quick fix on the code