Method

SeagullStatementbind_object

Declaration [src]

gboolean
seagull_statement_bind_object (
  SeagullStatement* statement,
  const char* prefix,
  GObject* obj,
  GError** error
)

Description [src]

Binds an object to the query.

The parameters of the statement will be walked and if a property matching the name of a parameter is found, then the parameter will be bound to the value of that property.

If parameters have conflicting names, you can pass a prefix to make sure the correct ones are bound. Note that the prefix needs to look like a valid SQL column name, so no spaces or dashes. See the following example.

stmt = seagull_statement_new("INSERT INTO messages(id, author) "
                             "VALUES(:msg-id, :author-id)");
seagull_statement_bind_object(stmt, "msg_", message, &error);
seagull_statement_bind_object(stmt, "author_", author, &error);

This will look for properties named id on both the message and author instances.

Note that if a prefix is provided, it will be required for all parameters. See the following example

stmt = seagull_statement_new("INSERT INTO messages(id, author) "
                             "VALUES(:id, :author-id)");
// This bind doesn't match anything as there are no parameters with a msg-
// prefix.
seagull_statement_bind_object(stmt, "msg_", message, &error);

// By not using a prefix, the :id parameter will get match to message:id.
seagull_statement_bind_object(stmt, NULL, message, &error);

// Using a prefix with the author will only match the author-id parameter
// and leave the id parameter to the previously bound value.
seagull_statement_bind_object(stmt, "author_", author, &error);

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: GObject

The 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 a NULL GError*.
The argument will be left initialized to NULL by 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.

Return value

Type: gboolean

True on success; otherwise false with error set.