Trying to run the program generates the following error:
Query.val: 41.24-41.34: error: The name 'name' does not exist in the context of 'Sqlite.Statement?'
The line where the error is generated is at the moment of obtaining the values:
while (stmt.step () == Sqlite.ROW) {
string val = stmt.column_name ("nombre");
stdout.printf ("servicio: %s\n", val);
}
How could I get the values from my query?
Here the code:
using Gtk;
using Sqlite3;
using AppIndicator;
public class IndicatorExample {
public static int main(string[] args) {
Gtk.init(ref args);
Sqlite.Database db;
string errmsg;
var indicador = new Indicator("com.iuninefrendor", "indicator-messages",
IndicatorCategory.APPLICATION_STATUS);
indidator.set_status(IndicatorStatus.ACTIVE);
indidator.set_attention_icon("indicator-messages-new");
var menu = new Gtk.Menu();
var item = new Gtk.MenuItem.with_label("Consultar servicios");
item.activate.connect(() => {
indicator.set_status(IndicatorStatus.ATTENTION);
int ec = Sqlite.Database.open ("servicios.db", out this.db);
if (ec != Sqlite.OK) {
stderr.printf ("Ocurrio un error al abrir la db: %d: %s\n", this.db.errcode (), this.db.errmsg ());
return -1;
}
Sqlite.Statement stmt;
const string consulta = "SELECT * FROM servicios;";
ec = db.prepare_v2 (consulta, consulta.length, out stmt);
if (ec != Sqlite.OK) {
stderr.printf ("Error en la consulta: %d: %s\n", this.db.errcode (), this.db.errmsg ());
return -1;
}
int columnas = stmt.column_count ();
while (stmt.step () == Sqlite.ROW) {
string val = stmt.column_name ("nombre");
stdout.printf ("servicio: %s\n", val);
}
}
});
item.show();
menu.append(item);
indicator.set_menu(menu);
Gtk.main();
return 0;
}
}