switch (action)
{
case AUDIT_ACTION_INSERT:
- /* saving all fields */
- sql = g_strdup_printf ("SELECT * FROM %s",
- table_name);
-
- sql_where = g_strdup (" WHERE TRUE");
+ /* TODO for now it saves all the fields passed */
+ /* saving just key's fields */
for (strpart = 0; strpart < l; strpart++)
{
field_name = (gchar *)fields_values[strpart];
value = (gchar *)fields_values[++strpart];
if (value == NULL) break;
- /* TODO the db field can be other type than string */
- sql_where = g_strconcat (sql_where, " AND ", field_name, " = ", value, "", NULL);
- }
- sql = g_strconcat (sql, sql_where, NULL);
- dm = gdaex_query (datasource->gdaex, sql);
-
- if (dm == NULL) 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++)
- {
- /* find the 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, 0, col));
+ insert_value (audit, id, table, field_name, value);
}
break;
break;
case AUDIT_ACTION_DELETE:
- /* saving just key's fields */
+ /* saving all fields */
+ sql = g_strdup_printf ("SELECT * FROM %s",
+ table_name);
+
+ sql_where = g_strdup (" WHERE TRUE");
for (strpart = 0; strpart < l; strpart++)
{
field_name = (gchar *)fields_values[strpart];
value = (gchar *)fields_values[++strpart];
if (value == NULL) break;
- insert_value (audit, id, table, field_name, value);
+ /* TODO the db field can be other type than string */
+ sql_where = g_strconcat (sql_where, " AND ", field_name, " = ", value, "", NULL);
+ }
+ sql = g_strconcat (sql, sql_where, NULL);
+ dm = gdaex_query (datasource->gdaex, sql);
+
+ if (dm == NULL) 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++)
+ {
+ /* find the 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, 0, col));
}
break;
gda_connection_statement_execute_non_select (conn, stmt, NULL, NULL, NULL);
audit_action_from_gdastatement (audit, AUDIT_ACTION_INSERT, "I", "audit_test1", stmt);
- stmt = gda_sql_parser_parse_string (parser, "UPDATE test1 SET age=130 WHERE id = 2", NULL, NULL);
+ stmt = gda_sql_parser_parse_string (parser, "UPDATE test1 SET income=99999999.99 WHERE id = 2", NULL, NULL);
if (stmt == NULL)
{
g_warning ("GdaStatement NULL");