1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-10-27 20:34:16 +00:00
gnosygnu_xowa/140_dbs/src/gplx/dbs/Db_sql_select.java

79 lines
3.5 KiB
Java
Raw Normal View History

2015-07-13 01:10:02 +00:00
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs; import gplx.*;
import gplx.core.criterias.*;
interface Db_sql_qry {
String Tbl_main();
}
class Db_sql_qry__select {
public Db_sql_qry__select(String from) {this.from = from;}
2016-06-20 03:58:10 +00:00
public String From() {return from;} private final String from;
2015-07-13 01:10:02 +00:00
public Db_sql_col[] Select() {return select;} private Db_sql_col[] select;
// public Criteria Where() {return where;} private Criteria where;
// public Db_sql_col[] Group_bys() {return group_bys;} private Db_sql_col[] group_bys;
// public Db_sql_col[] Order_bys() {return order_bys;} private Db_sql_col[] order_bys;
// public int Limit() {return limit;} private int limit;
// public int Offset() {return offset;} private int offset;
public Db_sql_qry__select Select_all_() {this.select = Db_sql_col_.Ary(new Db_sql_col__all(0, from)); return this;}
2015-10-19 02:17:57 +00:00
public Db_sql_qry__select Select_flds_(String... ary) {this.select = Db_sql_col_bldr.Instance.new_fld_many(ary); return this;}
2015-07-13 01:10:02 +00:00
public static Db_sql_qry__select new_(String from) {return new Db_sql_qry__select(from);}
}
class Db_sql_bldr {
public void Test() {
// Db_sql_qry__select qry = null;
// qry = Db_sql_qry__select.new_("tbl").Select_all_();
// qry = Db_sql_qry__select.new_("tbl").Select_flds_("fld1", "fld2");
// qry = Db_sql_qry__select.new_("tbl").Select_flds_("fld1", "fld2").Where_("fld3");
// , String_.Ary("col1", "col2"), String_.Ary("col3")).Limit_(10).;
// Db_sql_qry__select qry = Db_sql_qry__select_.new_("tbl").Cols_("col1", "col2").Where_eq_one("col3").Limit_(10);
}
}
interface Db_sql_col {
int Ord();
String Alias();
}
class Db_sql_col_ {
public static Db_sql_col[] Ary(Db_sql_col... v) {return v;}
}
class Db_sql_col_bldr {
2016-06-20 03:58:10 +00:00
private final List_adp tmp_list = List_adp_.New();
2015-07-13 01:10:02 +00:00
public Db_sql_col[] new_fld_many(String[] ary) {
tmp_list.Clear();
int ord = -1;
for (int i = 0; i < ary.length; ++i) {
String fld_key = ary[i];
2016-01-18 04:18:07 +00:00
if (fld_key == Dbmeta_fld_itm.Key_null) continue;
2015-07-13 01:10:02 +00:00
Db_sql_col__name fld = new Db_sql_col__name(++ord, fld_key);
tmp_list.Add(fld);
}
return (Db_sql_col[])tmp_list.To_ary_and_clear(Db_sql_col.class);
}
2016-06-20 03:58:10 +00:00
public static final Db_sql_col_bldr Instance = new Db_sql_col_bldr(); Db_sql_col_bldr() {}
2015-07-13 01:10:02 +00:00
}
class Db_sql_col__name {
public Db_sql_col__name(int ord, String key) {this.ord = ord; this.key = key;}
2016-06-20 03:58:10 +00:00
public int Ord() {return ord;} private final int ord;
public String Key() {return key;} private final String key;
2015-07-13 01:10:02 +00:00
}
class Db_sql_col__all implements Db_sql_col {
public Db_sql_col__all(int ord, String tbl) {this.ord = ord; this.tbl = tbl;}
2016-06-20 03:58:10 +00:00
public int Ord() {return ord;} private final int ord;
public String Tbl() {return tbl;} private final String tbl;
2015-07-13 01:10:02 +00:00
public String Alias() {return "*";}
}