00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00029 #include "config.h"
00030
00031 #include <glib.h>
00032 #include <string.h>
00033
00034 #include "dui-initdb.h"
00035 #include "duifield.h"
00036 #include "duifield-sql.h"
00037 #include "duiresolver.h"
00038 #include "perr.h"
00039
00040
00041 struct sql_field_s
00042 {
00043 DuiDBRecordSet *recordset;
00044 };
00045
00046
00047 struct where_field_s
00048 {
00049 gchar * compareop;
00050 };
00051
00052
00053
00054 static void
00055 update_field_clear (DuiField *f)
00056 {
00057 g_free (f->fieldname);
00058 f->type = DUI_FIELD_NONE;
00059 }
00060
00061 static void
00062 where_field_clear (DuiField *f)
00063 {
00064 struct where_field_s * gf = (struct where_field_s *) get_gobj_field (f);
00065 g_free (f->fieldname);
00066 g_free (gf->compareop);
00067 f->type = DUI_FIELD_NONE;
00068 }
00069
00070
00071
00072 static const gchar *
00073 get_sql_value (DuiField *fs)
00074 {
00075 const gchar * fieldval = NULL;
00076 struct sql_field_s * gf = (struct sql_field_s *) get_gobj_field (fs);
00077 fieldval = dui_recordset_get_value (gf->recordset,
00078 fs->fieldname);
00079 return fieldval;
00080 }
00081
00082 void
00083 dui_field_set_sql (DuiField *ft, const gchar * fieldname)
00084 {
00085 struct sql_field_s * gf = (struct sql_field_s *) get_gobj_field (ft);
00086 ft->type = DUI_FIELD_SQL;
00087 ft->get_field_value = get_sql_value;
00088 ft->set_field_value = NULL;
00089 ft->clear_field = update_field_clear;
00090
00091 ft->fieldname = g_strdup (fieldname);
00092 gf->recordset = NULL;
00093 }
00094
00095 void
00096 dui_field_set_where (DuiField *ft, const gchar * fieldname,
00097 const gchar * compareop)
00098 {
00099 struct where_field_s * gf = (struct where_field_s *) get_gobj_field (ft);
00100 ft->type = DUI_FIELD_WHERE;
00101 ft->get_field_value = NULL;
00102 ft->set_field_value = NULL;
00103 ft->clear_field = where_field_clear;
00104
00105 ft->fieldname = g_strdup (fieldname);
00106 gf->compareop = g_strdup (compareop);
00107 }
00108
00109 const gchar *
00110 dui_field_where_get_op (DuiField *ft)
00111 {
00112 struct where_field_s * gf;
00113 if (!ft) return NULL;
00114 gf = (struct where_field_s *) get_gobj_field (ft);
00115
00116 if (0 != g_ascii_strncasecmp(DUI_FIELD_WHERE, ft->type, 0)) return NULL;
00117 return gf->compareop;
00118 }
00119
00120
00121
00122 void
00123 dui_field_resolve_recordset (DuiField *fs, DuiDBRecordSet *rset)
00124 {
00125 struct sql_field_s * gf = (struct sql_field_s *) get_gobj_field (fs);
00126 if (!DUI_FIELD_IS_TYPE(fs,DUI_FIELD_SQL)) return;
00127 gf->recordset = rset;
00128 }
00129
00130