SQCloudExecArray

SQCloudResult *SQCloudExecArray (SQCloudConnection *connection, const char *command, const char **values, uint32_t len[], SQCLOUD_VALUE_TYPE types[], uint32_t n);

Description

Submits a command to the server and waits for the result. The command can be any SQLite statement or any built-in SQLite Cloud command. This function is equivalent to the SQCloudExec function but special placeholders can be used to bind values to the statement (most of the time avoiding the need to perform copies and to encode data).

Parameters

  • connection: a valid connection object obtained by SQCloudConnect or SQCloudConnectWithString
  • command: a NULL terminated string with the command to execute
  • values: an array of n values
  • len: an array of n length
  • types: an array of n types
  • n number of array elements

Return value

A pointer to an opaque SQCloudResult struct that must be explicitly deallocated with SQCloudResultFree

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

    // perform an SQL statement using bindings
    const char *dbname = "main";
    const char *tblname = "mytable";
    const char *colname = "mycolumn";
    int n = 3;

    const char *values[3] = {dbname, tblname, colname};
    uint32_t len[3] = {(uint32_t)strlen(dbname), (uint32_t)strlen(tblname), (uint32_t)strlen(colname)};
    SQCLOUD_VALUE_TYPE types[3] = {VALUE_TEXT, VALUE_TEXT, VALUE_TEXT};

    const char *command = "LIST METADATA ? TABLE ? COLUMN ?";
    SQCloudResult *r2 = SQCloudExecArray(conn, command, values, len, types, n);

    // ...
}