* @audit: l'oggetto #Audit su cui effettuare l'azione.
* @action: il tipo di azione.
* @dn: lo username che effettua l'azione.
- * @datasource:
- * @tabella:
+ * @datasource_name: the datasource's name.
+ * @table_name: the table's name.
+ * @...: a #NULL terminated list of couples field-value.
*
* Returns: #TRUE se l'azione viene effettuata con successo.
*/
const gchar *datasource_name,
const gchar *table_name,
...)
+{
+ va_list vargs;
+ gchar *str;
+ gchar **fields_values;
+ gchar *field_name;
+ gchar *field_value;
+
+ gboolean ret;
+
+ ret = FALSE;
+ str = g_strdup ("");
+
+ va_start (vargs, table_name);
+
+ field_name = va_arg (vargs, gchar *);
+ while (field_name != NULL)
+ {
+ field_value = va_arg (vargs, gchar *);
+ if (field_value == NULL) break;
+
+ str = g_strconcat (str, (g_strcmp0 (str, "") != 0 ? "|" : ""), field_name, "|", field_value, NULL);
+
+ field_name = va_arg (vargs, gchar *);
+ }
+
+ va_end (vargs);
+
+ if (g_strcmp0 (str, "") != 0)
+ {
+ ret = audit_action_v (audit, action, dn, datasource_name, table_name, (const gchar **)g_strsplit (str, "|", -1));
+ }
+
+ return ret;
+}
+
+/**
+ * audit_action_v:
+ * @audit: l'oggetto #Audit su cui effettuare l'azione.
+ * @action: the action's type.
+ * @dn: lo username che effettua l'azione.
+ * @datasource_name: the datasource's name.
+ * @table_name: the table's name.
+ * @fields_values: a #NULL-terminated array of strings in the form
+ * "<field_name><field_value><field_name><field_value>...#NULL"
+ *
+ * Returns: #TRUE se l'azione viene effettuata con successo.
+ */
+gboolean
+audit_action_v (Audit *audit,
+ enum AuditActions action,
+ const gchar *dn,
+ const gchar *datasource_name,
+ const gchar *table_name,
+ const gchar **fields_values)
{
GdaDataModel *dm;
gchar *sql;
gchar *field_name;
gchar *value;
gchar *value_new;
+ gint l;
+ gint strpart;
gint id = 0;
gint cols;
gint col;
time_t t;
struct tm *tm_ora;
- va_list vargs;
Datasource *datasource;
Table *table;
gdaex_execute (priv->gdaex, sql);
}
- /* fields */
- va_start (vargs, table_name);
+ l = g_strv_length ((gchar **)fields_values);
+ /* fields */
switch (action)
{
case AUDIT_ACTION_INSERT:
table_name);
sql_where = g_strdup (" WHERE TRUE");
- field_name = va_arg (vargs, gchar *);
- while (field_name != NULL)
+ for (strpart = 0; strpart < l; strpart++)
{
- value = va_arg (vargs, gchar *);
+ field_name = (gchar *)fields_values[strpart];
+ if (field_name == NULL) break;
+
+ if (strpart + 1 >= l) break;
+
+ 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);
- field_name = va_arg (vargs, gchar *);
}
sql = g_strconcat (sql, sql_where, NULL);
dm = gdaex_query (datasource->gdaex, sql);
table_name);
sql_where = g_strdup (" WHERE TRUE");
- field_name = va_arg (vargs, gchar *);
- while (field_name != NULL)
+ for (strpart = 0; strpart < l; strpart++)
{
- value = va_arg (vargs, gchar *);
+ field_name = (gchar *)fields_values[strpart];
+ if (field_name == NULL) break;
+
+ if (strpart + 1 >= l) break;
+
+ 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);
- field_name = va_arg (vargs, gchar *);
}
sql = g_strconcat (sql, sql_where, NULL);
dm = gdaex_query (datasource->gdaex, sql);
table_name);
sql_where = g_strdup (" WHERE TRUE");
- field_name = va_arg (vargs, gchar *);
- while (field_name != NULL)
+ for (strpart = 0; strpart < l; strpart++)
{
- value = va_arg (vargs, gchar *);
+ field_name = (gchar *)fields_values[strpart];
+ if (field_name == NULL) break;
+
+ if (strpart + 1 >= l) break;
+
+ 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);
- field_name = va_arg (vargs, gchar *);
}
sql = g_strconcat (sql, sql_where, NULL);
dm = gdaex_query (datasource->gdaex, sql);
case AUDIT_ACTION_DELETE:
/* salvo solo i fields della chiave */
- field_name = va_arg (vargs, gchar *);
- while (field_name != NULL)
+ for (strpart = 0; strpart < l; strpart++)
{
- value = va_arg (vargs, gchar *);
+ field_name = (gchar *)fields_values[strpart];
+ if (field_name == NULL) break;
+
+ if (strpart + 1 >= l) break;
+
+ value = (gchar *)fields_values[++strpart];
if (value == NULL) break;
insert_value (audit, id, table, field_name, value);
-
- field_name = va_arg (vargs, gchar *);
}
break;
return FALSE;
};
- va_end (vargs);
-
return TRUE;
}