QOF
0.8.0
|
QOF client-side SQL parser - interfaces with libgda. More...
#include "config.h"
#include <stdlib.h>
#include <errno.h>
#include <glib.h>
#include <libintl.h>
#include "sql_parser.h"
#include <time.h>
#include "qof.h"
#include "qofsql-p.h"
#include "qofquery-p.h"
Go to the source code of this file.
Defines | |
#define | _(String) dgettext (GETTEXT_PACKAGE, String) |
#define | QSQL_KVP_TABLE "sql_kvp" |
#define | END_DB_VERSION " dbversion int );" |
Typedefs | |
typedef struct ent_and_string | eas |
Functions | |
QofSqlQuery * | qof_sql_query_new (void) |
void | qof_sql_query_destroy (QofSqlQuery *q) |
QofQuery * | qof_sql_query_get_query (QofSqlQuery *q) |
void | qof_sql_query_set_book (QofSqlQuery *q, QofBook *book) |
void | qof_sql_query_set_kvp (QofSqlQuery *q, KvpFrame *kvp) |
static void | get_table_and_param (char *str, char **tab, char **param) |
static char * | dequote_string (char *str) |
static QofQuery * | handle_single_condition (QofSqlQuery *query, sql_condition *cond) |
static QofQuery * | handle_where (QofSqlQuery *query, sql_where *swear) |
static void | handle_sort_order (QofSqlQuery *query, GList *sorder_list) |
static void | qof_sql_insertCB (const QofParam *param, const gchar *insert_string, QofSqlQuery *query) |
static void | qof_query_set_insert_table (QofSqlQuery *query) |
static QofEntity * | qof_query_insert (QofSqlQuery *query) |
static const char * | sql_type_as_string (sql_statement_type type) |
void | qof_sql_query_parse (QofSqlQuery *query, const char *str) |
GList * | qof_sql_query_run (QofSqlQuery *query, const char *str) |
GList * | qof_sql_query_rerun (QofSqlQuery *query) |
static void | create_sql_from_param_cb (QofParam *param, gpointer user_data) |
static gchar * | string_param_to_sql (QofParam *param) |
static void | string_param_foreach (QofParam *param, gpointer user_data) |
static void | create_param_list (QofParam *param, gpointer user_data) |
list just the parameter names | |
static void | kvpvalue_to_sql_insert (const gchar *key, KvpValue *val, gpointer user_data) |
static void | kvpvalue_to_sql_update (const gchar *key, KvpValue *val, gpointer user_data) |
gchar * | qof_sql_object_create_table (QofObject *obj) |
Build a SQL 'CREATE' statement for this object. | |
gchar * | qof_sql_entity_create_table (QofEntity *ent) |
Build a SQL 'CREATE' statement for this entity. | |
gchar * | qof_sql_entity_insert (QofEntity *ent) |
Build a SQL 'INSERT' statement for this entity. | |
static void | collect_kvp (QofEntity *ent, gpointer user_data) |
gchar * | qof_sql_entity_update (QofEntity *ent) |
Build a SQL 'UPDATE' statement for the current entity parameter. | |
gchar * | qof_sql_entity_update_kvp (QofEntity *ent) |
Build a SQL 'UPDATE' statement for the KVP data in this entity. | |
gchar * | qof_sql_entity_update_list (QofEntity *ent, GList **params) |
Build a SQL 'UPDATE' statement for a list of parameters. | |
gchar * | qof_sql_entity_delete (QofEntity *ent) |
Build a SQL 'DELETE' statement for this entity. | |
gchar * | qof_sql_entity_drop_table (QofEntity *ent) |
Build a SQL 'DROP' statement for this entity type. | |
void | qof_sql_entity_set_kvp_tablename (const gchar *name) |
Set a default KVP table name for each backend. | |
void | qof_sql_entity_set_kvp_id (gulong id) |
Set the initial index value of the KVP table. | |
gulong | qof_sql_entity_get_kvp_id (void) |
Get the index value of the KVP table after the operation(s). | |
void | qof_sql_entity_set_kvp_exists (gboolean exist) |
Set or clear a flag that the KVP table exists or not. | |
Variables | |
static gchar * | kvp_table_name = NULL |
static QofLogModule | log_module = "qof-query" |
static gulong | kvp_id = 0 |
static gboolean | kvp_table_exists = FALSE |
QOF client-side SQL parser - interfaces with libgda.
Intended to parse incoming SQL into QOF queries (SELECT or INSERT) and prepare SQL commands from QOF entities (CREATE, UPDATE, INSERT, DELETE and DROP) for use in SQL-based backends.
Definition in file qofsql.c.
typedef struct ent_and_string eas |
simple helper struct for passing between SQL-generating functions
static void create_param_list | ( | QofParam * | param, |
gpointer | user_data | ||
) | [static] |
list just the parameter names
Definition at line 1220 of file qofsql.c.
{ eas * data = (eas *)user_data; g_return_if_fail (data->str); /* avoid creating database fields for calculated values */ if (!param->param_setfcn) return; /* avoid setting KVP even if a param_setfcn has been set because a QofSetterFunc for KVP is quite pointless. */ if (0 == safe_strcmp (param->param_type, QOF_TYPE_KVP)) { PINFO (" kvp support tag"); return; } if (!g_str_has_suffix (data->str, "(")) { gchar *add; add = g_strconcat (data->str, ", ", param->param_name, NULL); g_free (data->str); data->str = add; } else { gchar * add; add = g_strjoin ("", data->str, param->param_name, NULL); g_free (data->str); data->str = add; } }
static void kvpvalue_to_sql_insert | ( | const gchar * | key, |
KvpValue * | val, | ||
gpointer | user_data | ||
) | [static] |
returns the VALUES for INSERT in pre-defined order
Definition at line 1252 of file qofsql.c.
{ eas * data; KvpValueType n; gchar * path; path = g_strdup(""); ENTER (" "); data = (eas*)user_data; g_return_if_fail (key && val && data); n = kvp_value_get_type (val); switch (n) { case KVP_TYPE_GINT64: case KVP_TYPE_DOUBLE: case KVP_TYPE_NUMERIC: case KVP_TYPE_STRING: case KVP_TYPE_GUID: case KVP_TYPE_TIME: case KVP_TYPE_BOOLEAN: { path = g_strjoin ("/", data->full_kvp_path, key, NULL); data->str = g_strdup_printf ("'%s', '%s', '%s'", key, path, kvp_value_to_bare_string (val)); DEBUG (" %s", data->str); break; } case KVP_TYPE_FRAME: { path = g_strjoin ("/", data->full_kvp_path, key, NULL); g_free (data->full_kvp_path); data->full_kvp_path = path; kvp_frame_for_each_slot (kvp_value_get_frame (val), kvpvalue_to_sql_insert, data); break; } default: { PERR (" unsupported value = %d", kvp_value_get_type (val)); break; } } LEAVE (" %s", data->str); }
static void kvpvalue_to_sql_update | ( | const gchar * | key, |
KvpValue * | val, | ||
gpointer | user_data | ||
) | [static] |
returns the VALUES for UPDATE in pre-defined order
Definition at line 1300 of file qofsql.c.
{ eas * data; KvpValueType n; gchar * path; ENTER (" key=%s", key); data = (eas*)user_data; g_return_if_fail (key && val && data); n = kvp_value_get_type (val); switch (n) { case KVP_TYPE_GINT64: case KVP_TYPE_DOUBLE: case KVP_TYPE_NUMERIC: case KVP_TYPE_STRING: case KVP_TYPE_GUID: case KVP_TYPE_TIME: case KVP_TYPE_BOOLEAN: { path = g_strjoin ("/", data->full_kvp_path, key, NULL); data->str = g_strdup_printf ("type='%s', value='%s' WHERE path='%s' and ", key, kvp_value_to_bare_string (val), path); DEBUG (" %s", data->str); break; } case KVP_TYPE_FRAME: { path = g_strjoin ("/", data->full_kvp_path, key, NULL); g_free (data->full_kvp_path); data->full_kvp_path = path; kvp_frame_for_each_slot (kvp_value_get_frame (val), kvpvalue_to_sql_update, data); break; } default: { PERR (" unsupported value = %d", kvp_value_get_type (val)); break; } } LEAVE (" %s", data->str); }
static gchar* string_param_to_sql | ( | QofParam * | param | ) | [static] |
Definition at line 1134 of file qofsql.c.
{ /* Handle the entity GUID. Ensure that reference GUIDs must not also try to be primary keys and can be NULL. */ if ((0 == safe_strcmp (param->param_type, QOF_TYPE_GUID)) && (0 == safe_strcmp (param->param_name, QOF_PARAM_GUID))) return g_strdup_printf (" %s char(32) primary key not null", param->param_name); if (0 == safe_strcmp (param->param_type, QOF_TYPE_GUID)) return g_strdup_printf (" %s char(32)", param->param_name); /* avoid creating database fields for calculated values */ if (!param->param_setfcn) return NULL; if (0 == safe_strcmp (param->param_type, QOF_TYPE_STRING)) return g_strdup_printf (" %s mediumtext", param->param_name); if (0 == safe_strcmp (param->param_type, QOF_TYPE_BOOLEAN)) return g_strdup_printf (" %s int", param->param_name); if ((0 == safe_strcmp (param->param_type, QOF_TYPE_NUMERIC)) || (0 == safe_strcmp (param->param_type, QOF_TYPE_DOUBLE)) || (0 == safe_strcmp (param->param_type, QOF_TYPE_DEBCRED))) { return g_strdup_printf (" %s text", param->param_name); } if (0 == safe_strcmp (param->param_type, QOF_TYPE_INT32)) return g_strdup_printf (" %s int", param->param_name); if (0 == safe_strcmp (param->param_type, QOF_TYPE_TIME)) return g_strdup_printf (" %s datetime", param->param_name); if (0 == safe_strcmp (param->param_type, QOF_TYPE_CHAR)) return g_strdup_printf (" %s char(1)", param->param_name); /* kvp data is stored separately - actually this is really a no-op because entities do not need a param_setfcn for kvp data. */ if (0 == safe_strcmp (param->param_type, QOF_TYPE_KVP)) return g_strdup (""); if (0 == safe_strcmp (param->param_type, QOF_TYPE_COLLECT)) return g_strdup (""); // return g_strdup_printf (" %s char(32)", param->param_name); /* catch references */ return g_strdup_printf (" %s char(32)", param->param_name); }
gchar* kvp_table_name = NULL [static] |