You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 31, 2020. It is now read-only.
Following the code under "examples" in this repository, I've brought up a MySQL DB and a simple server based on "server.go". I've created the "blog" table as per the "testdata/initdb/sql/init_db.sql" example and added some values. Finally, I've created a test client. Connections and mapping work for integer values and I get a correct BlogResponse. However, the varchar "title" field is blank.
After some debugging, I found that it was not correctly converted. The varchar was read as a []uint8 from the DB. I modified the function "MapResponse" in "mapper.go" to include a conversion to a string. Something like this:
func B2S(bs []uint8) string {
b := make([]byte, len(bs))
for i, v := range bs {
b[i] = byte(v)
}
return string(b)
}
func (m *Mapper) MapResponse(respMap *ResponseMapping) error {
....
arrayUint8, ok := sqlMapVals.ProtoValues[i].([]uint8)
if ok == true {
str := B2S(arrayUint8)
setProto(respField, str)
} else {
setProto(respField, sqlMapVals.ProtoValues[i])
}
With that fix, the full BlogResponse object is returned correctly.
Is this a known problem? I have configured the DB (MySql / MariaDB) wrong? Or maybe it's a driver or configuration problem?
The text was updated successfully, but these errors were encountered:
I predominately work with Postgres, but From what I remember, MySQL needs a prepare statement to return correct data type. When using query() directly, the MySQL will return your data in form of bytes.
This is not the case with Postgres.
The fix would involve adding a prepare statement in the generator.
Until I do that and thoroughly test it, feel free to use https://github.com/jackskj/carta
if you are using MySQL, just make sure to use prepare statement.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Following the code under "examples" in this repository, I've brought up a MySQL DB and a simple server based on "server.go". I've created the "blog" table as per the "testdata/initdb/sql/init_db.sql" example and added some values. Finally, I've created a test client. Connections and mapping work for integer values and I get a correct BlogResponse. However, the varchar "title" field is blank.
After some debugging, I found that it was not correctly converted. The varchar was read as a []uint8 from the DB. I modified the function "MapResponse" in "mapper.go" to include a conversion to a string. Something like this:
With that fix, the full BlogResponse object is returned correctly.
Is this a known problem? I have configured the DB (MySql / MariaDB) wrong? Or maybe it's a driver or configuration problem?
The text was updated successfully, but these errors were encountered: