2

I’m testing GridDB Cloud with the C client. I insert a couple of rows into a container, but when I query them back, the row values sometimes come out as NULL (empty), even though I just inserted data.

Here’s a minimal example:

GSContainer *cont;
GSRow *row;
GSQuery *qry;
GSRowSet *rs;

// create row and insert
gsGetContainer(store, "sensor_data", &cont);

gsCreateRowByContainer(cont, &row);
gsSetRowFieldByString(row, 0, "sensor-01");
gsSetRowFieldByFloat(row, 1, 22.5f);
gsSetRowFieldByTimestamp(row, 2, gsCurrentTime());
gsPutRow(cont, NULL, row, NULL);
gsCloseRow(&row);

// query back
qry = gsQuery(cont, "SELECT *");
gsFetch(qry, &rs);

while (gsHasNextRow(rs)) {
    GSRow *fetched;
    gsNextRow(rs, &fetched);

    const char *id;
    float temp;
    GSTimestamp ts;

    gsGetRowFieldAsString(fetched, 0, &id);
    gsGetRowFieldAsFloat(fetched, 1, &temp);
    gsGetRowFieldAsTimestamp(fetched, 2, &ts);

    printf("id=%s temp=%.2f ts=%lld\n", id, temp, (long long)ts);
    gsCloseRow(&fetched);
}

I expected to get back the same row values:

  • sensor-01

  • 22.5

  • timestamp

Sometimes id prints (null) and temp prints 0.00.

Am I handling gsNextRow and gsGetRowFieldAs… correctly? Do I need to commit/flush after gsPutRow, or is there something else in the C API that ensures the data is visible immediately after insert?

3
  • Have you tried to remove gsCloseRow(&fetched); and also move GSRow *fetched; before the loop? Commented Sep 11 at 10:02
  • 1
    Hassan Saeed, gsGetRowFieldAsString() and others return a value. Re-write code to check each function return value and the answer will certainly become more clear. Its faster than posting on SO. Commented Sep 11 at 10:15
  • Thanks, I’ll try moving GSRow *fetched before the loop and avoid closing it too early. Commented Sep 11 at 11:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.