I have a function called "updateRow()" that take a struct as parameter. This fuction is called in a goroutine and i have hundred of goroutine at time, but that's not the point because without goroutine it doesn't work too.
But when i'm trying to update rows with SQL update statement, it appear that nothing happen, the updateRow() function never return.
db : Mariadb
Here is my code :
package main
import (
"fmt"
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func dbcon(){
db, err := sql.Open(dbDriver, dbUser ":" dbPass "@tcp(" dbHost ":3306)/" dbName)
checkErr(err)
return db
}
func updateRow(site Site) {
fmt.Println("Updating ", site)
// And this never print "executed" or never return.
sqlStatement := "UPDATE `sites` SET `http_url`=?,`http_code`=?,`http_state`=?,`ssl_url`=?,`ssl_code`=?,`ssl_state`=? WHERE `domain`=?;"
updateStmt, err := db.Exec(sqlStatement, site.final_url_http, site.http_code, site.http_state, site.final_url_ssl, site.ssl_code, site.ssl_state, site.domain)
fmt.Println("executed ")
if err != nil {
fmt.Println("Error : ", err)
return
}
affect, err := updateStmt.RowsAffected()
if err != nil {
fmt.Println("Error : ", err)
return
}
fmt.Println("Records affected", affect)
}
Here, "updating" is printed but nothing more happen.
In my script i'm using a function who's select rows in DB and return as string array and that's work but update statement doesn't.
EDIT :
Okay, sometimes i have this error :
Error 1205: Lock wait timeout exceeded; try restarting transaction
I'll come back soon.
Edit ANSWER :
My problem was that i'm not using primary key and resulted with TimeOut.
Remember kids, optimise your queries for large DB.
CodePudding user response:
The problem was my query timeout, using primary key instead of string:domain solved the problem in this case.
UPDATE sites SET ... domain=?
Changed to:
UPDATE sites SET ... id=?
