40 #include <libsql/sql_parser.h> 42 #include "sql_parser.h" 47 #include "qofquery-p.h" 49 #define _(String) dgettext (GETTEXT_PACKAGE, String) 53 #define QSQL_KVP_TABLE "sql_kvp" 55 #define END_DB_VERSION " dbversion int );" 63 sql_statement *parse_result;
66 gchar *single_global_tablename;
77 QofSqlQuery *sqn = (QofSqlQuery *) g_new0 (QofSqlQuery, 1);
79 sqn->qof_query = NULL;
80 sqn->parse_result = NULL;
82 sqn->single_global_tablename = NULL;
91 qof_sql_query_destroy (QofSqlQuery * q)
96 sql_destroy (q->parse_result);
133 get_table_and_param (
char *str,
char **tab,
char **param)
135 char *end = strchr (str,
'.');
148 dequote_string (
char *str)
152 if ((
'\'' == str[0]) || (
'\"' == str[0]))
162 handle_single_condition (QofSqlQuery * query, sql_condition * cond)
168 sql_field_item *sparam, *svalue;
169 gchar *qparam_name, *qvalue_name, *table_name, *param_name;
170 gchar *sep, *path, *str, *p;
182 PWARN (
"missing condition");
188 if (NULL == cond->d.pair.left)
190 PWARN (
"missing left parameter");
193 sparam = cond->d.pair.left->item;
194 if (SQL_name != sparam->type)
196 PWARN (
"we support only parameter names at this time (parsed %d)",
200 qparam_name = sparam->d.name->data;
201 if (NULL == qparam_name)
203 PWARN (
"missing parameter name");
210 if (NULL == cond->d.pair.right)
212 PWARN (
"missing right parameter");
215 svalue = cond->d.pair.right->item;
216 if (SQL_name != svalue->type)
218 PWARN (
"we support only simple values (parsed as %d)",
222 qvalue_name = svalue->d.name->data;
223 if (NULL == qvalue_name)
225 PWARN (
"missing value");
228 qvalue_name = dequote_string (qvalue_name);
233 if (0 == strncasecmp (qvalue_name,
"kvp://", 6))
235 if (NULL == query->kvp_join)
237 PWARN (
"missing kvp frame");
240 kv = kvp_frame_get_value (query->kvp_join, qvalue_name + 5);
245 kvt = kvp_value_get_type (kv);
248 qvalue_name = tmpbuff;
254 sprintf (tmpbuff,
"%" G_GINT64_FORMAT
"\n", ival);
259 double ival = kvp_value_get_double (kv);
260 sprintf (tmpbuff,
"%26.18g\n", ival);
277 PWARN (
"unhandled kvp type=%d", kvt);
284 param_list = qof_query_build_param_list (qparam_name, NULL);
290 qop = QOF_COMPARE_EQUAL;
293 qop = QOF_COMPARE_GT;
296 qop = QOF_COMPARE_LT;
299 qop = QOF_COMPARE_GTE;
302 qop = QOF_COMPARE_LTE;
305 qop = QOF_COMPARE_NEQ;
310 PWARN (
"Unsupported compare op (parsed as %u)", cond->op);
317 get_table_and_param (qparam_name, &table_name, ¶m_name);
318 if (NULL == table_name)
320 table_name = query->single_global_tablename;
322 if (NULL == table_name)
324 PWARN (
"Need to specify an object class to query");
330 PWARN (
"The query object \'%s\' is not known", table_name);
337 PWARN (
"The parameter \'%s\' on object \'%s\' is not known",
338 param_name, table_name);
342 if (!strcmp (param_type, QOF_TYPE_STRING))
344 pred_data = qof_query_string_predicate (qop,
346 QOF_STRING_MATCH_CASEINSENSITIVE,
349 else if (!strcmp (param_type, QOF_TYPE_CHAR))
352 if (QOF_COMPARE_NEQ == qop)
353 cm = QOF_CHAR_MATCH_NONE;
354 pred_data = qof_query_char_predicate (cm, qvalue_name);
356 else if (!strcmp (param_type, QOF_TYPE_INT32))
358 gint32 ival = atoi (qvalue_name);
359 pred_data = qof_query_int32_predicate (qop, ival);
361 else if (!strcmp (param_type, QOF_TYPE_INT64))
363 gint64 ival = atoll (qvalue_name);
364 pred_data = qof_query_int64_predicate (qop, ival);
366 else if (!strcmp (param_type, QOF_TYPE_DOUBLE))
368 double ival = atof (qvalue_name);
369 pred_data = qof_query_double_predicate (qop, ival);
371 else if (!strcmp (param_type, QOF_TYPE_BOOLEAN))
374 pred_data = qof_query_boolean_predicate (qop, ival);
385 qof_query_time_predicate (qop, QOF_DATE_MATCH_NORMAL,
388 else if (!strcmp (param_type, QOF_TYPE_NUMERIC))
393 qof_query_numeric_predicate (qop, QOF_NUMERIC_MATCH_ANY, ival);
395 else if (!strcmp (param_type, QOF_TYPE_DEBCRED))
401 qof_query_numeric_predicate (qop, QOF_NUMERIC_MATCH_ANY, ival);
403 else if (!strcmp (param_type, QOF_TYPE_GUID))
409 PWARN (
"unable to parse guid: %s", qvalue_name);
417 if (QOF_COMPARE_NEQ == qop)
418 gm = QOF_GUID_MATCH_NONE;
419 guid_list = g_list_append (NULL, &guid);
420 pred_data = qof_query_guid_predicate (gm, guid_list);
422 g_list_free (guid_list);
424 else if (!strcmp (param_type, QOF_TYPE_KVP))
429 sep = strchr (qvalue_name,
':');
444 if ((32 == len) && (32 == strspn (str,
"0123456789abcdef")))
448 kval = kvp_value_new_guid (&guid);
450 else if (len == strspn (str,
"0123456789"))
452 kval = kvp_value_new_gint64 (atoll (str));
454 else if ((p = strchr (str,
'.')) &&
455 ((len - 1) == (strspn (str,
"0123456789") +
456 strspn (p + 1,
"0123456789"))))
458 kval = kvp_value_new_double (atof (str));
461 else if ((p = strchr (str,
'/')) &&
462 ((len - 1) == (strspn (str,
"0123456789") +
463 strspn (p + 1,
"0123456789"))))
467 kval = kvp_value_new_numeric (num);
469 else if ((p = strchr (str,
'-')) &&
470 (p = strchr (p + 1,
'-')) &&
471 (p = strchr (p + 1,
' ')) &&
472 (p = strchr (p + 1,
':')) && (p = strchr (p + 1,
':')))
480 kvp_value_new_time (qt);
487 kval = kvp_value_new_string (str);
493 PWARN (
"The predicate type \"%s\" is unsupported for now",
506 handle_where (QofSqlQuery * query, sql_where * swear)
515 QofQuery *qleft = handle_where (query, swear->d.pair.left);
516 QofQuery *qright = handle_where (query, swear->d.pair.right);
521 switch (swear->d.pair.op)
542 QofQuery *qq = handle_where (query, swear->d.negated);
550 sql_condition *cond = swear->d.single;
551 return handle_single_condition (query, cond);
560 handle_sort_order (QofSqlQuery * query, GList * sorder_list)
564 gboolean direction[3];
566 sql_order_field *sorder;
572 for (i = 0; i < 3; i++)
579 sorder = sorder_list->data;
582 if (SQL_asc == sorder->order_type)
590 qparam_name = n->data;
594 qof_query_build_param_list (qparam_name, NULL);
601 sorder_list = sorder_list->next;
608 direction[1], direction[2]);
614 qof_sql_insertCB (
const QofParam * param,
const gchar * insert_string,
618 sql_insert_statement *sis;
619 gboolean G_GNUC_UNUSED registered_type;
627 gchar cm_char, *tail;
632 void (*string_setter) (
QofEntity *,
const gchar *);
635 void (*double_setter) (
QofEntity *, gdouble);
636 void (*boolean_setter) (
QofEntity *, gboolean);
637 void (*i32_setter) (
QofEntity *, gint32);
638 void (*i64_setter) (
QofEntity *, gint64);
639 void (*char_setter) (
QofEntity *, gchar);
642 g_return_if_fail (param || insert_string || query);
643 ent = query->inserted_entity;
644 sis = query->parse_result->statement;
645 type = g_strdup_printf (
"%s", sis->table->d.simple);
647 ENTER (
" param=%s param_type=%s type=%s content=%s",
648 param->param_name, param->param_type, type, insert_string);
649 if (
safe_strcmp (param->param_type, QOF_TYPE_STRING) == 0)
652 (void (*)(
QofEntity *,
const char *)) param->param_setfcn;
653 if (string_setter != NULL)
655 string_setter (ent, insert_string);
657 registered_type = TRUE;
659 if (
safe_strcmp (param->param_type, QOF_TYPE_TIME) == 0)
667 if((time_setter != NULL) && (qof_time_is_valid(qt)))
669 time_setter (ent, qt);
672 if ((
safe_strcmp (param->param_type, QOF_TYPE_NUMERIC) == 0) ||
673 (
safe_strcmp (param->param_type, QOF_TYPE_DEBCRED) == 0))
678 if (numeric_setter != NULL)
680 numeric_setter (ent, cm_numeric);
683 if (
safe_strcmp (param->param_type, QOF_TYPE_GUID) == 0)
685 cm_guid = g_new (
GUID, 1);
688 LEAVE (
" string to guid failed for %s", insert_string);
703 if (
safe_strcmp (param->param_type, QOF_TYPE_INT32) == 0)
706 cm_i32 = (gint32) strtol (insert_string, &tail, 0);
710 (void (*)(
QofEntity *, gint32)) param->param_setfcn;
711 if (i32_setter != NULL)
713 i32_setter (ent, cm_i32);
724 (_(
"When converting SQLite strings into numbers, an " 725 "overflow has been detected. The SQLite database " 726 "'%s' contains invalid data in a field that is meant " 727 "to hold a number."), TRUE));
730 if (
safe_strcmp (param->param_type, QOF_TYPE_INT64) == 0)
733 cm_i64 = strtoll (insert_string, &tail, 0);
737 (void (*)(
QofEntity *, gint64)) param->param_setfcn;
738 if (i64_setter != NULL)
740 i64_setter (ent, cm_i64);
751 (_(
"When converting SQLite strings into numbers, an " 752 "overflow has been detected. The SQLite database " 753 "'%s' contains invalid data in a field that is meant " 754 "to hold a number."), TRUE));
757 if (
safe_strcmp (param->param_type, QOF_TYPE_DOUBLE) == 0)
760 cm_double = strtod (insert_string, &tail);
764 (void (*)(
QofEntity *, double)) param->param_setfcn;
765 if (double_setter != NULL)
767 double_setter (ent, cm_double);
771 if (
safe_strcmp (param->param_type, QOF_TYPE_BOOLEAN) == 0)
784 (void (*)(
QofEntity *, gboolean)) param->param_setfcn;
785 if (boolean_setter != NULL)
787 boolean_setter (ent, cm_boolean);
790 if (
safe_strcmp (param->param_type, QOF_TYPE_KVP) == 0)
794 if (
safe_strcmp (param->param_type, QOF_TYPE_CHAR) == 0)
796 cm_char = *insert_string;
797 char_setter = (void (*)(
QofEntity *, char)) param->param_setfcn;
798 if (char_setter != NULL)
800 char_setter (ent, cm_char);
807 qof_query_set_insert_table (QofSqlQuery * query)
809 sql_insert_statement *sis;
811 sis = query->parse_result->statement;
812 switch (sis->table->type)
817 query->single_global_tablename =
818 g_strdup_printf (
"%s", sis_t->d.simple);
820 query->single_global_tablename);
821 PINFO (
" insert set to table: %s", sis_t->d.simple);
826 PWARN (
"SQL insert only handles simple statements");
832 qof_query_insert (QofSqlQuery * query)
834 GList *field_list, *value_list, *cur;
835 const gchar *param_name;
840 sql_insert_statement *sis;
842 sql_field_item *item;
845 query->param_list = NULL;
852 sis = query->parse_result->statement;
853 if (!sis->fields || !sis->values)
855 LEAVE (
" NULL insert statement");
858 type = g_strdup (query->single_global_tablename);
862 LEAVE (
" unable to create instance of type %s", type);
865 query->inserted_entity = &inst->
entity;
866 value_list = sis->values;
867 for (field_list = sis->fields; field_list != NULL;
868 field_list = field_list->next)
870 field = value_list->data;
872 for (cur = item->d.name; cur != NULL; cur = cur->next)
875 g_strdup_printf (
"%s",
876 dequote_string ((
char *) cur->data));
878 field = field_list->data;
880 for (cur = item->d.name; cur != NULL; cur = cur->next)
882 param_name = g_strdup_printf (
"%s", (
char *) cur->data);
887 qof_sql_insertCB (param, value, query);
889 value_list = g_list_next (value_list);
892 return query->inserted_entity;
896 sql_type_as_string (sql_statement_type type)
928 sql_select_statement *sss;
935 if (query->qof_query)
938 sql_destroy (query->parse_result);
939 query->qof_query = NULL;
943 buf = g_strdup (str);
944 query->parse_result = sql_parse (buf);
947 if (!query->parse_result)
949 LEAVE (
"parse error");
953 if ((SQL_select != query->parse_result->type)
954 && (SQL_insert != query->parse_result->type))
957 (
"currently, only SELECT or INSERT statements are supported, " 958 "got type=%s", sql_type_as_string (query->parse_result->type));
967 tables = sql_statement_get_tables (query->parse_result);
968 if (1 == g_list_length (tables))
970 query->single_global_tablename = tables->data;
973 if (SQL_insert == query->parse_result->type)
976 qof_query_set_insert_table (query);
977 LEAVE (
" insert statement parsed OK");
980 sss = query->parse_result->statement;
985 query->qof_query = handle_where (query, swear);
986 if (NULL == query->qof_query)
988 LEAVE (
" no query found");
997 handle_sort_order (query, sss->order);
1004 query->single_global_tablename);
1019 if (NULL == query->qof_query)
1021 PINFO (
" Null query");
1029 qof_query_print (query->qof_query);
1031 if (SQL_insert == query->parse_result->type)
1034 results = g_list_append (results, qof_query_insert (query));
1051 if (NULL == query->qof_query)
1059 qof_query_print (query->qof_query);
1068 typedef struct ent_and_string
1073 gchar * full_kvp_path;
1076 static gulong kvp_id = 0;
1077 static gboolean kvp_table_exists = FALSE;
1080 create_sql_from_param_cb (
QofParam * param, gpointer user_data)
1086 g_return_if_fail (param);
1087 data = (
eas*) user_data;
1088 ENTER (
"%s %s", data->ent->e_type, param->param_name);
1089 g_return_if_fail (data->ent);
1091 data->str = g_strdup (
"");
1093 if (!param->param_setfcn)
1097 if (0 ==
safe_strcmp (param->param_type, QOF_TYPE_KVP))
1100 if (g_list_find (references, param))
1105 e = param->param_getfcn (data->ent, param);
1108 PINFO (
" ref=%p GUID=%s", e, value);
1113 g_strescape (value, NULL);
1115 value = g_strdup (
"");
1116 if (!g_str_has_suffix (data->str,
"("))
1119 tmp = g_strjoin (
"", data->str,
", '", value,
"'", NULL);
1126 tmp = g_strjoin (
"", data->str,
"'", value,
"'", NULL);
1130 LEAVE (
"%s", data->str);
1144 if ((0 ==
safe_strcmp (param->param_type, QOF_TYPE_GUID)) &&
1145 (0 ==
safe_strcmp (param->param_name, QOF_PARAM_GUID)))
1146 return g_strdup_printf (
" %s char(32) primary key not null",
1148 if (0 ==
safe_strcmp (param->param_type, QOF_TYPE_GUID))
1149 return g_strdup_printf (
" %s char(32)", param->param_name);
1151 if (!param->param_setfcn)
1153 if (0 ==
safe_strcmp (param->param_type, QOF_TYPE_STRING))
1154 return g_strdup_printf (
" %s mediumtext", param->param_name);
1155 if (0 ==
safe_strcmp (param->param_type, QOF_TYPE_BOOLEAN))
1156 return g_strdup_printf (
" %s int", param->param_name);
1157 if ((0 ==
safe_strcmp (param->param_type, QOF_TYPE_NUMERIC))
1158 || (0 ==
safe_strcmp (param->param_type, QOF_TYPE_DOUBLE))
1159 || (0 ==
safe_strcmp (param->param_type, QOF_TYPE_DEBCRED)))
1161 return g_strdup_printf (
" %s text", param->param_name);
1163 if (0 ==
safe_strcmp (param->param_type, QOF_TYPE_INT32))
1164 return g_strdup_printf (
" %s int", param->param_name);
1165 if (0 ==
safe_strcmp (param->param_type, QOF_TYPE_TIME))
1166 return g_strdup_printf (
" %s datetime", param->param_name);
1167 if (0 ==
safe_strcmp (param->param_type, QOF_TYPE_CHAR))
1168 return g_strdup_printf (
" %s char(1)", param->param_name);
1171 if (0 ==
safe_strcmp (param->param_type, QOF_TYPE_KVP))
1172 return g_strdup (
"");
1176 return g_strdup (
"");
1179 return g_strdup_printf (
" %s char(32)", param->param_name);
1184 string_param_foreach (
QofParam * param, gpointer user_data)
1186 gchar *p_str, * tmp;
1189 PINFO (
"string_param_foreach:%s", param->param_name);
1190 data = (
eas *)user_data;
1191 if ((0 ==
safe_strcmp (param->param_type, QOF_TYPE_KVP)) &&
1192 (kvp_table_exists == FALSE))
1194 g_free (data->kvp_str);
1196 g_strdup_printf (
" CREATE TABLE %s (%s, %s, %s, %s, %s, %s",
1198 "guid char(32)",
"path mediumtext",
"type mediumtext",
1199 "value text", END_DB_VERSION);
1207 data->str = g_strdup(
"");
1208 tmp = g_strjoin (
"", data->str, p_str,
",", NULL);
1222 eas * data = (
eas *)user_data;
1223 g_return_if_fail (data->str);
1225 if (!param->param_setfcn)
1229 if (0 ==
safe_strcmp (param->param_type, QOF_TYPE_KVP))
1231 PINFO (
" kvp support tag");
1234 if (!g_str_has_suffix (data->str,
"("))
1237 add = g_strconcat (data->str,
", ", param->param_name, NULL);
1244 add = g_strjoin (
"", data->str, param->param_name, NULL);
1258 path = g_strdup(
"");
1260 data = (
eas*)user_data;
1261 g_return_if_fail (key && val && data);
1262 n = kvp_value_get_type (val);
1273 path = g_strjoin (
"/", data->full_kvp_path, key, NULL);
1275 g_strdup_printf (
"'%s', '%s', '%s'", key, path,
1277 DEBUG (
" %s", data->str);
1282 path = g_strjoin (
"/", data->full_kvp_path, key, NULL);
1283 g_free (data->full_kvp_path);
1284 data->full_kvp_path = path;
1291 PERR (
" unsupported value = %d", kvp_value_get_type (val));
1295 LEAVE (
" %s", data->str);
1306 ENTER (
" key=%s", key);
1307 data = (
eas*)user_data;
1308 g_return_if_fail (key && val && data);
1309 n = kvp_value_get_type (val);
1320 path = g_strjoin (
"/", data->full_kvp_path, key, NULL);
1322 g_strdup_printf (
"type='%s', value='%s' WHERE path='%s' and ",
1324 DEBUG (
" %s", data->str);
1329 path = g_strjoin (
"/", data->full_kvp_path, key, NULL);
1330 g_free (data->full_kvp_path);
1331 data->full_kvp_path = path;
1338 PERR (
" unsupported value = %d", kvp_value_get_type (val));
1342 LEAVE (
" %s", data->str);
1348 gchar * sql_str, * start;
1353 ENTER (
"create table for %s", obj->e_type);
1354 start = g_strdup_printf (
"CREATE TABLE %s (", obj->e_type);
1356 data.str = g_strdup(
"");
1357 data.kvp_str = g_strdup(
"");
1359 sql_str = g_strjoin (
"", start, data.str, END_DB_VERSION, data.kvp_str, NULL);
1361 g_free (data.kvp_str);
1363 LEAVE (
"sql_str=%s", sql_str);
1370 gchar * sql_str, * start;
1373 g_return_val_if_fail (ent, NULL);
1376 ENTER (
"create table for %s", ent->e_type);
1377 start = g_strdup_printf (
"CREATE TABLE %s (", ent->e_type);
1379 data.str = g_strdup(
"");
1380 data.kvp_str = g_strdup(
"");
1382 sql_str = g_strjoin (
"", start, data.str, END_DB_VERSION, data.kvp_str, NULL);
1384 LEAVE (
"sql_str=%s", sql_str);
1393 gchar * command, * fields, * values, *id, *gstr, *sql_str, *kvp;
1396 data.str = g_strdup(
"");
1399 ENTER (
" insert a single '%s'", ent->e_type);
1402 DEBUG (
" guid=%s", gstr);
1403 command = g_strdup_printf (
"INSERT into %s (guid ", ent->e_type);
1406 fields = g_strdup(data.str);
1409 data.str = g_strdup(
"");
1410 data.full_kvp_path = g_strdup(
"");
1418 id = g_strdup_printf (
"%lu", kvp_id);
1422 " (kvp_id, guid, type, path, value) VALUES ('",
id,
"', '",
1423 gstr,
"', ", data.str,
");", NULL);
1428 sql_str = g_strjoin (
"", command, fields,
") VALUES ('", gstr,
"' ",
1429 values,
");", kvp, NULL);
1434 g_free (data.full_kvp_path);
1435 LEAVE (
"sql_str=%s", sql_str);
1440 collect_kvp (
QofEntity * ent, gpointer user_data)
1444 gchar * gstr, * name, * key;
1445 const QofParam * G_GNUC_UNUSED param;
1447 name = (gchar *) user_data;
1449 key = g_strconcat (
"collection/", name,
"/guid/", NULL);
1452 collguid = kvp_value_new_string(gstr);
1462 gchar *gstr, * sql_str, * param_str;
1469 ENTER (
" modified %s param:%s", ent->e_type, inst->
param->param_name);
1472 param = inst->
param;
1478 coll = param->param_getfcn (ent, param);
1479 name = g_strdup (param->param_name);
1486 g_strescape (param_str, NULL);
1487 sql_str = g_strconcat (
"UPDATE ", ent->e_type,
" SET ",
1488 inst->
param->param_name,
" = '", param_str,
1489 "' WHERE ", QOF_TYPE_GUID,
"='", gstr,
"';", NULL);
1490 LEAVE (
"sql_str=%s", sql_str);
1498 gchar *gstr, * sql_str;
1510 ENTER (
" modified %s param:%s", ent->e_type, inst->
param->param_name);
1513 data.str = g_strdup(
"");
1514 data.full_kvp_path = g_strdup(
"");
1516 start = g_strjoin (
"",
"UPDATE ",
kvp_table_name,
" SET ", NULL);
1520 sql_str = g_strjoin (
"", start, data.str,
" guid='", gstr,
"';", NULL);
1522 g_free (data.full_kvp_path);
1524 LEAVE (
"sql_str=%s", sql_str);
1537 gchar * gstr, * sql_str;
1538 ENTER (
" %s", ent->e_type);
1541 sql_str = g_strconcat (
"DELETE from ", ent->e_type,
" WHERE ",
1543 " WHERE kvp_id ",
"='", gstr,
"';", NULL);
1552 ENTER (
" drop table for '%s'", ent->e_type);
1553 sql_str = g_strdup_printf (
"DROP TABLE %s;", ent->e_type);
1554 LEAVE (
"sql_str=%s", sql_str);
1560 g_return_if_fail (name);
1576 kvp_table_exists = exist;
const gchar * qof_util_whitespace_filter(const gchar *val)
#define QOF_DATE_FORMAT_UTC
QOF UTC format, xsd:date compatible. QOF_UTC_DATE_FORMAT "%Y-%m-%dT%H:%M:%SZ".
QofErrorId qof_error_register(const gchar *err_message, gboolean use_file)
Generate and register a new error.
#define PERR(format, args...)
gpointer qof_object_new_instance(QofIdTypeConst type_name, QofBook *book)
QofQueryPredData * qof_query_kvp_predicate_path(QofQueryCompare how, const gchar *path, const KvpValue *value)
#define QOF_TYPE_COLLECT
secondary collections are used for one-to-many references between entities and are implemented using ...
#define PINFO(format, args...)
void qof_sql_query_parse(QofSqlQuery *query, const gchar *str)
gboolean qof_class_is_registered(QofIdTypeConst obj_name)
struct _QofNumeric QofNumeric
A rational-number type.
void qof_date_free(QofDate *date)
void qof_class_param_foreach(QofIdTypeConst obj_name, QofParamForeachCB cb, gpointer user_data)
gchar * qof_sql_entity_insert(QofEntity *ent)
Build a SQL 'INSERT' statement for this entity.
KvpValueType
possible types in the union KvpValue
gboolean string_to_guid(const gchar *string, GUID *guid)
gchar * qof_sql_object_create_table(QofObject *obj)
Build a SQL 'CREATE' statement for this object.
struct _KvpFrame KvpFrame
void qof_sql_query_set_book(QofSqlQuery *q, QofBook *book)
static void kvpvalue_to_sql_update(const gchar *key, KvpValue *val, gpointer user_data)
gboolean qof_log_check(QofLogModule log_module, QofLogLevel log_level)
void qof_sql_entity_set_kvp_id(gulong id)
Set the initial index value of the KVP table.
gint qof_util_bool_to_int(const gchar *val)
void qof_query_set_sort_increasing(QofQuery *q, gboolean prim_inc, gboolean sec_inc, gboolean tert_inc)
gulong qof_sql_entity_get_kvp_id(void)
Get the index value of the KVP table after the operation(s).
gboolean kvp_frame_is_empty(KvpFrame *frame)
QofBook * qof_instance_get_book(QofInstance *inst)
#define LEAVE(format, args...)
#define GUID_ENCODING_LENGTH
struct _QofQuery QofQuery
QofTime * qof_date_to_qtime(const QofDate *qd)
Full range replacement for struct tm.
KvpFrame * kvp_frame_set_value(KvpFrame *frame, const gchar *key_path, const KvpValue *value)
Copy the KvpValue into the frame.
128bit denominator/numerator maths.
gchar * qof_sql_entity_update(QofEntity *ent)
Build a SQL 'UPDATE' statement for the current entity parameter.
gint64 kvp_value_get_gint64(const KvpValue *value)
gchar * qof_sql_entity_create_table(QofEntity *ent)
Build a SQL 'CREATE' statement for this entity.
struct QofCollection_s QofCollection
const QofParam * qof_class_get_parameter(QofIdTypeConst obj_name, const gchar *parameter)
const GUID * qof_instance_get_guid(QofInstance *inst)
QofDate * qof_date_parse(const gchar *str, QofDateFormat df)
Convert a timestamp to a QofTime.
struct _KvpValue KvpValue
void qof_query_destroy(QofQuery *q)
KvpFrame * qof_instance_get_slots(QofInstance *inst)
gchar * qof_sql_entity_update_list(QofEntity *ent, GList **params)
Build a SQL 'UPDATE' statement for a list of parameters.
static gchar * string_param_to_sql(QofParam *param)
gboolean qof_numeric_from_string(const gchar *str, QofNumeric *n)
QofQuery * qof_sql_query_get_query(QofSqlQuery *q)
void qof_collection_foreach(QofCollection *col, QofEntityForeachCB cb_func, gpointer user_data)
void qof_query_add_term(QofQuery *q, GSList *param_list, QofQueryPredData *pred_data, QofQueryOp op)
void qof_sql_query_set_kvp(QofSqlQuery *q, KvpFrame *kvp)
static gchar * kvp_table_name
#define DEBUG(format, args...)
void qof_query_set_book(QofQuery *q, QofBook *book)
void qof_query_set_sort_order(QofQuery *q, GSList *params1, GSList *params2, GSList *params3)
gchar * qof_util_param_to_string(QofEntity *ent, const QofParam *param)
Converts a parameter to a string for storage or display.
static void create_param_list(QofParam *param, gpointer user_data)
list just the parameter names
gchar * guid_to_string_buff(const GUID *guid, gchar *buff)
void qof_sql_entity_set_kvp_exists(gboolean exist)
Set or clear a flag that the KVP table exists or not.
gchar * kvp_value_to_bare_string(const KvpValue *val)
General purpose function to convert any KvpValue to a string.
QofQuery * qof_query_merge(QofQuery *q1, QofQuery *q2, QofQueryOp op)
gchar * kvp_value_get_string(const KvpValue *value)
Private QOF SQL generation routines.
QofSqlQuery * qof_sql_query_new(void)
GList * qof_class_get_referenceList(QofIdTypeConst type)
List of the parameters that could be references.
gchar * qof_sql_entity_update_kvp(QofEntity *ent)
Build a SQL 'UPDATE' statement for the KVP data in this entity.
QofQuery * qof_query_invert(QofQuery *q)
gchar * qof_sql_entity_drop_table(QofEntity *ent)
Build a SQL 'DROP' statement for this entity type.
void kvp_frame_for_each_slot(KvpFrame *f, KvpValueForeachCB proc, gpointer data)
void qof_sql_entity_set_kvp_tablename(const gchar *name)
Set a default KVP table name for each backend.
GList * qof_query_run(QofQuery *q)
const gchar * QofIdTypeConst
#define PWARN(format, args...)
struct QofTime64 QofTime
Use a 64-bit signed int QofTime.
const GUID * qof_entity_get_guid(QofEntity *ent)
QofType qof_class_get_parameter_type(QofIdTypeConst obj_name, const gchar *param_name)
QofBackend * qof_book_get_backend(QofBook *book)
Retrieve the backend used by this book.
gint safe_strcmp(const gchar *da, const gchar *db)
KvpFrame * kvp_value_get_frame(const KvpValue *value)
GList * qof_sql_query_run(QofSqlQuery *query, const gchar *str)
Perform the query, return the results.
struct ent_and_string eas
#define ENTER(format, args...)
gchar * qof_sql_entity_delete(QofEntity *ent)
Build a SQL 'DELETE' statement for this entity.
QofQuery * qof_query_create(void)
const gchar * QofLogModule
#define QOF_QUERY_FIRST_TERM
64bit time/date handling.
void qof_query_search_for(QofQuery *q, QofIdTypeConst obj_type)
GList * qof_sql_query_rerun(QofSqlQuery *query)
static void kvpvalue_to_sql_insert(const gchar *key, KvpValue *val, gpointer user_data)