Adding FA.db_query in Haxe.
authorMaxime Bourget <bmx007@gmail.com>
Mon, 27 May 2013 17:25:49 +0000 (18:25 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Mon, 27 May 2013 17:25:49 +0000 (18:25 +0100)
.vimrc [new file with mode: 0644]
haxe/ItemScheduler.hx

diff --git a/.vimrc b/.vimrc
new file mode 100644 (file)
index 0000000..b299534
--- /dev/null
+++ b/.vimrc
@@ -0,0 +1 @@
+set path=.,includes,haxe
index 92d0212e40bf74181cec1a0fa11486888e0f7ffc..2ce0fa0783c3874237c4dd99f1e31383c02a2aa1 100644 (file)
@@ -1,4 +1,41 @@
 import php.Lib;
+
+enum Maybe<T> {
+       Nothing;
+       Just(v : T);
+}
+
+class QueryIterator<T> {
+       var result : Dynamic;
+       var nextValue : Maybe<T>;
+       public function new(result) {
+               this.result= result;
+               /* We fetch the first row , so we can answer hasNext */
+               fetch();
+       }
+
+       private function fetch() {
+               var next = untyped __call__('db_fetch', this.result);
+               this.nextValue = if(next) Just(next) else Nothing;
+       }
+
+       public function  hasNext() : Bool {
+               return this.next == Nothing;
+       }
+
+       public function next() : T {
+               switch(this.nextValue) {
+               case Nothing : throw 'Iterator exhausted';
+               case Just(v) : return v;
+               }
+       }
+}
+class FA {
+       static public function query(sql: String) {
+               var result = untyped __call__('db_query', sql);
+               return QueryIterator(result);
+       }
+}
 class ItemScheduler {
        var stock_id:String;
        function new(stock_id: String) {
@@ -21,7 +58,12 @@ class ItemScheduler {
        }
 
        function schedules() {
-               return ["a", "b", "c"];
+               var tb : String =  untyped __php__('TB_PREF');
+               var sql : String = "SELECT *  
+                                               FROM "+tb+"denorm_order_details_queue 
+                                               JOIN  "+tb+"sales_orders ON (order_no = order_id)
+                                               WHERE stock_id = '"+this.stock_id+"'";
+               return FA.query(sql);
        }
 }