N
N
Nikolay Korolev2018-10-03 10:50:53
go
Nikolay Korolev, 2018-10-03 10:50:53

Why does the code work on local but not on live?

On the locale, it outputs to the console

35316 2018-10-02 17:01:58 38 35316 17 899.41
35316 2018-10-02 17:01:58 38 35316 18 0
35316 2018-10-02 17:01:58 38 35316 19 0
35316 2018-10-02 17:01:58 38 35316 20 0

(Small excerpt)
On the server
80058 2018-10-03 00:27:50 35 0 0 0 
80058 2018-10-03 00:27:50 35 0 0 0 
80058 2018-10-03 00:27:50 35 0 0 0

The last three variables are always zero
Code snippet:
var rows *sql.Rows

  if len(r.Ids) < 300 {
    query_sql = "SELECT `id`,`time`,`meter_id`,`shot_id`,`type_id`,`value` FROM measures_shots,measures_values WHERE `time` BETWEEN ? AND ? AND id=shot_id AND type_id IN(2,17,18,19,20)"
    rows, err = conn.Query(query_sql, sql_time_from, sql_time_to)
  } else {
    sql_params = append(sql_params, sql_time_from, sql_time_to)
    query_sql = "SELECT `id`,`time`,`meter_id`,`shot_id`,`type_id`,`value` FROM measures_shots,measures_values WHERE `meter_id` IN(%s) AND `time` BETWEEN ? AND ? AND id=shot_id AND type_id IN(2,17,18,19,20)"
    rows, err = conn.Query(fmt.Sprintf(query_sql, strings.Join(sql_q, ",")), sql_time_from, sql_time_to)
  }
  if err != nil {
    log.Println(err)
    return nil, err
  }

  sql_q = nil
  sql_params = nil

  var (
    time_str      string
    shots_ln      map[uint64]rep_server_shots_ln = make(map[uint64]rep_server_shots_ln)
    sheet_ln      *Rep_sheet_ln
    sql_shots_ids []string
    id            uint64
    types         int
    value         float32
    shot_id       uint16
  )

  var arr = make(map[int]uint16)
  i := 1
  for rows.Next() {
    rows.Scan(&id, &time_str, &meter_id, &shot_id, &types, &value)
    fmt.Println(id, time_str, meter_id, shot_id, types, value)
    if shot_id == 0 {
      continue
    }
    sheet_ln, ok = ln_sheet[meter_id]
    if !ok {
      continue
    }

    sheet = sheet_ln.Sheet
    if shot_id != arr[i-1] {
      row = sheet.AddRow()
      cell = row.AddCell()
      cell.SetString(time_str)
    } else {
      cell = row.AddCell()
    }
    if types == 2 {
      cell = row.AddCell()
    }

    cell.SetValue(value)

    arr[i] = shot_id
    i++
    sql_shots_ids = append(sql_shots_ids, fmt.Sprintf("%d", id))

    row_pos_ln[meter_id]++

    shots_ln[id] = rep_server_shots_ln{
      meter_id: meter_id,
      row_num:  row_pos_ln[meter_id],
    }
  }
  rows.Close()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Petro Kvartsianyi, 2019-01-23
@Patrick12

Maybe your server is just in a different time zone?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question