1
.TH "QOF Command Line Interface" 3 "26 Jun 2008" "Version 0.1.6" "gpe-expenses" \" -*- nroff -*-
5
QOF Command Line Interface \-
6
.SH "Detailed Description"
8
Includes common functions for all QOF CLI programs and provides generic functions to implement command line and interactive shell options.
10
QOF provides an outline CLI that is easily patched from the qof-generator project to make it easier to keep various QOF projects updated.
12
This CLI is easily extended to support your own functions and options and includes macros to help you keep up to date with changes in main QOF options. It is recommended that you do not edit this file, instead please feed patches back to the QOF-devel mailing list at http://lists.sourceforge.net/mailman/listinfo/qof-devel so that other projects can be updated.
18
.RI "file \fBqof-main.c\fP"
20
.RI "\fICommon functions for the QOF external framework. \fP"
25
.RI "file \fBqof-main.h\fP"
27
.RI "\fICommon functions for the QOF external framework. \fP"
35
.RI "struct \fBQofMain_s\fP"
37
.RI "\fIThe qof-main context struct. \fP"
43
.RI "#define \fB_GNU_SOURCE\fP"
46
.RI "#define \fBMAX_LINE\fP 79"
49
.RI "#define \fBERR_INDENT\fP strlen(PACKAGE) + 2"
51
.RI "\fIIndent error messages as paragraphs. \fP"
53
.RI "#define \fBQOF_DATE_STRING_LENGTH\fP MAX_DATE_LENGTH"
56
.RI "#define \fBQOF_MAIN_CLI\fP 'QOF-mod-command-line'"
59
.RI "#define \fBCATEGORY_NAME\fP 'category'"
61
.RI "\fICategory name. \fP"
63
.RI "#define \fBQSF_COMPRESS\fP 'compression_level'"
66
.RI "#define \fBQSF_ENCODING\fP 'encoding_string'"
69
.RI "#define \fBQSF_DATE_CONVERT\fP 'convert_date_to_time'"
72
.RI "#define \fBQOF_SQL_SUPPORTED\fP '^SELECT|INSERT'"
75
.RI "#define \fBQOF_CLI_OPTIONS\fP"
77
.RI "\fICommon QOF CLI options. \fP"
79
.RI "#define \fBQOF_MAIN_OP\fP"
82
.RI "#define \fBQOF_OP_VARS\fP"
85
.RI "#define \fBQOF_OP_INIT\fP"
92
.RI "typedef struct \fBQofMain_s\fP \fBQofMainContext\fP"
94
.RI "\fIThe qof-main context struct. \fP"
100
.RI "void \fBqof_main_wrap_line\fP (FILE *fp, gint indent, const gchar *template_str,...) __attribute__((format(printf"
102
.RI "\fIWrap long lines in popt-style. \fP"
104
.RI "gchar * \fBqof_main_make_utf8\fP (gchar *string)"
106
.RI "\fIConvert strings received from the wrapped objects into UTF-8. \fP"
108
.RI "static void \fBqof_main_run_sql\fP (\fBQofMainContext\fP *context)"
111
.RI "static void \fBqof_main_run_query\fP (\fBQofMainContext\fP *context)"
114
.RI "void \fBqof_main_free\fP (\fBQofMainContext\fP *context)"
117
.RI "static void \fBfind_param_cb\fP (QofParam *param, gpointer user_data)"
120
.RI "static void \fBbuild_database_list\fP (QofIdTypeConst obj_type, \fBQofMainContext\fP *context)"
123
.RI "static void \fBselect_cb\fP (QofObject *obj, gpointer data)"
126
.RI "void \fBqof_main_moderate_query\fP (\fBQofMainContext\fP *context)"
128
.RI "\fIAssemble the components of the query. \fP"
130
.RI "static void \fBoption_cb\fP (QofBackendOption *option, gpointer data)"
133
.RI "void \fBqof_mod_compression\fP (gint64 gz_level, \fBQofMainContext\fP *context)"
136
.RI "void \fBqof_mod_encoding\fP (const gchar *encoding, \fBQofMainContext\fP *context)"
139
.RI "void \fBqof_mod_convert_deprecated\fP (gint64 convert, \fBQofMainContext\fP *context)"
142
.RI "void \fBqof_cmd_xmlfile\fP (\fBQofMainContext\fP *context)"
145
.RI "static void \fBqof_main_list\fP (QofObject *obj, gpointer G_GNUC_UNUSED data)"
148
.RI "void \fBqof_main_select\fP (\fBQofMainContext\fP *context)"
151
.RI "void \fBqof_cmd_list\fP (void)"
153
.RI "\fILists all databases supported by the current QOF framework. \fP"
155
.RI "static void \fBexplain_cb\fP (QofParam *param, gpointer G_GNUC_UNUSED user_data)"
158
.RI "void \fBqof_cmd_explain\fP (\fBQofMainContext\fP *context)"
161
.RI "void \fBqof_mod_category\fP (const gchar *category, \fBQofMainContext\fP *data)"
163
.RI "\fIShorthand to only query objects that are set to the specified category. \fP"
165
.RI "glong \fBqof_mod_get_local_offset\fP (void)"
167
.RI "\fIGet the gmt_off offset for this locale. \fP"
169
.RI "void \fBqof_mod_database\fP (const gchar *database, \fBQofMainContext\fP *data)"
171
.RI "\fIShorthand to only query objects within one specific supported database. \fP"
173
.RI "void \fBqof_mod_time\fP (const gchar *date_time, \fBQofMainContext\fP *data)"
175
.RI "\fIShorthand to only query objects that contain the specified date. \fP"
177
.RI "void \fBqof_mod_exclude\fP (const gchar *exclude, \fBQofMainContext\fP *data)"
179
.RI "\fIShorthand to exclude a supported database from the query. \fP"
181
.RI "void \fBqof_mod_sql\fP (const gchar *sql_query, \fBQofMainContext\fP *data)"
183
.RI "\fISpecify a SQL query on the command line. \fP"
185
.RI "void \fBqof_mod_sql_file\fP (const gchar *sql_file, \fBQofMainContext\fP *data)"
187
.RI "\fISpecify one or more SQL queries contained in a file. \fP"
189
.RI "void \fBqof_mod_write\fP (const gchar *write_file, \fBQofMainContext\fP *data)"
191
.RI "\fIWrite the results of any query to the file. \fP"
193
.RI "void \fBqof_main_show_error\fP (QofSession *session)"
195
.RI "\fIOutput error messages from QOF. \fP"
197
.RI "GSList * \fBqof_main_get_param_list\fP (QofIdTypeConst object_type, QofType param_type)"
199
.RI "\fIList of all parameters for this object of one QOF type. \fP"
205
.RI "static QofLogModule \fBlog_module\fP = 'QOF-mod-command-line'"
208
.SH "Define Documentation"
210
.SS "#define CATEGORY_NAME 'category'"
214
The name of the parameter that holds the category of the entity.
216
Many CLI data sources categorise data by user-editable category strings. If your program does not, simply implement a modified QOF_CLI_OPTIONS in your code without the category option:
220
{"category", 'c', POPT_ARG_STRING, &category, qof_op_category,
221
_("Shorthand to only query objects that are set to the specified category."),
228
Definition at line 118 of file qof-main.h.
229
.SS "#define QOF_CLI_OPTIONS"
231
Common QOF CLI options.
233
These are definitions for popt support in the CLI. Every program's popt table should start with QOF_CLI_OPTIONS or a replacement to insert the standard options into it. Also enables autohelp. End your popt option list with POPT_TABLEEND. If you want to remove any of these options, simply copy QOF_CLI_OPTIONS into a macro of your own and remove the options you do not need.
235
Definition at line 433 of file qof-main.h.
236
.SS "#define QOF_DATE_STRING_LENGTH MAX_DATE_LENGTH"
238
Maximum length of the UTC timestamp used by QSF
240
QOF_UTC_DATE_FORMAT '%Y-%m-%dT%H:%M:%SZ'
242
Definition at line 100 of file qof-main.h.
243
.SS "#define QOF_MAIN_CLI 'QOF-mod-command-line'"
245
Debug module for qof-main
247
Definition at line 103 of file qof-main.h.
248
.SS "#define QOF_MAIN_OP"
253
_(qof_op_noop, = 0) \
256
_(qof_op_category,) \
257
_(qof_op_database,) \
261
_(qof_op_sql_file,) \
265
_(qof_op_compress,) \
268
use only if you have no extended options, otherwise use as a template.
270
Definition at line 470 of file qof-main.h.
271
.SS "#define QOF_OP_INIT"
284
initialise the standard QOF CLI option variables.
286
A simple convenience macro.
288
Definition at line 499 of file qof-main.h.
289
.SS "#define QOF_OP_VARS"
294
const gchar *exclude, *date_time, *category, *database; \
295
const gchar *sql_file, *write_file, *sql_query, *filename;
297
Define the variables for the standard QOF CLI options.
299
If you remove any QOF CLI options, ensure you also remove the option variable and it's initialiser.
301
Definition at line 491 of file qof-main.h.
302
.SS "#define QOF_SQL_SUPPORTED '^SELECT|INSERT'"
304
The SQL commands supported by QOF
306
A regular expression used to exclude unsupported commands from SQL files. Anything that does \fBnot\fP match the expression will be silently ignored. This allows genuine SQL dump files to be parsed without errors.
308
A QOF object is similar to a definition of a SQL table.
310
A QOF entity is similar to an instance of a SQL record.
312
A QOF parameter is similar to data in a SQL field.
314
Certain SQL commands have no QOF equivalent and should always be ignored silently:
316
ALTER (the object parameters cannot be changed at runtime)
318
CREATE (new tables - new objects - cannot be created at runtime)
320
DROP (an object cannot be 'de-registered' without re-compiling)
322
FLUSH (QOF has no permissions system)
334
USE (QOF only has one database, itself.)
338
Definition at line 159 of file qof-main.h.
340
Referenced by qof_mod_sql_file().
341
.SS "#define QSF_COMPRESS 'compression_level'"
343
backend configuration index string for QSF
345
The identifier for the configuration option within QSF supported by the CLI. Matches the QofBackendOption->option_name in the KvpFrame holding the options.
347
Definition at line 127 of file qof-main.h.
348
.SS "#define QSF_DATE_CONVERT 'convert_date_to_time'"
350
convert deprecated date fields into times.
352
Definition at line 133 of file qof-main.h.
353
.SS "#define QSF_ENCODING 'encoding_string'"
355
backend configuration encoding string
357
Definition at line 130 of file qof-main.h.
358
.SH "Typedef Documentation"
360
.SS "typedef struct \fBQofMain_s\fP \fBQofMainContext\fP"
362
The qof-main context struct.
364
Intended as a core type for QOF-based CLI programs, wrap your own context struct around qof_main_context
365
.SH "Function Documentation"
367
.SS "void qof_cmd_explain (\fBQofMainContext\fP * context)"
369
Print a list of available parameters for a database.
371
Used with qof_mod_database to print a list of QofParam for the QofObject set in context->database.
373
Definition at line 473 of file qof-main.c.
375
References QofMain_s::database, and QofMain_s::error.
379
475 if (context->error)
381
477 fprintf (stdout, _('\nParameters of the %s database:\n\n'),
382
478 context->database);
383
479 qof_class_param_foreach (context->database, explain_cb, NULL);
384
480 fprintf (stdout, _('\nThank you for using %s\n\n'), PACKAGE);
388
.SS "void qof_cmd_list (void)"
390
Lists all databases supported by the current QOF framework.
392
Prints the name and description for each object type registered with this instance of QOF. No options are used.
394
Definition at line 445 of file qof-main.c.
396
References qof_main_wrap_line().
400
447 qof_main_wrap_line (stdout, 0,
401
448 /* Translators: This line is wrapped by the program -
402
449 please make sure you do NOT add line endings here. */
403
450 _('\n%s: You can use the supported database names with '%s -d' '
404
451 'and in SQL queries (as the table name) with '%s -s|f'. '
405
452 'Descriptions are shown only for readability.\n'),
406
453 PACKAGE, PACKAGE, PACKAGE);
407
454 fprintf (stdout, '%-20s%-20s\n', _('Name'), _('Description'));
408
455 qof_object_foreach_type (qof_main_list, NULL);
409
456 qof_main_wrap_line (stdout, 0,
410
457 /* Translators: This line is wrapped by the program -
411
458 please make sure you do NOT add line endings here. */
412
459 _('\nUse '%s -d <database> --explain' to see the list of fields '
413
460 'within any supported database.'), PACKAGE);
414
461 fprintf (stdout, _('\nThank you for using %s\n\n'), PACKAGE);
418
.SS "void qof_cmd_xmlfile (\fBQofMainContext\fP * context)"
420
query the QSF XML data
422
Definition at line 383 of file qof-main.c.
424
References QofMain_s::database, QofMain_s::encoding, ERR_INDENT, QofMain_s::exclude, QofMain_s::export_session, QofMain_s::filename, QofMain_s::gz_level, QofMain_s::input_session, qof_main_moderate_query(), qof_main_show_error(), qof_main_wrap_line(), qof_mod_compression(), qof_mod_encoding(), and QofMain_s::write_file.
428
385 QofSession *input_session, *export_session;
431
388 input_session = context->input_session;
432
389 if (0 == safe_strcmp (context->exclude, context->database)
433
390 && (context->exclude != NULL))
435
392 qof_main_wrap_line (stderr, ERR_INDENT,
436
393 /* Translators: This line is wrapped by the program -
437
394 please make sure you do NOT add line endings here. */
438
395 _('%s: Error: Cannot exclude database \'%s\' with option -e '
439
396 'because option -d is set to include the database: \'%s\'. '
440
397 'Use the \'-l\' command to see the full list of supported '
441
398 'databases.\n'), PACKAGE, context->exclude,
442
399 context->database);
443
400 qof_session_end (input_session);
444
401 LEAVE (' conflicting options');
447
404 qof_session_begin (input_session, context->filename, TRUE, FALSE);
448
405 qof_main_show_error (input_session);
449
406 if (0 != safe_strcmp (QOF_STDOUT, context->filename))
450
407 qof_session_load (input_session, NULL);
451
408 qof_main_show_error (input_session);
452
409 export_session = qof_session_new ();
453
410 context->export_session = export_session;
454
411 if (context->write_file)
456
413 qof_session_begin (export_session, context->write_file, TRUE,
458
415 qof_mod_compression (context->gz_level, context);
461
418 qof_session_begin (export_session, QOF_STDOUT, TRUE, FALSE);
462
419 qof_main_show_error (export_session);
463
420 /* ensure encoding value is set in the new export_session */
464
421 qof_mod_encoding (context->encoding, context);
465
422 qof_main_moderate_query (context);
466
423 qof_session_save (export_session, NULL);
467
424 qof_main_show_error (export_session);
468
425 qof_main_show_error (input_session);
469
426 qof_session_end (input_session);
470
427 qof_session_end (export_session);
475
.SS "void qof_main_free (\fBQofMainContext\fP * context)"
477
Free qof_main_context values when work is done.
479
Definition at line 162 of file qof-main.c.
481
References QofMain_s::category, QofMain_s::database, QofMain_s::filename, QofMain_s::sql_file, and QofMain_s::write_file.
483
Referenced by gpe_expense_close().
487
164 g_free (context->filename);
488
165 g_free (context->write_file);
489
166 g_free (context->sql_file);
490
167 g_free (context->database);
491
168 g_free (context->category);
495
.SS "GSList* qof_main_get_param_list (QofIdTypeConst object_type, QofType param_type)"
497
List of all parameters for this object of one QOF type.
499
Return a GSList of all parameters of this object that are a particular QOF type, QOF_TYPE_STRING, QOF_TYPE_BOOLEAN etc.
501
The returned GSList should be freed by the caller.
505
The return list is a singly linked list - GSList - \fBnot\fP the doubly-linked list - GList - returned by qof_class_get_referenceList.
510
\fIobject_type\fP object->e_type for the relevant object.
512
\fIparam_type\fP The type of parameter to match, QOF_TYPE_STRING etc.
517
GSList of all matching parameters or NULL if none exist.
521
.SS "gchar * qof_main_make_utf8 (gchar * string)"
523
Convert strings received from the wrapped objects into UTF-8.
527
use qof_util_make_utf8 from QOF 0.7.3
530
A wrapper for g_locale_to_utf8 that removes the extra arguments. If the string is already valid UTF-8, it is returned unchanged.
534
the converted string or the original, unchanged, string on error or if the string is already UTF-8.
539
Definition at line 103 of file qof-main.c.
541
Referenced by gpe_currency_lookup().
549
109 if (g_utf8_validate (string, -1, NULL))
551
111 value = g_locale_to_utf8 (string, -1, NULL, NULL, NULL);
554
114 PWARN (' unable to convert from locale %s', string);
555
115 PINFO ('trying to convert from ISO-8859-15.');
556
116 value = g_convert (string, -1, 'UTF-8', 'ISO-8859-15',
557
117 NULL, NULL, NULL);
560
120 PERR (' conversion failed');
569
.SS "void qof_main_moderate_query (\fBQofMainContext\fP * context)"
571
Assemble the components of the query.
573
If any SQL statements are found, run separately from any -c, -d or -t options.
575
All queries are additive: Successive queries add more entities to the result set but no entity is set more than once.
577
Definition at line 250 of file qof-main.c.
579
References QofMain_s::database, QofMain_s::exclude, QofMain_s::query, QofMain_s::sql_list, and QofMain_s::sql_str.
581
Referenced by qof_cmd_xmlfile().
585
252 GSList *date_param_list, *category_param_list;
590
257 context->query = qof_query_create ();
591
258 date_param_list = NULL;
592
259 category_param_list = NULL;
593
260 while (context->sql_list)
595
262 PINFO ('running sql_list');
596
263 context->sql_str = g_strdup (context->sql_list->data);
597
264 qof_main_run_sql (context);
598
265 qof_main_run_query (context);
599
266 if (context->query)
600
267 qof_query_clear (context->query);
601
268 g_free (context->sql_str);
602
269 context->sql_str = NULL;
604
271 context->sql_list = g_list_next (context->sql_list);
606
273 if (0 < g_list_length (context->sql_list))
608
275 context->sql_str = NULL;
609
276 g_list_free (context->sql_list);
612
279 if (context->sql_str != NULL)
614
281 PINFO ('running sql_str');
615
282 qof_main_run_sql (context);
616
283 qof_main_run_query (context);
617
284 if (context->query)
618
285 qof_query_clear (context->query);
621
288 if ((context->exclude != NULL)
622
289 && (qof_class_is_registered (context->exclude)))
624
291 qof_object_foreach_type (select_cb, context);
627
294 if ((context->database != NULL)
628
295 && (qof_class_is_registered (context->database)))
630
297 build_database_list (context->database, context);
634
301 qof_object_foreach_type (select_cb, context);
639
.SS "void qof_main_show_error (QofSession * session)"
641
Output error messages from QOF.
643
QOF will set errors in the QofSession. The application determines how to output those messages and for the CLI, this will be to stderr. Not all these messages are implemented in any one QOF CLI.
647
\fIsession\fP Any current session.
652
Definition at line 629 of file qof-main.c.
654
References ERR_INDENT, and qof_main_wrap_line().
656
Referenced by qof_cmd_xmlfile().
660
631 const gchar *fmt;
662
633 if (qof_error_check (session))
664
635 fmt = '%s: %s\n';
665
636 qof_main_wrap_line (stderr, ERR_INDENT, fmt, PACKAGE,
666
637 qof_error_get_message (session));
671
.SS "void qof_main_wrap_line (FILE * fp, gint indent, const gchar * template_str, ...)"
673
Wrap long lines in popt-style.
675
Defaults to a line width of 79 characters. Indents lines following the first according to the value of indent.
679
\fIfp\fP A file stream, including stdout or stderr.
681
\fIindent\fP The number of characters to indent from the left. Values over or equal to 79 or less than zero are adjusted.
683
\fItemplate_str\fP String to be wrapped, containing positional parameters, as specified in the Single Unix Specification. Can be translated but should \fBnot\fP contain newline characters except at the beginning or end of the message.
688
Once wrapped, the line has a newline appended. Adding a newline to the incoming string will generate a blank line.
693
Definition at line 56 of file qof-main.c.
695
Referenced by qof_cmd_list(), qof_cmd_xmlfile(), qof_main_show_error(), and qof_mod_sql_file().
699
59 gint line_length, msg_length;
703
63 line_length = MAX_LINE;
704
64 /* note the modulus. Don't use CLAMP here */
705
65 /* indent != line_length or particularly close to it. */
706
66 indent = indent >= line_length ? indent % line_length : indent;
707
67 indent = indent < 0 ? 0 : indent;
709
69 g_return_if_fail (template);
710
70 va_start (wraps, template);
711
71 message = g_strdup_vprintf (template, wraps);
713
73 g_return_if_fail (message);
714
74 msg_length = strlen (message);
715
75 while (msg_length > line_length)
720
80 chunk = message + line_length - 1;
721
81 while (chunk > message && !g_ascii_isspace (*chunk))
723
83 if (chunk == message)
724
84 break; /* give up */
725
85 while (chunk > (message + 1) && g_ascii_isspace (*chunk))
728
88 g_sprintf (format, '%%.%ds\n%%%ds', (gint) (chunk - message),
730
90 g_fprintf (fp, format, message, '');
732
92 while (g_ascii_isspace (*message) && *message)
734
94 msg_length = strlen (message);
735
95 if (line_length == MAX_LINE)
736
96 line_length -= indent;
739
99 g_fprintf (fp, '%s\n', message);
743
.SS "void qof_mod_category (const gchar * category, \fBQofMainContext\fP * data)"
745
Shorthand to only query objects that are set to the specified category.
747
Modifies the QOF query to only query objects that are set to \fIcategory\fP.
749
Definition at line 484 of file qof-main.c.
751
References QofMain_s::category.
755
486 data->category = g_strdup (category);
759
.SS "void qof_mod_compression (gint64 gz_level, \fBQofMainContext\fP * context)"
761
Pass the requested compression to QSF
765
\fIgz_level\fP Integer between 0 and 9, 9 highest compression, 0 for none.
767
\fIcontext\fP The QofMain context.
772
Definition at line 327 of file qof-main.c.
774
References QofMain_s::export_session, and QofMain_s::gz_level.
776
Referenced by qof_cmd_xmlfile().
780
329 KvpFrame *be_config;
784
333 ENTER (' compression=%' G_GINT64_FORMAT, gz_level);
785
334 if ((gz_level > 0) && (gz_level <= 9))
787
336 book = qof_session_get_book (context->export_session);
788
337 be = qof_book_get_backend (book);
789
338 be_config = qof_backend_get_config (be);
790
339 context->gz_level = gz_level;
791
340 qof_backend_option_foreach (be_config, option_cb, context);
792
341 qof_backend_load_config (be, be_config);
798
.SS "void qof_mod_convert_deprecated (gint64 convert, \fBQofMainContext\fP * context)"
800
configure handling of deprecated date fields.
802
Definition at line 364 of file qof-main.c.
804
References QofMain_s::convert, and QofMain_s::export_session.
808
366 KvpFrame *be_config;
813
371 set = (convert == 0) ? FALSE : TRUE;
814
372 ENTER (' convert deprecated date values? %i No if 0.', set);
815
373 book = qof_session_get_book (context->export_session);
816
374 be = qof_book_get_backend (book);
817
375 be_config = qof_backend_get_config (be);
818
376 context->convert = convert;
819
377 qof_backend_option_foreach (be_config, option_cb, context);
820
378 qof_backend_load_config (be, be_config);
825
.SS "void qof_mod_database (const gchar * database, \fBQofMainContext\fP * data)"
827
Shorthand to only query objects within one specific supported database.
829
Used to only query objects within the specified database.
831
Definition at line 504 of file qof-main.c.
833
References QofMain_s::database.
837
506 if (qof_class_is_registered (database))
838
507 data->database = g_strdup (database);
842
.SS "void qof_mod_encoding (const gchar * encoding, \fBQofMainContext\fP * context)"
844
Pass an encoding string to the backend.
846
Definition at line 347 of file qof-main.c.
848
References QofMain_s::encoding, and QofMain_s::export_session.
850
Referenced by qof_cmd_xmlfile().
854
349 KvpFrame *be_config;
858
353 ENTER (' encode to %s', encoding);
859
354 book = qof_session_get_book (context->export_session);
860
355 be = qof_book_get_backend (book);
861
356 be_config = qof_backend_get_config (be);
862
357 context->encoding = encoding;
863
358 qof_backend_option_foreach (be_config, option_cb, context);
864
359 qof_backend_load_config (be, be_config);
869
.SS "void qof_mod_exclude (const gchar * exclude, \fBQofMainContext\fP * data)"
871
Shorthand to exclude a supported database from the query.
873
Excludes the (single) specified database from the query.
875
Definition at line 559 of file qof-main.c.
877
References QofMain_s::exclude.
881
561 if (qof_class_is_registered (exclude))
882
562 data->exclude = g_strdup (exclude);
886
.SS "glong qof_mod_get_local_offset (void)"
888
Get the gmt_off offset for this locale.
890
User specified strings can be assumed to be in localtime, but values are stored as UTC. This offset allows the application to modify the minimum and maximum time settings for queries so that the user gets the expected results.
892
If the timezone is +0100 and the date is 24th July 2006, values could be stored as 11pm on 23rd July 2006 UTC. qof_mod_get_local_offset returns -86400. Add this value to the minimum and maximum time passed to the query to ensure queries select expected timeframe: 2006-07-23T23:00:00Z to 2006-07-24T22:59:59Z.
896
the number of seconds difference between localtime and UTC.
901
Definition at line 490 of file qof-main.c.
903
Referenced by qof_mod_time().
907
492 glong local_offset;
911
496 local_offset = 0; /* UTC */
912
497 now = time (NULL);
913
498 local = *localtime_r (&now, &local);
914
499 local_offset -= local.tm_gmtoff;
915
500 return local_offset;
919
.SS "void qof_mod_sql (const gchar * sql_query, \fBQofMainContext\fP * data)"
921
Specify a SQL query on the command line.
923
For SELECT, the returned list is a list of all of the instances of 'SomeObj' that match the query. The 'SORT' term is optional. The 'WHERE' term is optional; but if you don't include 'WHERE', you will get a list of all of the object instances. The Boolean operations 'AND' and 'OR' together with parenthesis can be used to construct arbitrarily nested predicates.
925
For INSERT, the returned list is a list containing the newly created instance of 'SomeObj'.
927
Date queries handle full date and time strings, using the format exported by the QSF backend. To query dates and times, convert user input into UTC time using qof_date_print and QOF_DATE_FORMAT_UTC
929
If the param is a KVP frame, then we use a special markup to indicate frame values. The markup should look like /some/kvp/path:value. Thus, for example,
931
SELECT * FROM SomeObj WHERE (param_a < '/some/kvp:10.0')
933
will search for the object where param_a is a KVP frame, and this KVP frame contains a path '/some/kvp' and the value stored at that path is floating-point and that float value is less than 10.0.
937
\fIsql_query\fP Examples:
940
'select * from pilot_address'
942
'select * from pilot_expenses where type_of_expense = 'Mileage';'
944
'SELECT * from pilot_datebook where start_time > '2004-04-06T00:00Z' and end_time < '2005-04-05T23:59:59Z';'
946
'insert into pilot_todo (description, date_due, todo_priority) values ('put the cat out', '2005-11-24T21:30:00Z', 1)'
950
\fIdata\fP The QofMain context.
955
Definition at line 566 of file qof-main.c.
957
References QofMain_s::sql_str.
961
568 data->sql_str = g_strdup (sql_query);
965
.SS "void qof_mod_sql_file (const gchar * sql_file, \fBQofMainContext\fP * data)"
967
Specify one or more SQL queries contained in a file.
969
The rules for single SQL commands also apply with regard to the lack of explicit support for joins and the pending support for selecting only certain parameters from a certain object.
971
See \fBqof_mod_sql\fP for information on the queries supported.
973
Definition at line 572 of file qof-main.c.
975
References ERR_INDENT, qof_main_wrap_line(), QOF_SQL_SUPPORTED, QofMain_s::sql_file, and QofMain_s::sql_list.
979
574 FILE *filehandle;
980
575 #ifndef HAVE_GETLINE
981
576 gchar lineptr[1024];
989
584 gint reg_exp_check;
990
585 const gchar *fmt;
991
586 static gchar *pattern = QOF_SQL_SUPPORTED;
994
589 data->sql_file = g_strdup (sql_file);
997
592 data->sql_list = NULL;
998
593 filehandle = fopen (sql_file, 'r');
1001
596 fmt = _('%s: There was an error reading the file '%s'.\n');
1002
597 qof_main_wrap_line (stderr, ERR_INDENT, fmt, PACKAGE, sql_file);
1005
600 r = g_new (regex_t, 1);
1006
601 #ifndef HAVE_GETLINE
1007
602 while (NULL != (fgets (lineptr, sizeof (lineptr), filehandle)))
1010
605 while (0 < getline (&lineptr, &n, filehandle))
1014
609 regcomp (r, pattern, REG_ICASE | REG_NOSUB | REG_EXTENDED);
1015
610 g_return_if_fail (reg_exp_check == 0);
1016
611 if (0 != regexec (r, lineptr, 0, NULL, 0))
1018
613 buf = g_strdup (g_strchomp (lineptr));
1019
614 data->sql_list = g_list_prepend (data->sql_list, buf);
1023
618 fclose (filehandle);
1024
619 LEAVE (' sql_list=%d', g_list_length (data->sql_list));
1028
.SS "void qof_mod_time (const gchar * date_time, \fBQofMainContext\fP * data)"
1030
Shorthand to only query objects that contain the specified date.
1032
Used to modify the QOF query to only query objects that contain at least one parameter containing a QOF_TYPE_TIME that matches the range specified. Dates need to be specified as YY-MM-DD, i.e. QOF_DATE_FORMAT_ISO.
1034
You can specify a UTC timestring, just as normally output by QSF, but the time will not be matched when using the shorthand option, only the year, month and day.
1036
For more precise time matches or to set a defined period that doesn't follow whole calendar months, (e.g. the UK financial year) use a SQL statement:
1038
'SELECT * from pilot_datebook where start_time > '2004-04-06T00:00Z'
1040
and end_time < '2005-04-05T23:59:59Z';'
1042
Partial matches are allowed, so YY-MM matches any object where a date is within the specified month and year, YY matches any object where a date is within the specified year.
1044
The query range starts at midnight on the first day of the range and ends at 1 second to midnight on the last day of the range.
1046
Definition at line 511 of file qof-main.c.
1048
References QofMain_s::max_qt, QofMain_s::min_qt, and qof_mod_get_local_offset().
1053
514 gboolean all_year, all_month;
1054
515 gint adding_days;
1057
518 /* incoming date is assumed to be localtime */
1058
519 ENTER (' date_time=%s', date_time);
1059
520 all_month = all_year = FALSE;
1060
521 g_return_if_fail (date_time);
1061
522 qd = qof_date_parse (date_time, QOF_DATE_FORMAT_ISO);
1063
524 qd = qof_date_parse (date_time, QOF_DATE_FORMAT_UTC);
1064
525 info = qof_date_print (qd, QOF_DATE_FORMAT_ISO8601);
1065
526 PINFO (' parsed start_time=%s', info);
1067
528 /* set first second of day, UTC */
1068
529 qof_date_set_day_start (qd);
1069
530 data->min_qt = qof_date_to_qtime (qd);
1070
531 /* adjust for incoming localtime */
1071
532 qof_time_add_secs (data->min_qt,
1072
533 qof_mod_get_local_offset());
1073
534 /* year specified but no month or day, select the entire year */
1074
535 if (strlen (date_time) == 4)
1076
537 PINFO (' match entire year %s', date_time);
1077
538 /* go to end of this year, not first day of next. */
1078
539 adding_days = qof_date_isleap(qd->qd_year) ? 365 : 364;
1079
540 qof_date_adddays (qd, adding_days);
1081
542 /* month specified, but no day, select entire month */
1082
543 if (strlen (date_time) == 7)
1084
545 PINFO (' match entire month %s', date_time);
1085
546 adding_days = qof_date_get_mday (qd->qd_mon, qd->qd_year);
1086
547 qof_date_adddays (qd, adding_days - 1);
1088
549 /* set last second of day */
1089
550 qof_date_set_day_end (qd);
1090
551 data->max_qt = qof_date_to_qtime (qd);
1091
552 /* adjust for incoming localtime */
1092
553 qof_time_add_secs (data->max_qt,
1093
554 qof_mod_get_local_offset());
1098
.SS "void qof_mod_write (const gchar * write_file, \fBQofMainContext\fP * data)"
1100
Write the results of any query to the file.
1102
\fIfilename\fP of the file to be written out.
1104
Definition at line 623 of file qof-main.c.
1106
References QofMain_s::write_file.
1110
625 data->write_file = g_strdup (write_file);