Giter VIP home page Giter VIP logo

Comments (8)

jazzthinking avatar jazzthinking commented on June 27, 2024

自己跟踪发现是下面这个函数里报的错:
func (session *Session) row2Bean(rows *sql.Rows, fields []string, fieldsCount int, bean interface{})

字段是字符串类型就会报错,
fieldType.Kind()
rawValueType.Kind()
这两个的类型不一致,导致会到 bytes2Value 里处理,然后出错。

from xorm.

lunny avatar lunny commented on June 27, 2024

能否将你的数据库结构贴一下?我测试了你的代码是正常的。

fmt.Sprintf("%v:%v@tcp(%v:3306)/%v?  charset=utf8"

这个代码中在?和charset之间的空格应去掉。
另NewEngine返回的第二个参数err应检查是否不为nil

from xorm.

lunny avatar lunny commented on June 27, 2024

能否将你的数据库结构贴一下?我测试了你的代码是正常的。

fmt.Sprintf("%v:%v@tcp(%v:3306)/%v?  charset=utf8"

这个代码中在?和charset之间的空格应去掉。
另NewEngine返回的第二个参数err应检查是否不为nil

from xorm.

lunny avatar lunny commented on June 27, 2024

能否将你的数据库结构贴一下?我测试了你的代码是正常的。

fmt.Sprintf("%v:%v@tcp(%v:3306)/%v?  charset=utf8"

这个代码中在?和charset之间的空格应去掉。
另NewEngine返回的第二个参数err应检查是否不为nil

from xorm.

jazzthinking avatar jazzthinking commented on June 27, 2024

谢谢lunny回复,真实代码里没有没有空格,数据连接没有问题,我测过,如果只返回一个整数字段时是没有问题的,

表结构如下:
CREATE TABLE IF NOT EXISTS User (
Id bigint(20) NOT NULL AUTO_INCREMENT,
UserName varchar(255) DEFAULT NULL,
FullName varchar(255) DEFAULT NULL,
Created datetime DEFAULT NULL,
PRIMARY KEY (Id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

from xorm.

jazzthinking avatar jazzthinking commented on June 27, 2024

lunny是否理解有误,我是说,数据库的连接是正常的,如果结果集只返回一个整数字段时是没有问题的,如果有string字段时,查询依然报错。

type User struct {
Id int32
UserName string
}

from xorm.

lunny avatar lunny commented on June 27, 2024

再更新下看看好了没有?你用的是SameMapper?

from xorm.

jazzthinking avatar jazzthinking commented on June 27, 2024

已更新,解决了,多谢,用的是SameMapper。

from xorm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.