8 class QueryIterator<T> {
10 var nextValue : Maybe<T>;
11 public function new(result) {
13 /* We fetch the first row , so we can answer hasNext */
17 private function fetch() {
18 var next : Dynamic = untyped __call__('db_fetch', this.result);
19 nextValue = if(next) Just(next) else Nothing;
22 public function hasNext() : Bool {
23 return this.nextValue != Nothing;
26 public function next() : T {
27 switch(this.nextValue) {
28 case Nothing : throw 'Iterator exhausted';
37 static public function query(sql: String) {
38 var result = untyped __call__('db_query', sql, sql);
39 return new QueryIterator(result);
44 function new(stock_id: String) {
45 this.stock_id = stock_id;
48 function tableHeader() {
49 return ["A", "B", "C"];
52 function generateTable(): Void {
53 for(schedule in this.schedules()) {
54 this.formatRow(schedule);
58 function formatRow(row) {
59 var array = php.Lib.hashOfAssociativeArray(row);
60 php.Lib.print('<tr><td>'+array.get('stock_id')+'</td></tr>');
64 function schedules() {
65 var tb : String = untyped __php__('TB_PREF');
66 var sql : String = "SELECT *
67 FROM "+tb+"denorm_order_details_queue
68 JOIN "+tb+"sales_orders ON (order_no = order_id)
69 WHERE stock_id = '"+this.stock_id+"'";