Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of net.IP type causes "row value misused" error #36

Closed
JonathonReinhart opened this issue Mar 21, 2021 · 1 comment
Closed

Use of net.IP type causes "row value misused" error #36

JonathonReinhart opened this issue Mar 21, 2021 · 1 comment
Assignees

Comments

@JonathonReinhart
Copy link

Description

Attempting to use a net.IP field in a gorm model causes a sqlite row value misued error on INSERT.

To Reproduce

I did not create a playground PR because this is so simple to reproduce:

package main

import (
	"net"
	"gorm.io/gorm"
	"gorm.io/driver/sqlite"
)

type Client struct {
	gorm.Model
	SourceIP net.IP
}

func main() {
	db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
	if err != nil {
		panic("Failed to connect to db")
	}

	db.AutoMigrate(&Client{})

	db.Create(&Client{
		SourceIP: net.ParseIP("192.168.1.1"),
	})
}

Output:

2021/03/21 00:33:35 gorm-sqlite-netIP/main.go:22 row value misused
[0.134ms] [rows:0] INSERT INTO `clients` (`created_at`,`updated_at`,`deleted_at`,`source_ip`) VALUES ("2021-03-21 00:33:35.378","2021-03-21 00:33:35.378",NULL,(0,0,0,0,0,0,0,0,0,0,255,255,192,168,1,1))

This happens in the sqlite3 CLI also:

sqlite> INSERT INTO `clients` (`created_at`,`updated_at`,`deleted_at`,`source_ip`) VALUES ("2021-03-21 00:33:35.378","2021-03-21 00:33:35.378",NULL,(0,0,0,0,0,0,0,0,0,0,255,255,192,168,1,1));
Error: row value misused

It seems that the nested parenthesis syntax for a BLOB is not correct.

@jinzhu
Copy link
Member

jinzhu commented Oct 9, 2022

Which seems works with latest version.

@jinzhu jinzhu closed this as completed Oct 9, 2022
samuelncui pushed a commit to samuelncui/gorm-sqlite that referenced this issue Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants