QOF  0.8.7
Macros | Functions | Variables
qof-sqlite.c File Reference

Public interface of qof-backend-sqlite. More...

#include "config.h"
#include <errno.h>
#include <stdlib.h>
#include <time.h>
#include <glib/gstdio.h>
#include <sqlite.h>
#include <glib.h>
#include <libintl.h>
#include "qof.h"
#include "qofsql-p.h"
#include "qof-sqlite.h"
#include "kvputil-p.h"

Go to the source code of this file.

Macros

#define _(String)   dgettext (GETTEXT_PACKAGE, String)
 
#define ACCESS_METHOD   "sqlite"
 
#define PRIORITY_HIGH   9
 
#define PRIORITY_STANDARD   5
 
#define PRIORITY_LOW   0
 
#define QSQL_ERROR   -1
 
#define QSQL_KVP_TABLE   "sqlite_kvp"
 
#define END_DB_VERSION   " dbversion int );"
 

Functions

static KvpValuestring_to_kvp_value (const gchar *content, KvpValueType type)
 
static G_GNUC_UNUSED void kvpvalue_to_sql (const gchar *key, KvpValue *val, gpointer builder)
 
static void delete_event (QofEntity *ent, QofEventId event_type, gpointer handler_data, gpointer event_data)
 use the new-style event handlers for insert and update insert runs after QOF_EVENT_CREATE delete runs before QOF_EVENT_DESTROY
 
static void create_event (QofEntity *ent, QofEventId event_type, gpointer handler_data, gpointer event_data)
 
static void qsql_modify (QofBackend *be, QofInstance *inst)
 
static gint record_foreach (gpointer builder, gint col_num, gchar **strings, gchar **columnNames)
 
static void update_dirty (gpointer value, gpointer builder)
 
static gint create_dirty_list (gpointer builder, gint col_num, gchar **strings, gchar **columnNames)
 
static gint mark_entity (gpointer builder, gint col_num, gchar **strings, gchar **columnNames)
 
static void qsql_create (QofBackend *be, QofInstance *inst)
 
static void check_state (QofEntity *ent, gpointer builder)
 
static gint build_kvp_table (gpointer builder, gint col_num, gchar **strings, gchar **columnNames)
 chekc kvp data once per record More...
 
static void qsql_load_kvp (QSQLiteBackend *qsql_be)
 
static void qsql_class_foreach (QofObject *obj, gpointer data)
 
static void qsql_backend_createdb (QofBackend *be, QofSession *session)
 
static void qsql_backend_opendb (QofBackend *be, QofSession *session)
 
static void qsqlite_session_begin (QofBackend *be, QofSession *session, const gchar *book_path, gboolean ignore_lock, gboolean create_if_nonexistent)
 
static void qsqlite_db_load (QofBackend *be, QofBook *book)
 
static void qsqlite_write_db (QofBackend *be, QofBook *book)
 
static gboolean qsql_determine_file_type (const gchar *path)
 
static void qsqlite_session_end (QofBackend *be)
 
static void qsqlite_destroy_backend (QofBackend *be)
 
static void qsql_provider_free (QofBackendProvider *prov)
 
static QofBackendqsql_backend_new (void)
 Starts the backend and creates the context. More...
 
void qof_sqlite_provider_init (void)
 Initialises the SQLite backend. More...
 

Variables

static QofLogModule log_module = QOF_MOD_SQLITE
 
static gboolean loading = FALSE
 

Detailed Description

Public interface of qof-backend-sqlite.

Author
Copyright 2006-2008 Neil Williams linux.nosp@m.@cod.nosp@m.ehelp.nosp@m..co..nosp@m.uk

Definition in file qof-sqlite.c.

Macro Definition Documentation

#define PRIORITY_HIGH   9

Indicates an item with high priority.

Definition at line 46 of file qof-sqlite.c.

#define PRIORITY_LOW   0

Indicates a low priority item.

Definition at line 50 of file qof-sqlite.c.

#define PRIORITY_STANDARD   5

Indicates an item with default priority.

Definition at line 48 of file qof-sqlite.c.

#define QSQL_ERROR   -1

Indicate an error to sqlite

Definition at line 52 of file qof-sqlite.c.

#define QSQL_KVP_TABLE   "sqlite_kvp"

One KVP table per file for all instances.

Definition at line 55 of file qof-sqlite.c.

Function Documentation

static gint build_kvp_table ( gpointer  builder,
gint  col_num,
gchar **  strings,
gchar **  columnNames 
)
static

chekc kvp data once per record

creates a new KvpFrame as data for a GHashTable with the guid as key

Todo:
improve error checking support in case the SQLite data is tweaked manually.

Definition at line 663 of file qof-sqlite.c.

665 {
666  QSQLiteBackend *qsql_be;
667  struct QsqlBuilder *qb;
668  KvpFrame *frame;
669  KvpValueType type;
670  KvpValue *value;
671  gulong max;
672  gchar *tail;
673 
674  g_return_val_if_fail (builder, QSQL_ERROR);
675  qb = (struct QsqlBuilder *) builder;
676  max = 0;
677  qsql_be = qb->qsql_be;
678  g_return_val_if_fail ((col_num < 4), QSQL_ERROR);
679  g_return_val_if_fail (strings[2], QSQL_ERROR);
680  frame = kvp_frame_new ();
681  /* columnNames = fields strings = values
682  [0]=kvp_id, [1]=guid, [2]=path, [3]=type, [4]=value
683  get type from type_string */
684  type = qof_id_to_kvp_value_type (strings[3]);
685  if (type == 0)
686  {
687  PERR (" invalid type returned from kvp table");
688  return QSQL_ERROR;
689  }
690  /* use the type to make a KvpValue from value */
691  value = string_to_kvp_value (strings[4], type);
692  if (!value)
693  {
694  PERR (" invalid KvpValue for type: %d", type);
695  return QSQL_ERROR;
696  }
697  /* add the KvpValue to the frame at path */
698  kvp_frame_set_value (frame, strings[2], value);
699  /* index the frame under the entity GUID */
700  g_hash_table_insert (qsql_be->kvp_table, strings[1], frame);
701  /* index the guid under the kvp_id */
702  g_hash_table_insert (qsql_be->kvp_id, strings[0], strings[1]);
703  errno = 0;
704  max = strtol (strings[0], &tail, 0);
705  if (errno == 0)
706  {
707  qsql_be->index = (max > qsql_be->index) ? max : qsql_be->index;
708  }
709  return SQLITE_OK;
710 }
#define PERR(format, args...)
Definition: qoflog.h:183
static KvpValue * string_to_kvp_value(const gchar *content, KvpValueType type)
Definition: qof-sqlite.c:117
KvpValueType
possible types in the union KvpValue
Definition: kvpframe.h:87
struct _KvpFrame KvpFrame
Definition: kvpframe.h:74
KvpFrame * kvp_frame_set_value(KvpFrame *frame, const gchar *key_path, const KvpValue *value)
Copy the KvpValue into the frame.
Definition: kvpframe.c:496
struct _KvpValue KvpValue
Definition: kvpframe.h:78
KvpValueType qof_id_to_kvp_value_type(QofIdTypeConst type_string)
Convert a QofIdType to a KvpValueType.
Definition: kvputil.c:228
KvpFrame * kvp_frame_new(void)
Definition: kvpframe.c:97
#define QSQL_ERROR
Definition: qof-sqlite.c:52
static void create_event ( QofEntity ent,
QofEventId  event_type,
gpointer  handler_data,
gpointer  event_data 
)
static

receives QSQLiteBackend, passes on QsqlBuilder

Bug:
create one func to create_param_list and create_each_param

Definition at line 293 of file qof-sqlite.c.

295 {
296  QofBackend *be;
297  struct QsqlBuilder qb;
298  QSQLiteBackend *qsql_be;
299  gchar *gstr;
300  KvpFrame *slots;
301 
302  qsql_be = (QSQLiteBackend *) handler_data;
303  be = (QofBackend *) qsql_be;
304  if (!ent)
305  return;
306  if (0 == safe_strcmp (ent->e_type, QOF_ID_BOOK))
307  return;
308  if (!qof_class_is_registered (ent->e_type))
309  return;
310  switch (event_type)
311  {
312  case QOF_EVENT_CREATE:
313  {
314  ENTER (" insert:%s", ent->e_type);
315  gstr = g_strnfill (GUID_ENCODING_LENGTH + 1, ' ');
317  ent), gstr);
318  DEBUG (" guid=%s", gstr);
319  qb.ent = ent;
320  qb.sql_str = qof_sql_entity_insert (ent);
322  DEBUG (" sql_str=%s", qb.sql_str);
323  if (sqlite_exec (qsql_be->sqliteh, qb.sql_str,
324  NULL, &qb, &qsql_be->err) != SQLITE_OK)
325  {
326  qof_error_set_be (be, qsql_be->err_insert);
327  qsql_be->error = TRUE;
328  PERR (" error on create_event:%s", qsql_be->err);
329  }
330  else
331  {
332  ((QofInstance *) ent)->dirty = FALSE;
333  qsql_be->error = FALSE;
334  g_free (qb.sql_str);
335  g_free (gstr);
336  LEAVE (" ");
337  break;
338  }
339  /* insert sqlite_kvp data */
340  slots = qof_instance_get_slots ((QofInstance *) ent);
341  if (slots)
342  {
343  /* id, guid, path, type, value */
344  qb.sql_str = qof_sql_entity_insert (ent);
345  if (sqlite_exec (qsql_be->sqliteh, qb.sql_str,
346  NULL, &qb, &qsql_be->err) != SQLITE_OK)
347  {
348  qof_error_set_be (be, qsql_be->err_insert);
349  qsql_be->error = TRUE;
350  PERR (" error on KVP create_event:%s", qsql_be->err);
351  }
352  else
353  {
354  ((QofInstance *) ent)->dirty = FALSE;
355  qsql_be->error = FALSE;
356  g_free (qb.sql_str);
357  g_free (gstr);
358  LEAVE (" ");
359  break;
360  }
361  }
362  g_free (qb.sql_str);
363  g_free (gstr);
364  LEAVE (" ");
365  break;
366  }
367  default:
368  break;
369  }
370 }
#define PERR(format, args...)
Definition: qoflog.h:183
gboolean qof_class_is_registered(QofIdTypeConst obj_name)
Definition: qofclass.c:133
gchar * qof_sql_entity_insert(QofEntity *ent)
Build a SQL &#39;INSERT&#39; statement for this entity.
Definition: qofsql.c:1389
struct _KvpFrame KvpFrame
Definition: kvpframe.h:74
#define LEAVE(format, args...)
Definition: qoflog.h:227
#define GUID_ENCODING_LENGTH
Definition: guid.h:64
#define QOF_EVENT_CREATE
Definition: qofevent.h:71
const GUID * qof_instance_get_guid(QofInstance *inst)
Definition: qofinstance.c:79
KvpFrame * qof_instance_get_slots(QofInstance *inst)
Definition: qofinstance.c:95
#define DEBUG(format, args...)
Definition: qoflog.h:208
gchar * guid_to_string_buff(const GUID *guid, gchar *buff)
gint safe_strcmp(const gchar *da, const gchar *db)
Definition: qofutil.c:75
#define ENTER(format, args...)
Definition: qoflog.h:217
static G_GNUC_UNUSED void kvpvalue_to_sql ( const gchar *  key,
KvpValue val,
gpointer  builder 
)
static

returns the VALUES for INSERT in pre-defined order

Definition at line 195 of file qof-sqlite.c.

196 {
197  QSQLiteBackend *qsql_be;
198  struct QsqlBuilder *qb;
199  KvpValueType n;
200 
201  ENTER (" ");
202  qb = (struct QsqlBuilder *) builder;
203  qsql_be = qb->qsql_be;
204  g_return_if_fail (key && val && qsql_be);
205  n = kvp_value_get_type (val);
206  switch (n)
207  {
208  case KVP_TYPE_GINT64:
209  case KVP_TYPE_DOUBLE:
210  case KVP_TYPE_NUMERIC:
211  case KVP_TYPE_STRING:
212  case KVP_TYPE_GUID:
213  case KVP_TYPE_TIME:
214  case KVP_TYPE_BOOLEAN:
215  {
216  /* ("kvp_id int primary key not null", "guid char(32)", "path mediumtext",
217  "type mediumtext", "value text", */
218 
219  qb->sql_str =
220  g_strdup_printf (" kvp key=%s val=%s type=%s", key,
223  DEBUG (" %s", qb->sql_str);
224  qb->has_slots = TRUE;
225  break;
226  }
227  case KVP_TYPE_FRAME:
228  {
230  kvpvalue_to_sql, qb);
231  break;
232  }
233  default:
234  {
235  PERR (" unsupported value = %d", kvp_value_get_type (val));
236  break;
237  }
238  }
239  LEAVE (" %s", qb->sql_str);
240 }
#define PERR(format, args...)
Definition: qoflog.h:183
QofIdTypeConst kvp_value_type_to_qof_id(KvpValueType n)
Convert a KvpValueType to a QofIdType.
Definition: kvputil.c:246
KvpValueType
possible types in the union KvpValue
Definition: kvpframe.h:87
Unique identifier.
Definition: kvpframe.h:118
#define LEAVE(format, args...)
Definition: qoflog.h:227
128bit denominator/numerator maths.
Definition: kvpframe.h:106
64bit integer
Definition: kvpframe.h:94
#define DEBUG(format, args...)
Definition: qoflog.h:208
gchar * kvp_value_to_bare_string(const KvpValue *val)
General purpose function to convert any KvpValue to a string.
Definition: kvpframe.c:1834
void kvp_frame_for_each_slot(KvpFrame *f, KvpValueForeachCB proc, gpointer data)
Definition: kvpframe.c:1642
Simple boolean type.
Definition: kvpframe.h:136
standard C string
Definition: kvpframe.h:112
static G_GNUC_UNUSED void kvpvalue_to_sql(const gchar *key, KvpValue *val, gpointer builder)
Definition: qof-sqlite.c:195
KvpFrame * kvp_value_get_frame(const KvpValue *value)
Definition: kvpframe.c:1546
standard C double type
Definition: kvpframe.h:100
#define ENTER(format, args...)
Definition: qoflog.h:217
64bit time/date handling.
Definition: kvpframe.h:124
static QofBackend* qsql_backend_new ( void  )
static

Starts the backend and creates the context.

Note
Take care when handling the main QSQLiteBackend context and the QsqlBuilder context. QSQLiteBackend contains the long-term data, QsqlBuilder the transient. Only QSQLiteBackend is guaranteed to exist at any one time. All functions need to be able to locate the QSQLiteBackend. Functions started from the QofBackend routines or from the event handlers will be passed the QofBackend which can be cast to QSQLiteBackend. Internal functions create a local QsqlBuilder struct and set the QSQLiteBackend pointer before passing a pointer to the QsqlBuilder. Use the qsql_ prefix only for functions that are started from QofBackend and the _event suffix for QofEvent.

Definition at line 1012 of file qof-sqlite.c.

1013 {
1014  QSQLiteBackend *qsql_be;
1015  QofBackend *be;
1016 
1017  ENTER (" ");
1018  qsql_be = g_new0 (QSQLiteBackend, 1);
1019  be = (QofBackend *) qsql_be;
1020  qof_backend_init (be);
1021  qsql_be->kvp_table = g_hash_table_new (g_str_hash, g_str_equal);
1022  qsql_be->kvp_id = g_hash_table_new (g_str_hash, g_str_equal);
1023  qsql_be->dbversion = QOF_OBJECT_VERSION;
1024  qsql_be->stm_type = SQL_NONE;
1025  qsql_be->err_delete =
1026  qof_error_register (_("Unable to delete record."), FALSE);
1027  qsql_be->err_create =
1028  qof_error_register (_("Unable to create record."), FALSE);
1029  qsql_be->err_insert =
1030  qof_error_register (_("Unable to insert a new record."), FALSE);
1031  qsql_be->err_update =
1032  qof_error_register (_("Unable to update existing record."), FALSE);
1033  be->session_begin = qsqlite_session_begin;
1034 
1035  be->session_end = qsqlite_session_end;
1036  be->destroy_backend = qsqlite_destroy_backend;
1037  be->load = qsqlite_db_load;
1038  be->save_may_clobber_data = NULL;
1039  /* begin: create an empty entity if none exists,
1040  even if events are suspended. */
1041  be->begin = qsql_create;
1042  /* commit: write to sqlite, commit undo record. */
1043  be->commit = qsql_modify;
1044  be->rollback = NULL;
1045  /* would need a QofQuery back to QofSqlQuery conversion. */
1046  be->compile_query = NULL;
1047  /* unused */
1048  be->free_query = NULL;
1049  be->run_query = NULL;
1050  be->counter = NULL;
1051  /* The QOF SQLite backend is not multi-user - all QOF users are the same. */
1052  be->events_pending = NULL;
1053  be->process_events = NULL;
1054 
1055  be->sync = qsqlite_write_db;
1056  be->load_config = NULL;
1057  be->get_config = NULL;
1058  LEAVE (" ");
1059  return be;
1060 }
QofErrorId qof_error_register(const gchar *err_message, gboolean use_file)
Generate and register a new error.
Definition: qoferror.c:73
gboolean(* save_may_clobber_data)(QofBackend *)
Definition: qofbackend-p.h:320
#define QOF_OBJECT_VERSION
Definition: qofobject.h:57
#define LEAVE(format, args...)
Definition: qoflog.h:227
#define ENTER(format, args...)
Definition: qoflog.h:217
static void qsql_class_foreach ( QofObject obj,
gpointer  data 
)
static

receives QSQLiteBackend from QofBackend

Definition at line 755 of file qof-sqlite.c.

756 {
757  struct QsqlBuilder qb;
758  QSQLiteBackend *qsql_be;
759  QofBackend *be;
760 
761  qsql_be = (QSQLiteBackend *) data;
762  be = (QofBackend *) qsql_be;
763  qb.qsql_be = qsql_be;
764  qb.e_type = obj->e_type;
765  ENTER (" obj_type=%s", qb.e_type);
766  switch (qsql_be->stm_type)
767  {
768  case SQL_NONE:
769  case SQL_INSERT:
770  case SQL_DELETE:
771  case SQL_UPDATE:
772  {
773  break;
774  }
775  case SQL_CREATE:
776  {
777  /* KVP is handled separately */
778  qb.sql_str = qof_sql_object_create_table (obj);
779  if (sqlite_exec (qsql_be->sqliteh, qb.sql_str,
780  NULL, NULL, &qsql_be->err) != SQLITE_OK)
781  {
782  qof_error_set_be (be, qsql_be->err_create);
783  qsql_be->error = TRUE;
784  PERR (" error on SQL_CREATE:%s", qsql_be->err);
785  }
786  g_free (qb.sql_str);
787  break;
788  }
789  case SQL_LOAD:
790  {
791  qb.sql_str =
792  g_strdup_printf ("SELECT * FROM %s;", obj->e_type);
793  PINFO (" sql=%s", qb.sql_str);
794  if (sqlite_exec (qsql_be->sqliteh, qb.sql_str,
795  record_foreach, &qb, &qsql_be->err) != SQLITE_OK)
796  {
797  qsql_be->error = TRUE;
798  PERR (" error on SQL_LOAD:%s", qsql_be->err);
799  }
800  break;
801  }
802  case SQL_WRITE:
803  {
804  if (!qof_book_not_saved (qsql_be->book))
805  break;
806  qof_object_foreach (obj->e_type, qsql_be->book, check_state,
807  &qb);
808  break;
809  }
810  }
811  LEAVE (" ");
812 }
#define PERR(format, args...)
Definition: qoflog.h:183
#define PINFO(format, args...)
Definition: qoflog.h:199
void qof_object_foreach(QofIdTypeConst type_name, QofBook *book, QofEntityForeachCB cb, gpointer user_data)
Definition: qofobject.c:174
gchar * qof_sql_object_create_table(QofObject *obj)
Build a SQL &#39;CREATE&#39; statement for this object.
Definition: qofsql.c:1346
#define LEAVE(format, args...)
Definition: qoflog.h:227
gboolean qof_book_not_saved(QofBook *book)
Definition: qofbook.c:135
static gint record_foreach(gpointer builder, gint col_num, gchar **strings, gchar **columnNames)
Definition: qof-sqlite.c:417
#define ENTER(format, args...)
Definition: qoflog.h:217
static void qsql_load_kvp ( QSQLiteBackend *  qsql_be)
static

only call once per book

Definition at line 714 of file qof-sqlite.c.

715 {
716  struct QsqlBuilder qb;
717  QofBackend *be;
718  gint sq_code;
719 
720  g_return_if_fail (qsql_be);
721  sq_code = SQLITE_OK;
722  be = (QofBackend *) qsql_be;
723  qb.sql_str =
724  g_strdup_printf ("SELECT kvp_id from %s;", QSQL_KVP_TABLE);
725  sq_code = sqlite_exec (qsql_be->sqliteh, qb.sql_str, build_kvp_table,
726  &qb, &qsql_be->err);
727  /* catch older files without a sqlite_kvp table */
728  if (sq_code == SQLITE_ERROR)
729  {
730  g_free (qb.sql_str);
731  qb.sql_str =
732  g_strdup_printf ("CREATE TABLE %s (%s, %s, %s, %s, %s, %s",
733  QSQL_KVP_TABLE, "kvp_id int primary key not null",
734  "guid char(32)", "path mediumtext", "type mediumtext",
735  "value text", END_DB_VERSION);
736  PINFO (" creating kvp table. sql=%s", qb.sql_str);
737  if (sqlite_exec (qsql_be->sqliteh, qb.sql_str,
738  record_foreach, &qb, &qsql_be->err) != SQLITE_OK)
739  {
740  qsql_be->error = TRUE;
741  PERR (" unable to create kvp table:%s", qsql_be->err);
742  }
743  }
744  else if (sq_code != SQLITE_OK)
745  {
746  qof_error_set_be (be, qsql_be->err_create);
747  qsql_be->error = TRUE;
748  PERR (" error on KVP select:%s:%s:%d", qb.sql_str, qsql_be->err, sq_code);
749  }
750  g_free (qb.sql_str);
751 }
#define PERR(format, args...)
Definition: qoflog.h:183
#define QSQL_KVP_TABLE
Definition: qof-sqlite.c:55
#define PINFO(format, args...)
Definition: qoflog.h:199
static gint build_kvp_table(gpointer builder, gint col_num, gchar **strings, gchar **columnNames)
chekc kvp data once per record
Definition: qof-sqlite.c:663
static gint record_foreach(gpointer builder, gint col_num, gchar **strings, gchar **columnNames)
Definition: qof-sqlite.c:417
static gint record_foreach ( gpointer  builder,
gint  col_num,
gchar **  strings,
gchar **  columnNames 
)
static
Todo:
need a KVP version to load data into the slots

Definition at line 417 of file qof-sqlite.c.

419 {
420  QSQLiteBackend *qsql_be;
421  struct QsqlBuilder *qb;
422  const QofParam *param;
423  QofInstance *inst;
424  QofEntity *ent;
425  gint i;
426 
427  g_return_val_if_fail (builder, QSQL_ERROR);
428  qb = (struct QsqlBuilder *) builder;
429  qsql_be = qb->qsql_be;
431  inst = (QofInstance *) qof_object_new_instance (qb->e_type, qsql_be->book);
432  ent = &inst->entity;
433  for (i = 0; i < col_num; i++)
434  {
435  /* get param and set as string */
436  param = qof_class_get_parameter (qb->e_type, columnNames[i]);
437  if (!param)
438  continue;
439  /* set the inst->param entry */
440  inst->param = param;
441  if (0 == safe_strcmp (columnNames[i], QOF_TYPE_GUID))
442  {
443  GUID *guid;
444  guid = guid_malloc ();
445  if (!string_to_guid (strings[i], guid))
446  {
447  DEBUG (" set guid failed:%s", strings[i]);
448  return QSQL_ERROR;
449  }
450  qof_entity_set_guid (ent, guid);
451  }
452  if (strings[i])
453  qof_util_param_set_string (ent, param, strings[i]);
454  }
455  qof_event_resume ();
456  return SQLITE_OK;
457 }
gpointer qof_object_new_instance(QofIdTypeConst type_name, QofBook *book)
Definition: qofobject.c:42
GUID * guid_malloc(void)
Definition: guid.c:64
gboolean string_to_guid(const gchar *string, GUID *guid)
const QofParam * qof_class_get_parameter(QofIdTypeConst obj_name, const gchar *parameter)
Definition: qofclass.c:147
#define DEBUG(format, args...)
Definition: qoflog.h:208
gboolean qof_util_param_set_string(QofEntity *ent, const QofParam *param, const gchar *value_string)
Set a parameter from a value string.
Definition: qofutil.c:647
QofEntity entity
Definition: qofinstance-p.h:39
Definition: guid.h:53
void qof_event_suspend(void)
Suspend all engine events.
Definition: qofevent.c:145
void qof_event_resume(void)
Definition: qofevent.c:156
void qof_entity_set_guid(QofEntity *ent, const GUID *guid)
Definition: qofid.c:92
gint safe_strcmp(const gchar *da, const gchar *db)
Definition: qofutil.c:75
const QofParam * param
Definition: qofinstance-p.h:53
#define QSQL_ERROR
Definition: qof-sqlite.c:52
static KvpValue* string_to_kvp_value ( const gchar *  content,
KvpValueType  type 
)
static
Todo:
reconcile the duplication with the QSF (and GDA) version

Definition at line 117 of file qof-sqlite.c.

118 {
119  gchar *tail;
120  gint64 cm_i64;
121  gdouble cm_double;
122  QofNumeric cm_numeric;
123  GUID *cm_guid;
124 
125  switch (type)
126  {
127  case KVP_TYPE_GINT64:
128  {
129  errno = 0;
130  cm_i64 = strtoll (content, &tail, 0);
131  if (errno == 0)
132  {
133  return kvp_value_new_gint64 (cm_i64);
134  }
135  break;
136  }
137  case KVP_TYPE_DOUBLE:
138  {
139  errno = 0;
140  cm_double = strtod (content, &tail);
141  if (errno == 0)
142  return kvp_value_new_double (cm_double);
143  break;
144  }
145  case KVP_TYPE_NUMERIC:
146  {
147  qof_numeric_from_string (content, &cm_numeric);
148  return kvp_value_new_numeric (cm_numeric);
149  break;
150  }
151  case KVP_TYPE_STRING:
152  {
153  return kvp_value_new_string (content);
154  break;
155  }
156  case KVP_TYPE_GUID:
157  {
158  cm_guid = g_new0 (GUID, 1);
159  if (TRUE == string_to_guid (content, cm_guid))
160  return kvp_value_new_guid (cm_guid);
161  break;
162  }
163  case KVP_TYPE_TIME:
164  {
165  QofDate *qd;
166  QofTime *qt;
167  KvpValue *retval;
168 
169  qd = qof_date_parse (content, QOF_DATE_FORMAT_UTC);
170  if (qd)
171  {
172  qt = qof_date_to_qtime (qd);
173  retval = kvp_value_new_time (qt);
174  qof_date_free (qd);
175  qof_time_free (qt);
176  return retval;
177  }
178  else
179  PERR (" failed to parse date");
180  }
181  case KVP_TYPE_BOOLEAN:
182  {
183  gboolean val;
184  val = qof_util_bool_to_int (content);
185  return kvp_value_new_boolean (val);
186  }
187  default:
188  break;
189  }
190  return NULL;
191 }
#define QOF_DATE_FORMAT_UTC
QOF UTC format, xsd:date compatible. QOF_UTC_DATE_FORMAT "%Y-%m-%dT%H:%M:%SZ".
Definition: qofdate.h:277
#define PERR(format, args...)
Definition: qoflog.h:183
void qof_date_free(QofDate *date)
Definition: qofdate.c:642
gboolean string_to_guid(const gchar *string, GUID *guid)
Unique identifier.
Definition: kvpframe.h:118
KvpValue * kvp_value_new_boolean(gboolean value)
Definition: kvpframe.c:1223
gint qof_util_bool_to_int(const gchar *val)
Definition: qofutil.c:252
QofTime * qof_date_to_qtime(const QofDate *qd)
Definition: qofdate.c:926
Full range replacement for struct tm.
Definition: qofdate.h:138
128bit denominator/numerator maths.
Definition: kvpframe.h:106
QofDate * qof_date_parse(const gchar *str, QofDateFormat df)
Convert a timestamp to a QofTime.
Definition: qofdate.c:557
struct _KvpValue KvpValue
Definition: kvpframe.h:78
gboolean qof_numeric_from_string(const gchar *str, QofNumeric *n)
Definition: qofnumeric.c:1116
void qof_time_free(QofTime *qt)
Free a QofTime when no longer required.
Definition: qoftime.c:56
64bit integer
Definition: kvpframe.h:94
Definition: guid.h:53
struct QofTime64 QofTime
Use a 64-bit signed int QofTime.
Definition: qoftime.h:112
Simple boolean type.
Definition: kvpframe.h:136
standard C string
Definition: kvpframe.h:112
standard C double type
Definition: kvpframe.h:100
64bit time/date handling.
Definition: kvpframe.h:124