SQCloudConnect

SQCloudConnection *SQCloudConnect (const char *hostname, int port, SQCloudConfig *config);

Description

Initiate a new connection to a database node specified by hostname and port. This function will always return a non-null object pointer, unless there is too little memory even to allocate the SQCloudConnection object.

Parameters

  • hostname: a NULL terminated string that contains host name or host ip address
  • port: database server port (you can use the SQCLOUD_DEFAULT_PORT macro)
  • config: a pointer to a SQCloudConfig struct (cannot be NULL)

Return value

A pointer to an opaque SQCloudConnection struct.

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

    // do something with the conn object
}