Method
SeagullStatementcolumn_object
since: 0.3
Declaration [src]
gboolean
seagull_statement_column_object (
SeagullStatement* statement,
const char* prefix,
GObject* obj,
GError** error
)
Description [src]
Updates the properties of any object based on the current result of a statement.
This will look for columns with the same name of the properties in obj, and
if found, set the property in obj to the return value. This is a helper
around manually calling seagull_statement_column_double(),
seagull_statement_column_int(), seagull_statement_column_text(), etc.
prefix may be used to limit what columns to look for. Note that you most
likely will need to use the SQL AS keyword to make the column names have
the prefix like the following example.
sql = "SELECT id AS message_id, content AS message_content "
"FROM messages WHERE conversion_id=:conversation-id "
"ORDER BY created_timestamp DESC LIMIT 10";
stmt = seagull_statement_new(db, SQL, NULL);
seagull_statement_bind_string(stmt, "conversation-id", "some-random-id", -1,
NULL, NULL);
seagull_statement_step(stmt, NULL);
message = new_message();
seagull_statement_column_object(stmt, "message_", message, NULL);
Note that the object must exist for this to work, so if the object has a construct only property you can pull that out ahead of time and create the object and then call this function. See the following example.
sql = "SELECT id, title AS conversation_title, topic AS conversation_topic "
"FROM conversations WHERE account_id=:account-id";
stmt = seagull_statement_new(db, sql, NULL);
seagull_statement_bind_string(stmt, "account-id", "some-account-id", -1,
NULL, NULL);
seagull_statement_step(stmt, NULL);
conversation_id = seagull_statement_column_string(stmt, "id", NULL);
conversation = conversation_new(conversation_id);
seagull_statement_column_object(stmt, "conversation_", conversation, NULL);
Note that true will be returned even if no properties in obj have been updated.
Available since: 0.3
Parameters
prefix-
Type:
const char*An optional prefix.
The argument can be NULL.The data is owned by the caller of the method. The value is a NUL terminated UTF-8 string. obj-
Type:
GObjectThe object.
The data is owned by the caller of the method. error-
Type:
GError **The return location for a recoverable error.
The argument can be NULL.If the return location is not NULL, then you must initialize it to aNULLGError*.The argument will be left initialized to NULLby the method if there are no errors.In case of error, the argument will be set to a newly allocated GError; the caller will take ownership of the data, and be responsible for freeing it.