mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v1.6.5.1
This commit is contained in:
99
140_dbs/tst/gplx/dbs/AnsiSqlWtr_tst.java
Normal file
99
140_dbs/tst/gplx/dbs/AnsiSqlWtr_tst.java
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
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 AnsiSqlWtr_tst {
|
||||
Sql_cmd_wtr sqlWtr = Sql_cmd_wtr_ansi_.default_();
|
||||
@Test public void Insert() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.insert_("people").Arg_("id", 1).Arg_("name", "me")
|
||||
, "INSERT INTO people (id, name) VALUES (1, 'me')"
|
||||
);
|
||||
}
|
||||
@Test public void Delete() {
|
||||
Criteria crt = Db_crt_.eq_("id", 1);
|
||||
tst_XtoSql
|
||||
( Db_qry_.delete_("people", crt)
|
||||
, "DELETE FROM people WHERE id=1"
|
||||
);
|
||||
}
|
||||
@Test public void Update() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.update_("people", Db_crt_.eq_("id", 1)).Arg_("name", "me")
|
||||
, "UPDATE people SET name='me' WHERE id=1"
|
||||
);
|
||||
}
|
||||
@Test public void SelectAll() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.select_().From_("people")
|
||||
, "SELECT * FROM people"
|
||||
);
|
||||
}
|
||||
@Test public void SelectFlds() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.select_().Cols_("id", "name").From_("people")
|
||||
, "SELECT id, name FROM people"
|
||||
);
|
||||
}
|
||||
@Test public void SelectOrderBy() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.select_().From_("people").OrderBy_("name", false)
|
||||
, "SELECT * FROM people ORDER BY name DESC"
|
||||
);
|
||||
}
|
||||
@Test public void SelectWhere() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.select_().From_("people").Where_(Db_crt_.eq_("id", 1))
|
||||
, "SELECT * FROM people WHERE id=1"
|
||||
);
|
||||
}
|
||||
@Test public void Select_From_Alias() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.select_().From_("people", "p")
|
||||
, "SELECT * FROM people p"
|
||||
);
|
||||
}
|
||||
@Test public void Select_Join_Alias() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.select_().From_("people", "p").Join_("roles", "r", Sql_join_itm.same_("p", "id"))
|
||||
, "SELECT * FROM people p INNER JOIN roles r ON p.id=r.id"
|
||||
);
|
||||
}
|
||||
@Test public void Prepare() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.insert_("people").Arg_("id", 1).Arg_("name", "me")
|
||||
, "INSERT INTO people (id, name) VALUES (?, ?)"
|
||||
, true
|
||||
);
|
||||
|
||||
tst_XtoSql
|
||||
( Db_qry_.delete_("people", Db_crt_.eq_("id", 1))
|
||||
, "DELETE FROM people WHERE id=?"
|
||||
, true
|
||||
);
|
||||
|
||||
tst_XtoSql
|
||||
( Db_qry_.update_("people", Db_crt_.eq_("id", 1)).Arg_("name", "me")
|
||||
, "UPDATE people SET name=? WHERE id=?"
|
||||
, true
|
||||
);
|
||||
}
|
||||
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.XtoSqlQry(cmd, prepare));}
|
||||
}
|
||||
37
140_dbs/tst/gplx/dbs/AnsiValWtr_tst.java
Normal file
37
140_dbs/tst/gplx/dbs/AnsiValWtr_tst.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; 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_();
|
||||
}
|
||||
24
140_dbs/tst/gplx/dbs/DbTstDat.java
Normal file
24
140_dbs/tst/gplx/dbs/DbTstDat.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
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 DbTstDat {
|
||||
public int Idx() {return idx;} public DbTstDat Idx_(int val) {idx = val; return this;} int idx = -1;
|
||||
public String Fld() {return fld;} public DbTstDat Fld_(String v) {fld = v; return this;} private String fld = null;
|
||||
public Object Val() {return val;} public DbTstDat Val_(Object v) {val = v; return this;} Object val = null;
|
||||
public static DbTstDat new_() {return new DbTstDat();} DbTstDat() {}
|
||||
}
|
||||
31
140_dbs/tst/gplx/dbs/DbTstRow.java
Normal file
31
140_dbs/tst/gplx/dbs/DbTstRow.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
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 DbTstRow {
|
||||
public int Idx() {return idx;} public DbTstRow Idx_(int val) {idx = val; return this;} int idx = -1;
|
||||
public DbTstDat[] Dat() {return dat;} DbTstDat[] dat = null;
|
||||
public static DbTstRow vals_only_(Object... ary) {
|
||||
DbTstRow rv = new DbTstRow();
|
||||
int len = Array_.Len(ary);
|
||||
rv.dat = new DbTstDat[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv.dat[i] = DbTstDat.new_().Val_(ary[i]);
|
||||
return rv;
|
||||
}
|
||||
public static DbTstRow new_() {return new DbTstRow();} DbTstRow() {}
|
||||
}
|
||||
53
140_dbs/tst/gplx/dbs/Db_crt_tst.java
Normal file
53
140_dbs/tst/gplx/dbs/Db_crt_tst.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
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 Db_crt_tst {
|
||||
@Before public void setup() {
|
||||
row = GfoNde_.vals_(GfoFldList_.new_().Add("id", IntClassXtn._).Add("name", StringClassXtn._), Object_.Ary(1, "me"));
|
||||
}
|
||||
@Test public void EqualTest() {
|
||||
crt = Db_crt_.eq_("id", 1);
|
||||
tst_Match(true, row, crt);
|
||||
}
|
||||
@Test public void EqualFalseTest() {
|
||||
crt = Db_crt_.eq_("id", 2);
|
||||
tst_Match(false, row, crt);
|
||||
}
|
||||
@Test public void AndCompositeTest() {
|
||||
crt = Criteria_.And(Db_crt_.eq_("id", 1), Db_crt_.eq_("name", "me"));
|
||||
tst_Match(true, row, crt);
|
||||
|
||||
crt = Criteria_.And(Db_crt_.eq_("id", 1), Db_crt_.eq_("name", "you"));
|
||||
tst_Match(false, row, crt);
|
||||
}
|
||||
@Test public void OrCompositeTest() {
|
||||
crt = Criteria_.Or(Db_crt_.eq_("id", 1), Db_crt_.eq_("name", "you"));
|
||||
tst_Match(true, row, crt);
|
||||
|
||||
crt = Criteria_.Or(Db_crt_.eq_("id", 2), Db_crt_.eq_("name", "you"));
|
||||
tst_Match(false, row, crt);
|
||||
}
|
||||
|
||||
void tst_Match(boolean epxd, GfoNde row, Criteria crt) {
|
||||
boolean actl = crt.Matches(row);
|
||||
Tfds.Eq(epxd, actl);
|
||||
}
|
||||
GfoNde row; Criteria crt;
|
||||
}
|
||||
54
140_dbs/tst/gplx/dbs/Db_provider_fxt.java
Normal file
54
140_dbs/tst/gplx/dbs/Db_provider_fxt.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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.Rls();}
|
||||
|
||||
public static Db_provider Mysql() {return Db_provider_.new_(Db_connect_mysql.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_provider Tdb(String fileName) {return Db_provider_.new_(Db_connect_.tdb_(Tfds.RscDir.GenSubDir_nest("140_dbs", "tdbs").GenSubFil(fileName)));}
|
||||
public static Db_provider Postgres() {return Db_provider_.new_(Db_connect_postgres.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_provider Sqlite() {return Db_provider_.new_(Db_connect_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;
|
||||
}
|
||||
54
140_dbs/tst/gplx/dbs/Db_qry_fxt.java
Normal file
54
140_dbs/tst/gplx/dbs/Db_qry_fxt.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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_qry_fxt {
|
||||
public static void Insert_kvo(Db_provider provider, String tblName, KeyValList kvList) {
|
||||
Db_qry_insert qry = Db_qry_.insert_(tblName);
|
||||
for (int i = 0; i < kvList.Count(); i++) {
|
||||
KeyVal kv = kvList.GetAt(i);
|
||||
qry.Arg_obj_(kv.Key(), kv.Val());
|
||||
}
|
||||
qry.Exec_qry(provider);
|
||||
}
|
||||
public static GfoNde SelectAll(Db_provider provider, String tblName) {
|
||||
return Db_qry_.select_tbl_(tblName).ExecRdr_nde(provider);
|
||||
}
|
||||
public static int SelectAll_count(Db_provider provider, String tblName) {
|
||||
GfoNde nde = Db_qry_fxt.SelectAll(provider, tblName);
|
||||
return nde.Subs().Count();
|
||||
}
|
||||
public static void DeleteAll(Db_provider provider, String... ary) {
|
||||
for (String s : ary)
|
||||
Db_qry_.delete_tbl_(s).Exec_qry(provider);
|
||||
}
|
||||
public static void tst_Select(Db_provider provider, String tblName, DbTstRow... expdAry) {
|
||||
GfoNde nde = Db_qry_fxt.SelectAll(provider, tblName);
|
||||
int len = Array_.Len(expdAry);
|
||||
for (int i = 0; i < len; i++) {
|
||||
DbTstRow expdRow = expdAry[i];
|
||||
int actlIdx = (expdRow.Idx() == -1) ? i : expdRow.Idx();
|
||||
GfoNde actlNde = nde.Subs().FetchAt_asGfoNde(actlIdx);
|
||||
int fldLen = Array_.Len(expdRow.Dat());
|
||||
for (int j = 0; j < fldLen; j++) {
|
||||
DbTstDat expdDat = expdRow.Dat()[j];
|
||||
Object actlVal = expdDat.Fld() == null ? actlNde.ReadAt(j) : actlNde.Read(expdDat.Fld());
|
||||
Tfds.Eq(expdDat.Val(), actlVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
140_dbs/tst/gplx/dbs/GfoNdeTstr.java
Normal file
32
140_dbs/tst/gplx/dbs/GfoNdeTstr.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
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 GfoNdeTstr {
|
||||
public static void tst_ValsByCol(GfoNde nde, String fld, Object... expdAry) {
|
||||
ListAdp expd = ListAdp_.new_();
|
||||
for (int i = 0; i < expdAry.length; i++) {
|
||||
expd.Add(Object_.XtoStr_OrEmpty(expdAry[i]));
|
||||
}
|
||||
ListAdp actl = ListAdp_.new_();
|
||||
for (int i = 0; i < nde.Subs().Count(); i++) {
|
||||
GfoNde sub = nde.Subs().FetchAt_asGfoNde(i);
|
||||
actl.Add(Object_.XtoStr_OrEmpty(sub.Read(fld)));
|
||||
}
|
||||
Tfds.Eq_ary(expd.XtoStrAry(), actl.XtoStrAry());
|
||||
}
|
||||
}
|
||||
60
140_dbs/tst/gplx/dbs/IoSqlCriteriaWriter_tst.java
Normal file
60
140_dbs/tst/gplx/dbs/IoSqlCriteriaWriter_tst.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
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.*; /*Criteria_base*/
|
||||
import gplx.ios.*;
|
||||
public class IoSqlCriteriaWriter_tst {
|
||||
@Test public void Type() {
|
||||
fld = IoItm_base_.Prop_Type;
|
||||
tst_Write("type=1", ioCrt_(fld, Criteria_.eq_(IoItmDir.Type_Dir)));
|
||||
tst_Write("type=2", ioCrt_(fld, Criteria_.eq_(IoItmFil.Type_Fil)));
|
||||
}
|
||||
@Test public void Ext() {
|
||||
fld = IoItm_base_.Prop_Ext;
|
||||
tst_Write("ext='.txt'", ioCrt_(fld, Criteria_.eq_(".txt")));
|
||||
tst_Write("ext IN ('.txt', '.xml', '.html')", ioCrt_(fld, Criteria_.in_(".txt", ".xml", ".html")));
|
||||
tst_Write("ext NOT IN ('.dll', '.exe')", ioCrt_(fld, Criteria_.inn_(".dll", ".exe")));
|
||||
}
|
||||
@Test public void Title() {
|
||||
fld = IoItm_base_.Prop_Title;
|
||||
tst_Write("title='bin'", ioCrt_(fld, Criteria_.eq_("bin")));
|
||||
tst_Write("title NOT IN ('bin', 'obj')", ioCrt_(fld, Criteria_.inn_("bin", "obj")));
|
||||
}
|
||||
@Test public void Url() {
|
||||
fld = IoItm_base_.Prop_Path;
|
||||
tst_Write("url='C:\\fil.txt'", ioCrt_(fld, Criteria_.eq_("C:\\fil.txt")));
|
||||
tst_Write("url IOMATCH '*.txt'", ioCrt_(fld, Criteria_ioMatch.parse_(true, "*.txt", false)));
|
||||
}
|
||||
@Test public void Binary() {
|
||||
// parentheses around lhs and rhs
|
||||
tst_Write(
|
||||
"(type=1 OR type=2)"
|
||||
, Criteria_.Or
|
||||
( ioCrt_(IoItm_base_.Prop_Type, Criteria_.eq_(IoItmDir.Type_Dir)), ioCrt_(IoItm_base_.Prop_Type, Criteria_.eq_(IoItmFil.Type_Fil))
|
||||
));
|
||||
}
|
||||
Criteria ioCrt_(String fld, Criteria crt) {return Criteria_wrapper.new_(fld, crt);}
|
||||
String fld;
|
||||
void tst_Write(String expd, Criteria crt) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
Sql_cmd_wtr whereWtr = Sql_cmd_wtr_ansi_.default_();
|
||||
whereWtr.BldWhere(sb, crt);
|
||||
Tfds.Eq(expd, sb.XtoStr());
|
||||
}
|
||||
}
|
||||
56
140_dbs/tst/gplx/dbs/PoolIds_tst.java
Normal file
56
140_dbs/tst/gplx/dbs/PoolIds_tst.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
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 PoolIds_tst {
|
||||
@Before public void setup() {
|
||||
provider = Db_provider_pool._.FetchOrNew(Db_connect_.Test);
|
||||
Db_qry_fxt.DeleteAll(provider, PoolIds.Tbl_Name);
|
||||
mgr = PoolIds._;
|
||||
}
|
||||
@Test public void FetchNextId() {
|
||||
tst_Fetch("/test0", 0);
|
||||
}
|
||||
@Test public void ChangeNextId_Insert() {
|
||||
run_Change("/test0", 1);
|
||||
|
||||
tst_Fetch("/test0", 1);
|
||||
}
|
||||
@Test public void ChangeNextId_Update() {
|
||||
run_Change("/test0", 0);
|
||||
run_Change("/test0", 1);
|
||||
|
||||
tst_Fetch("/test0", 1);
|
||||
}
|
||||
@Test public void FetchNextId_Multiple() {
|
||||
run_Change("/test0", 0);
|
||||
run_Change("/test1", 1);
|
||||
|
||||
tst_Fetch("/test0", 0);
|
||||
tst_Fetch("/test1", 1);
|
||||
}
|
||||
void run_Change(String url, int expd) {
|
||||
mgr.Commit(provider, url, expd);
|
||||
}
|
||||
void tst_Fetch(String url, int expd) {
|
||||
int actl = mgr.FetchNext(provider, url);
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
Db_provider provider;
|
||||
PoolIds mgr;
|
||||
}
|
||||
43
140_dbs/tst/gplx/dbs/Sql_cmd_wtr_ansi_tst.java
Normal file
43
140_dbs/tst/gplx/dbs/Sql_cmd_wtr_ansi_tst.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
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());
|
||||
}
|
||||
}
|
||||
95
140_dbs/tst/gplx/dbs/groupBys/GroupBys_base_tst.java
Normal file
95
140_dbs/tst/gplx/dbs/groupBys/GroupBys_base_tst.java
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
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.groupBys; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*;
|
||||
public abstract class GroupBys_base_tst {
|
||||
protected abstract Db_provider provider_();
|
||||
protected Db_provider provider;
|
||||
@Before public void setup() {
|
||||
provider = provider_();
|
||||
Db_qry_.delete_tbl_("dbs_group_bys").Exec_qry(provider);
|
||||
}
|
||||
@After public void teardown() {
|
||||
provider.Rls();
|
||||
}
|
||||
protected void GroupBy_1fld_hook() {
|
||||
provider.Exec_qry(Db_qry_.insert_("dbs_group_bys").Arg_("key1", "a").Arg_("val_int", 1));
|
||||
provider.Exec_qry(Db_qry_.insert_("dbs_group_bys").Arg_("key1", "a").Arg_("val_int", 2));
|
||||
|
||||
DataRdr rdr = Db_qry_.select_().From_("dbs_group_bys")
|
||||
.Cols_("key1")
|
||||
.GroupBy_("key1")
|
||||
.Exec_qry_as_rdr(provider);
|
||||
GfoNde nde = GfoNde_.rdr_(rdr);
|
||||
GfoNdeTstr.tst_ValsByCol(nde, "key1", "a");
|
||||
}
|
||||
protected void GroupBy_2fld_hook() {
|
||||
provider.Exec_qry(Db_qry_.insert_("dbs_group_bys").Arg_("key1", "a").Arg_("key2", "b").Arg_("val_int", 1));
|
||||
provider.Exec_qry(Db_qry_.insert_("dbs_group_bys").Arg_("key1", "a").Arg_("key2", "b").Arg_("val_int", 2));
|
||||
|
||||
DataRdr rdr = Db_qry_.select_().From_("dbs_group_bys")
|
||||
.Cols_("key1", "key2")
|
||||
.GroupBy_("key1", "key2")
|
||||
.Exec_qry_as_rdr(provider);
|
||||
GfoNde nde = GfoNde_.rdr_(rdr);
|
||||
GfoNdeTstr.tst_ValsByCol(nde, "key1", "a");
|
||||
GfoNdeTstr.tst_ValsByCol(nde, "key2", "b");
|
||||
}
|
||||
protected void MinMax_hook(boolean min) {
|
||||
provider.Exec_qry(Db_qry_.insert_("dbs_group_bys").Arg_("key1", "a").Arg_("val_int", 1));
|
||||
provider.Exec_qry(Db_qry_.insert_("dbs_group_bys").Arg_("key1", "a").Arg_("val_int", 2));
|
||||
|
||||
Db_qry_select qry = Db_qry_.select_().From_("dbs_group_bys")
|
||||
.Cols_("key1")
|
||||
.GroupBy_("key1");
|
||||
int expd = min ? 1 : 2;
|
||||
if (min)
|
||||
qry.Cols_groupBy_min("val_int", "val_int_func");
|
||||
else
|
||||
qry.Cols_groupBy_max("val_int", "val_int_func");
|
||||
|
||||
DataRdr rdr = qry.Exec_qry_as_rdr(provider);
|
||||
GfoNde nde = GfoNde_.rdr_(rdr);
|
||||
GfoNdeTstr.tst_ValsByCol(nde, "key1", "a");
|
||||
GfoNdeTstr.tst_ValsByCol(nde, "val_int_func", expd);
|
||||
}
|
||||
protected void Count_hook() {
|
||||
provider.Exec_qry(Db_qry_.insert_("dbs_group_bys").Arg_("key1", "a").Arg_("val_int", 10));
|
||||
provider.Exec_qry(Db_qry_.insert_("dbs_group_bys").Arg_("key1", "a").Arg_("val_int", 20));
|
||||
|
||||
DataRdr rdr = Db_qry_.select_().From_("dbs_group_bys")
|
||||
.Cols_("key1").Cols_groupBy_count("val_int", "val_int_func")
|
||||
.GroupBy_("key1")
|
||||
.Exec_qry_as_rdr(provider);
|
||||
GfoNde nde = GfoNde_.rdr_(rdr);
|
||||
GfoNdeTstr.tst_ValsByCol(nde, "key1", "a");
|
||||
GfoNdeTstr.tst_ValsByCol(nde, "val_int_func", 2);
|
||||
}
|
||||
protected void Sum_hook() {
|
||||
provider.Exec_qry(Db_qry_.insert_("dbs_group_bys").Arg_("key1", "a").Arg_("val_int", 10));
|
||||
provider.Exec_qry(Db_qry_.insert_("dbs_group_bys").Arg_("key1", "a").Arg_("val_int", 20));
|
||||
|
||||
DataRdr rdr = Db_qry_.select_().From_("dbs_group_bys")
|
||||
.Cols_("key1").Cols_groupBy_sum("val_int", "val_int_func")
|
||||
.GroupBy_("key1")
|
||||
.Exec_qry_as_rdr(provider);
|
||||
GfoNde nde = GfoNde_.rdr_(rdr);
|
||||
GfoNdeTstr.tst_ValsByCol(nde, "key1", "a");
|
||||
GfoNdeTstr.tst_ValsByCol(nde, "val_int_func", 30);
|
||||
}
|
||||
}
|
||||
28
140_dbs/tst/gplx/dbs/groupBys/GroupBys_mysql_tst.java
Normal file
28
140_dbs/tst/gplx/dbs/groupBys/GroupBys_mysql_tst.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.groupBys; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*;
|
||||
public class GroupBys_mysql_tst extends GroupBys_base_tst {
|
||||
@Override protected Db_provider provider_() {return Db_provider_fxt.Mysql();}
|
||||
@Test public void GroupBy_1fld() {super.GroupBy_1fld_hook();}
|
||||
@Test public void GroupBy_2fld() {super.GroupBy_2fld_hook();}
|
||||
@Test public void Min() {super.MinMax_hook(true);}
|
||||
@Test public void Max() {super.MinMax_hook(false);}
|
||||
@Test public void Count() {super.Count_hook();}
|
||||
@Test public void Sum() {super.Sum_hook();}
|
||||
}
|
||||
29
140_dbs/tst/gplx/dbs/groupBys/GroupBys_tdb_tst.java
Normal file
29
140_dbs/tst/gplx/dbs/groupBys/GroupBys_tdb_tst.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
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.groupBys; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*;
|
||||
public class GroupBys_tdb_tst extends GroupBys_base_tst {
|
||||
@Override protected Db_provider provider_() {return Db_provider_fxt.Tdb("130_dbs_group_bys.dsv");}
|
||||
@Test public void GroupBy_1fld() {super.GroupBy_1fld_hook();}
|
||||
@Test public void GroupBy_2fld() {super.GroupBy_2fld_hook();}
|
||||
@Test public void Min() {super.MinMax_hook(true);}
|
||||
@Test public void Max() {super.MinMax_hook(false);}
|
||||
@Test public void Count() {super.Count_hook();}
|
||||
@Test public void Sum() {super.Sum_hook();}
|
||||
// Avg, CountDistinct
|
||||
}
|
||||
60
140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_base_tst.java
Normal file
60
140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_base_tst.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
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.insertIntos; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*;
|
||||
public abstract class InsertIntos_base_tst {
|
||||
protected abstract Db_provider provider_();
|
||||
protected Db_provider provider;
|
||||
@Before public void setup() {
|
||||
provider = provider_();
|
||||
provider.Exec_qry(Db_qry_delete.new_().BaseTable_("dbs_group_bys"));
|
||||
provider.Exec_qry(Db_qry_delete.new_().BaseTable_("dbs_insert_intos"));
|
||||
}
|
||||
@After public void teardown() {
|
||||
provider.Rls();
|
||||
}
|
||||
protected void Select_hook() {
|
||||
provider.Exec_qry(Db_qry_.insert_("dbs_group_bys").Arg_("key1", "a").Arg_("val_int", 1));
|
||||
|
||||
provider.Exec_qry
|
||||
(Db_qry_.insert_("dbs_insert_intos")
|
||||
.Cols_("key1", "val_int")
|
||||
.Select_
|
||||
( Db_qry_select.new_().Cols_("key1", "val_int").From_("dbs_group_bys")
|
||||
)
|
||||
);
|
||||
DataRdr rdr = provider.Exec_qry_as_rdr(Db_qry_select.new_().Cols_("key1", "val_int").From_("dbs_insert_intos"));
|
||||
GfoNde nde = GfoNde_.rdr_(rdr);
|
||||
GfoNdeTstr.tst_ValsByCol(nde, "key1", "a");
|
||||
}
|
||||
protected void GroupBy_hook() {
|
||||
provider.Exec_qry(Db_qry_.insert_("dbs_group_bys").Arg_("key1", "a").Arg_("val_int", 1));
|
||||
provider.Exec_qry(Db_qry_.insert_("dbs_group_bys").Arg_("key1", "a").Arg_("val_int", 2));
|
||||
|
||||
provider.Exec_qry
|
||||
(Db_qry_.insert_("dbs_insert_intos")
|
||||
.Cols_("key1", "val_int")
|
||||
.Select_
|
||||
( Db_qry_select.new_().Cols_("key1").Cols_groupBy_sum("val_int", "val_int_func")
|
||||
.From_("dbs_group_bys").GroupBy_("key1")
|
||||
));
|
||||
DataRdr rdr = provider.Exec_qry_as_rdr(Db_qry_select.new_().Cols_("key1", "val_int").From_("dbs_insert_intos"));
|
||||
GfoNde nde = GfoNde_.rdr_(rdr);
|
||||
GfoNdeTstr.tst_ValsByCol(nde, "val_int", 3);
|
||||
}
|
||||
}
|
||||
24
140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_mysql_tst.java
Normal file
24
140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_mysql_tst.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
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.insertIntos; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*;
|
||||
public class InsertIntos_mysql_tst extends InsertIntos_base_tst {
|
||||
@Override protected Db_provider provider_() {return Db_provider_fxt.Mysql();}
|
||||
@Test public void Select() {super.Select_hook();}
|
||||
@Test public void GroupBy() {super.GroupBy_hook();}
|
||||
}
|
||||
24
140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_tdb_tst.java
Normal file
24
140_dbs/tst/gplx/dbs/insertIntos/InsertIntos_tdb_tst.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
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.insertIntos; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*;
|
||||
public class InsertIntos_tdb_tst extends InsertIntos_base_tst {
|
||||
@Override protected Db_provider provider_() {return Db_provider_fxt.Tdb("140_dbs_insert_intos.dsv");}
|
||||
@Test public void Select() {super.Select_hook();}
|
||||
@Test public void GroupBy() {super.GroupBy_hook();}
|
||||
}
|
||||
44
140_dbs/tst/gplx/dbs/joins/Joins_base_tst.java
Normal file
44
140_dbs/tst/gplx/dbs/joins/Joins_base_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.joins; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*;
|
||||
public abstract class Joins_base_tst {
|
||||
protected Db_provider provider;
|
||||
@Before public void setup() {
|
||||
provider = provider_();
|
||||
Db_qry_delete.new_().BaseTable_("dbs_crud_ops").Exec_qry(provider);
|
||||
Db_qry_delete.new_().BaseTable_("dbs_join1").Exec_qry(provider);
|
||||
}
|
||||
@After public void teardown() {
|
||||
provider.Rls();
|
||||
}
|
||||
protected void InnerJoin_hook() {
|
||||
provider.Exec_qry(Db_qry_insert.new_().BaseTable_("dbs_crud_ops").Arg_("id", 0).Arg_("name", "me"));
|
||||
provider.Exec_qry(Db_qry_insert.new_().BaseTable_("dbs_crud_ops").Arg_("id", 1).Arg_("name", "you"));
|
||||
provider.Exec_qry(Db_qry_insert.new_().BaseTable_("dbs_join1").Arg_("join_id", 0).Arg_("join_data", "data0"));
|
||||
provider.Exec_qry(Db_qry_insert.new_().BaseTable_("dbs_join1").Arg_("join_id", 1).Arg_("join_data", "data1"));
|
||||
Db_qry_select select = Db_qry_select.new_().From_("dbs_crud_ops").Join_("dbs_join1", "j1", Sql_join_itm.new_("join_id", "dbs_crud_ops", "id")).Cols_("id", "name", "join_data");
|
||||
|
||||
DataRdr rdr = provider.Exec_qry_as_rdr(select);
|
||||
GfoNde table = GfoNde_.rdr_(rdr);
|
||||
Tfds.Eq(table.Subs().Count(), 2);
|
||||
Tfds.Eq(table.Subs().FetchAt_asGfoNde(0).Read("join_data"), "data0");
|
||||
Tfds.Eq(table.Subs().FetchAt_asGfoNde(1).Read("join_data"), "data1");
|
||||
}
|
||||
protected abstract Db_provider provider_();
|
||||
}
|
||||
31
140_dbs/tst/gplx/dbs/joins/Joins_tdb_tst.java
Normal file
31
140_dbs/tst/gplx/dbs/joins/Joins_tdb_tst.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
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.joins; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*;
|
||||
public class Joins_tdb_tst extends Joins_base_tst {
|
||||
@Override protected Db_provider provider_() {return Db_provider_fxt.Tdb("120_dbs_joins.dsv");}
|
||||
@Test public void InnerJoin() {
|
||||
try {
|
||||
InnerJoin_hook();
|
||||
}
|
||||
catch (Exception exc) {
|
||||
if (String_.Has(Err_.Message_lang(exc), "joins not supported for tdbs")) return;
|
||||
}
|
||||
Tfds.Fail("'joins not supported for tdbs' error not thrown");
|
||||
}
|
||||
}
|
||||
52
140_dbs/tst/gplx/dbs/orderBys/OrderBys_base_tst.java
Normal file
52
140_dbs/tst/gplx/dbs/orderBys/OrderBys_base_tst.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.orderBys; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*;
|
||||
public abstract class OrderBys_base_tst {
|
||||
@Before public void setup() {
|
||||
provider = provider_();
|
||||
fx.Provider_(provider);
|
||||
Db_qry_delete.new_().BaseTable_("dbs_crud_ops").Exec_qry(provider);
|
||||
} protected Db_provider_fxt fx = new Db_provider_fxt();
|
||||
@After public void teardown() {provider.Rls();}
|
||||
protected abstract Db_provider provider_(); protected Db_provider provider;
|
||||
protected void Basic_hook() {
|
||||
fx.tst_ExecDml(1, Db_qry_insert.new_().BaseTable_("dbs_crud_ops").Arg_("id", 1).Arg_("name", "you"));
|
||||
fx.tst_ExecDml(1, Db_qry_insert.new_().BaseTable_("dbs_crud_ops").Arg_("id", 0).Arg_("name", "me"));
|
||||
|
||||
fx.tst_ExecRdr(2, Db_qry_select.new_().From_("dbs_crud_ops").OrderBy_("id", true));
|
||||
fx.tst_RowAry(0, 0, "me");
|
||||
fx.tst_RowAry(1, 1, "you");
|
||||
|
||||
fx.tst_ExecRdr(2, Db_qry_select.new_().From_("dbs_crud_ops").OrderBy_("id", false));
|
||||
fx.tst_RowAry(0, 1, "you");
|
||||
fx.tst_RowAry(1, 0, "me");
|
||||
}
|
||||
protected void SameVals_hook() {
|
||||
fx.tst_ExecDml(1, Db_qry_insert.new_().BaseTable_("dbs_crud_ops").Arg_("id", 0).Arg_("name", "me"));
|
||||
fx.tst_ExecDml(1, Db_qry_insert.new_().BaseTable_("dbs_crud_ops").Arg_("id", 0).Arg_("name", "you"));
|
||||
|
||||
fx.tst_ExecRdr(2, Db_qry_select.new_().From_("dbs_crud_ops").OrderBy_("id", true));
|
||||
fx.tst_RowAry(0, 0, "me");
|
||||
fx.tst_RowAry(1, 0, "you");
|
||||
|
||||
fx.tst_ExecRdr(2, Db_qry_select.new_().From_("dbs_crud_ops").OrderBy_("id", false));
|
||||
fx.tst_RowAry(0, 0, "me");
|
||||
fx.tst_RowAry(1, 0, "you");
|
||||
}
|
||||
}
|
||||
38
140_dbs/tst/gplx/dbs/orderBys/OrderBys_tdb_tst.java
Normal file
38
140_dbs/tst/gplx/dbs/orderBys/OrderBys_tdb_tst.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.orderBys; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*;
|
||||
public class OrderBys_tdb_tst extends OrderBys_base_tst {
|
||||
@Override protected Db_provider provider_() {return Db_provider_fxt.Tdb("120_dbs_joins.dsv");}
|
||||
@Test public void Basic() {
|
||||
Basic_hook();
|
||||
}
|
||||
@Test public void SameVals() {
|
||||
SameVals_hook();
|
||||
}
|
||||
}
|
||||
//namespace gplx.dbs.crudOps {
|
||||
// import org.junit.*;
|
||||
// public class CrudOps_tdb_tst {
|
||||
// @Before public void setup() {fx = new CrudOpsFxt(Db_provider_fxt.Tdb("100_dbs_crud_ops.dsv"));} CrudOpsFxt fx;
|
||||
// @Test public void FlushToDisk() {
|
||||
// fx.Fx().tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Arg_("id", 2).Arg_("name", "you"));
|
||||
// Db_qry_flush.new_("dbs_crud_ops").Exec_qry(fx.Fx().Provider());
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
Reference in New Issue
Block a user