Permalink
Browse files

modified: commands.vala

	modified:   test.gs
  • Loading branch information...
iloveaok
iloveaok committed Apr 28, 2012
1 parent 21d05e8 commit 4ad1d0e89b212c80c024e5378fbdbcb704979d60
Showing with 63 additions and 22 deletions.
  1. +58 −17 commands.vala
  2. +5 −5 test.gs
View
@@ -22,32 +22,73 @@ class Model : Object {
/* Easy interface to GdaSqlBuilder
* maybe extend to other backends later */
-class Command : Object {
+abstract class Command : Object {
/* every Command object has one (main) Model object associated with it (?) */
- //public model : Model
/* a Database object is in place for convenience */
public Database db;
/* all subclasses need to be able to be converted into each other
back and forth, so any information must be avaiable, even if
irrelevant for current operation */
- /*public ArrayList<Column> relevant_columns;
+ public ArrayList<Column> relevant_columns;
public ArrayList<Column> groupby_columns;
- public LinkedList<Value> values_commit;
- public LinkedList<Value> values_where;
- public LinkedList<Value> values_having;*/
- /* take list of either String or Colmn objects
- possibilities for strings:
- tablename.columnname
- columnname // requires "from" clause
- customexpr?? */
- //construct from_strings(columns : list of string)
- // init//code that pertains to the initlization of the class
+ public ValueArray values_commit;
+ public ValueArray values_where;
+ public ValueArray values_having;
construct {
- //relevant_columns = new ArrayList<Column> ();
- //groupby_columns = new ArrayList<Column> ();
+ db = null;
+ relevant_columns = new ArrayList<Column>();
+ groupby_columns = new ArrayList<Column>();
+ values_commit = new ValueArray(0);
+ values_where = new ValueArray(0);
+ values_having = new ValueArray(0);
}
- Command(ArrayList<Column> columns) {
- //relevant_columns = columns;
+ public void values(ValueArray vals) {
+ //values_commit = vals; // replaces them!
+ }
+ /** returns all values related to this command depending on it's type */
+ public abstract ValueArray get_values();
+}
+
+class Insert : Command {
+ // [GIR (name = "foo")]
+ public Insert(ArrayList<Column> into_columns) {
+ relevant_columns = into_columns;
+ }
+ public override ValueArray get_values() {
+ return values_commit.copy();
+ }
+}
+
+class Update : Command {
+ public Update(ArrayList<Column> updated_columns) {
+ relevant_columns = updated_columns;
+ }
+ public override ValueArray get_values() {
+ // values_commit + values_where # ensure the right order
+ var tmp = new ValueArray(values_commit.n_values + values_where.n_values);
+ foreach (Value el in values_commit) tmp.append(el);
+ foreach (Value el in values_where) tmp.append(el);
+ return tmp;
+ }
+}
+
+class Delete : Command {
+ public Delete() {} // Context should get more precise in WHERE clause
+ public override ValueArray get_values() {
+ return values_where.copy();
+ }
+}
+
+class Select : Command {
+ public Select(ArrayList<Column> columns) {
+ relevant_columns = columns;
+ }
+ public override ValueArray get_values() {
+ // values_commit + values_having # ensure the right order
+ var tmp = new ValueArray(values_where.n_values + values_having.n_values);
+ foreach (Value el in values_where) tmp.append(el);
+ foreach (Value el in values_having) tmp.append(el);
+ return tmp;
}
}
View
10 test.gs
@@ -1,17 +1,17 @@
uses Gee
class Test : Object
- prop d : dict of string,string
+ prop d : dict of string,Value
prop l : list of string
init
print "init"
l = new list of string
- d = new dict of string,string
+ d = new dict of string,Value
construct (li : list of string)
print "construct1"
for s in li
l.add(s) // segfaults
- construct from_dict(di : dict of string,string)
+ construct from_dict(di : dict of string,Value)
print "construct2"
for entry in di.entries
d[entry.key] = entry.value // segfaults
@@ -20,12 +20,12 @@ init
// ARRAY
var lst = new list of string
lst.add("one")
- var t = new Test(lst)
+ //var t = new Test(lst)
// DICT
var map = new dict of string,string
map["four"] = "4" // same as map.set ("four", 4)
map["five"] = "5"
var a = map.get ("four")
var b = map["four"] // same as map.get ("four")
assert (a == b)
- var tt = new Test.from_dict(map)
+ //var tt = new Test.from_dict(map)

0 comments on commit 4ad1d0e

Please sign in to comment.