Database Reports
[Estron support library]


Detailed Description

A 'txnreport' will fill in a bunch of field values, based on a previously obtained collection of SQL records (i.e. the results of a previous SQL query.) This is typically used to fill in fields that are in gtk widgets, and/or possibly a gtk table widget. The txnreport can handle multiple table rows in the latter case.

The set of db records should probably be obtained using DuiTxnQuery, although this is not a requirement (yet?).

Another way to think of this thing as being a grouping of fieldmaps, a 'table' as it were. Data is copied from the SQL query into this grouping as a unit.

Bug:
except that this is wrong. we have two competing concepts: the set of data that came in from sql, and the way that it will be mapped to the targets. We need a distinct concept of target tables with matchers.
but this is the matcher. We need to declare the matching terms here, not else where.


Files

file  duitxnreport.h

Typedefs

typedef struct DuiTxnReport_s DuiTxnReport

Functions

DuiTxnReport * dui_txnreport_new (const char *name, int nest)
void dui_txnreport_destroy (DuiTxnReport *row)
const char * dui_txnreport_get_name (DuiTxnReport *)
int dui_txnreport_get_nest (DuiTxnReport *)
void dui_txnreport_add_term (DuiTxnReport *row, DuiFieldMap *fm)
void dui_txnreport_add_match_term (DuiTxnReport *row, DuiFieldMap *fm)
void dui_txnreport_set_resolver (DuiTxnReport *row, DuiResolver *res)
gboolean dui_txnreport_is_empty (DuiTxnReport *row, DuiDBRecordSet *recs)
void dui_txnreport_run (DuiTxnReport *row, DuiDBRecordSet *recs)


Function Documentation

void dui_txnreport_add_match_term ( DuiTxnReport *  row,
DuiFieldMap *  fm 
)

Specify a 'matcher' term which must be satisfied for a row to be filled out. The matcher will typically indicate a row in a table widget, or a specific instance of an object.

Definition at line 131 of file duitxnreport.c.

00132 {
00133     if (!row || !fm) return;
00134 
00135     if (row->match)
00136     {
00137         PERR ("Target Row Matcher already specified!\n");
00138     }
00139     dui_resolver_add_field (row->resolver, &fm->source);
00140     dui_resolver_add_field (row->resolver, &fm->target);
00141     dui_field_map_resolve (fm);
00142 
00143     row->match = fm;
00144 }

void dui_txnreport_add_term ( DuiTxnReport *  row,
DuiFieldMap *  fm 
)

Add a 'column' to this 'row'. The fieldmap acts to specify a data target when the report is run.

Definition at line 120 of file duitxnreport.c.

00121 {
00122     if (!row || !fm) return;
00123     dui_resolver_add_field (row->resolver, &fm->source);
00124     dui_resolver_add_field (row->resolver, &fm->target);
00125     dui_field_map_resolve (fm);
00126 
00127     row->columns = g_list_append (row->columns, fm);
00128 }

gboolean dui_txnreport_is_empty ( DuiTxnReport *  row,
DuiDBRecordSet *  recs 
)

Return TRUE if no data transfer would result, for instance because there's no data in the recordset

Definition at line 178 of file duitxnreport.c.

00179 {
00180     gint more_rows = 1;
00181 
00182     if (!row) return TRUE;
00183 
00184     /* Check to see if there's any data to display at all.  Note
00185      * that 'recs' may be NULL; there could still be static data
00186      * or non-sql data. So must go through loop at least once.
00187      * Note also that the empty string "" is a valid value, and
00188      * its used to clear out/empty target fields.
00189      *
00190      * However, if DB returned zero rows, then the DB may be offline,
00191      * or the query may have been badly constructed.  Should check
00192      * for these errors ...
00193      */
00194     dui_recordset_rewind (recs);
00195     while (more_rows)
00196     {
00197         GList *cnode;
00198         for (cnode=row->columns; cnode; cnode=cnode->next)
00199         {
00200             DuiFieldMap *col = cnode->data;
00201             const gchar * val;
00202 
00203             dui_field_resolve_recordset (&col->source, recs);
00204             val = dui_field_map_get_value (col);
00205             if (val)
00206             {
00207                 PINFO ("have data rows for row=%p %s", row, row->row_name);
00208                 return FALSE;
00209             }
00210         }
00211 
00212         more_rows = dui_recordset_fetch_row (recs);
00213     }
00214     PINFO ("empty row=%p %s", row, row->row_name);
00215     return TRUE;
00216 }

void dui_txnreport_run ( DuiTxnReport *  row,
DuiDBRecordSet *  recs 
)

Force the data transer to occur

Definition at line 222 of file duitxnreport.c.

00223 {
00224     gint more_rows = 1;
00225     DuiField *iterator = NULL;
00226 
00227     if (!row) return;
00228     ENTER ("(rowname=%s, recs=%p)", row->row_name, recs);
00229 
00230     /* Handle the matching term first */
00231     if (row->match)
00232     {
00233         iterator = &row->match->target;
00234     }
00235 
00236     dui_field_iter_pre (iterator, (0 == row->nest_level));
00237 
00238     /* Note, we must pass through this at least once, even
00239      * if there  are no rows in the recordset.  That's because
00240      * some fields will be static, not coming from SQL
00241      *
00242      * However, if DB returned zero rows, then the DB may be offline,
00243      * or the query may have been badly constructed.  Should check
00244      * for these errors...
00245      */
00246     dui_recordset_rewind (recs);
00247     more_rows = 1;
00248     while (more_rows)
00249     {
00250         gboolean do_transfer;
00251         /* Fetch the match value, if its been set */
00252         if (row->match)
00253         {
00254             dui_field_resolve_recordset (&row->match->source, recs);
00255             dui_field_map_transfer_data (row->match);
00256         }
00257 
00258         do_transfer = dui_field_iter_next (iterator);
00259 
00260         if (do_transfer)
00261         {
00262             GList *cnode;
00263             for (cnode=row->columns; cnode; cnode=cnode->next)
00264             {
00265                 DuiFieldMap *col = cnode->data;
00266 
00267                 dui_field_resolve_recordset (&col->source, recs);
00268                 dui_field_iter_column (&col->target, iterator);
00269 
00270                 /* OK, finally move data from source to dest */
00271                 dui_field_map_transfer_data (col);
00272             }
00273         }
00274 
00275         more_rows = 0;
00276         if (recs) more_rows = dui_recordset_fetch_row (recs);
00277         PINFO ("recs=%p more_rows=%d", recs, more_rows);
00278     }
00279 
00280     dui_field_iter_post (iterator);
00281     LEAVE ("(rowname=%s) iterator=%p", row->row_name, iterator);
00282 }


Generated on Tue Apr 29 21:27:54 2008 for estron by  doxygen 1.5.5