affected/package: database/sql "Deficiency in the code"

go version: go 1.19

my problem is with the database/sql package. I have plsql code available in service. values are sent to the service via map. but the number is not limited,

I need to send to db.exec() via sql.Named, I checked with loop and with interface, it didn’t work.

Please help me.

my codes are:

in the controller

	const begin = `
		jsonData.Put('stateid', :stateid);
	`

       array_for_param := map[string]string{
		"stateid": "a",
	}

	temp, err := services.Perform(c, begin, array_for_param, i_User_Id)

	if err != nil {
		log.Fatal(err)
	}

service code:

	var params []interface{}

	for key, value := range array_for_param {
		params = append(params, sql.Named(key, value))
	}

	if _, err := db.Exec(declare+begin+end,
		sql.Named("i_User_Id", i_User_Id),
		params...,
	); err != nil {
		log.Fatal(err)
	}
	); err != nil {
		log.Fatal(err)
	}

The main problem I have is that I need to send the sql.Named code using a for, which is an unknown number

	if _, err := db.Exec(declare+begin+end,
		sql.Named("i_User_Id", i_User_Id),
		for key, value := range array_for_param {
			return sql.Named(key, value)
		}
	); err != nil {
		log.Fatal(err)
	}

I did that too

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.