Giter VIP home page Giter VIP logo

Comments (1)

Issues-translate-bot avatar Issues-translate-bot commented on June 5, 2024

Bot detected the issue body's language is not English, translate it automatically. πŸ‘―πŸ‘­πŸ»πŸ§‘β€πŸ€β€πŸ§‘πŸ‘«πŸ§‘πŸΏβ€πŸ€β€πŸ§‘πŸ»πŸ‘©πŸΎβ€πŸ€β€πŸ‘¨πŸΏπŸ‘¬πŸΏ


Description

type Data struct{
   ID int64
   IntCol int64
}

createSql:=`CREATE TABLE IF NOT EXISTS %s (
id SERIAL PRIMARY KEY,
int_col INT);`
pgsql := g.DB("pgsql")
tableName := "Type_Table_" + gtime.Now().TimestampMilliStr()
// pgsql will convert the table name to lowercase
pgsql.Exec(ctx, fmt.Sprintf(createSql, tableName))

//Insert data
//Write any data
var data = Data {
    Id:1,
   IntCol:2,
}
// The tableName here is the same variable as above.
_, err := pgsql.Model(tableName).Data(data).Insert()
fmt.Println(err)
//output:
// INSERT INTO "Type_Table_1714453562918"("") VALUES() : pq: delimiter identifier of length 0 at or near """"
// The error given is confusing

// When the table name is the same as the one that just created the table, after randomly inserting a piece of data into the table
// update data,
_, err = pgsql.Model(tableName).Where("id", 1).Data(g.Map{
"int_col": 9999,
}).Update()
fmt.Printf("%+v\n", err)
//output:
// data cannot be empty
// The error given is also confusing

After debugging, I found that (c *Core) mappingAndFilterData This method will get all the fields of the table, and then compare it with the field name of the structure to be inserted, and delete the ones that do not exist, but because the table I passed in during the Insert operation The name is not all lowercase, so the field cannot be found and no error is returned. As a result, when inserting later, there is no data and an error is reported.

// when inserting
3333

// when updating
4444

Additional

No response

from gf.

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.