FFSql

FFSql — Class for handling SQL statements.

Synopsis


#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);


Description

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

Details

struct FFSql

struct FFSql;


struct FFSqlClass

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.

ff_sql_new ()

FFSql*      ff_sql_new                      (void);

Constructor for FFSql class.

Returns : A new FFSql object.

ff_sql_get_default_transaction ()

FFTransaction* ff_sql_get_default_transaction
                                            (FFSql *self);

Get default transaction.

self : A FFSql.
Returns : A FFTransaction.

ff_sql_set_default_transaction ()

void        ff_sql_set_default_transaction  (FFSql *self,
                                             FFTransaction *tr);

Set self default transaction.

self : A FFSql.
tr : A FFTransaction.

ff_sql_get_string ()

const gchar* ff_sql_get_string              (FFSql *self);

Get SQL string.

self : A FFSql.
Returns : A string containing an SQL statement.

ff_sql_set_string ()

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.

ff_sql_get_field_name ()

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.

ff_sql_get_field_precision ()

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.

ff_sql_get_field_table_name ()

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.

ff_sql_get_field_length ()

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.

ff_sql_get_field_firebird_type_name ()

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.

ff_sql_get_parameter_name ()

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.

ff_sql_field_count ()

guint       ff_sql_field_count              (FFSql *self);

Get number of fields in SQL.

self : A FFSql.
Returns : Number of fields.

ff_sql_parameter_count ()

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.

ff_sql_record_count ()

gulong      ff_sql_record_count             (FFSql *self);

Get number of records already fetched.

self : A FFSql.
Returns : Number of fetched records.

ff_sql_affected_rows ()

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.

ff_sql_execute ()

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.

ff_sql_execute_direct ()

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.

ff_sql_close ()

gboolean    ff_sql_close                    (FFSql *self);

Close a prepared SQL statement.

self : A FFSql.
Returns : TRUE if successfully closed, or FALSE otherwise.

ff_sql_prepare ()

gboolean    ff_sql_prepare                  (FFSql *self);

Prepares an unprepared statement

self : A FFSql.
Returns : TRUE if sql prepared successfully, or FALSE otherwise

ff_sql_eof ()

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.

ff_sql_fetch ()

gboolean    ff_sql_fetch                    (FFSql *self);

Fetch next record.

self : A FFSql.
Returns : TRUE if fetched successfully, or FALSE otherwise.

ff_sql_is_prepared ()

gboolean    ff_sql_is_prepared              (FFSql *self);

Get self prepared status.

self : A FFSql.
Returns : TRUE if self is prepared, or FALSE otherwise.

ff_sql_get_value ()

FFValue*    ff_sql_get_value                (FFSql *self,
                                             guint field_number);

Get field_number value. The returned FFValue must be freed by programmer.

self : A FFSql.
field_number : Unsigned int with field number
Returns : A new FFValue initialized with field_number value, or NULL otherwise.

ff_sql_get_value_list ()

GList*      ff_sql_get_value_list           (FFSql *self);

Get a list with values from the last fetch.

self : A FFSql.
Returns : A new list of FFValue.

ff_sql_get_parameter ()

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.

ff_sql_get_parameter_list ()

GList*      ff_sql_get_parameter_list       (FFSql *self);

Get a list with self parameters.

self : A FFSql.
Returns : A new list of FFParameter.

ff_get_parameter_names ()

GList*      ff_get_parameter_names          (FFSql *self);

self :
Returns :

ff_get_field_names ()

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.

ff_sql_get_statement_type ()

gint        ff_sql_get_statement_type       (FFSql *self);

Gets statement type.

self : A FFSql.
Returns : -1 if error or isc_info_sql_stmt_select, isc_info_sql_stmt_insert, isc_info_sql_stmt_update, isc_info_sql_stmt_delete, isc_info_sql_stmt_ddl, ...(see ibase.h for more).