Skip to Content
Author's profile photo Former Member

How do you publish bigdatetime data with the C SDK to ESP?

A couple of weeks ago, I was asked how to publish bigdatetime data to ESP using the C SDK.  The crux of the problem was that the API used to set the bigdatetime column required an “EspBigDatetime” value as the second parameter:

ESPAPICALL int32_t esp_relative_rowwriter_set_bigdatetime ( EspRelativeRowWriter * writer,
const EspBigDatetime * bigdatetime_value,
EspError * error
)

How does one populate an EspBigDatetime variable?

It turns out that there are two ways to populate an EspBigDatetime variable:

1) The first method works best if your bigdatetime data is coming from a string source (for example, reading from a file):

ESPAPICALL EspBigDatetime* esp_bigdatetime_create_string ( const char * string_value,
EspError * error
)

// NOTE: The string must be in the standard ESP bigdatetime format which is “yyyy-MM-ddTHH:mm:ss.UUUUUU” where the letter ‘U’ stands for microseconds.

char timestamp[27] = “2013-08-24T09:45:23.543221”;

EspBigDatetime *espDatetime;

// Create and populate the espDatetime variable

espDatetime = esp_bigdatetime_create_string(timestamp, espError);

if(espDatetime == NULL)

{

          print_ESP_error_and_exit(espError,__LINE__);

}

// Set the espDatetime value in the current row

rc=esp_relative_rowwriter_set_bigdatetime(row,espDatetime,espError);

if(rc!=0)

{

          print_ESP_error(espError,__LINE__);

          esp_bigdatetime_free(espDatetime, espError);

          exit(1);

}

esp_bigdatetime_free(espDatetime, espError);

2) The second method works best if your bigdatetime data is in a numeric microsecond format (for example, getting the system’s current date and time):

ESPAPICALL EspBigDatetime* esp_bigdatetime_create_microseconds ( const int64_t microseconds,
EspError * error
)

 

EspBigDatetime *espDatetime;

time_t tmstamp;

// Get the current date and time in microseconds

tmstamp = getMicroseconds();

// Create and populate the espDatetime variable

espDatetime = esp_bigdatetime_create_microseconds(tmstamp, espError);

if(espDatetime == NULL)

{

          print_ESP_error_and_exit(espError,__LINE__);

}

// Set the espDatetime value in the current row

rc=esp_relative_rowwriter_set_bigdatetime(row,espDatetime,espError);

if(rc!=0)

{

          print_ESP_error(espError,__LINE__);

          esp_bigdatetime_free(espDatetime, espError);

          exit(1);

}

esp_bigdatetime_free(espDatetime, espError);

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.