SQCloudBlobOpen

SQCloudBlob *SQCloudBlobOpen (SQCloudConnection *connection, const char *dbname, const char *tablename, const char *colname, int64_t rowid, bool wrflag);

Description

The SQCloudBlobOpen interface opens a BLOB for incremental I/O. This interfaces opens a handle to the BLOB located in row rowid, column colname, table tablename in database dbname; in other words, the same BLOB that would be selected by: SELECT colname FROM dbname.tablename WHERE rowid = rowid;

This function fails if any of the following conditions are true:

  • Database dbname does not exist
  • Table tablename does not exist within database dbname
  • Table tablename is a WITHOUT ROWID table
  • Column colname does not exist
  • Row rowid is not present in the table
  • The specified column of row rowid contains a value that is not a TEXT or BLOB value
  • Column colname is part of an index, PRIMARY KEY or UNIQUE constraint and the blob is being opened for read/write access
  • Foreign key constraints are enabled, column colname is part of a child key definition and the blob is being opened for read/write access

This function resembles the sqlite3_blob_open SQLite API.

Parameters

  • connection: a valid connection object obtained by SQCloudConnect or SQCloudConnectWithString
  • dbname: symbolic name of the database (usually main, if NULL main is used)
  • tablename: table name that contains the BLOB column
  • colname: name of the BLOB column
  • rowid: rowid of the BLOB to open
  • wrflag: if 0 the BLOB is opened for read-only access, otherwise the BLOB is opened for read and write access.

Return value

An SQCloudBlob opaque datatype.

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
    SQCloudResult *r = SQCloudExec(conn, "USE DATABASE mydatabase.sqlite;");

    // open a BLOB for reading
    SQCloudBlobOpen *blob = SQCloudBlobOpen(conn, NULL, "mytable", "mycolumn", 1, 0);

    // ...
}