SQCloudRowsetValueType
SQCLOUD_VALUE_TYPE SQCloudRowsetValueType (SQCloudResult *result, uint32_t row, uint32_t col);
Description
If the result of the function SQCloudResultType is RESULT_ROWSET then use this function to retrieve the type of each rowset item identified by a given row and column index.
Parameters
- result: A valid SQCloudResult pointer returned by an SQCloud function.
- row: A row index (from 0 to SQCloudRowsetRows-1)
- col: A column index (from 0 to SQCloudRowsetCols-1)
Return value
An int
represented by the SQCLOUD_VALUE_TYPE enum type:
typedef enum {
VALUE_INTEGER = 1,
VALUE_FLOAT = 2,
VALUE_TEXT = 3,
VALUE_BLOB = 4,
VALUE_NULL = 5
} SQCLOUD_VALUE_TYPE;
Example
int main (int argc, const char * argv[]) {
// setup config
SQCloudConfig config = {0};
config.username = "myusername";
config.password = "mypassword"
SQCloudConnection *conn = SQCloudConnect("myproject.sqlite.cloud", SQCLOUD_DEFAULT_PORT, &config);
if (SQCloudIsError(conn)) {
printf("ERROR connecting: %s (%d)\n", SQCloudErrorMsg(conn), SQCloudErrorCode(conn));
return -1;
} else {
printf("Connection to host OK...\n\n");
}
// choose a database first (no error check here)
SQCloudResult *r1 = SQCloudExec(conn, "USE DATABASE mydatabase.sqlite;");
SQCloudResultFree(r1);
// perform a sample query
SQCloudResult *r = SQCloudExec(conn, "SELECT * FROM mytable;");
if (SQCloudResultType(r) == RESULT_ROWSET) {
uint32_t nrows = SQCloudRowsetRows(r);
uint32_t ncols = SQCloudRowsetCols(r);
// print column names
for (uint32_t i=0; i<ncols; ++i) {
uint32_t len;
char *value = SQCloudRowsetColumnName(result, i, &len);
printf("%.*s\n", len, value);
}
// print values
for (uint32_t i=0; i<nrows; ++i) {
for (uint32_t j=0; j<ncols; ++j) {
SQCLOUD_VALUE_TYPE type = SQCloudRowsetValueType(r, i, j);
switch (type) {
case VALUE_NULL: {
printf("NULL\n");
break;
}
case VALUE_INTEGER: {
int32_t value = SQCloudRowsetInt32Value(r, i, j);
printf("%d\n", value);
// int64_t value = SQCloudRowsetInt64Value(r, i, j);
// printf("%lld\n", value);
break;
}
case VALUE_FLOAT: {
float value = SQCloudRowsetFloatValue(r, i);
printf("%f\n", value);
// double value = SQCloudRowsetDoubleValue(r, i, j);
// printf("%f\n", value);
break;
}
case VALUE_BLOB:
case VALUE_TEXT: {
uint32_t len;
char *value = SQCloudRowsetValue(result, i, j, &len);
if (type == VALUE_BLOB) printf("[%d] BLOB size %d\n", i, len);
else printf("[%d] %.*s\n", i, len, value);
break;
}
}
}
}
}
SQCloudResultFree(r);
}