问题描述
您正在使用哪个版本的Go($ go version
go version go1.14 linux/amd64
)?
go env
此问题会在最新版本中重现吗?
是
您正在使用什么操作系统和处理器体系结构($ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/home/zabludovsky/go/bin"
GOCACHE="/home/zabludovsky/.cache/go-build"
GOENV="/home/zabludovsky/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY="gl.rosst.ru/backend/*"
GONOSUMDB="gl.rosst.ru/backend/*"
GOOS="linux"
GOPATH="/home/zabludovsky/go"
GOPRIVATE="gl.rosst.ru/backend/*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/zabludovsky/go/src/awesomeProject1/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build174435943=/tmp/go-build -gno-record-gcc-switches"
?
package main
import (
"database/sql"
"fmt"
"strconv"
_ "github.com/lib/pq"
)
func main() {
err := selectFromDb(65536)
if err != nil{
panic(err)
}
println("where was no errors!")
}
func selectFromDb(argsNumber int) (err error){
//open connect to postgres database,put your database connection string below,instead of second argument
db,err := sql.Open("postgres","postgres://mayber:password@localhost:5432/test?sslmode=disable")
if err != nil {
return
}
//preparing query,you can call this func with argsNumber = 10(or some not huge number)
//to check that it is working correct
var args []interface{}
query := "SELECT id FROM test_tbl WHERE id IN ("
for i := 0; i < argsNumber; i++ {
args = append(args,strconv.Itoa(i))
query = fmt.Sprintf("%s $%d,",query,i+1)
fmt.Printf("preparing query,%d/%d \n",i,argsNumber)
}
query = fmt.Sprintf("%s);",query[:len(query)-2])
fmt.Println("preparing finished:")
//uncomment string bellow to see result query and check it
//fmt.Println(query)
//preparing query
stmt,err := db.Prepare(query)
if err != nil {
return
}
//selecting
rows,err := stmt.Query(args...)
if err != nil{
return
}
//closing db connection
err = rows.Close()
if err != nil{
return
}
return
}
您做了什么?
preparing query,0/65536
preparing query,1/65536
...
preparing query,60535/65536
preparing finished:
where was no errors!
您期望看到什么?
preparing finished:
panic: sql: expected 0 arguments,got 65536
相反,您看到了什么?
[HttpGet]
[JWTAuthenticate]
[CustomAttribute]
[LogInfo]
[LogException]
[Route("Overview")]
public string GetAccount()
{
return "Hello this is a sample api";
}
[HttpGet]
[JWTAuthenticate]
[CustomAttribute]
[LogInfo]
[LogException]
[Route("GetMenu")]
public ResponseStatus GetMainMenuSubmenu()
{
ResponseStatus objResponseStatus = new ResponseStatus();
JObject obj = new JObject();
MenuResponseModel objMMSMModel = new MenuResponseModel();
string allowedMenus = "";
try
{
allowedMenus = CommonUtility.GetConfigValue("AllowedMenuIDs");
MainMenuViewModel objMainMenuViewModel = LoginBizModel.GetMainMenuSubmenu(Convert.ToString(System.Web.HttpContext.Current.Items["emailID"]));
if (objMainMenuViewModel != null && objMainMenuViewModel.MainMenuDetails != null && objMainMenuViewModel.MainMenuDetails.Count > 0)
{
objMMSMModel.CustomerName = Convert.ToString(System.Web.HttpContext.Current.Items["CustomerName"]);
objMMSMModel.UserName = Convert.ToString(System.Web.HttpContext.Current.Items["userName"]);
objMMSMModel.emailID = Convert.ToString(System.Web.HttpContext.Current.Items["emailID"]);
objMMSMModel.roleName = Convert.ToString(System.Web.HttpContext.Current.Items["RoleName"]);
objMMSMModel.MenuDetails = new List<MenuSubMenuModel>();
//Expose menu(s) only that are given in webconfig
objMainMenuViewModel.MainMenuDetails = objMainMenuViewModel.MainMenuDetails.Where(x => allowedMenus.Contains(x.MainMenuName)).ToList();
foreach (MenuModel mm in objMainMenuViewModel.MainMenuDetails)
{
MenuSubMenuModel menu = new MenuSubMenuModel();
menu.MainMenuName = mm.MainMenuName;
menu.SubMenuName = mm.SubMenuName;
menu.SubMenuId = mm.SubMenuId;
objMMSMModel.MenuDetails.Add(menu);
}
}
objResponseStatus = ResponseStatus.SetResponseStatus(objResponseStatus,1000,Constants.Success,objMMSMModel);
}
catch (Exception ex)
{
Common.LogError(System.Reflection.MethodBase.GetCurrentMethod().Name,ex,new System.Diagnostics.StackTrace(ex,true).GetFrame(0).GetFileLineNumber());
ResponseStatus.SetExceptionResponseStatus(objResponseStatus,ex);
}
return objResponseStatus;
}
了解更多详情,https://github.com/GlebZabl/golang_postgres_bug
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)