mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Refactor: Pull more classes into baselib
This commit is contained in:
@@ -14,29 +14,28 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.sqls.wtrs;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.String_;
|
||||
import gplx.Tfds;
|
||||
import gplx.types.custom.brys.wtrs.BryWtr;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import gplx.core.criterias.Criteria;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.sqls.SqlQryWtr;
|
||||
import gplx.dbs.sqls.SqlQryWtrUtl;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.types.basics.utls.BoolUtl;
|
||||
class Sql_core_wtr_fxt {
|
||||
private final Sql_core_wtr__sqlite wtr = new Sql_core_wtr__sqlite();
|
||||
private final Sql_wtr_ctx ctx = new Sql_wtr_ctx(false);
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
private final BryWtr bfr = BryWtr.New();
|
||||
public Sql_core_wtr_fxt Sql_wtr_(SqlQryWtr v) {sql_wtr = v; return this;} private SqlQryWtr sql_wtr = SqlQryWtrUtl.NewSqlite();
|
||||
public void Test__val(Object val, String expd) {
|
||||
wtr.Val_wtr().Bld_val(bfr, ctx, val);
|
||||
Tfds.Eq_str(expd, bfr.To_str_and_clear());
|
||||
GfoTstr.Eq(expd, bfr.ToStrAndClear());
|
||||
}
|
||||
public void Test__where(Criteria crt, String... expd) {
|
||||
wtr.Where_wtr().Bld_where_elem(bfr, ctx, crt);
|
||||
Tfds.Eq_str_lines(String_.Concat_lines_nl_skip_last(expd), bfr.To_str_and_clear());
|
||||
GfoTstr.EqLines(StringUtl.ConcatLinesNlSkipLast(expd), bfr.ToStrAndClear());
|
||||
}
|
||||
public void Test__qry(Db_qry qry, String expd) {
|
||||
Tfds.Eq_str_lines(expd, sql_wtr.ToSqlStr(qry, BoolUtl.N));
|
||||
GfoTstr.EqLines(expd, sql_wtr.ToSqlStr(qry, BoolUtl.N));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@ package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sq
|
||||
import org.junit.*;
|
||||
public class Sql_from_wtr_tst {
|
||||
private final Sql_core_wtr_fxt fxt = new Sql_core_wtr_fxt();
|
||||
@Test public void Abrv() {
|
||||
@Test public void Abrv() {
|
||||
fxt.Test__qry(Db_qry_.select_().Cols_all_().From_("tbl", "t"), "SELECT * FROM tbl t");
|
||||
}
|
||||
@Test public void Db() {
|
||||
@Test public void Db() {
|
||||
fxt.Test__qry(Db_qry_.select_().Cols_all_().From_("db", "tbl", "t"), "SELECT * FROM db.tbl t");
|
||||
}
|
||||
@Test public void Join() {
|
||||
@Test public void Join() {
|
||||
fxt.Test__qry
|
||||
( Db_qry_.select_().Cols_all_().From_("src", "s").Join_("trg", "t", Db_qry_.New_join__join("trg_id", "s", "src_id"))
|
||||
, "SELECT * FROM src s INNER JOIN trg t ON s.src_id = t.trg_id");
|
||||
|
||||
@@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
package gplx.dbs.sqls.wtrs; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import org.junit.*;
|
||||
import gplx.core.criterias.*;
|
||||
public class Sql_qry_wtr__ansi__tst {
|
||||
@@ -93,5 +94,5 @@ public class Sql_qry_wtr__ansi__tst {
|
||||
);
|
||||
}
|
||||
void tst_XtoSql(Db_qry cmd, String expd) {tst_XtoSql(cmd, expd, false);}
|
||||
void tst_XtoSql(Db_qry cmd, String expd, boolean prepare) {Tfds.Eq(expd, sqlWtr.ToSqlStr(cmd, prepare));}
|
||||
void tst_XtoSql(Db_qry cmd, String expd, boolean prepare) {GfoTstr.EqObj(expd, sqlWtr.ToSqlStr(cmd, prepare));}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,10 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.sqls.wtrs; import gplx.*;
|
||||
package gplx.dbs.sqls.wtrs;
|
||||
import gplx.dbs.sqls.*;
|
||||
import gplx.types.custom.brys.wtrs.BryWtr;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import org.junit.*;
|
||||
import gplx.core.criterias.*; /*Criteria_base*/
|
||||
import gplx.core.ios.*;
|
||||
@@ -53,8 +55,8 @@ public class Sql_qry_wtr__iosql__tst {
|
||||
private final Sql_wtr_ctx ctx = new Sql_wtr_ctx(false);
|
||||
void tst_Write(String expd, Criteria crt) {
|
||||
Sql_where_wtr where_wtr = ((Sql_core_wtr)SqlQryWtrUtl.NewBasic()).Where_wtr();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
BryWtr bfr = BryWtr.New();
|
||||
where_wtr.Bld_where_elem(bfr, ctx, crt);
|
||||
Tfds.Eq(expd, bfr.To_str_and_clear());
|
||||
GfoTstr.EqObj(expd, bfr.ToStrAndClear());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
package gplx.dbs.sqls.wtrs; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
import gplx.frameworks.tests.GfoTstr;
|
||||
import gplx.types.basics.utls.StringUtl;
|
||||
import org.junit.*;
|
||||
public class Sql_schema_wtr_tst {
|
||||
@Before public void setup() {} private final Sql_schema_wtr_fxt fxt = new Sql_schema_wtr_fxt();
|
||||
@@ -35,7 +37,7 @@ public class Sql_schema_wtr_tst {
|
||||
flds.AddText("fld_text");
|
||||
flds.AddBry("fld_bry");
|
||||
fxt.Test_create_tbl(Dbmeta_tbl_itm.New("tbl_name", flds.ToFldAry())
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
, StringUtl.ConcatLinesNlSkipLast
|
||||
( "CREATE TABLE IF NOT EXISTS tbl_name"
|
||||
, "( fld_int_pkey integer NOT NULL PRIMARY KEY"
|
||||
, ", fld_bool boolean NOT NULL"
|
||||
@@ -60,7 +62,7 @@ public class Sql_schema_wtr_tst {
|
||||
}
|
||||
class Sql_schema_wtr_fxt {
|
||||
private Sql_schema_wtr sqlbldr = SqlQryWtrUtl.NewSqlite().Schema_wtr();
|
||||
public void Test_create_idx(Dbmeta_idx_itm idx, String expd) {Tfds.Eq(expd, sqlbldr.Bld_create_idx(idx));}
|
||||
public void Test_create_tbl(Dbmeta_tbl_itm tbl, String expd) {Tfds.Eq_str_lines(expd, sqlbldr.Bld_create_tbl(tbl));}
|
||||
public void Test_alter_tbl_add(String tbl, DbmetaFldItm fld, String expd) {Tfds.Eq_str_lines(expd, sqlbldr.Bld_alter_tbl_add(tbl, fld));}
|
||||
public void Test_create_idx(Dbmeta_idx_itm idx, String expd) {GfoTstr.EqObj(expd, sqlbldr.Bld_create_idx(idx));}
|
||||
public void Test_create_tbl(Dbmeta_tbl_itm tbl, String expd) {GfoTstr.EqLines(expd, sqlbldr.Bld_create_tbl(tbl));}
|
||||
public void Test_alter_tbl_add(String tbl, DbmetaFldItm fld, String expd) {GfoTstr.EqLines(expd, sqlbldr.Bld_alter_tbl_add(tbl, fld));}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@ package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sq
|
||||
import org.junit.*;
|
||||
public class Sql_select_wtr_tst {
|
||||
private final Sql_core_wtr_fxt fxt = new Sql_core_wtr_fxt();
|
||||
@Test public void Offset__automatically_add_limit() {
|
||||
@Test public void Offset__automatically_add_limit() {
|
||||
fxt.Test__qry(Db_qry_.select_tbl_("tbl").Offset_(1), "SELECT * FROM tbl LIMIT -1 OFFSET 1");
|
||||
}
|
||||
@Test public void Offset__do_not_overwrite_limit() {
|
||||
@Test public void Offset__do_not_overwrite_limit() {
|
||||
fxt.Test__qry(Db_qry_.select_tbl_("tbl").Limit_(20).Offset_(1), "SELECT * FROM tbl LIMIT 20 OFFSET 1");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,29 +14,27 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.sqls.wtrs;
|
||||
import gplx.Byte_;
|
||||
import gplx.DateAdp_;
|
||||
import gplx.Decimal_adp_;
|
||||
import gplx.Short_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.types.commons.GfoDateUtl;
|
||||
import gplx.types.commons.GfoDecimalUtl;
|
||||
import gplx.types.basics.utls.BoolUtl;
|
||||
import gplx.types.basics.utls.ByteUtl;
|
||||
import org.junit.Test;
|
||||
public class Sql_val_wtr_tst {
|
||||
private final Sql_core_wtr_fxt fxt = new Sql_core_wtr_fxt();
|
||||
@Test public void Null() {fxt.Test__val(null , "NULL");}
|
||||
@Test public void Bool__n() {fxt.Test__val(BoolUtl.N , "0");}
|
||||
@Test public void Bool__y() {fxt.Test__val(BoolUtl.Y , "1");}
|
||||
@Test public void Byte() {fxt.Test__val(Byte_.By_int(2) , "2");}
|
||||
@Test public void Short() {fxt.Test__val(Short_.By_int(3) , "3");}
|
||||
@Test public void Int() {fxt.Test__val(4 , "4");}
|
||||
@Test public void Long() {fxt.Test__val(5 , "5");}
|
||||
@Test public void Float() {fxt.Test__val(6.1f , "6.1");}
|
||||
@Test public void Double() {fxt.Test__val(7.1d , "7.1");}
|
||||
@Test public void Decimal() {fxt.Test__val(Decimal_adp_.float_(8) , "'8'");}
|
||||
@Test public void Str() {fxt.Test__val("abc" , "'abc'");}
|
||||
@Test public void Str__apos_mid() {fxt.Test__val("a'b" , "'a''b'");}
|
||||
@Test public void Str__apos_bgn() {fxt.Test__val("'ab" , "'''ab'");}
|
||||
@Test public void Str__apos_end() {fxt.Test__val("ab'" , "'ab'''");}
|
||||
@Test public void Str__apos_many() {fxt.Test__val("a'b'c" , "'a''b''c'");}
|
||||
@Test public void Str__back() {fxt.Test__val("a\\b" , "'a\\b'");}
|
||||
@Test public void Date() {fxt.Test__val(DateAdp_.parse_gplx("2016-02-03") , "'2016-02-03 00:00:00.000'");}
|
||||
@Test public void Null() {fxt.Test__val(null , "NULL");}
|
||||
@Test public void Bool__n() {fxt.Test__val(BoolUtl.N , "0");}
|
||||
@Test public void Bool__y() {fxt.Test__val(BoolUtl.Y , "1");}
|
||||
@Test public void Byte() {fxt.Test__val(ByteUtl.ByInt(2) , "2");}
|
||||
@Test public void Int() {fxt.Test__val(4 , "4");}
|
||||
@Test public void Long() {fxt.Test__val(5 , "5");}
|
||||
@Test public void Float() {fxt.Test__val(6.1f , "6.1");}
|
||||
@Test public void Double() {fxt.Test__val(7.1d , "7.1");}
|
||||
@Test public void Decimal() {fxt.Test__val(GfoDecimalUtl.NewByFloat(8) , "'8'");}
|
||||
@Test public void Str() {fxt.Test__val("abc" , "'abc'");}
|
||||
@Test public void Str__apos_mid() {fxt.Test__val("a'b" , "'a''b'");}
|
||||
@Test public void Str__apos_bgn() {fxt.Test__val("'ab" , "'''ab'");}
|
||||
@Test public void Str__apos_end() {fxt.Test__val("ab'" , "'ab'''");}
|
||||
@Test public void Str__apos_many() {fxt.Test__val("a'b'c" , "'a''b''c'");}
|
||||
@Test public void Str__back() {fxt.Test__val("a\\b" , "'a\\b'");}
|
||||
@Test public void Date() {fxt.Test__val(GfoDateUtl.ParseGplx("2016-02-03") , "'2016-02-03 00:00:00.000'");}
|
||||
}
|
||||
|
||||
@@ -19,16 +19,16 @@ import gplx.dbs.Db_crt_;
|
||||
import org.junit.Test;
|
||||
public class Sql_where_wtr_tst {
|
||||
private final Sql_core_wtr_fxt fxt = new Sql_core_wtr_fxt();
|
||||
@Test public void Eq() {fxt.Test__where(Db_crt_.New_eq ("fld", 1) , "fld = 1");}
|
||||
@Test public void Eq_not() {fxt.Test__where(Db_crt_.New_eq_not ("fld", 1) , "fld != 1");}
|
||||
@Test public void Eq_pre() {fxt.Test__where(Db_crt_.New_eq ("a", "fld", 1) , "a.fld = 1");}
|
||||
@Test public void Lt() {fxt.Test__where(Db_crt_.New_lt ("fld", 1) , "fld < 1");}
|
||||
@Test public void Lte() {fxt.Test__where(Db_crt_.New_lte ("fld", 1) , "fld <= 1");}
|
||||
@Test public void Mt() {fxt.Test__where(Db_crt_.New_mt ("fld", 1) , "fld > 1");}
|
||||
@Test public void Mte() {fxt.Test__where(Db_crt_.New_mte ("fld", 1) , "fld >= 1");}
|
||||
@Test public void Between() {fxt.Test__where(Db_crt_.New_between ("fld", 1, 3) , "fld BETWEEN 1 AND 3");}
|
||||
@Test public void In() {fxt.Test__where(Db_crt_.New_in ("fld", 1, 2, 3) , "fld IN (1, 2, 3)");}
|
||||
@Test public void Like() {fxt.Test__where(Db_crt_.New_like ("fld", "A%") , "fld LIKE 'A%' ESCAPE '|'");}
|
||||
@Test public void Eq() {fxt.Test__where(Db_crt_.New_eq ("fld", 1) , "fld = 1");}
|
||||
@Test public void Eq_not() {fxt.Test__where(Db_crt_.New_eq_not ("fld", 1) , "fld != 1");}
|
||||
@Test public void Eq_pre() {fxt.Test__where(Db_crt_.New_eq ("a", "fld", 1) , "a.fld = 1");}
|
||||
@Test public void Lt() {fxt.Test__where(Db_crt_.New_lt ("fld", 1) , "fld < 1");}
|
||||
@Test public void Lte() {fxt.Test__where(Db_crt_.New_lte ("fld", 1) , "fld <= 1");}
|
||||
@Test public void Mt() {fxt.Test__where(Db_crt_.New_mt ("fld", 1) , "fld > 1");}
|
||||
@Test public void Mte() {fxt.Test__where(Db_crt_.New_mte ("fld", 1) , "fld >= 1");}
|
||||
@Test public void Between() {fxt.Test__where(Db_crt_.New_between ("fld", 1, 3) , "fld BETWEEN 1 AND 3");}
|
||||
@Test public void In() {fxt.Test__where(Db_crt_.New_in ("fld", 1, 2, 3) , "fld IN (1, 2, 3)");}
|
||||
@Test public void Like() {fxt.Test__where(Db_crt_.New_like ("fld", "A%") , "fld LIKE 'A%' ESCAPE '|'");}
|
||||
@Test public void And__subs__2() {
|
||||
fxt.Test__where
|
||||
( Criteria_.And
|
||||
|
||||
Reference in New Issue
Block a user