1 module hunt.sql.ast.SQLLimit;
2 
3 import hunt.sql.ast.SQLObject;
4 import hunt.sql.ast.SQLObjectImpl;
5 import hunt.sql.ast.SQLExpr;
6 import hunt.sql.visitor.SQLASTVisitor;
7 import hunt.sql.ast.expr.SQLIntegerExpr;
8 
9 public  class SQLLimit : SQLObjectImpl {
10 
11     public this() {
12 
13     }
14 
15     public this(SQLExpr rowCount) {
16         this.setRowCount(rowCount);
17     }
18 
19     public this(SQLExpr offset, SQLExpr rowCount) {
20         this.setOffset(offset);
21         this.setRowCount(rowCount);
22     }
23 
24     private SQLExpr rowCount;
25     private SQLExpr offset;
26 
27     public SQLExpr getRowCount() {
28         return rowCount;
29     }
30 
31     public void setRowCount(SQLExpr rowCount) {
32         if (rowCount !is null) {
33             rowCount.setParent(this);
34         }
35         this.rowCount = rowCount;
36     }
37 
38     public void setRowCount(int rowCount) {
39         this.setRowCount(new SQLIntegerExpr(rowCount));
40     }
41 
42     public SQLExpr getOffset() {
43         return offset;
44     }
45 
46     public void setOffset(int offset) {
47         this.setOffset(new SQLIntegerExpr(offset));
48     }
49 
50     public void setOffset(SQLExpr offset) {
51         if (offset !is null) {
52             offset.setParent(this);
53         }
54         this.offset = offset;
55     }
56 
57     protected override void accept0(SQLASTVisitor visitor) {
58         if (visitor.visit(this)) {
59             acceptChild(visitor, offset);
60             acceptChild(visitor, rowCount);
61         }
62         visitor.endVisit(this);
63     }
64 
65     public override SQLLimit clone() {
66         SQLLimit x = new SQLLimit();
67 
68         if (offset !is null) {
69             x.setOffset(offset.clone());
70         }
71 
72         if (rowCount !is null) {
73             x.setRowCount(rowCount.clone());
74         }
75 
76         return x;
77     }
78 
79 }