Re: [gnome-db] New API to build statement from a strutural description.





2009/3/24 Daniel Espinosa <esodan gmail com>
I think the API for GdaSqlBuilder could be like:

_new (GdaSqlStatementType type)
* This must build the most basic statement with no fields, table or parameters.

_set_table (GdaSqlBuilder *builder, const gchar* table, gboolean fill, GError *error)
* This could set the table to use in the statament and if 'fill' is set to TRUE then adds the all the table's fields and a condition for the Primary Key(s) to a where clausure.

_new_for_table (GdaSqlStatementType type, const gchar *table)
* This must build the most basic statement for the type specified using the given table and with a where clasure for the PrimaryKey(s) and one parameter to set (may be called "+1"). For INSERT one parameter for each filed in the table.

_add_condition_from_string (GdaSqlBuilder *builder, gint where_id, const gchar* condition, GError *error)
* This adds a new condition at the given 'where_id' parsing the 'condition', if the given fields not exists in the statement's tables then set 'error'.

_add_condition (GdaSqlBuilder *builder, gint where_id, const gchar* field, GdaSqlOperatorType operator_type, const gchar *paramenter_name, GError *error)
* This adds a new condition at the given 'where_id', use 'field', 'operator_type' and 'parameter_name' to create a condition in the form, for a GDA_SQL_OPERATOR_TYPE_EQ, 'field = ##parameter_name'. If the given field not exists in the statement's tables then set 'error'.

_add_field (GdaSqlBuilder *builder, gint part_id, const gchar* field, GError *error)
* Adds a field at the given 'part_id' (for example the main SELECT or a sub-SELECT), if the given fields not exists in the statement's tables then set 'error'.

Some general ideas:

You can add a field and get its ID, then when adding a condition with that id (may be just given the field's name), it could create a 'default' condition like FIELD = ##PARAMETER, getting the condition ID you can change the OperatorType and parameter's name.

More to come... just let me check in detail the actual code.

Thanks for the ideas. I'll keep those good ideas when I expand the API, but I want to focus first on the principles used in the whole GdaSqlBuilder which is to build pieces and identify them using an integer. Obviously you seem to like that way of doing since you already have many ideas of functions to add...

Cheers,

Vivien



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]