mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.1.4.1a
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
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 org.junit.*;
|
||||
public class AnsiValWtr_tst {
|
||||
@Test public void BldValStr() {
|
||||
tst_XtoSqlVal(null, "NULL");
|
||||
tst_XtoSqlVal(true, "1");
|
||||
tst_XtoSqlVal(false, "0");
|
||||
tst_XtoSqlVal(1, "1");
|
||||
tst_XtoSqlVal(1.1, "1.1");
|
||||
tst_XtoSqlVal("a", "'a'");
|
||||
tst_XtoSqlVal("a'b", "'a''b'");
|
||||
}
|
||||
void tst_XtoSqlVal(Object val, String expd) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
Db_arg prm = new Db_arg("not needed", val);
|
||||
valWtr.BldValStr(sb, prm);
|
||||
Tfds.Eq(expd, sb.XtoStr());
|
||||
}
|
||||
Sql_cmd_wtr valWtr = Sql_cmd_wtr_ansi_.default_();
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
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.*;
|
||||
public class Db_provider_fxt implements RlsAble {
|
||||
public Db_provider Provider() {return provider;} public Db_provider_fxt Provider_(Db_provider v) {provider = v; return this;} Db_provider provider;
|
||||
public void DmlAffectedAvailable_(boolean v) {dmlAffectedAvailable = v;} private boolean dmlAffectedAvailable = true;
|
||||
public void ini_DeleteAll(String tbl) {provider.Exec_qry(Db_qry_.delete_tbl_(tbl));}
|
||||
public void tst_ExecDml(int expd, Db_qry qry) {
|
||||
int actl = provider.Exec_qry(qry);
|
||||
if (dmlAffectedAvailable)
|
||||
Tfds.Eq(expd, actl, "Exec_qry failed: sql={0}", qry.XtoSql());
|
||||
}
|
||||
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 = provider.Exec_qry_as_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.XtoSql());
|
||||
} 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() {provider.Conn_term();}
|
||||
|
||||
public static Db_provider Mysql() {return Db_provider_.new_and_open_(Db_conn_info__mysql.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_provider Tdb(String fileName) {return Db_provider_.new_and_open_(Db_conn_info_.tdb_(Tfds.RscDir.GenSubDir_nest("140_dbs", "tdbs").GenSubFil(fileName)));}
|
||||
public static Db_provider Postgres() {return Db_provider_.new_and_open_(Db_conn_info__postgres.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_provider Sqlite() {return Db_provider_.new_and_open_(Db_conn_info__sqlite.load_(Tfds.RscDir.GenSubFil_nest("140_dbs", "sqlite", "unit_tests.db")));}
|
||||
// public static Db_provider Mssql() {return MssqlConnectUrl.WindowsAuth(".", "unit_tests");
|
||||
public static final boolean SkipPostgres = Tfds.SkipDb || true;
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
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 org.junit.*;
|
||||
import gplx.criterias.*;
|
||||
public class Sql_cmd_wtr_ansi_tst {
|
||||
Sql_cmd_wtr whereWtr = Sql_cmd_wtr_ansi_.default_();
|
||||
@Test public void Basic() {
|
||||
tst_XtoSql_where(Db_crt_.eq_("id", 1), "id=1");
|
||||
tst_XtoSql_where(Db_crt_.eqn_("id", 1), "id!=1");
|
||||
tst_XtoSql_where(Db_crt_.mt_("id", 1), "id>1");
|
||||
tst_XtoSql_where(Db_crt_.mte_("id", 1), "id>=1");
|
||||
tst_XtoSql_where(Db_crt_.lt_("id", 1), "id<1");
|
||||
tst_XtoSql_where(Db_crt_.lte_("id", 1), "id<=1");
|
||||
tst_XtoSql_where(Db_crt_.between_("id", 1, 2), "id BETWEEN 1 AND 2");
|
||||
tst_XtoSql_where(Db_crt_.in_("id", 1, 2, 3), "id IN (1, 2, 3)");
|
||||
}
|
||||
@Test public void AndOr() {
|
||||
tst_XtoSql_where(Criteria_.And(Db_crt_.eq_("id", 1), Db_crt_.eq_("name", "me")), "(id=1 AND name='me')");
|
||||
tst_XtoSql_where(Criteria_.Or(Db_crt_.eq_("id", 1), Db_crt_.eq_("name", "me")), "(id=1 OR name='me')");
|
||||
tst_XtoSql_where(Criteria_.Or(Db_crt_.eq_("id", 1), Criteria_.And(Db_crt_.eq_("name", "me"), Db_crt_.eq_("id", 1))), "(id=1 OR (name='me' AND id=1))");
|
||||
}
|
||||
void tst_XtoSql_where(Criteria crt, String expd) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
whereWtr.BldWhere(sb, crt);
|
||||
Tfds.Eq(expd, sb.XtoStr());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user