[libgda/libgda-vala: 73/73] Initial setup vala module for DataObject as database persistence GObject.
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda/libgda-vala: 73/73] Initial setup vala module for DataObject as database persistence GObject.
- Date: Fri, 11 Nov 2011 21:41:50 +0000 (UTC)
commit 9003db75acf4ae433d74fa25345af1831a98e592
Author: Daniel Espinosa <despinosa src gnome org>
Date: Fri Nov 11 15:38:01 2011 -0600
Initial setup vala module for DataObject as database persistence GObject.
libgda/vala/DataObject.vala | 66 +++++++++++++++++++++++++++++++++
libgda/vala/SelectQuery.vala | 82 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 148 insertions(+), 0 deletions(-)
---
diff --git a/libgda/vala/DataObject.vala b/libgda/vala/DataObject.vala
new file mode 100644
index 0000000..d63d461
--- /dev/null
+++ b/libgda/vala/DataObject.vala
@@ -0,0 +1,66 @@
+/* -*- Mode: Vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * libgda
+ * Copyright (C) Daniel Espinosa Ortiz 2008 <esodan gmail com>
+ *
+ * libgda is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libgda is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gda;
+
+namespace Gda {
+ public abstract class DataObject : Object {
+
+ private DataModel? _model;
+ private string _field_id;
+ private Value _id_value;
+
+ protected _table;
+ protected Connection _cnn;
+
+ public SqlBuilder sql {
+ get {
+ var q = new SelectQuery();
+ q.connection = this._cnn;
+ q.table = this._table;
+ q.set_condition(this._field_id, this._id_value, SqlOperatorType.EQ);
+ return q.build();
+ }
+ }
+
+ public string get_field_id ()
+ {
+ return this._field_id;
+ }
+
+ public Value get_value_id ()
+ {
+ return this._id_value;
+ }
+
+ public void set_id (string field, Value cond)
+ {
+ this._field_id = field;
+ this._id_value = cond;
+ var q = this.sql;
+ var m = this._cnn.statement_execute_select(q.get_statement(), null);
+ this._model = new DataProxy(m);
+ }
+
+ public Value? get_value (string field)
+ {
+ return this._model.get_value_at(this._model.get_column_index(field), 0);
+ }
+ }
+}
diff --git a/libgda/vala/SelectQuery.vala b/libgda/vala/SelectQuery.vala
new file mode 100644
index 0000000..a565571
--- /dev/null
+++ b/libgda/vala/SelectQuery.vala
@@ -0,0 +1,82 @@
+/* -*- Mode: Vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * libgda
+ * Copyright (C) Daniel Espinosa Ortiz 2008 <esodan gmail com>
+ *
+ * libgda is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libgda is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+using Gee;
+
+namespace Gda {
+ [Compact]
+ private class SelectQuery {
+
+ public Gee.ArrayList<string> _fields;
+ private SqlBuilder _sql;
+
+ public string table { set; get; }
+ public Connection connection { set; get; }
+
+ SelectQuery()
+ {
+ this.fields.add("*");
+ this._cond = 0;
+ this.table = "";
+ }
+
+ public void add_field (string field)
+ {
+ if (this._fields.get(0) == "*")
+ {
+ this._fields.clear();
+ }
+
+ this.fields.add(field);
+ }
+
+ public SqlBuilder build (void)
+ {
+ this._sql = new SqlBuilder(Gda.SqlStatementType.SELECT);
+
+ foreach string f in this._fields {
+ this._sql.select_add_field (f, null, null);
+ }
+ this._sql.select_add_target(this.table, null);
+ }
+
+ public void set_fields_to_all (void)
+ {
+ this._fields.clear();
+ this._fields.add("*");
+ }
+
+ public void set_condition (string field, Value v, SqlOperatorType op)
+ {
+ var f_id = this._sql.add_id (c.field);
+ var e_id = this._sql.add_expr_value (null, c.v);
+ var c_id = this._sql.add_cond(c.op, f_id, e_id, 0);
+ this._sql.set_where(c_id);
+ }
+
+ public DataModel execute (void)
+ throws Error
+ requires (this.connection.is_opened())
+ {
+ /* Build Select Query */
+ var b = this.build();
+ var s = b.get_statement();
+ return this.connection.statement_execute_select(s, null);
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]