mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.2.1.1
This commit is contained in:
@@ -16,7 +16,7 @@ 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.criterias.*;
|
||||
import gplx.core.criterias.*;
|
||||
public class Db_qry_ {
|
||||
public static Db_qry_select select_cols_(String tbl, Criteria crt, String... cols){return select_().From_(tbl).Where_(crt).Cols_(cols);}
|
||||
public static Db_qry_select select_val_(String tbl, String col, Criteria crt) {return select_().From_(tbl).Where_(crt).Cols_(col);}
|
||||
|
||||
@@ -16,16 +16,17 @@ 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.strings.*; import gplx.core.criterias.*;
|
||||
public class Db_qry__select_in_tbl implements Db_qry {
|
||||
public Db_qry__select_in_tbl(String tbl_name, String[] select_flds, String[] where_flds, String group_by_sql, String having_sql, String order_by_sql, String limit_sql) {
|
||||
this.tbl_name = tbl_name; this.select_flds = select_flds; this.where_flds = where_flds; this.group_by_sql = group_by_sql; this.having_sql = having_sql; this.order_by_sql = order_by_sql; this.limit_sql = limit_sql;
|
||||
public Db_qry__select_in_tbl(String base_table, String[] select_flds, String[] where_flds, String group_by_sql, String having_sql, String order_by_sql, String limit_sql) {
|
||||
this.base_table = base_table; this.select_flds = select_flds; this.where_flds = where_flds; this.group_by_sql = group_by_sql; this.having_sql = having_sql; this.order_by_sql = order_by_sql; this.limit_sql = limit_sql;
|
||||
}
|
||||
public int Tid() {return Db_qry_.Tid_select_in_tbl;}
|
||||
public boolean Exec_is_rdr() {return true;}
|
||||
public String Base_table() {return tbl_name;} private final String tbl_name;
|
||||
public String From() {return tbl_name;}
|
||||
public String[] Select_flds() {return select_flds;} private final String[] select_flds;
|
||||
public String[] Where_flds() {return where_flds;} private final String[] where_flds;
|
||||
public String Base_table() {return base_table;} private final String base_table;
|
||||
public Criteria Where() {return where;} private Criteria where;
|
||||
public String[] Select_flds() {return select_flds;} private final String[] select_flds;
|
||||
private final String[] where_flds;
|
||||
public void Where_sql(String_bldr sb) {
|
||||
if (where_flds == null) return;
|
||||
int where_flds_len = where_flds.length;
|
||||
@@ -48,17 +49,19 @@ public class Db_qry__select_in_tbl implements Db_qry {
|
||||
if (i != 0) sb.Add(",");
|
||||
sb.Add(select_flds[i]);
|
||||
}
|
||||
sb.Add(" FROM ").Add(tbl_name);
|
||||
if (where_flds != null) {sb.Add(" WHERE "); Where_sql(sb);}
|
||||
sb.Add(" FROM ").Add(base_table);
|
||||
if (where_flds != null && where_flds.length != 0) {sb.Add(" WHERE "); Where_sql(sb);}
|
||||
if (group_by_sql != null) sb.Add(group_by_sql);
|
||||
if (having_sql != null) sb.Add(having_sql);
|
||||
if (order_by_sql != null) {sb.Add(" ORDER BY "); sb.Add(order_by_sql);}
|
||||
if (limit_sql != null) sb.Add(limit_sql);
|
||||
return sb.XtoStr();
|
||||
}
|
||||
public static Db_qry__select_in_tbl new_(String tbl_name, String[] where_flds, String[] select_flds) {
|
||||
Db_qry__select_in_tbl rv = new Db_qry__select_in_tbl(tbl_name, select_flds, where_flds, null, null, null, null);
|
||||
public static Db_qry__select_in_tbl new_(String base_table, String[] where_flds, String[] select_flds) {
|
||||
Db_qry__select_in_tbl rv = new Db_qry__select_in_tbl(base_table, select_flds, where_flds, null, null, null, null);
|
||||
rv.where = Db_crt_.eq_many_(where_flds);
|
||||
return rv;
|
||||
}
|
||||
public static final String[] Where_flds__all = null;
|
||||
public static Db_qry__select_in_tbl as_(Object obj) {return obj instanceof Db_qry__select_in_tbl ? (Db_qry__select_in_tbl)obj : null;}
|
||||
public static final String[] Where_flds__all = String_.Ary_empty;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ 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.criterias.*; import gplx.dbs.sqls.*;
|
||||
import gplx.core.criterias.*; import gplx.dbs.sqls.*;
|
||||
public class Db_qry_delete implements Db_qry {
|
||||
Db_qry_delete(String base_table, Criteria where) {this.base_table = base_table; this.where = where;}
|
||||
public int Tid() {return Db_qry_.Tid_delete;}
|
||||
@@ -25,17 +25,7 @@ public class Db_qry_delete implements Db_qry {
|
||||
public String Xto_sql() {return Sql_qry_wtr_.I.Xto_str(this, false);}
|
||||
public Criteria Where() {return where;} private final Criteria where;
|
||||
public int Exec_qry(Db_conn conn) {return conn.Exec_qry(this);}
|
||||
|
||||
public String[] Where_cols() {return where_cols;} private String[] where_cols;
|
||||
public static Db_qry_delete new_all_(String tbl) {
|
||||
Db_qry_delete rv = new_(tbl, Criteria_.All);
|
||||
rv.where_cols = String_.Ary_empty;
|
||||
return rv;
|
||||
}
|
||||
public static Db_qry_delete new_(String tbl, String... where) {
|
||||
Db_qry_delete rv = Db_qry_delete.new_(tbl, Db_crt_.eq_many_(where));
|
||||
rv.where_cols = where;
|
||||
return rv;
|
||||
}
|
||||
public static Db_qry_delete new_(String tbl, Criteria where) {return new Db_qry_delete(tbl, where);}
|
||||
public static Db_qry_delete new_all_(String tbl) {return new Db_qry_delete(tbl, Criteria_.All);}
|
||||
public static Db_qry_delete new_(String tbl, String... where) {return new Db_qry_delete(tbl, Db_crt_.eq_many_(where));}
|
||||
public static Db_qry_delete new_(String tbl, Criteria where) {return new Db_qry_delete(tbl, where);}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import org.junit.*;
|
||||
import gplx.criterias.*;
|
||||
import gplx.core.criterias.*;
|
||||
public class Db_qry_dml_tst {
|
||||
@Test public void Delete_basic() {
|
||||
tst_XtoSql(Db_qry_delete.new_("tbl0", Db_crt_.eq_("fld0", "val0"))
|
||||
|
||||
@@ -21,10 +21,12 @@ public class Db_qry_insert implements Db_qry_arg_owner {
|
||||
public Db_qry_insert(String base_table) {this.base_table = base_table;}
|
||||
public int Tid() {return Db_qry_.Tid_insert;}
|
||||
public boolean Exec_is_rdr() {return false;}
|
||||
public String Base_table() {return base_table;} private String base_table;
|
||||
public String Xto_sql() {return Sql_qry_wtr_.I.Xto_str(this, false);}
|
||||
public int Exec_qry(Db_conn conn) {return conn.Exec_qry(this);}
|
||||
public String Base_table() {return base_table;} private String base_table;
|
||||
public String[] Cols_for_insert() {return cols_for_insert;} private String[] cols_for_insert;
|
||||
public Db_qry_arg_owner From_(String tbl) {base_table = tbl; return this;}
|
||||
public KeyValHash Args() {return args;} private final KeyValHash args = KeyValHash.new_();
|
||||
public Db_qry_arg_owner Arg_(String k, DecimalAdp v) {return Arg_obj_type_(k, v.Xto_decimal(), Db_val_type.Tid_decimal);}
|
||||
public Db_qry_arg_owner Arg_(String k, DateAdp v) {return Arg_obj_type_(k, v, Db_val_type.Tid_date);}
|
||||
public Db_qry_arg_owner Arg_byte_(String k, byte v) {return Arg_obj_type_(k, v, Db_val_type.Tid_byte);}
|
||||
@@ -49,10 +51,8 @@ public class Db_qry_insert implements Db_qry_arg_owner {
|
||||
cols.Add(Sql_select_fld_fld.new_(Sql_select_fld_base.Tbl_null, fld, fld));
|
||||
return this;
|
||||
}
|
||||
public KeyValHash Args() {return args;} private final KeyValHash args = KeyValHash.new_();
|
||||
@gplx.Internal protected Sql_select_fld_list Cols() {return cols;} private Sql_select_fld_list cols;
|
||||
|
||||
public String[] Cols_for_insert() {return cols_for_insert;} private String[] cols_for_insert;
|
||||
public static Db_qry_insert new_() {return new Db_qry_insert();} Db_qry_insert() {}
|
||||
public static Db_qry_insert new_(String tbl, String... keys) {
|
||||
Db_qry_insert rv = Db_qry_insert.new_();
|
||||
|
||||
@@ -16,13 +16,13 @@ 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.criterias.*; import gplx.dbs.sqls.*;
|
||||
import gplx.core.criterias.*; import gplx.dbs.sqls.*;
|
||||
public class Db_qry_select implements Db_qry {
|
||||
public int Tid() {return Db_qry_.Tid_select;}
|
||||
public boolean Exec_is_rdr() {return true;}
|
||||
public String Base_table() {return from.BaseTable().TblName();}
|
||||
public String Xto_sql() {return Sql_qry_wtr_.I.Xto_str(this, false);}
|
||||
public DataRdr Exec_qry_as_rdr(Db_conn conn) {return conn.Exec_qry_as_rdr(this);}
|
||||
public DataRdr Exec_qry_as_rdr(Db_conn conn) {return conn.Exec_qry_as_rdr(this);}
|
||||
public GfoNde ExecRdr_nde(Db_conn conn) {
|
||||
DataRdr rdr = DataRdr_.Null;
|
||||
try {return GfoNde_.rdr_(Exec_qry_as_rdr(conn));} finally {rdr.Rls();}
|
||||
@@ -65,6 +65,7 @@ public class Db_qry_select implements Db_qry {
|
||||
}
|
||||
|
||||
@gplx.Internal protected Sql_select Cols() {return cols;} Sql_select cols = Sql_select.All;
|
||||
public String[] Cols_ary() {return cols.Flds().To_str_ary();}
|
||||
public Db_qry_select Cols_all_() {return this;}
|
||||
public Db_qry_select Cols_alias_(String expr, String alias) {
|
||||
if (cols == Sql_select.All) cols = Sql_select.new_();
|
||||
@@ -100,7 +101,7 @@ public class Db_qry_select implements Db_qry {
|
||||
return this;
|
||||
}
|
||||
|
||||
@gplx.Internal protected Sql_where Where() {return where;} public Db_qry_select Where_(Criteria crt) {where = Sql_where.new_(crt); return this;} Sql_where where;
|
||||
public Criteria Where() {return where;} public Db_qry_select Where_(Criteria crt) {where = crt; return this;} Criteria where;
|
||||
@gplx.Internal protected Sql_order_by OrderBy() {return orderBy;} Sql_order_by orderBy = null;
|
||||
public Db_qry_select OrderBy_(String fieldName, boolean ascending) {
|
||||
Sql_order_by_itm item = Sql_order_by_itm.new_(fieldName, ascending);
|
||||
|
||||
@@ -16,14 +16,17 @@ 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.criterias.*; import gplx.dbs.sqls.*;
|
||||
import gplx.core.criterias.*; import gplx.dbs.sqls.*;
|
||||
public class Db_qry_update implements Db_qry_arg_owner {
|
||||
public int Tid() {return Db_qry_.Tid_update;}
|
||||
public boolean Exec_is_rdr() {return false;}
|
||||
public String Base_table() {return baseTable;}
|
||||
public String Xto_sql() {return Sql_qry_wtr_.I.Xto_str(this, false);}
|
||||
public int Exec_qry(Db_conn conn) {return conn.Exec_qry(this);}
|
||||
public Db_qry_arg_owner From_(String tbl) {baseTable = tbl; return this;}
|
||||
public int Exec_qry(Db_conn conn) {return conn.Exec_qry(this);}
|
||||
public String Base_table() {return base_table;} private String base_table;
|
||||
public String[] Cols_for_update() {return cols_for_update;} private String[] cols_for_update;
|
||||
public Criteria Where() {return where;} public Db_qry_update Where_(Criteria crt) {where = crt; return this;} private Criteria where;
|
||||
public Db_qry_arg_owner From_(String tbl) {base_table = tbl; return this;}
|
||||
public KeyValHash Args() {return args;} private final KeyValHash args = KeyValHash.new_();
|
||||
public Db_qry_arg_owner Arg_(String k, DecimalAdp v) {return Arg_obj_type_(k, v.Xto_decimal(), Db_val_type.Tid_decimal);}
|
||||
public Db_qry_arg_owner Arg_(String k, DateAdp v) {return Arg_obj_type_(k, v, Db_val_type.Tid_date);}
|
||||
public Db_qry_arg_owner Arg_byte_(String k, byte v) {return Arg_obj_type_(k, v, Db_val_type.Tid_byte);}
|
||||
@@ -40,21 +43,15 @@ public class Db_qry_update implements Db_qry_arg_owner {
|
||||
}
|
||||
public Db_qry_arg_owner Key_arg_(String k, int v) {return Key_arg_obj_(k, v);}
|
||||
public Db_qry_arg_owner Key_arg_(String k, String v) {return Key_arg_obj_(k, v);}
|
||||
Db_qry_arg_owner Key_arg_obj_(String k, Object v) {
|
||||
private Db_qry_arg_owner Key_arg_obj_(String k, Object v) {
|
||||
Criteria crt = Db_crt_.eq_(k, v);
|
||||
where = Sql_where.merge_or_new_(where, crt);
|
||||
where = where == null ? crt : Criteria_.And(where, crt);
|
||||
return this;
|
||||
}
|
||||
public KeyValHash Args() {return args;} private final KeyValHash args = KeyValHash.new_();
|
||||
@gplx.Internal protected String BaseTable() {return baseTable;} private String baseTable;
|
||||
@gplx.Internal protected Sql_where Where() {return where;} public Db_qry_update Where_(Criteria crt) {where = Sql_where.new_(crt); return this;} private Sql_where where;
|
||||
public String[] Cols_where() {return cols_where;} private String[] cols_where;
|
||||
public String[] Cols_update() {return cols_update;} private String[] cols_update;
|
||||
public static Db_qry_update new_() {return new Db_qry_update();} Db_qry_update() {}
|
||||
public static Db_qry_update new_(String tbl, String[] where, String... update) {
|
||||
Db_qry_update rv = Db_qry_.update_(tbl, Db_crt_.eq_many_(where));
|
||||
rv.cols_update = update;
|
||||
rv.cols_where = where;
|
||||
rv.cols_for_update = update;
|
||||
int len = update.length;
|
||||
for (int i = 0; i < len; i++)
|
||||
rv.Arg_obj_(update[i], null);
|
||||
|
||||
Reference in New Issue
Block a user