mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Embeddable: Fix if_exists (restore)
This commit is contained in:
36
140_dbs/src/gplx/dbs/sqls/itms/Db_obj_ary_crt.java
Normal file
36
140_dbs/src/gplx/dbs/sqls/itms/Db_obj_ary_crt.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
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.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
import gplx.core.criterias.*;
|
||||
public class Db_obj_ary_crt implements gplx.core.criterias.Criteria {
|
||||
public byte Tid() {return Criteria_.Tid_db_obj_ary;}
|
||||
public Db_obj_ary_fld[] Flds() {return flds;} public Db_obj_ary_crt Flds_(Db_obj_ary_fld[] v) {this.flds = v; return this;} private Db_obj_ary_fld[] flds;
|
||||
public Object[][] Vals() {return vals;} public void Vals_(Object[][] v) {this.vals = v;} private Object[][] vals;
|
||||
public void Val_from_args(Hash_adp args) {throw Err_.new_unimplemented();}
|
||||
public void Val_as_obj_(Object v) {throw Err_.new_unimplemented();}
|
||||
public boolean Matches(Object obj) {return false;}
|
||||
public String To_str() {return "";}
|
||||
public static Db_obj_ary_crt new_(Db_obj_ary_fld... flds) {return new Db_obj_ary_crt().Flds_(flds);}
|
||||
public static Db_obj_ary_crt new_by_type(byte type_tid, String... names) {
|
||||
int len = names.length;
|
||||
Db_obj_ary_fld[] flds = new Db_obj_ary_fld[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
flds[i] = new Db_obj_ary_fld(names[i], type_tid);
|
||||
return new Db_obj_ary_crt().Flds_(flds);
|
||||
}
|
||||
}
|
||||
23
140_dbs/src/gplx/dbs/sqls/itms/Db_obj_ary_fld.java
Normal file
23
140_dbs/src/gplx/dbs/sqls/itms/Db_obj_ary_fld.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
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.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
public class Db_obj_ary_fld {
|
||||
public Db_obj_ary_fld(String name, int type_tid) {this.name = name; this.type_tid = type_tid;}
|
||||
public String Name() {return name;} public Db_obj_ary_fld Name_(String v) {name = v; return this;} private String name;
|
||||
public int Type_tid() {return type_tid;} public Db_obj_ary_fld Type_tid_(int v) {type_tid = v; return this;} private int type_tid;
|
||||
}
|
||||
44
140_dbs/src/gplx/dbs/sqls/itms/Db_obj_ary_tst.java
Normal file
44
140_dbs/src/gplx/dbs/sqls/itms/Db_obj_ary_tst.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
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.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
import org.junit.*; import gplx.core.strings.*; import gplx.dbs.sqls.*;
|
||||
import gplx.dbs.sqls.wtrs.*;
|
||||
public class Db_obj_ary_tst {
|
||||
@Before public void init() {} private Db_obj_ary_fxt fxt = new Db_obj_ary_fxt();
|
||||
@Test public void Int() {
|
||||
fxt.Init_fld("fld_0", Type_adp_.Tid__int).Init_fld("fld_1", Type_adp_.Tid__int).Init_vals(1, 10).Init_vals(2, 20).Test_sql("(fld_0=1 AND fld_1=10) OR (fld_0=2 AND fld_1=20)");
|
||||
}
|
||||
@Test public void Str() {
|
||||
fxt.Init_fld("fld_0", Type_adp_.Tid__int).Init_fld("fld_1", Type_adp_.Tid__str).Init_vals(1, "a").Init_vals(2, "b").Test_sql("(fld_0=1 AND fld_1='a') OR (fld_0=2 AND fld_1='b')");
|
||||
}
|
||||
}
|
||||
class Db_obj_ary_fxt {
|
||||
private final Db_obj_ary_crt crt = new Db_obj_ary_crt();
|
||||
private final Sql_wtr_ctx ctx = new Sql_wtr_ctx(false);
|
||||
public Db_obj_ary_fxt Init_fld(String name, int tid) {flds_list.Add(new Db_obj_ary_fld(name, tid)); return this;} private List_adp flds_list = List_adp_.New();
|
||||
public Db_obj_ary_fxt Init_vals(Object... ary) {vals_list.Add(ary); return this;} private List_adp vals_list = List_adp_.New();
|
||||
public Db_obj_ary_fxt Test_sql(String expd) {
|
||||
Sql_core_wtr cmd_wtr = (Sql_core_wtr)Sql_qry_wtr_.New__basic();
|
||||
crt.Flds_((Db_obj_ary_fld[])flds_list.To_ary_and_clear(Db_obj_ary_fld.class));
|
||||
crt.Vals_((Object[][])vals_list.To_ary_and_clear(Object[].class));
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
cmd_wtr.Where_wtr().Bld_where__db_obj(bfr, ctx, crt);
|
||||
Tfds.Eq(expd, bfr.To_str_and_clear());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
26
140_dbs/src/gplx/dbs/sqls/itms/Sql_from_clause.java
Normal file
26
140_dbs/src/gplx/dbs/sqls/itms/Sql_from_clause.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
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.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
public class Sql_from_clause {
|
||||
public Sql_from_clause(Sql_tbl_itm base_tbl) {
|
||||
this.Base_tbl = base_tbl;
|
||||
Tbls.Add(base_tbl);
|
||||
}
|
||||
public final List_adp Tbls = List_adp_.New();
|
||||
public final Sql_tbl_itm Base_tbl;
|
||||
}
|
||||
28
140_dbs/src/gplx/dbs/sqls/itms/Sql_group_clause.java
Normal file
28
140_dbs/src/gplx/dbs/sqls/itms/Sql_group_clause.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
public class Sql_group_clause {
|
||||
public List_adp Flds() {return flds;} List_adp flds = List_adp_.New();
|
||||
|
||||
public static Sql_group_clause new_(String... ary) {
|
||||
Sql_group_clause rv = new Sql_group_clause();
|
||||
for (String itm : ary)
|
||||
rv.flds.Add(itm);
|
||||
return rv;
|
||||
} Sql_group_clause() {}
|
||||
}
|
||||
34
140_dbs/src/gplx/dbs/sqls/itms/Sql_join_fld.java
Normal file
34
140_dbs/src/gplx/dbs/sqls/itms/Sql_join_fld.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
public class Sql_join_fld {
|
||||
public Sql_join_fld(String trg_fld, String src_tbl, String src_fld) {
|
||||
this.Trg_fld = trg_fld;
|
||||
this.Src_tbl = src_tbl;
|
||||
this.Src_fld = src_fld;
|
||||
}
|
||||
public final String Src_tbl;
|
||||
public final String Src_fld;
|
||||
public final String Trg_fld;
|
||||
|
||||
public String To_fld_sql(boolean fld_is_src, String trg_tbl) {
|
||||
return fld_is_src ? Src_tbl + "." + Src_fld : trg_tbl + "." + Trg_fld;
|
||||
}
|
||||
|
||||
public static final Sql_join_fld[] Ary__empty = new Sql_join_fld[0];
|
||||
}
|
||||
27
140_dbs/src/gplx/dbs/sqls/itms/Sql_order_clause.java
Normal file
27
140_dbs/src/gplx/dbs/sqls/itms/Sql_order_clause.java
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
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.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
public class Sql_order_clause {
|
||||
private final List_adp list = List_adp_.New();
|
||||
private Sql_order_fld[] ary;
|
||||
public void Flds__add(Sql_order_fld fld) {list.Add(fld);}
|
||||
public Sql_order_fld[] Flds() {
|
||||
if (ary == null) ary = (Sql_order_fld[])list.To_ary_and_clear(Sql_order_fld.class);
|
||||
return ary;
|
||||
}
|
||||
}
|
||||
37
140_dbs/src/gplx/dbs/sqls/itms/Sql_order_fld.java
Normal file
37
140_dbs/src/gplx/dbs/sqls/itms/Sql_order_fld.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
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.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
public class Sql_order_fld {
|
||||
public Sql_order_fld(String tbl, String name, byte sort) {this.Tbl = tbl; this.Name = name; this.Sort = sort;}
|
||||
public final String Tbl;
|
||||
public final String Name;
|
||||
public final byte Sort;
|
||||
public String To_sql() {
|
||||
String rv = this.Name;
|
||||
if (Tbl != null) rv = Tbl + "." + rv;
|
||||
switch (Sort) {
|
||||
case Sort__asc: rv += " ASC"; break;
|
||||
case Sort__dsc: rv += " DESC"; break;
|
||||
case Sort__nil: break;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static final String Tbl__null = String_.Null;
|
||||
public static final byte Sort__asc = Bool_.Y_byte, Sort__dsc = Bool_.N_byte, Sort__nil = Bool_.__byte;
|
||||
}
|
||||
41
140_dbs/src/gplx/dbs/sqls/itms/Sql_order_fld_sorter.java
Normal file
41
140_dbs/src/gplx/dbs/sqls/itms/Sql_order_fld_sorter.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
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.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
import gplx.core.gfo_ndes.*;
|
||||
import gplx.core.lists.*;
|
||||
public class Sql_order_fld_sorter implements ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
GfoNde lhs = (GfoNde)lhsObj; GfoNde rhs = (GfoNde)rhsObj;
|
||||
Sql_order_fld item = null; Object lhsData = null, rhsData = null;
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
item = items[i];
|
||||
lhsData = lhs.Read(item.Name); rhsData = rhs.Read(item.Name);
|
||||
int compare = CompareAble_.Compare_obj(lhsData, rhsData);
|
||||
if (compare == CompareAble_.Same) continue;
|
||||
int ascendingVal = item.Sort == Sql_order_fld.Sort__dsc ? -1 : 1;
|
||||
return compare * ascendingVal;
|
||||
}
|
||||
return CompareAble_.Same;
|
||||
}
|
||||
Sql_order_fld[] items;
|
||||
public static ComparerAble new_(Sql_order_fld[] items) {
|
||||
Sql_order_fld_sorter rv = new Sql_order_fld_sorter();
|
||||
rv.items = items;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
22
140_dbs/src/gplx/dbs/sqls/itms/Sql_select_clause.java
Normal file
22
140_dbs/src/gplx/dbs/sqls/itms/Sql_select_clause.java
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
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.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
public class Sql_select_clause {
|
||||
public boolean Distinct = false;
|
||||
public final Sql_select_fld_list Flds = new Sql_select_fld_list();
|
||||
}
|
||||
66
140_dbs/src/gplx/dbs/sqls/itms/Sql_select_fld.java
Normal file
66
140_dbs/src/gplx/dbs/sqls/itms/Sql_select_fld.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
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.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
|
||||
public abstract class Sql_select_fld {
|
||||
public Sql_select_fld(String tbl, String fld, String alias) {
|
||||
this.Tbl = tbl; this.Fld = fld; this.Alias = alias;
|
||||
}
|
||||
public final String Tbl; // tbl_alias; EX: "t1."
|
||||
public final String Fld; // fld_key; EX: "fld"
|
||||
public final String Alias; // alias; EX: " AS [Field Name]"; NOTE: must be fld name if no alias defined; EX: "SELECT fld1" should have tbl='', fld='fld1' and alias='fld1'
|
||||
public abstract String To_fld_sql(); // EX: "t1.fld AS [Field Name]"
|
||||
public String To_fld_alias() {return Alias;} // EX: "t1.fld AS [Field Name]" -> "Field Name"; "t1.fld1" -> "fld1"
|
||||
public String To_fld_key() {return Tbl == Tbl__null ? Fld : Tbl + "." + Fld;}
|
||||
|
||||
public static final String Tbl__null = null, Fld__wildcard = "*";
|
||||
public static Sql_select_fld New_fld (String tbl, String fld, String alias) {return new Sql_select_fld_col(tbl, fld, alias);}
|
||||
public static Sql_select_fld Wildcard = Sql_select_fld_wild.Instance;
|
||||
public static Sql_select_fld New_count (String tbl, String fld, String alias) {return new Sql_select_fld_count(tbl, fld, alias);}
|
||||
public static Sql_select_fld New_sum (String tbl, String fld, String alias) {return new Sql_select_fld_sum(tbl, fld, alias);}
|
||||
public static Sql_select_fld New_min (String tbl, String fld, String alias) {return new Sql_select_fld_minMax(CompareAble_.Less, tbl, fld, alias);}
|
||||
public static Sql_select_fld New_max (String tbl, String fld, String alias) {return new Sql_select_fld_minMax(CompareAble_.More, tbl, fld, alias);}
|
||||
public static String Bld_tbl_w_fld(String tbl, String fld) {return tbl == null ? fld : tbl + "." + fld;}
|
||||
|
||||
// tdb related functions
|
||||
public ClassXtn Val_type() {return val_type;} public void Val_type_(ClassXtn val) {val_type = val;} private ClassXtn val_type = ObjectClassXtn.Instance;
|
||||
public abstract Object GroupBy_eval(Object groupByVal, Object curVal, ClassXtn type);
|
||||
@gplx.Virtual public void GroupBy_type(ClassXtn type) {this.Val_type_(type);}
|
||||
}
|
||||
class Sql_select_fld_wild extends Sql_select_fld { Sql_select_fld_wild() {super(Sql_select_fld.Tbl__null, Fld__wildcard, Fld__wildcard);}
|
||||
@Override public String To_fld_sql() {return Fld__wildcard;}
|
||||
|
||||
public static final Sql_select_fld_wild Instance = new Sql_select_fld_wild();
|
||||
|
||||
// tdb-related functions
|
||||
@Override public Object GroupBy_eval(Object groupByVal, Object curVal, ClassXtn type) {throw Err_.new_wo_type("group by eval not allowed on *");}
|
||||
@Override public void GroupBy_type(ClassXtn type) {throw Err_.new_wo_type("group by type not allowed on *");}
|
||||
}
|
||||
class Sql_select_fld_col extends Sql_select_fld { public Sql_select_fld_col(String tbl, String fld, String alias) {super(tbl, fld, alias);}
|
||||
@Override public String To_fld_sql() {
|
||||
String rv = Fld;
|
||||
if (this.Tbl != Tbl__null)
|
||||
rv = this.Tbl + "." + Fld;
|
||||
if (!String_.Eq(Alias, Fld))
|
||||
rv = rv + " AS " + Alias;
|
||||
return rv;
|
||||
}
|
||||
|
||||
// tdb-related functions
|
||||
@Override public Object GroupBy_eval(Object groupByVal, Object curVal, ClassXtn type) {return curVal;}
|
||||
}
|
||||
52
140_dbs/src/gplx/dbs/sqls/itms/Sql_select_fld_func.java
Normal file
52
140_dbs/src/gplx/dbs/sqls/itms/Sql_select_fld_func.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
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.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
import gplx.core.type_xtns.*;
|
||||
abstract class Sql_select_fld_func extends Sql_select_fld { public Sql_select_fld_func(String tbl, String fld, String alias) {super(tbl, fld, alias);}
|
||||
public abstract String XtoSql_functionName();
|
||||
@Override public String To_fld_sql() {
|
||||
return String_.Format("{0}({1}) AS {2}", XtoSql_functionName(), Fld, Alias);
|
||||
}
|
||||
}
|
||||
class Sql_select_fld_count extends Sql_select_fld_func { public Sql_select_fld_count(String tbl, String fld, String alias) {super(tbl, fld, alias);}
|
||||
@Override public String XtoSql_functionName() {return "COUNT";}
|
||||
@Override public void GroupBy_type(ClassXtn type) {this.Val_type_(IntClassXtn.Instance);}
|
||||
@Override public Object GroupBy_eval(Object groupByVal, Object curVal, ClassXtn type) {
|
||||
if (groupByVal == null) return 1;
|
||||
return Int_.cast(groupByVal) + 1;
|
||||
}
|
||||
}
|
||||
class Sql_select_fld_sum extends Sql_select_fld_func { public Sql_select_fld_sum(String tbl, String fld, String alias) {super(tbl, fld, alias);}
|
||||
@Override public String XtoSql_functionName() {return "SUM";}
|
||||
@Override public void GroupBy_type(ClassXtn type) {this.Val_type_(IntClassXtn.Instance);}
|
||||
@Override public Object GroupBy_eval(Object groupByVal, Object curVal, ClassXtn type) {
|
||||
if (groupByVal == null) return Int_.cast(curVal);
|
||||
return Int_.cast(groupByVal) + Int_.cast(curVal);
|
||||
}
|
||||
}
|
||||
class Sql_select_fld_minMax extends Sql_select_fld_func { private final int compareType;
|
||||
public Sql_select_fld_minMax(int compareType, String tbl, String fld, String alias) {super(tbl, fld, alias);
|
||||
this.compareType = compareType;
|
||||
}
|
||||
@Override public String XtoSql_functionName() {return compareType == CompareAble_.Less ? "MIN" : "MAX";}
|
||||
@Override public Object GroupBy_eval(Object groupByVal, Object curVal, ClassXtn type) {
|
||||
if (groupByVal == null) return curVal;
|
||||
int compareVal = CompareAble_.Compare_obj(curVal, groupByVal);
|
||||
return compareVal * compareType > 0 ? curVal : groupByVal;
|
||||
}
|
||||
}
|
||||
25
140_dbs/src/gplx/dbs/sqls/itms/Sql_select_fld_list.java
Normal file
25
140_dbs/src/gplx/dbs/sqls/itms/Sql_select_fld_list.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
public class Sql_select_fld_list {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Len() {return hash.Count();}
|
||||
public Sql_select_fld_list Clear() {hash.Clear();return this;}
|
||||
public Sql_select_fld Get_at(int i) {return (Sql_select_fld)hash.Get_at(i);}
|
||||
public void Add(Sql_select_fld fld) {hash.Add(fld.Alias, fld);}
|
||||
}
|
||||
44
140_dbs/src/gplx/dbs/sqls/itms/Sql_tbl_itm.java
Normal file
44
140_dbs/src/gplx/dbs/sqls/itms/Sql_tbl_itm.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
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.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
public class Sql_tbl_itm {
|
||||
public Sql_tbl_itm(int join_tid, String db, String name, String alias, Sql_join_fld[] join_flds) {
|
||||
this.Join_tid = join_tid;
|
||||
this.Db = db;
|
||||
this.Name = name;
|
||||
this.Alias = alias;
|
||||
this.Join_flds = join_flds;
|
||||
}
|
||||
public final int Join_tid;
|
||||
public final String Db;
|
||||
public final String Name;
|
||||
public final String Alias;
|
||||
public boolean Db_enabled = true;
|
||||
public final Sql_join_fld[] Join_flds;
|
||||
|
||||
public static final String Alias__null = String_.Null;
|
||||
public static final String Db__null = String_.Null;
|
||||
public static final int
|
||||
Tid__from = 0 // "FROM"
|
||||
, Tid__inner = 1 // "INNER JOIN"
|
||||
, Tid__left = 2 // "LEFT JOIN"
|
||||
, Tid__right = 3 // "RIGHT JOIN"
|
||||
, Tid__outer = 4 // "OUTER JOIN"
|
||||
, Tid__cross = 5 // "CROSS JOIN"
|
||||
;
|
||||
}
|
||||
25
140_dbs/src/gplx/dbs/sqls/itms/Sql_where_clause.java
Normal file
25
140_dbs/src/gplx/dbs/sqls/itms/Sql_where_clause.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
import gplx.core.criterias.*;
|
||||
public class Sql_where_clause {
|
||||
public Criteria Root = Criteria_.All;
|
||||
public static final Object Where__null = null;
|
||||
|
||||
public static final Sql_where_clause All = new Sql_where_clause();
|
||||
}
|
||||
Reference in New Issue
Block a user