CREATE TABLE datasources (
id integer NOT NULL,
- name character(30) DEFAULT '',
- cnc_string character(255) DEFAULT '',
- status character(1) DEFAULT '',
+ name character varying(30) DEFAULT '',
+ cnc_string character varying(255) DEFAULT '',
+ status character varying(1) DEFAULT '',
CONSTRAINT datasources_pkey PRIMARY KEY (id)
);
CREATE TABLE tables (
id integer NOT NULL,
- name character(30) DEFAULT '',
- status character(1) DEFAULT '',
+ name character varying(30) DEFAULT '',
+ status character varying(1) DEFAULT '',
id_datasources integer NOT NULL,
CONSTRAINT tables_pkey PRIMARY KEY (id)
);
CREATE TABLE fields (
id integer NOT NULL,
id_tables integer NOT NULL,
- name character(30) DEFAULT '',
- status character(1) DEFAULT '',
+ name character varying(30) DEFAULT '',
+ status character varying(1) DEFAULT '',
CONSTRAINT campi_pkey PRIMARY KEY (id)
);
CREATE TABLE actions (
id bigint NOT NULL,
type integer,
- dn character(200) DEFAULT '',
+ dn character varying(200) DEFAULT '',
date timestamp without time zone,
id_tables integer,
CONSTRAINT actions_pkey PRIMARY KEY (id)
datas->name = gdaex_data_model_get_field_value_stringify_at (dm, row, "name");
datas->cnc_string = gdaex_data_model_get_field_value_stringify_at (dm, row, "cnc_string");
+ g_debug ("DATASOURCE\nid: %d\nname: %s\ncnc_string: %s",
+ datas->id, datas->name, datas->cnc_string);
+
datas->gdaex = gdaex_new_from_string (datas->cnc_string);
priv->datasources = g_list_append (priv->datasources, (gpointer)datas);
while (c != NULL)
{
- if (strcmp (((Field *)c->data)->name, field) == 0)
+ if (g_strcmp0 (((Field *)c->data)->name, field) == 0)
{
return (Field *)c->data;
}
while (t != NULL)
{
- if (strcmp (((Table *)t->data)->name, table) == 0)
+ if (g_strcmp0 (((Table *)t->data)->name, table) == 0)
{
return (Table *)t->data;
}
while (f != NULL)
{
- if (strcmp (((Datasource *)f->data)->name, datasource) == 0)
+ if (g_strcmp0 (((Datasource *)f->data)->name, datasource) == 0)
{
return (Datasource *)f->data;
}
static gboolean
insert_value (Audit *audit,
- gint id_azione,
+ gint id_actions,
Table *table,
gchar *field_name,
gchar *value)
}
else
{
+ /* find the new id */
+ GdaDataModel *dm;
+ guint id_new;
+
+ id_new = 0;
+ sql = g_strdup_printf ("SELECT COALESCE (MAX (id)) FROM values");
+ dm = gdaex_query (priv->gdaex, sql);
+ if (dm != NULL && gda_data_model_get_n_rows (dm) == 1)
+ {
+ id_new = gdaex_data_model_get_value_integer_at (dm, 0, 0);
+ }
+ id_new++;
+
sql = g_strdup_printf ("INSERT INTO values"
- " (id_actions, id_fields, value)"
- " VALUES (%d, %d, '%s')",
- id_azione, field->id, value);
+ " (id, id_actions, id_fields, value)"
+ " VALUES (%d, %d, %d, '%s')",
+ id_new, id_actions, field->id, value);
gdaex_execute (priv->gdaex, sql);
}
if (priv->gdaex == NULL)
{
- /* TO DO */
+ /* TODO */
+ g_message ("Error creating GdaEx object.");
return NULL;
}
/* carico i datasource */
if (!load_datasources (audit))
{
- /* TO DO */
+ /* TODO */
+ g_message ("Error loading datasources.");
return NULL;
}
- return audit;
+ return audit;
}
/**
if (priv->gdaex == NULL)
{
- /* TO DO */
+ /* TODO */
+ g_message ("Error creating GdaEx object.");
return NULL;
}
/* carico i datasource */
if (!load_datasources (audit))
{
- /* TO DO */
+ /* TODO */
+ g_message ("Error loading datasources.");
return NULL;
}
/* salvo l'azione */
if (action != AUDIT_ACTION_BEFORE_UPDATE)
{
+ /* TODO find the way to save more than 2 digits for the seconds */
sql = g_strdup_printf ("INSERT INTO actions"
- " (id, type, dn, date, id_tables, id_datasources)"
- " VALUES (%d, %d, '%s', '%04d-%02d-%02d %02d:%02d:%02d', %d, %d)",
+ " (id, type, dn, date, id_tables)"
+ " VALUES (%d, %d, '%s', '%04d-%02d-%02d %02d:%02d:%02d', %d)",
id, action, dn,
tm_ora->tm_year + 1900, tm_ora->tm_mon + 1, tm_ora->tm_mday,
tm_ora->tm_hour, tm_ora->tm_min, tm_ora->tm_sec,
- table->id, datasource->id);
+ table->id);
gdaex_execute (priv->gdaex, sql);
}
value = va_arg (vargs, gchar *);
if (value == NULL) break;
- sql_where = g_strconcat (sql_where, " AND ", field_name, "='", value, "'", NULL);
+ /* TODO the db field can be other type than string */
+ sql_where = g_strconcat (sql_where, " AND ", field_name, " = ", value, "", NULL);
field_name = va_arg (vargs, gchar *);
}
sql = g_strconcat (sql, sql_where, NULL);
if (dm == NULL) return FALSE;
- if (gda_data_model_get_n_rows (dm) == 0) return FALSE;
+ if (gda_data_model_get_n_rows (dm) == 0 ||
+ gda_data_model_get_n_rows (dm) > 1) return FALSE;
cols = gda_data_model_get_n_columns (dm);
for (col = 0; col < cols; col++)
/* trovo il field */
field_name = (gchar *)gda_data_model_get_column_title (dm, col);
insert_value (audit, id, table, field_name,
- gdaex_data_model_get_value_stringify_at (dm, col, 0));
+ gdaex_data_model_get_value_stringify_at (dm, 0, col));
}
break;
value = va_arg (vargs, gchar *);
if (value == NULL) break;
- sql_where = g_strconcat (sql_where, " AND ", field_name, " = '", value, "'", NULL);
+ /* TODO the db field can be other type than string */
+ sql_where = g_strconcat (sql_where, " AND ", field_name, " = ", value, "", NULL);
field_name = va_arg (vargs, gchar *);
}
sql = g_strconcat (sql, sql_where, NULL);
{
g_hash_table_insert (priv->fields_updated,
(gpointer)gda_data_model_get_column_title (dm, col),
- (gpointer)gdaex_data_model_get_value_stringify_at (dm, col, 0));
+ (gpointer)gdaex_data_model_get_value_stringify_at (dm, 0, col));
}
break;
value = va_arg (vargs, gchar *);
if (value == NULL) break;
- sql_where = g_strconcat (sql_where, " AND ", field_name, " = '", value, "'", NULL);
+ /* TODO the db field can be other type than string */
+ sql_where = g_strconcat (sql_where, " AND ", field_name, " = ", value, "", NULL);
field_name = va_arg (vargs, gchar *);
}
sql = g_strconcat (sql, sql_where, NULL);
field_name = (gchar *)gda_data_model_get_column_title (dm, col);
value = (gchar *)g_hash_table_lookup (priv->fields_updated, (gconstpointer)field_name);
- value_new = gdaex_data_model_get_value_stringify_at (dm, col, 0);
+ value_new = gdaex_data_model_get_value_stringify_at (dm, 0, col);
if (strcmp (value, value_new) != 0)
{
/* field modificato */