SQCloudArrayCount

uint32_t SQCloudArrayCount (SQCloudResult *result);

Description

If the result of the function SQCloudResultType is RESULT_ARRAY then use this function to retrieve the number of items in the SQCloudResult array.

Parameters

  • result: A valid SQCloudResult pointer returned by an SQCloud function.

Return value

An uint32_t value with the number of items in the array.

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");
    }

    // execute a TEST ARRAY command
    SQCloudResult *r = SQCloudExec(conn, "TEST ARRAY;");
    if (SQCloudResultType(r) == RESULT_ARRAY) {
        int count = SQCloudArrayCount(r);
        for (int i=0; i<count; ++i) {
            SQCLOUD_VALUE_TYPE type = SQCloudArrayValueType(r, i);
            switch (type) {
                case VALUE_NULL: {
                    printf("NULL\n");
                    break;
                }
                case VALUE_INTEGER: {
                    int32_t value = SQCloudArrayInt32Value(r, i);
                    printf("%d\n", value);
                    // int64_t value = SQCloudArrayInt64Value(r, i);
                    // printf("%lld\n", value);
                    break;
                }
                case VALUE_FLOAT: {
                    float value = SQCloudArrayFloatValue(r, i);
                    printf("%f\n", value);
                    // double value = SQCloudArrayDoubleValue(r, i);
                    // printf("%f\n", value);
                    break;
                }
                case VALUE_BLOB:
                case VALUE_TEXT: {
                    uint32_t len;
                    char *value = SQCloudArrayValue(result, i, &len);
                    if (type == VALUE_BLOB) printf("[%d] BLOB size %d\n", i, len);
                    else printf("[%d] %.*s\n", i, len, value);
                }
            }
        }
    }

    SQCloudResultFree(r);
}