Fire Foot API Reference Manual |
---|
FFSql — Class for handling SQL statements.
#include <ff-sql.h> struct FFSql; struct FFSqlClass; FFSql* ff_sql_new (void); FFTransaction* ff_sql_get_default_transaction (FFSql *self); void ff_sql_set_default_transaction (FFSql *self, FFTransaction *tr); const gchar* ff_sql_get_string (FFSql *self); void ff_sql_set_string (FFSql *self, const gchar *sql_string); const gchar* ff_sql_get_field_name (FFSql *self, guint field_position); glong ff_sql_get_field_precision (FFSql *self, guint field_position); const gchar* ff_sql_get_field_table_name (FFSql *self, guint field_position); glong ff_sql_get_field_length (FFSql *self, guint field_position); gchar* ff_sql_get_field_firebird_type_name (FFSql *self, guint field_position); const gchar* ff_sql_get_parameter_name (FFSql *self, guint parameter_position); guint ff_sql_field_count (FFSql *self); guint ff_sql_parameter_count (FFSql *self); gulong ff_sql_record_count (FFSql *self); gulong ff_sql_affected_rows (FFSql *self); gboolean ff_sql_execute (FFSql *self); gboolean ff_sql_execute_direct (FFSql *self, const gchar *sql_string, gboolean first_prepare); gboolean ff_sql_close (FFSql *self); gboolean ff_sql_prepare (FFSql *self); gboolean ff_sql_eof (FFSql *self); gboolean ff_sql_fetch (FFSql *self); gboolean ff_sql_is_prepared (FFSql *self); FFValue* ff_sql_get_value (FFSql *self, guint field_number); GList* ff_sql_get_value_list (FFSql *self); FFParameter* ff_sql_get_parameter (FFSql *self, guint parameter_number); GList* ff_sql_get_parameter_list (FFSql *self); GList* ff_get_parameter_names (FFSql *self); GList* ff_get_field_names (FFSql *self); gint ff_sql_get_statement_type (FFSql *self);
SQL objets are use to execute queries for data definition and manipulation. Queries can be parametrized. Each parameter has to be enclosed between a "{" and a "}". For example:
Example 1. Sintaxis of a parametrized query.
INSERT INTO EMPLOYEE(NAME, AGE) VALUES ({a_name}, {an_age}); INSERT INTO EMPLOYEE(NAME, AGE) VALUES ({a_name}, 22);
struct FFSqlClass { void (* on_execute) (FFSql *self, gpointer data); void (* on_close) (FFSql *self, gpointer data); void (* on_error) (FFSql *self, FFError *error, gpointer data); };
void (*on_execute) (FFSql *self, gpointer data) | Triggered after a statement execution. |
void (*on_close) (FFSql *self, gpointer data) | Triggered after SQL close. |
void (*on_error) (FFSql *self, FFError *error, gpointer data) | Triggered after an error is raised. |
FFTransaction* ff_sql_get_default_transaction (FFSql *self);
Get default transaction.
self : | A FFSql. |
Returns : | A FFTransaction. |
void ff_sql_set_default_transaction (FFSql *self, FFTransaction *tr);
Set self default transaction.
self : | A FFSql. |
tr : | A FFTransaction. |
const gchar* ff_sql_get_string (FFSql *self);
Get SQL string.
self : | A FFSql. |
Returns : | A string containing an SQL statement. |
void ff_sql_set_string (FFSql *self, const gchar *sql_string);
Set SQL string.
self : | A FFSql. |
sql_string : | A string containing an SQL statement. |
const gchar* ff_sql_get_field_name (FFSql *self, guint field_position);
Get field's name.
self : | A FFSql. |
field_position : | An unsigned long with field position. |
Returns : | Field's name. |
glong ff_sql_get_field_precision (FFSql *self, guint field_position);
Get field's number of decimals.
self : | A FFSql. |
field_position : | An unsigned long with field position. |
Returns : | Number of decimals. |
const gchar* ff_sql_get_field_table_name (FFSql *self, guint field_position);
Get field's table name.
self : | A FFSql. |
field_position : | An unsigned long with field position. |
Returns : | A string containing field's table name. |
glong ff_sql_get_field_length (FFSql *self, guint field_position);
Get field's length.
self : | A FFSql. |
field_position : | An unsigned long with field position. |
Returns : | Field's length. |
gchar* ff_sql_get_field_firebird_type_name (FFSql *self, guint field_position);
Get a string representation of field's Firebird data type.
self : | A FFSql. |
field_position : | An unsigned long with field position. |
Returns : | A string containing data type. |
const gchar* ff_sql_get_parameter_name (FFSql *self, guint parameter_position);
Get name of parameter number parameter_position.
self : | A FFSql. |
parameter_position : | Position of parameter. |
Returns : | Parameter name, or NULL if fail. |
guint ff_sql_field_count (FFSql *self);
Get number of fields in SQL.
self : | A FFSql. |
Returns : | Number of fields. |
guint ff_sql_parameter_count (FFSql *self);
Get number of parameters in SQL. Parameter format: {parameter_name} . Example: INSERT INTO TEST(NAME, AGE, COMENTS) VALUES ({name}, {age}, NULL);
self : | A FFSql. |
Returns : | Number of parameters. |
gulong ff_sql_record_count (FFSql *self);
Get number of records already fetched.
self : | A FFSql. |
Returns : | Number of fetched records. |
gulong ff_sql_affected_rows (FFSql *self);
Get number of affected rows. Function do not work for SELECT statements. Use it only for UPDATE, DELETE, and INSERT.
self : | A FFSql. |
Returns : | Number of affected rows or 0 if error. |
gboolean ff_sql_execute (FFSql *self);
Execute an unprepared DDL statement without parameter or any prepared statement.
self : | A FFSql. |
Returns : | TRUE if successfully executed, or FALSE otherwise. |
gboolean ff_sql_execute_direct (FFSql *self, const gchar *sql_string, gboolean first_prepare);
Execute sql_string statement. If first_prepare is TRUE statement will be prepared before execution.
self : | A FFSql. |
sql_string : | A string containing an SQL statement. |
first_prepare : | A boolean flag. |
Returns : | TRUE if executed successfully, or FALSE otherwise. |
gboolean ff_sql_close (FFSql *self);
Close a prepared SQL statement.
self : | A FFSql. |
Returns : | TRUE if successfully closed, or FALSE otherwise. |
gboolean ff_sql_prepare (FFSql *self);
Prepares an unprepared statement
self : | A FFSql. |
Returns : | TRUE if sql prepared successfully, or FALSE otherwise |
gboolean ff_sql_eof (FFSql *self);
Get End Of File status.
self : | A FFSql. |
Returns : | TRUE if no more fetches are possible, or FALSE otherwise. |
gboolean ff_sql_fetch (FFSql *self);
Fetch next record.
self : | A FFSql. |
Returns : | TRUE if fetched successfully, or FALSE otherwise. |
gboolean ff_sql_is_prepared (FFSql *self);
Get self prepared status.
self : | A FFSql. |
Returns : | TRUE if self is prepared, or FALSE otherwise. |
FFValue* ff_sql_get_value (FFSql *self, guint field_number);
Get field_number value. The returned FFValue must be freed by programmer.
GList* ff_sql_get_value_list (FFSql *self);
Get a list with values from the last fetch.
FFParameter* ff_sql_get_parameter (FFSql *self, guint parameter_number);
Get SQL parameter if statement is parametrized. The returned FFParameter must be freed by programmer.
self : | A FFSql. |
parameter_number : | Unsigned int with parameter number |
Returns : | A new FFParameter, or NULL on error. |
GList* ff_sql_get_parameter_list (FFSql *self);
Get a list with self parameters.
self : | A FFSql. |
Returns : | A new list of FFParameter. |
GList* ff_get_field_names (FFSql *self);
Get a list with field names. The return list must be released by programmer.
self : | A FFSql. |
Returns : | A list of strings with field names, or NULL if statement isn't a SELECT. |
<< FFTransaction | FFRecordset >> |