mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Refactor: Refactor baselib; merge Array_ and Bool_
This commit is contained in:
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
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; import gplx.*;
|
||||
import gplx.core.stores.*;
|
||||
import gplx.dbs.engines.sqlite.*; import gplx.dbs.engines.mysql.*; import gplx.dbs.engines.postgres.*; import gplx.core.gfo_ndes.*;
|
||||
public class Db_conn_fxt implements Rls_able {
|
||||
public Db_conn Conn() {return conn;} public Db_conn_fxt Conn_(Db_conn v) {conn = v; return this;} Db_conn conn;
|
||||
public void DmlAffectedAvailable_(boolean v) {dmlAffectedAvailable = v;} private boolean dmlAffectedAvailable = true;
|
||||
public void ini_DeleteAll(String tbl) {conn.Exec_qry(Db_qry_.delete_tbl_(tbl));}
|
||||
public void tst_ExecDml(int expd, Db_qry qry) {
|
||||
int actl = conn.Exec_qry(qry);
|
||||
if (dmlAffectedAvailable)
|
||||
Tfds.Eq(expd, actl, "Exec_qry failed: sql={0}", qry.ToSqlExec(conn.Engine().Sql_wtr()));
|
||||
}
|
||||
public void tst_ExecRdrTbl(int expd, String tblName) {tst_ExecRdr(expd, Db_qry_.select_tbl_(tblName));}
|
||||
public void tst_ExecRdr(int expd, Db_qry qry) {
|
||||
DataRdr rdr = DataRdr_.Null;
|
||||
try {
|
||||
rdr = conn.Exec_qry_as_old_rdr(qry);
|
||||
tbl = GfoNde_.rdr_(rdr);
|
||||
}
|
||||
catch (Exception e) {Err_.Noop(e); rdr.Rls();}
|
||||
Tfds.Eq(expd, tbl.Subs().Count(), "Exec_qry_as_rdr failed: sql={0}", qry.ToSqlExec(conn.Engine().Sql_wtr()));
|
||||
} GfoNde tbl;
|
||||
public GfoNde tst_RowAry(int index, Object... expdValAry) {
|
||||
GfoNde record = tbl.Subs().FetchAt_asGfoNde(index);
|
||||
Object[] actlValAry = new Object[expdValAry.length];
|
||||
for (int i = 0; i < actlValAry.length; i++)
|
||||
actlValAry[i] = record.ReadAt(i);
|
||||
Tfds.Eq_ary(actlValAry, expdValAry);
|
||||
return record;
|
||||
}
|
||||
public void Rls() {conn.Rls_conn();}
|
||||
|
||||
public static Db_conn Mysql() {return Db_conn_pool.Instance.Get_or_new(Mysql_conn_info.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_conn Tdb(String fileName) {return Db_conn_pool.Instance.Get_or_new(Db_conn_info_.tdb_(Tfds.RscDir.GenSubDir_nest("140_dbs", "tdbs").GenSubFil(fileName)));}
|
||||
public static Db_conn Postgres() {return Db_conn_pool.Instance.Get_or_new(Postgres_conn_info.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_conn Sqlite() {return Db_conn_pool.Instance.Get_or_new(Sqlite_conn_info.load_(Tfds.RscDir.GenSubFil_nest("140_dbs", "sqlite", "unit_tests.db")));}
|
||||
public static final boolean SkipPostgres = Tfds.SkipDb || true;
|
||||
}
|
||||
@@ -13,8 +13,16 @@ 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.*;
|
||||
import gplx.core.criterias.*;
|
||||
package gplx.dbs.sqls.wtrs;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.String_;
|
||||
import gplx.Tfds;
|
||||
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;
|
||||
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);
|
||||
@@ -29,6 +37,6 @@ class Sql_core_wtr_fxt {
|
||||
Tfds.Eq_str_lines(String_.Concat_lines_nl_skip_last(expd), bfr.To_str_and_clear());
|
||||
}
|
||||
public void Test__qry(Db_qry qry, String expd) {
|
||||
Tfds.Eq_str_lines(expd, sql_wtr.ToSqlStr(qry, Bool_.N));
|
||||
Tfds.Eq_str_lines(expd, sql_wtr.ToSqlStr(qry, BoolUtl.N));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,18 @@ 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.*;
|
||||
import org.junit.*;
|
||||
package gplx.dbs.sqls.wtrs;
|
||||
import gplx.Byte_;
|
||||
import gplx.DateAdp_;
|
||||
import gplx.Decimal_adp_;
|
||||
import gplx.Short_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
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(Bool_.N , "0");}
|
||||
@Test public void Bool__y() {fxt.Test__val(Bool_.Y , "1");}
|
||||
@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");}
|
||||
|
||||
@@ -1,53 +1,55 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
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.*;
|
||||
import org.junit.*; import gplx.core.criterias.*;
|
||||
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 And__subs__2() {
|
||||
fxt.Test__where
|
||||
( Criteria_.And
|
||||
( Db_crt_.New_eq("id", 1)
|
||||
, Db_crt_.New_eq("name", "me")
|
||||
), "(id = 1 AND name = 'me')");
|
||||
}
|
||||
@Test public void Or__subs__2() {
|
||||
fxt.Test__where
|
||||
( Criteria_.Or
|
||||
( Db_crt_.New_eq("id", 1)
|
||||
, Db_crt_.New_eq("name", "me")
|
||||
), "(id = 1 OR name = 'me')");
|
||||
}
|
||||
@Test public void Nested() {
|
||||
fxt.Test__where
|
||||
( Criteria_.Or
|
||||
( Db_crt_.New_eq("id", 1)
|
||||
, Criteria_.And
|
||||
( Db_crt_.New_eq("name", "me")
|
||||
, Db_crt_.New_eq("id", 2))
|
||||
), "(id = 1 OR (name = 'me' AND id = 2))");
|
||||
}
|
||||
}
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2021 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
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.core.criterias.Criteria_;
|
||||
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 And__subs__2() {
|
||||
fxt.Test__where
|
||||
( Criteria_.And
|
||||
( Db_crt_.New_eq("id", 1)
|
||||
, Db_crt_.New_eq("name", "me")
|
||||
), "(id = 1 AND name = 'me')");
|
||||
}
|
||||
@Test public void Or__subs__2() {
|
||||
fxt.Test__where
|
||||
( Criteria_.Or
|
||||
( Db_crt_.New_eq("id", 1)
|
||||
, Db_crt_.New_eq("name", "me")
|
||||
), "(id = 1 OR name = 'me')");
|
||||
}
|
||||
@Test public void Nested() {
|
||||
fxt.Test__where
|
||||
( Criteria_.Or
|
||||
( Db_crt_.New_eq("id", 1)
|
||||
, Criteria_.And
|
||||
( Db_crt_.New_eq("name", "me")
|
||||
, Db_crt_.New_eq("id", 2))
|
||||
), "(id = 1 OR (name = 'me' AND id = 2))");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user