Update by Exec with gorp

139 Views Asked by At

I working with gorp , i used Exec to UPDATE and INSERT .

updateDataQuery = " UPDATE time_tables SET line_code = ? , direction = ? , station_code = ? , " +
        "train_number = ? , train_type = ? , dept_station_code = ? ," +
        "arrv_station_code = ? , arrv_time = ? , dept_time = ? , time_table = ? " +
        "WHERE line_code = ? AND station_code = ? AND train_number = ? AND time_table = ? "

result, err := db.Exec(updateDataQuery,Model.LineCode, Model.Direction, Model.StationCode,
        Model.TrainNumber, Model.TrainType, Model.DeptStationCode,
        Model.ArrvStationCode, Model.ArrvTime, Model.DeptTime, Model.TimeTable,
        Model.LineCode, Model.StationCode, Model.TrainNumber, Model.TimeTable) 
row, _ := result.RowsAffected()
if row == 0 {
// insert
}

first run : row = 0 => insert

second run : Model not change row = 0 => insert

how to replace data first run by data second run ?

0

There are 0 best solutions below