From e65fb144c515bbc683e5772d08d72bfbc4a7d85a Mon Sep 17 00:00:00 2001 From: Maxime Bourget Date: Mon, 27 May 2013 18:25:49 +0100 Subject: [PATCH] Adding FA.db_query in Haxe. --- .vimrc | 1 + haxe/ItemScheduler.hx | 44 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 .vimrc diff --git a/.vimrc b/.vimrc new file mode 100644 index 0000000..b299534 --- /dev/null +++ b/.vimrc @@ -0,0 +1 @@ +set path=.,includes,haxe diff --git a/haxe/ItemScheduler.hx b/haxe/ItemScheduler.hx index 92d0212..2ce0fa0 100644 --- a/haxe/ItemScheduler.hx +++ b/haxe/ItemScheduler.hx @@ -1,4 +1,41 @@ import php.Lib; + +enum Maybe { + Nothing; + Just(v : T); +} + +class QueryIterator { + var result : Dynamic; + var nextValue : Maybe; + 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); } } -- 2.30.2