Error creating new row

I’m trying to insert a new row to MS SQL using denisenkom go-mssqldb package and driver

tsql := fmt.Sprintf("INSERT INTO Uploads (Fname, Fsize, Ftype) VALUES (@Fname, @Fsize, @Ftype );")
	fmt.Printf("tsql = %s\n", tsql)

	//Execute non-query with named parameters
	res, err := db.ExecContext(
		sql.Named("Fname", fname),
		sql.Named("Fsize", fsize),
		sql.Named("Ftype", ftype))

	if err != nil {
		log.Fatal(" AddRow_v1() -> Error creating new row: " + err.Error())
		return -1, err

I’m getting unncessary use of fmt.Sprintf
Also I’m getting a terminal error sql: expected 0 arguments

You see this error because you’re using Sprintf without using any formatting placeholder or variable. Instead, just assign the raw string to tsql:

tsql := "INSERT INTO Uploads (Fname, Fsize, Ftype) VALUES (@Fname, @Fsize, @Ftype );"
1 Like

About error sql: expected 0 arguments, which SQL library do you use? Does it support named parameters?

I’m using for Microsoft SQL Server 2014 - 12.0.2269.0 (X64) Jun 10 2015 03:35:45 Copyright (c) Microsoft Corporation Express Edition (64-bit) on Windows NT 6.3 <X64> (Build 19042: )

Which SQL library support named parameters?

I just had a quick look on mssql package - - but could not spot the problem, maybe someone else can help here?

1 Like

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