mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
App: Release v4.5.15.1709
This commit is contained in:
138
140_dbs/src/gplx/core/stores/DbMaprMgr_tst.java
Normal file
138
140_dbs/src/gplx/core/stores/DbMaprMgr_tst.java
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
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.core.stores; import gplx.*; import gplx.core.*;
|
||||
import org.junit.*;
|
||||
import gplx.dbs.*; /*Db_conn_info*/
|
||||
public class DbMaprMgr_tst {
|
||||
@Before public void setup() {
|
||||
mgr = DbMaprMgr.new_().RootIndexFlds_(DbMaprArg.new_("id", "disc_id"))
|
||||
.Root_
|
||||
( DbMaprItm.proto_(MockDisc.Instance, "discs", "mock_discs")
|
||||
. Flds_add(MockDisc.id_idk, "disc_id").Flds_add(MockDisc.name_idk, "disc_name")
|
||||
. ContextFlds_add(MockDisc.id_idk).Subs_add
|
||||
( DbMaprItm.proto_(MockTitle.Instance, "titles", "mock_titles")
|
||||
. Flds_add(MockTitle.id_idk, "title_id").Flds_add(MockTitle.name_idk, "title_name")
|
||||
. ContextFlds_add(MockTitle.id_idk).Subs_add
|
||||
( DbMaprItm.proto_(MockChapter.Instance, "chapters", "mock_chapters")
|
||||
. Flds_add(MockChapter.id_idk, "chapter_id").Flds_add(MockChapter.name_idk, "chapter_name")
|
||||
, DbMaprItm.proto_(MockStream.Instance, "audios", "mock_streams")
|
||||
. Flds_add(MockStream.id_idk, "stream_id").Flds_add(MockStream.name_idk, "stream_name")
|
||||
. ConstantFlds_add("stream_type", 0)
|
||||
, DbMaprItm.proto_(MockStream.Instance, "subtitles", "mock_streams")
|
||||
. Flds_add(MockStream.id_idk, "stream_id").Flds_add(MockStream.name_idk, "stream_name")
|
||||
. ConstantFlds_add("stream_type", 1)
|
||||
)));
|
||||
wtr = DbMaprWtr.new_by_url_(Db_conn_info_.Test);
|
||||
wtr.EnvVars().Add(DbMaprWtr.Key_Mgr, mgr);
|
||||
conn = Db_conn_pool.Instance.Get_or_new(Db_conn_info_.Test);
|
||||
Db_qry_fxt.DeleteAll(conn, "mock_discs", "mock_titles", "mock_chapters", "mock_streams");
|
||||
} DbMaprMgr mgr; DbMaprWtr wtr; Db_conn conn; MockDisc disc; MockTitle title; MockChapter chapter; MockStream audio, subtitle; SrlMgr rdr;
|
||||
@Test public void PurgeObjTree() {
|
||||
disc = MockDisc.new_().Id_(1);
|
||||
Db_qry_fxt.Insert_kvo(conn, "mock_discs", Keyval_list.New_with_one("disc_id", 1));
|
||||
DbMaprWtrUtl.PurgeObjTree(disc, mgr, conn);
|
||||
Tfds.Eq(0, Db_qry_fxt.SelectAll_count(conn, "mock_discs"));
|
||||
}
|
||||
@Test public void PurgeObjTree_deep() {
|
||||
disc = MockDisc.new_().Id_(1);
|
||||
Db_qry_fxt.Insert_kvo(conn, "mock_discs", Keyval_list.New_with_one("disc_id", 1));
|
||||
Db_qry_fxt.Insert_kvo(conn, "mock_titles", Keyval_list.New_with_one("disc_id", 1).Add("title_id", 1));
|
||||
Db_qry_fxt.Insert_kvo(conn, "mock_chapters", Keyval_list.New_with_one("disc_id", 1).Add("title_id", 2).Add("chapter_id", 3));
|
||||
Db_qry_fxt.Insert_kvo(conn, "mock_chapters", Keyval_list.New_with_one("disc_id", 2).Add("title_id", 2).Add("chapter_id", 3));
|
||||
DbMaprWtrUtl.PurgeObjTree(disc, mgr, conn);
|
||||
|
||||
Tfds.Eq(0, Db_qry_fxt.SelectAll_count(conn, "mock_discs"));
|
||||
Tfds.Eq(0, Db_qry_fxt.SelectAll_count(conn, "mock_titles"));
|
||||
Tfds.Eq(1, Db_qry_fxt.SelectAll_count(conn, "mock_chapters")); // ignore chapter with disc_id=2
|
||||
}
|
||||
@Test public void Save_root() {
|
||||
disc = MockDisc.new_().Id_(1).Name_("disc");
|
||||
|
||||
wtr.StoreRoot(disc, "mock_discs");
|
||||
Db_qry_fxt.tst_Select(conn, "mock_discs", Db_mock_row.vals_only_(1, "disc"));
|
||||
}
|
||||
@Test public void Save_subs() {
|
||||
disc = MockDisc.new_().Id_(1).Name_("disc");
|
||||
title = MockTitle.new_().Id_(2).Name_("title").Disc_(disc);
|
||||
|
||||
wtr.StoreRoot(disc, "mock_discs");
|
||||
Db_qry_fxt.tst_Select(conn, "mock_discs", Db_mock_row.vals_only_(1, "disc"));
|
||||
Db_qry_fxt.tst_Select(conn, "mock_titles", Db_mock_row.vals_only_(1, 2, "title"));
|
||||
}
|
||||
@Test public void Save_deep() {
|
||||
disc = MockDisc.new_().Id_(1).Name_("disc");
|
||||
title = MockTitle.new_().Id_(2).Name_("title").Disc_(disc);
|
||||
chapter = MockChapter.new_().Id_(3).Name_("chap").Title_(title);
|
||||
audio = MockStream.new_().Id_(4).Name_("audio").Title_(title.Audios());
|
||||
subtitle = MockStream.new_().Id_(5).Name_("subtitle").Title_(title.Subtitles());
|
||||
|
||||
wtr.StoreRoot(disc, "mock_discs");
|
||||
Db_qry_fxt.tst_Select(conn, "mock_discs", Db_mock_row.vals_only_(1, "disc"));
|
||||
Db_qry_fxt.tst_Select(conn, "mock_titles", Db_mock_row.vals_only_(1, 2, "title"));
|
||||
Db_qry_fxt.tst_Select(conn, "mock_chapters", Db_mock_row.vals_only_(1, 2, 3, "chap"));
|
||||
Db_qry_fxt.tst_Select(conn, "mock_streams"
|
||||
, Db_mock_row.vals_only_(1, 2, null, 4, "audio")
|
||||
, Db_mock_row.vals_only_(1, 2, null, 5, "subtitle")
|
||||
);
|
||||
}
|
||||
@Test public void Load_root() {
|
||||
rdr = rdr_();
|
||||
Db_qry_fxt.Insert_kvo(conn, "mock_discs", Keyval_list.New_with_one("disc_id", 1).Add("disc_name", "name"));
|
||||
disc = (MockDisc)rdr.StoreRoot(MockDisc.Instance, null);
|
||||
|
||||
Tfds.Eq(1, disc.Id());
|
||||
Tfds.Eq("name", disc.Name());
|
||||
Tfds.Eq(0, disc.Titles().Count());
|
||||
}
|
||||
@Test public void Load_subs() {
|
||||
rdr = rdr_();
|
||||
Db_qry_fxt.Insert_kvo(conn, "mock_discs", Keyval_list.New_with_one("disc_id", 1).Add("disc_name", "name"));
|
||||
Db_qry_fxt.Insert_kvo(conn, "mock_titles", Keyval_list.New_with_one("disc_id", 1).Add("title_id", 1).Add("title_name", "title1"));
|
||||
Db_qry_fxt.Insert_kvo(conn, "mock_titles", Keyval_list.New_with_one("disc_id", 1).Add("title_id", 2).Add("title_name", "title2"));
|
||||
disc = (MockDisc)rdr.StoreRoot(MockDisc.Instance, null);
|
||||
|
||||
Tfds.Eq(1, disc.Id());
|
||||
Tfds.Eq("name", disc.Name());
|
||||
Tfds.Eq(2, disc.Titles().Count());
|
||||
Tfds.Eq("title1", ((MockTitle)disc.Titles().Get_at(0)).Name());
|
||||
Tfds.Eq("title2", ((MockTitle)disc.Titles().Get_at(1)).Name());
|
||||
}
|
||||
@Test public void Load_deep() {
|
||||
rdr = rdr_();
|
||||
Db_qry_fxt.Insert_kvo(conn, "mock_discs", Keyval_list.New_with_one("disc_id", 1).Add("disc_name", "name"));
|
||||
Db_qry_fxt.Insert_kvo(conn, "mock_titles", Keyval_list.New_with_one("disc_id", 1).Add("title_id", 1).Add("title_name", "title1"));
|
||||
Db_qry_fxt.Insert_kvo(conn, "mock_chapters", Keyval_list.New_with_one("disc_id", 1).Add("title_id", 1).Add("chapter_id", 3).Add("chapter_name", "chapter1"));
|
||||
Db_qry_fxt.Insert_kvo(conn, "mock_streams", Keyval_list.New_with_one("disc_id", 1).Add("title_id", 1).Add("stream_id", 4).Add("stream_type", 0).Add("stream_name", "audio1"));
|
||||
Db_qry_fxt.Insert_kvo(conn, "mock_streams", Keyval_list.New_with_one("disc_id", 1).Add("title_id", 1).Add("stream_id", 5).Add("stream_type", 1).Add("stream_name", "subtitle1"));
|
||||
disc = (MockDisc)rdr.StoreRoot(MockDisc.Instance, null);
|
||||
|
||||
Tfds.Eq(1, disc.Id());
|
||||
Tfds.Eq("name", disc.Name());
|
||||
Tfds.Eq(1, disc.Titles().Count());
|
||||
MockTitle t = ((MockTitle)disc.Titles().Get_at(0));
|
||||
Tfds.Eq("title1", t.Name());
|
||||
Tfds.Eq("chapter1", ((MockChapter)t.Chapters().Get_at(0)).Name());
|
||||
Tfds.Eq(1, t.Audios().Count());
|
||||
Tfds.Eq(1, t.Subtitles().Count());
|
||||
Tfds.Eq("audio1", ((MockStream)t.Audios().Get_at(0)).Name());
|
||||
Tfds.Eq("subtitle1", ((MockStream)t.Subtitles().Get_at(0)).Name());
|
||||
}
|
||||
DbMaprRdr rdr_() {
|
||||
DbMaprRdr rv = DbMaprRdr.new_(Db_conn_info_.Test, Db_crt_.New_eq("disc_id", 1));
|
||||
rv.EnvVars().Add(DbMaprWtr.Key_Mgr, mgr);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
57
140_dbs/src/gplx/dbs/Db_attach_mgr__tst.java
Normal file
57
140_dbs/src/gplx/dbs/Db_attach_mgr__tst.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
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 org.junit.*; import gplx.core.tests.*; import gplx.dbs.qrys.*;
|
||||
public class Db_attach_mgr__tst {
|
||||
private final Db_attach_mgr__fxt fxt = new Db_attach_mgr__fxt();
|
||||
@Test public void Basic() {
|
||||
Db_qry__select_cmd qry = Db_qry_.select_()
|
||||
.Cols_w_tbl_("t1", "fld_1")
|
||||
.Cols_w_tbl_("t2", "fld_2")
|
||||
.Cols_w_tbl_("t3", "fld_3")
|
||||
.From_("db_1", "tbl_1", "t1")
|
||||
.Join_("db_2", "tbl_2", "t2", Db_qry_.New_join__same("t1", "fld_2"))
|
||||
.Join_("db_3", "tbl_3", "t3", Db_qry_.New_join__same("t1", "fld_3"))
|
||||
.Join_( "tbl_4", "t4", Db_qry_.New_join__same("t1", "fld_4"))
|
||||
;
|
||||
fxt.Init("db_2", fxt.Make__other("db_1"), fxt.Make__other("db_2"), fxt.Make__other("db_3"));
|
||||
fxt.Test__make_stmt_and_attach(qry
|
||||
, "SELECT t1.fld_1, t2.fld_2, t3.fld_3 "
|
||||
+ "FROM db_1.tbl_1 t1 "
|
||||
+ "INNER JOIN tbl_2 t2 ON t1.fld_2 = t2.fld_2 " // NOTE: curr is db_2 so do not prefix tbl_2 with db_2; fails if "db_2.tbl_2"
|
||||
+ "INNER JOIN db_3.tbl_3 t3 ON t1.fld_3 = t3.fld_3 "
|
||||
+ "INNER JOIN tbl_4 t4 ON t1.fld_4 = t4.fld_4"
|
||||
, String_.Ary("db_1", "db_3") // NOTE: no "db_2"
|
||||
);
|
||||
}
|
||||
}
|
||||
class Db_attach_mgr__fxt {
|
||||
private Db_attach_mgr mgr;
|
||||
public Db_attach_mgr__fxt() {
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
}
|
||||
public Db_conn Make__conn(String key) {return Db_conn_bldr.Instance.New(Io_url_.mem_fil_(key));}
|
||||
public Db_attach_itm Make__other(String key) {return new Db_attach_itm(key, Io_url_.mem_fil_("mem/" + key));}
|
||||
public void Init(String conn_key, Db_attach_itm... ary) {
|
||||
Db_conn conn = Make__conn(conn_key);
|
||||
mgr = new Db_attach_mgr(conn, ary);
|
||||
}
|
||||
public void Test__make_stmt_and_attach(Db_qry__select_cmd qry, String expd_sql, String[] expd_dbs) {
|
||||
mgr.Test__make_stmt_and_attach(qry, qry.From());
|
||||
Gftest.Eq__str(expd_sql, mgr.Test__attach_sql());
|
||||
Gftest.Eq__ary(expd_dbs, mgr.Test__attach_list_keys());
|
||||
}
|
||||
}
|
||||
46
140_dbs/src/gplx/dbs/Db_conn_info_tst.java
Normal file
46
140_dbs/src/gplx/dbs/Db_conn_info_tst.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
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 org.junit.*;
|
||||
public class Db_conn_info_tst {
|
||||
@Before public void setup() {
|
||||
regy.Add(Db_conn_info_mock.Instance);
|
||||
} private final Db_conn_info_pool regy = new Db_conn_info_pool();
|
||||
@Test public void Parse() {
|
||||
tst_Parse("gplx_key=mock;id=1;", kv_("id", "1")); // one; gplx_key removed
|
||||
tst_Parse("gplx_key=mock;id=1;name=me;", kv_("id", "1"), kv_("name", "me")); // many
|
||||
tst_Parse("gplx_key=mock;id=1;name=me" , kv_("id", "1"), kv_("name", "me")); // no semi-colon at end
|
||||
}
|
||||
private Keyval kv_(String key, Object val) {return Keyval_.new_(key, val);}
|
||||
private void tst_Parse(String raw, Keyval... expd) {
|
||||
Db_conn_info_mock mock = (Db_conn_info_mock)regy.Parse(raw);
|
||||
Tfds.Eq_ary_str(expd, mock.Kvs());
|
||||
}
|
||||
}
|
||||
class Db_conn_info_mock extends Db_conn_info__base {
|
||||
public Db_conn_info_mock(String raw, String db_api, String database) {super(raw, db_api, database);}
|
||||
public Keyval[] Kvs() {return kvs;} Keyval[] kvs;
|
||||
@Override public String Key() {return Tid_const;} public static final String Tid_const = "mock";
|
||||
@Override public Db_conn_info New_self(String raw, Keyval_hash hash) {
|
||||
Db_conn_info_mock rv = new Db_conn_info_mock("", "", "");
|
||||
int len = hash.Count();
|
||||
rv.kvs = new Keyval[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv.kvs[i] = hash.Get_at(i);
|
||||
return rv;
|
||||
}
|
||||
public static final Db_conn_info_mock Instance = new Db_conn_info_mock("", "", "");
|
||||
}
|
||||
50
140_dbs/src/gplx/dbs/Db_crt_tst.java
Normal file
50
140_dbs/src/gplx/dbs/Db_crt_tst.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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 org.junit.*; import gplx.core.criterias.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
|
||||
public class Db_crt_tst {
|
||||
@Before public void setup() {
|
||||
row = GfoNde_.vals_(GfoFldList_.new_().Add("id", IntClassXtn.Instance).Add("name", StringClassXtn.Instance), Object_.Ary(1, "me"));
|
||||
}
|
||||
@Test public void EqualTest() {
|
||||
crt = Db_crt_.New_eq("id", 1);
|
||||
tst_Match(true, row, crt);
|
||||
}
|
||||
@Test public void EqualFalseTest() {
|
||||
crt = Db_crt_.New_eq("id", 2);
|
||||
tst_Match(false, row, crt);
|
||||
}
|
||||
@Test public void AndCompositeTest() {
|
||||
crt = Criteria_.And(Db_crt_.New_eq("id", 1), Db_crt_.New_eq("name", "me"));
|
||||
tst_Match(true, row, crt);
|
||||
|
||||
crt = Criteria_.And(Db_crt_.New_eq("id", 1), Db_crt_.New_eq("name", "you"));
|
||||
tst_Match(false, row, crt);
|
||||
}
|
||||
@Test public void OrCompositeTest() {
|
||||
crt = Criteria_.Or(Db_crt_.New_eq("id", 1), Db_crt_.New_eq("name", "you"));
|
||||
tst_Match(true, row, crt);
|
||||
|
||||
crt = Criteria_.Or(Db_crt_.New_eq("id", 2), Db_crt_.New_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;
|
||||
}
|
||||
65
140_dbs/src/gplx/dbs/Db_qry_fxt.java
Normal file
65
140_dbs/src/gplx/dbs/Db_qry_fxt.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
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.dbs.qrys.*; import gplx.core.gfo_ndes.*;
|
||||
public class Db_qry_fxt {
|
||||
public static void Insert_kvo(Db_conn conn, String tblName, Keyval_list kvList) {
|
||||
Db_qry_insert qry = Db_qry_.insert_(tblName);
|
||||
for (int i = 0; i < kvList.Count(); i++) {
|
||||
Keyval kv = kvList.Get_at(i);
|
||||
qry.Val_obj(kv.Key(), kv.Val());
|
||||
}
|
||||
qry.Exec_qry(conn);
|
||||
}
|
||||
public static GfoNde SelectAll(Db_conn conn, String tblName) {
|
||||
return Db_qry_.Exec_as_nde(conn, Db_qry_.select_tbl_(tblName));
|
||||
}
|
||||
public static int SelectAll_count(Db_conn conn, String tblName) {
|
||||
GfoNde nde = Db_qry_fxt.SelectAll(conn, tblName);
|
||||
return nde.Subs().Count();
|
||||
}
|
||||
public static void DeleteAll(Db_conn conn, String... ary) {
|
||||
for (String s : ary)
|
||||
Db_qry_.delete_tbl_(s).Exec_qry(conn);
|
||||
}
|
||||
public static void tst_Select(Db_conn conn, String tblName, Db_mock_row... expdAry) {
|
||||
GfoNde nde = Db_qry_fxt.SelectAll(conn, tblName);
|
||||
int len = Array_.Len(expdAry);
|
||||
for (int i = 0; i < len; i++) {
|
||||
Db_mock_row 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++) {
|
||||
Db_mock_cell expdDat = expdRow.Dat()[j];
|
||||
Object actlVal = expdDat.Fld() == null ? actlNde.ReadAt(j) : actlNde.Read(expdDat.Fld());
|
||||
Tfds.Eq(expdDat.Val(), actlVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static String Db__print_tbl_as_str(Bry_bfr bfr, Db_conn conn, String tbl, String... cols) {
|
||||
int cols_len = cols.length;
|
||||
Db_rdr rdr = conn.Stmt_select(tbl, cols).Exec_select__rls_auto();
|
||||
while (rdr.Move_next()) {
|
||||
for (int i = 0; i < cols_len; ++i) {
|
||||
bfr.Add_obj(rdr.Read_at(i));
|
||||
bfr.Add_byte(i == cols_len - 1 ? Byte_ascii.Nl : Byte_ascii.Pipe);
|
||||
}
|
||||
}
|
||||
rdr.Rls();
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
105
140_dbs/src/gplx/dbs/diffs/builds/Gfdb_diff_bldr_tst.java
Normal file
105
140_dbs/src/gplx/dbs/diffs/builds/Gfdb_diff_bldr_tst.java
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
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.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import org.junit.*;
|
||||
import gplx.dbs.*; import gplx.dbs.metas.*; import gplx.dbs.engines.mems.*;
|
||||
public class Gfdb_diff_bldr_tst {
|
||||
private final Gfdb_diff_bldr_fxt fxt = new Gfdb_diff_bldr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Same() {
|
||||
fxt.Init__tbl__old(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__cur(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Test__bld();
|
||||
}
|
||||
@Test public void Update() {
|
||||
fxt.Init__tbl__old(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__cur(Object_.Ary(1, "A1") , Object_.Ary(2, "B1"));
|
||||
fxt.Test__bld("U|1|A1", "U|2|B1");
|
||||
}
|
||||
@Test public void Insert() {
|
||||
fxt.Init__tbl__old(Object_.Ary(1, "A"));
|
||||
fxt.Init__tbl__cur(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Test__bld("I|2|B");
|
||||
}
|
||||
@Test public void Delete() {
|
||||
fxt.Init__tbl__old(Object_.Ary(1, "A") , Object_.Ary(2, "B"));
|
||||
fxt.Init__tbl__cur(Object_.Ary(1, "A"));
|
||||
fxt.Test__bld("D|2");
|
||||
}
|
||||
@Test public void Basic() {
|
||||
fxt.Init__tbl__old
|
||||
( Object_.Ary(1, "A")
|
||||
, Object_.Ary(2, "B")
|
||||
, Object_.Ary(3, "C")
|
||||
);
|
||||
fxt.Init__tbl__cur
|
||||
( Object_.Ary(1, "A")
|
||||
, Object_.Ary(2, "B1")
|
||||
, Object_.Ary(4, "D")
|
||||
);
|
||||
fxt.Test__bld("U|2|B1", "D|3", "I|4|D");
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_bldr_fxt {
|
||||
private final Gfdb_diff_bldr bldr = new Gfdb_diff_bldr();
|
||||
private final Db_conn old_conn, new_conn;
|
||||
private final Gfdb_diff_tbl tbl;
|
||||
private final Gfdb_diff_wkr__test wkr = new Gfdb_diff_wkr__test();
|
||||
private final Dbmeta_fld_itm[] flds_ary;
|
||||
private final String tbl_name = "tbl";
|
||||
private final Gdif_bldr_ctx ctx = new Gdif_bldr_ctx();
|
||||
public Gfdb_diff_bldr_fxt() {
|
||||
old_conn = Db_conn_utl.Conn__new("old_db");
|
||||
new_conn = Db_conn_utl.Conn__new("new_db");
|
||||
this.flds_ary = new Dbmeta_fld_itm[] {Dbmeta_fld_itm.new_int("id").Primary_y_(), Dbmeta_fld_itm.new_str("val", 255)};
|
||||
tbl = Gfdb_diff_tbl.New(Dbmeta_tbl_itm.New(tbl_name, flds_ary));
|
||||
bldr.Init(wkr);
|
||||
}
|
||||
public void Clear() {
|
||||
ctx.Clear();
|
||||
old_conn.Meta_tbl_delete("tbl");
|
||||
new_conn.Meta_tbl_delete("tbl");
|
||||
}
|
||||
public void Init__tbl__old(Object[]... rows) {Db_conn_utl.Tbl__new(old_conn, "tbl", flds_ary, rows);}
|
||||
public void Init__tbl__cur(Object[]... rows) {Db_conn_utl.Tbl__new(new_conn, "tbl", flds_ary, rows);}
|
||||
public void Test__bld(String... expd) {
|
||||
bldr.Compare(ctx, tbl, old_conn, new_conn);
|
||||
Tfds.Eq_ary_str(expd, wkr.To_str_ary());
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_wkr__test implements Gfdb_diff_wkr {
|
||||
private final List_adp list = List_adp_.New();
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
private Db_rdr old_rdr, new_rdr;
|
||||
public void Init_rdrs(Gdif_bldr_ctx ctx, Gfdb_diff_tbl tbl, Db_rdr old_rdr, Db_rdr new_rdr) {
|
||||
this.old_rdr = old_rdr; this.new_rdr = new_rdr;
|
||||
}
|
||||
public void Term_tbls() {}
|
||||
public void Handle_same() {
|
||||
String old_val = old_rdr.Read_str("val");
|
||||
String new_val = new_rdr.Read_str("val");
|
||||
if (!String_.Eq(old_val, new_val))
|
||||
list.Add(bfr.Add_str_a7("U").Add_byte_pipe().Add_obj(old_rdr.Read_obj("id")).Add_byte_pipe().Add_str_a7(new_val).To_str_and_clear());
|
||||
}
|
||||
public void Handle_old_missing() {
|
||||
String new_val = new_rdr.Read_str("val");
|
||||
list.Add(bfr.Add_str_a7("I").Add_byte_pipe().Add_obj(new_rdr.Read_obj("id")).Add_byte_pipe().Add_str_a7(new_val).To_str_and_clear());
|
||||
}
|
||||
public void Handle_new_missing() {
|
||||
list.Add(bfr.Add_str_a7("D").Add_byte_pipe().Add_obj(old_rdr.Read_obj("id")).To_str_and_clear());
|
||||
}
|
||||
public String[] To_str_ary() {return list.To_str_ary_and_clear();}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
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.diffs.cmds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import org.junit.*;
|
||||
import gplx.dbs.*; import gplx.dbs.engines.mems.*;
|
||||
public class Gfdb_diff_cmd_sql_bldr_tst {
|
||||
private final Gfdb_diff_cmd_sql_bldr_fxt fxt = new Gfdb_diff_cmd_sql_bldr_fxt();
|
||||
@Test public void Insert() {
|
||||
fxt.Test__insert("tbl1", String_.Ary("key1", "key2"), String_.Ary("fld1", "fld2"), 0, 99, String_.Concat_lines_nl_skip_last
|
||||
( "INSERT INTO db_curr.tbl1"
|
||||
, "SELECT d.key1, d.key2, d.fld1, d.fld2"
|
||||
, "FROM db_temp.tbl1_pkey k"
|
||||
, " JOIN db_diff.tbl1 d ON k.key1 = d.key1 AND k.key2 = d.key2"
|
||||
, "WHERE k.diff_type = 1"
|
||||
, "AND k.diff_uid BETWEEN 0 AND 99;"
|
||||
));
|
||||
}
|
||||
@Test public void Update() {
|
||||
fxt.Test__update("tbl1", String_.Ary("key1", "key2"), String_.Ary("fld1", "fld2"), 0, 99, String_.Concat_lines_nl_skip_last
|
||||
( "REPLACE INTO db_curr.tbl1"
|
||||
, "SELECT d.key1, d.key2, d.fld1, d.fld2"
|
||||
, "FROM db_temp.tbl1_pkey k"
|
||||
, " JOIN db_diff.tbl1 d ON k.key1 = d.key1 AND k.key2 = d.key2"
|
||||
, "WHERE k.diff_type = 2"
|
||||
, "AND k.diff_uid BETWEEN 0 AND 99;"
|
||||
));
|
||||
}
|
||||
@Test public void Delete() {
|
||||
fxt.Test__delete("tbl1", String_.Ary("key1", "key2"), 0, 99, String_.Concat_lines_nl_skip_last
|
||||
( "DELETE db_curr.tbl1"
|
||||
, "WHERE key1 || '|' || key2 IN"
|
||||
, "( SELECT k.key1 || '|' || k.key2"
|
||||
, " FROM db_temp.tbl1_pkey k"
|
||||
, " JOIN db_diff.tbl1 d ON k.key1 = d.key1 AND k.key2 = d.key2"
|
||||
, " WHERE k.diff_type = 0"
|
||||
, " AND k.diff_uid BETWEEN 0 AND 99"
|
||||
, ");"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_cmd_sql_bldr_fxt {
|
||||
private Gfdb_diff_cmd_sql_bldr bldr = new Gfdb_diff_cmd_sql_bldr();
|
||||
private final Bry_bfr bfr = Bry_bfr_.New();
|
||||
public void Test__insert(String tbl_name, String[] keys, String[] flds, int rng_bgn, int rng_end, String expd) {
|
||||
bldr.Bld_insert(bfr, tbl_name, keys, flds, 0, 99);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
public void Test__update(String tbl_name, String[] keys, String[] flds, int rng_bgn, int rng_end, String expd) {
|
||||
bldr.Bld_update(bfr, tbl_name, keys, flds, 0, 99);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
public void Test__delete(String tbl_name, String[] keys, int rng_bgn, int rng_end, String expd) {
|
||||
bldr.Bld_delete(bfr, tbl_name, keys, 0, 99);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
72
140_dbs/src/gplx/dbs/engines/mems/Mem_db_fxt.java
Normal file
72
140_dbs/src/gplx/dbs/engines/mems/Mem_db_fxt.java
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
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.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
class Mem_db_fxt {
|
||||
public Mem_db_fxt() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
}
|
||||
public Db_conn Make_conn(String url) {return Db_conn_bldr.Instance.Get_or_autocreate(Bool_.Y, Io_url_.mem_fil_(url));}
|
||||
public Dbmeta_tbl_itm Exec__create_tbl(Db_conn conn, String tbl, String... fld_names) {
|
||||
Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
int len = fld_names.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
flds.Add_str(fld_names[i], 255);
|
||||
Dbmeta_tbl_itm rv = Dbmeta_tbl_itm.New(tbl, flds);
|
||||
conn.Meta_tbl_create(rv);
|
||||
return rv;
|
||||
}
|
||||
public void Exec__insert(Db_conn conn, String tbl_name, String[]... rows) {
|
||||
Mem_engine engine = (Mem_engine)conn.Engine();
|
||||
int rows_len = rows.length;
|
||||
Mem_tbl tbl = engine.Tbls__get(tbl_name);
|
||||
Dbmeta_fld_list flds_list = tbl.Meta().Flds().To_fld_list();
|
||||
int flds_len = flds_list.Len();
|
||||
Db_stmt stmt = conn.Stmt_insert(tbl_name, flds_list);
|
||||
for (int i = 0; i < rows_len; ++i) {
|
||||
stmt.Clear();
|
||||
String[] row = rows[i];
|
||||
for (int j = 0; j < flds_len; ++j)
|
||||
stmt.Val_str(flds_list.Get_at(j).Name(), row[j]);
|
||||
stmt.Exec_insert();
|
||||
}
|
||||
}
|
||||
public void Test__select(Db_conn conn, Db_qry qry, String[]... expd) {
|
||||
Db_stmt stmt = conn.Stmt_new(qry);
|
||||
Db_rdr rdr = new Mem_exec_select((Mem_engine)conn.Engine()).Select((Mem_stmt)stmt);
|
||||
List_adp actl_list = List_adp_.New();
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
int expd_len = expd.length;
|
||||
String[] expd_rows = new String[expd_len];
|
||||
for (int i = 0; i < expd_len; ++i) {
|
||||
String[] expd_row = expd[i];
|
||||
for (int j = 0; j < expd_row.length; ++j) {
|
||||
if (j != 0) tmp_bfr.Add_byte_pipe();
|
||||
tmp_bfr.Add_str_u8(expd_row[j]);
|
||||
}
|
||||
expd_rows[i] = tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
while (rdr.Move_next()) {
|
||||
int fld_len = rdr.Fld_len();
|
||||
for (int i = 0; i < fld_len; ++i) {
|
||||
if (i != 0) tmp_bfr.Add_byte_pipe();
|
||||
tmp_bfr.Add_obj_strict(rdr.Read_at(i));
|
||||
}
|
||||
actl_list.Add(tmp_bfr.To_str_and_clear());
|
||||
}
|
||||
Tfds.Eq_ary(expd_rows, (String[])actl_list.To_ary_and_clear(String.class));
|
||||
}
|
||||
}
|
||||
128
140_dbs/src/gplx/dbs/engines/mems/Mem_exec_select_tst.java
Normal file
128
140_dbs/src/gplx/dbs/engines/mems/Mem_exec_select_tst.java
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
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.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import org.junit.*; import gplx.dbs.sqls.itms.*;
|
||||
public class Mem_exec_select_tst {
|
||||
private final Mem_db_fxt__single fxt = new Mem_db_fxt__single();
|
||||
@Test public void Basic() {
|
||||
fxt.Exec__create_tbl("tbl_1", "fld_1");
|
||||
fxt.Exec__insert("tbl_1"
|
||||
, String_.Ary("a_1")
|
||||
, String_.Ary("a_2")
|
||||
, String_.Ary("a_0")
|
||||
);
|
||||
|
||||
// select all
|
||||
fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_()
|
||||
, String_.Ary("a_1")
|
||||
, String_.Ary("a_2")
|
||||
, String_.Ary("a_0")
|
||||
);
|
||||
|
||||
// order by
|
||||
fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_().Order_("fld_1", Bool_.N)
|
||||
, String_.Ary("a_2")
|
||||
, String_.Ary("a_1")
|
||||
, String_.Ary("a_0")
|
||||
);
|
||||
|
||||
// offset
|
||||
fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_().Offset_(1)
|
||||
, String_.Ary("a_2")
|
||||
, String_.Ary("a_0")
|
||||
);
|
||||
|
||||
// limit
|
||||
fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_().Limit_(2)
|
||||
, String_.Ary("a_1")
|
||||
, String_.Ary("a_2")
|
||||
);
|
||||
}
|
||||
@Test public void Join__single() {
|
||||
fxt.Exec__create_tbl("tbl_1", "fld_a", "fld_1a");
|
||||
fxt.Exec__create_tbl("tbl_2", "fld_a", "fld_2a");
|
||||
fxt.Exec__insert("tbl_1"
|
||||
, String_.Ary("a_0", "1a_0")
|
||||
, String_.Ary("a_1", "1a_1")
|
||||
, String_.Ary("a_2", "1a_2")
|
||||
);
|
||||
fxt.Exec__insert("tbl_2"
|
||||
, String_.Ary("a_0", "2a_0")
|
||||
, String_.Ary("a_2", "2a_2")
|
||||
);
|
||||
|
||||
// inner join
|
||||
fxt.Test__select(Db_qry_.select_()
|
||||
.Cols_w_tbl_("t1", "fld_a", "fld_1a").Cols_w_tbl_("t2", "fld_2a")
|
||||
.From_("tbl_1", "t1")
|
||||
. Join_("tbl_2", "t2", Db_qry_.New_join__join("fld_a", "t1", "fld_a"))
|
||||
, String_.Ary("a_0", "1a_0", "2a_0")
|
||||
, String_.Ary("a_2", "1a_2", "2a_2")
|
||||
);
|
||||
|
||||
// left join
|
||||
fxt.Test__select(Db_qry_.select_()
|
||||
.Cols_w_tbl_("t1", "fld_a", "fld_1a").Cols_w_tbl_("t2", "fld_2a")
|
||||
.From_("tbl_1", "t1")
|
||||
. Join_(Sql_tbl_itm.Tid__left, Sql_tbl_itm.Db__null, "tbl_2", "t2", Db_qry_.New_join__join("fld_a", "t1", "fld_a"))
|
||||
, String_.Ary("a_0", "1a_0", "2a_0")
|
||||
, String_.Ary("a_1", "1a_1", Db_null.Null_str)
|
||||
, String_.Ary("a_2", "1a_2", "2a_2")
|
||||
);
|
||||
}
|
||||
@Test public void Join__many() {
|
||||
fxt.Exec__create_tbl("tbl_1", "fld_a", "fld_1a");
|
||||
fxt.Exec__create_tbl("tbl_2", "fld_a", "fld_2a");
|
||||
fxt.Exec__insert("tbl_1"
|
||||
, String_.Ary("a_0", "1a_0")
|
||||
, String_.Ary("a_1", "1a_1")
|
||||
);
|
||||
fxt.Exec__insert("tbl_2"
|
||||
, String_.Ary("a_0", "2a_0")
|
||||
, String_.Ary("a_0", "2a_1")
|
||||
);
|
||||
|
||||
// inner join
|
||||
fxt.Test__select(Db_qry_.select_()
|
||||
.Cols_w_tbl_("t1", "fld_a", "fld_1a").Cols_w_tbl_("t2", "fld_2a")
|
||||
.From_("tbl_1", "t1")
|
||||
. Join_("tbl_2", "t2", Db_qry_.New_join__join("fld_a", "t1", "fld_a"))
|
||||
, String_.Ary("a_0", "1a_0", "2a_0")
|
||||
, String_.Ary("a_0", "1a_0", "2a_1")
|
||||
);
|
||||
|
||||
// left join
|
||||
fxt.Test__select(Db_qry_.select_()
|
||||
.Cols_w_tbl_("t1", "fld_a", "fld_1a").Cols_w_tbl_("t2", "fld_2a")
|
||||
.From_("tbl_1", "t1")
|
||||
. Join_(Sql_tbl_itm.Tid__left, Sql_tbl_itm.Db__null, "tbl_2", "t2", Db_qry_.New_join__join("fld_a", "t1", "fld_a"))
|
||||
, String_.Ary("a_0", "1a_0", "2a_0")
|
||||
, String_.Ary("a_0", "1a_0", "2a_1")
|
||||
, String_.Ary("a_1", "1a_1", Db_null.Null_str)
|
||||
);
|
||||
}
|
||||
}
|
||||
class Mem_db_fxt__single {
|
||||
private final Mem_db_fxt mem_fxt;
|
||||
private final Db_conn conn;
|
||||
public Mem_db_fxt__single() {
|
||||
this.mem_fxt = new Mem_db_fxt();
|
||||
this.conn = mem_fxt.Make_conn("mem/test.db");
|
||||
}
|
||||
public void Exec__create_tbl (String tbl, String... fld_names) {mem_fxt.Exec__create_tbl(conn, tbl, fld_names);}
|
||||
public void Exec__insert (String tbl, String[]... rows) {mem_fxt.Exec__insert(conn, tbl, rows);}
|
||||
public void Test__select (Db_qry qry, String[]... expd) {mem_fxt.Test__select(conn, qry, expd);}
|
||||
}
|
||||
30
140_dbs/src/gplx/dbs/engines/tdbs/TdbConnectInfo_tst.java
Normal file
30
140_dbs/src/gplx/dbs/engines/tdbs/TdbConnectInfo_tst.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
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.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import org.junit.*;
|
||||
public class TdbConnectInfo_tst {
|
||||
@Test public void Full() {
|
||||
Db_conn_info connectInfo = Db_conn_info_.parse("gplx_key=tdb;url=C:\\dir\\xmpl.tdb;format=dsv;");
|
||||
tst_Parse(connectInfo, Io_url_.new_any_("C:\\dir\\xmpl.tdb"), "dsv");
|
||||
}
|
||||
@Test public void DefaultFormat() {
|
||||
Db_conn_info connectInfo = Db_conn_info_.parse("gplx_key=tdb;url=C:\\dir\\xmpl.tdb"); // dsv Format inferred
|
||||
tst_Parse(connectInfo, Io_url_.new_any_("C:\\dir\\xmpl.tdb"), "dsv");
|
||||
}
|
||||
void tst_Parse(Db_conn_info connectInfo, Io_url url, String format) {
|
||||
Tfds.Eq(((Tdb_conn_info)connectInfo).Url(), url);
|
||||
}
|
||||
}
|
||||
99
140_dbs/src/gplx/dbs/engines/tdbs/TdbDbLoadMgr_tst.java
Normal file
99
140_dbs/src/gplx/dbs/engines/tdbs/TdbDbLoadMgr_tst.java
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
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.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
|
||||
import gplx.core.stores.*; /*DsvDataRdr*/ import gplx.langs.dsvs.*; /*DsvDataWtr*/
|
||||
public class TdbDbLoadMgr_tst {
|
||||
@Before public void setup() {
|
||||
Io_url dbInfo = Io_url_.mem_fil_("mem/dir/db0.dsv");
|
||||
db = TdbDatabase.new_(dbInfo);
|
||||
wtr = DsvDataWtr_.new_();
|
||||
}
|
||||
TdbDatabase db; TdbDbLoadMgr loadMgr = TdbDbLoadMgr.new_(); TdbDbSaveMgr saveMgr = TdbDbSaveMgr.new_();
|
||||
DataRdr rdr; DataWtr wtr;
|
||||
@Test public void ReadDbFiles() {
|
||||
String raw = String_.Concat_lines_crlf
|
||||
( "=======DIF======================, ,\" \",//"
|
||||
, "_files, ,\" \",#"
|
||||
, "==DEF==DIF======================, ,\" \",//"
|
||||
, "int," + StringClassXtn.Key_const + "," + StringClassXtn.Key_const + ", ,\" \",$"
|
||||
, "id,url,format, ,\" \",@"
|
||||
, "==DATA=DIF======================, ,\" \",//"
|
||||
, "1,mem/dir/db0.dsv,dsv"
|
||||
, "2,C:\\file.dsv,dsv"
|
||||
);
|
||||
rdr = rdr_(raw);
|
||||
|
||||
db.Files().DataObj_Rdr(rdr);
|
||||
Tfds.Eq(db.Files().Count(), 2);
|
||||
TdbFile file2 = db.Files().Get_by_or_fail(2);
|
||||
Tfds.Eq(file2.Path().Raw(), "C:\\file.dsv");
|
||||
|
||||
db.Files().DataObj_Wtr(wtr);
|
||||
Tfds.Eq(wtr.To_str(), raw);
|
||||
}
|
||||
@Test public void ReadDbTbls() {
|
||||
String raw = String_.Concat_lines_crlf
|
||||
( "=======DIF======================, ,\" \",//"
|
||||
, "_tables, ,\" \",#"
|
||||
, "==DEF==DIF======================, ,\" \",//"
|
||||
, "int," + StringClassXtn.Key_const + ",int, ,\" \",$"
|
||||
, "id,name,file_id, ,\" \",@"
|
||||
, "==DATA=DIF======================, ,\" \",//"
|
||||
, "1,tbl1,1"
|
||||
);
|
||||
rdr = rdr_(raw);
|
||||
|
||||
db.Tables().DataObj_Rdr(rdr, db.Files());
|
||||
Tfds.Eq(db.Tables().Count(), 1);
|
||||
TdbTable table = db.Tables().Get_by_or_fail("tbl1");
|
||||
Tfds.Eq(table.Name(), "tbl1");
|
||||
Tfds.Eq(table.File().Id(), 1);
|
||||
|
||||
db.Tables().DataObj_Wtr(wtr);
|
||||
Tfds.Eq(wtr.To_str(), raw);
|
||||
}
|
||||
@Test public void ReadTbl() {
|
||||
String raw = String_.Concat_lines_crlf
|
||||
( "=======DIF======================, ,\" \",//"
|
||||
, "tbl0, ,\" \",#"
|
||||
, "==DEF==DIF======================, ,\" \",//"
|
||||
, "int," + StringClassXtn.Key_const + ", ,\" \",$"
|
||||
, "id,name, ,\" \",@"
|
||||
, "==DATA=DIF======================, ,\" \",//"
|
||||
, "0,me"
|
||||
);
|
||||
rdr = rdr_(raw);
|
||||
|
||||
db.MakeTbl("tbl0", TdbFile.MainFileId);
|
||||
db.Tables().Get_by_or_fail(rdr.NameOfNode()).DataObj_Rdr(rdr);
|
||||
Tfds.Eq(db.Tables().Count(), 1);
|
||||
TdbTable tbl = db.Tables().Get_by_or_fail("tbl0");
|
||||
Tfds.Eq(tbl.Rows().Count(), 1);
|
||||
|
||||
GfoNde row = tbl.Rows().FetchAt_asGfoNde(0);
|
||||
Tfds.Eq(row.Read("id"), 0);
|
||||
Tfds.Eq(row.Read("name"), "me");
|
||||
|
||||
tbl.DataObj_Wtr(wtr);
|
||||
Tfds.Eq(wtr.To_str(), raw);
|
||||
}
|
||||
DataRdr rdr_(String raw) {
|
||||
DataRdr rdr = DsvDataRdr_.dsv_(raw);
|
||||
rdr.MoveNextPeer(); // must move next as cur is not set and ReadProcs assume cur is set
|
||||
return rdr;
|
||||
}
|
||||
}
|
||||
75
140_dbs/src/gplx/dbs/engines/tdbs/TdbDbSaveMgr_tst.java
Normal file
75
140_dbs/src/gplx/dbs/engines/tdbs/TdbDbSaveMgr_tst.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
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.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import org.junit.*; import gplx.core.stores.*;
|
||||
import gplx.langs.dsvs.*; import gplx.core.type_xtns.*;
|
||||
public class TdbDbSaveMgr_tst {
|
||||
@Before public void setup() {
|
||||
Io_url dbInfo = Io_url_.mem_fil_("mem/dir/db0.dsv");
|
||||
db = TdbDatabase.new_(dbInfo);
|
||||
wtr.Clear();
|
||||
} TdbDatabase db; TdbDbSaveMgr saveMgr = TdbDbSaveMgr.new_(); DataWtr wtr = DsvDataWtr_.new_();
|
||||
@Test public void WriteDbFils() {
|
||||
String expd = String_.Concat_lines_crlf
|
||||
( ""
|
||||
, ""
|
||||
, "================================, ,\" \",//"
|
||||
, "_files, ,\" \",#"
|
||||
, "================================, ,\" \",//"
|
||||
, "int," + StringClassXtn.Key_const + "," + StringClassXtn.Key_const + ", ,\" \",$"
|
||||
, "id,url,format, ,\" \",@"
|
||||
, "================================, ,\" \",//"
|
||||
, "1,mem/dir/db0.dsv,dsv"
|
||||
);
|
||||
db.Files().DataObj_Wtr(wtr);
|
||||
String actl = wtr.To_str();
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
@Test public void WriteDbTbls() {
|
||||
String expd = String_.Concat_lines_crlf
|
||||
( ""
|
||||
, ""
|
||||
, "================================, ,\" \",//"
|
||||
, "_tables, ,\" \",#"
|
||||
, "================================, ,\" \",//"
|
||||
, "int," + StringClassXtn.Key_const + ",int, ,\" \",$"
|
||||
, "id,name,file_id, ,\" \",@"
|
||||
, "================================, ,\" \",//"
|
||||
);
|
||||
db.Tables().DataObj_Wtr(wtr);
|
||||
String actl = wtr.To_str();
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
@Test public void WriteTbl() {
|
||||
String expd = String_.Concat_lines_crlf
|
||||
( ""
|
||||
, ""
|
||||
, "================================, ,\" \",//"
|
||||
, "tbl, ,\" \",#"
|
||||
, "================================, ,\" \",//"
|
||||
, "int," + StringClassXtn.Key_const + ", ,\" \",$"
|
||||
, "id,name, ,\" \",@"
|
||||
, "================================, ,\" \",//"
|
||||
);
|
||||
TdbTable tbl = db.MakeTbl("tbl", TdbFile.MainFileId);
|
||||
tbl.Flds().Add("id", IntClassXtn.Instance);
|
||||
tbl.Flds().Add("name", StringClassXtn.Instance);
|
||||
|
||||
tbl.DataObj_Wtr(wtr);
|
||||
String actl = wtr.To_str();
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
}
|
||||
117
140_dbs/src/gplx/dbs/engines/tdbs/TdbFlush_tst.java
Normal file
117
140_dbs/src/gplx/dbs/engines/tdbs/TdbFlush_tst.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
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.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.ios.*; /*IoMgrFxt*/ import gplx.dbs.qrys.*; import gplx.core.type_xtns.*;
|
||||
public class TdbFlush_tst {
|
||||
@Before public void setup() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
engine = fx_engine.run_MakeEngine(dbPath);
|
||||
}
|
||||
TdbEngine engine; Io_url dbPath = Io_url_.mem_fil_("mem/dir/db0.dsv"); DateAdp time = DateAdp_.parse_gplx("2001-01-01");
|
||||
TdbEngineFxt fx_engine = TdbEngineFxt.new_(); IoMgrFxt fx_io = IoMgrFxt.new_();
|
||||
@Test public void FlushNewDb() {
|
||||
fx_engine.tst_FilesCount(engine, 1);
|
||||
fx_engine.tst_File(engine, 0, TdbFile.MainFileId, Io_url_.mem_fil_("mem/dir/db0.dsv"), "dsv");
|
||||
fx_io.tst_Exists(false, dbPath);
|
||||
|
||||
engine.FlushAll();
|
||||
fx_io.tst_Exists(true, dbPath);
|
||||
}
|
||||
@Test public void IgnoreFlushedDb() {
|
||||
engine.FlushAll();
|
||||
fx_io.tst_Exists(true, dbPath);
|
||||
fx_io.run_UpdateFilModifiedTime(dbPath, time);
|
||||
|
||||
engine.FlushAll();
|
||||
fx_io.tst_QueryFilModified(true, dbPath, time);
|
||||
}
|
||||
@Test public void FlushNewTbl() {
|
||||
engine.FlushAll();
|
||||
fx_engine.run_MakeTbl(engine, "tbl0", TdbFile.MainFileId);
|
||||
fx_io.run_UpdateFilModifiedTime(dbPath, time);
|
||||
|
||||
engine.FlushAll();
|
||||
fx_io.tst_QueryFilModified(false, dbPath, time);
|
||||
}
|
||||
@Test public void IgnoreFlushedTbl() {
|
||||
fx_engine.run_MakeTbl(engine, "tbl0", TdbFile.MainFileId);
|
||||
engine.FlushAll();
|
||||
fx_io.run_UpdateFilModifiedTime(dbPath, time);
|
||||
|
||||
engine.FlushAll();
|
||||
fx_io.tst_QueryFilModified(true, dbPath, time);
|
||||
}
|
||||
@Test public void FlushDirtyTbl() {
|
||||
fx_engine.run_MakeTbl(engine, "tbl0", TdbFile.MainFileId);
|
||||
engine.FlushAll();
|
||||
fx_io.run_UpdateFilModifiedTime(dbPath, time);
|
||||
|
||||
fx_engine.run_InsertRow(engine, "tbl0", 1);
|
||||
engine.FlushAll();
|
||||
fx_io.tst_QueryFilModified(false, dbPath, time);
|
||||
}
|
||||
@Test public void FlushDirtyFilOnly() {
|
||||
Io_url dbPathOther = Io_url_.mem_fil_("mem/dir/db1.dsv");
|
||||
TdbFile filOther = fx_engine.run_MakeFile(engine, dbPathOther); Tfds.Eq(false, Object_.Eq(filOther.Id(), TdbFile.MainFileId));
|
||||
fx_engine.run_MakeTbl(engine, "tbl0", TdbFile.MainFileId); fx_engine.run_MakeTbl(engine, "tbl1", filOther.Id());
|
||||
engine.FlushAll();
|
||||
fx_io.run_UpdateFilModifiedTime(dbPath, time); fx_io.run_UpdateFilModifiedTime(dbPathOther, time);
|
||||
|
||||
fx_engine.run_InsertRow(engine, "tbl1", 1);
|
||||
engine.FlushAll();
|
||||
fx_io.tst_QueryFilModified(true, dbPath, time);
|
||||
fx_io.tst_QueryFilModified(false, dbPathOther, time);
|
||||
}
|
||||
}
|
||||
class TdbEngineFxt {
|
||||
public TdbEngine run_MakeEngine(Io_url url) {
|
||||
Db_conn_info connectInfo = Db_conn_info_.tdb_(url);
|
||||
TdbEngine engine = (TdbEngine)TdbEngine.Instance.New_clone(connectInfo);
|
||||
engine.Conn_open();
|
||||
return engine;
|
||||
}
|
||||
public TdbFile run_MakeFile(TdbEngine engine, Io_url url) {return engine.Db().MakeFile(url);}
|
||||
public TdbTable run_MakeTbl(TdbEngine engine, String tblName, int srcId) {
|
||||
TdbTable rv = engine.Db().MakeTbl(tblName, srcId);
|
||||
rv.Flds().Add("id", IntClassXtn.Instance);
|
||||
return rv;
|
||||
}
|
||||
public void run_InsertRow(TdbEngine engine, String tblName, int idVal) {
|
||||
Db_qry_insert cmd = new Db_qry_insert(tblName);
|
||||
cmd.Val_int("id", idVal);
|
||||
engine.Exec_as_obj(cmd);
|
||||
}
|
||||
|
||||
public void tst_FilesCount(TdbEngine engine, int count) {Tfds.Eq(engine.Db().Files().Count(), count);}
|
||||
public void tst_File(TdbEngine engine, int index, int id, Io_url url, String format) {
|
||||
TdbFile src = engine.Db().Files().Get_by_or_fail(id);
|
||||
Tfds.Eq(src.Path().Raw(), url.Raw());
|
||||
}
|
||||
public static TdbEngineFxt new_() {return new TdbEngineFxt();} TdbEngineFxt() {}
|
||||
}
|
||||
class IoMgrFxt {
|
||||
public void run_UpdateFilModifiedTime(Io_url url, DateAdp val) {Io_mgr.Instance.UpdateFilModifiedTime(url, val);}
|
||||
public void tst_QueryFilModified(boolean expdMatch, Io_url url, DateAdp expt) {
|
||||
IoItmFil filItem = Io_mgr.Instance.QueryFil(url);
|
||||
DateAdp actl = filItem.ModifiedTime();
|
||||
boolean actlMatch = String_.Eq(expt.XtoStr_gplx(), actl.XtoStr_gplx());
|
||||
Tfds.Eq(expdMatch, actlMatch, expt.XtoStr_gplx() + (expdMatch ? "!=" : "==") + actl.XtoStr_gplx());
|
||||
}
|
||||
public void tst_Exists(boolean expd, Io_url url) {Tfds.Eq(expd, Io_mgr.Instance.ExistsFil(url));}
|
||||
|
||||
public static IoMgrFxt new_() {return new IoMgrFxt();} IoMgrFxt() {}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
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.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import org.junit.*;
|
||||
public class Dbmeta_parser__fld_tst {
|
||||
@Before public void init() {fxt.Clear();} private Dbmeta_parser__fld_fxt fxt = new Dbmeta_parser__fld_fxt();
|
||||
@Test public void Parse_type() {
|
||||
fxt.Test_parse_type("int" , fxt.Make_type(Dbmeta_fld_tid.Tid__int));
|
||||
fxt.Test_parse_type("varchar(255)" , fxt.Make_type(Dbmeta_fld_tid.Tid__str, 255));
|
||||
fxt.Test_parse_type("decimal(12,10)" , fxt.Make_type(Dbmeta_fld_tid.Tid__decimal, 12, 10));
|
||||
fxt.Test_parse_type(" int" , fxt.Make_type(Dbmeta_fld_tid.Tid__int));
|
||||
fxt.Test_parse_type(" decimal ( 12 , 10 )" , fxt.Make_type(Dbmeta_fld_tid.Tid__decimal, 12, 10));
|
||||
}
|
||||
@Test public void Parse_fld() {
|
||||
fxt.Test_parse_fld("name_1 int" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_unknown));
|
||||
fxt.Test_parse_fld("name_1 int null" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_null));
|
||||
fxt.Test_parse_fld("name_1 int not null" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_not_null));
|
||||
fxt.Test_parse_fld("name_1 int not null autoincrement" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_not_null, Bool_.N, Bool_.Y));
|
||||
fxt.Test_parse_fld("name_1 int not null primary key" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_not_null, Bool_.Y, Bool_.N));
|
||||
fxt.Test_parse_fld("name_1 int not null default -1" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_not_null, Bool_.Y, Bool_.N, -1));
|
||||
fxt.Test_parse_fld("name_1 varchar(3) not null default 'abc'" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__str, Dbmeta_fld_itm.Nullable_not_null, Bool_.Y, Bool_.N, "abc"));
|
||||
}
|
||||
@Test public void Comment() {
|
||||
fxt.Test_parse_fld("name_1 int --a\n" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_unknown));
|
||||
}
|
||||
}
|
||||
class Dbmeta_parser__fld_fxt {
|
||||
private final Dbmeta_parser__fld fld_parser = new Dbmeta_parser__fld();
|
||||
private final Sql_bry_rdr rdr = new Sql_bry_rdr();
|
||||
public void Clear() {}
|
||||
public Dbmeta_fld_tid Make_type(int tid_ansi) {return new Dbmeta_fld_tid(tid_ansi, -1, null, Int_.Min_value, Int_.Min_value);}
|
||||
public Dbmeta_fld_tid Make_type(int tid_ansi, int len_1) {return new Dbmeta_fld_tid(tid_ansi, -1, null, len_1, Int_.Min_value);}
|
||||
public Dbmeta_fld_tid Make_type(int tid_ansi, int len_1, int len_2) {return new Dbmeta_fld_tid(tid_ansi, -1, null, len_1, len_2);}
|
||||
public Dbmeta_fld_itm Make_fld(String name, int tid_ansi, int nullable) {return Make_fld(name, tid_ansi, nullable, false, false, null);}
|
||||
public Dbmeta_fld_itm Make_fld(String name, int tid_ansi, int nullable, boolean autonumber, boolean primary_key) {return Make_fld(name, tid_ansi, nullable, false, false, null);}
|
||||
public Dbmeta_fld_itm Make_fld(String name, int tid_ansi, int nullable, boolean autonumber, boolean primary_key, Object default_val) {
|
||||
Dbmeta_fld_itm rv = new Dbmeta_fld_itm(name, Make_type(tid_ansi));
|
||||
rv.Nullable_tid_(nullable);
|
||||
if (autonumber) rv.Autonum_y_();
|
||||
if (primary_key) rv.Primary_y_();
|
||||
rv.Default_(default_val);
|
||||
return rv;
|
||||
}
|
||||
public void Test_parse_type(String src, Dbmeta_fld_tid expd_type) {
|
||||
rdr.Init_by_src(Bry_.new_u8(src));
|
||||
Dbmeta_fld_tid actl_type = fld_parser.Parse_type(rdr);
|
||||
Tfds.Eq(expd_type.Tid_ansi() , actl_type.Tid_ansi());
|
||||
Tfds.Eq(expd_type.Len_1() , actl_type.Len_1());
|
||||
Tfds.Eq(expd_type.Len_2() , actl_type.Len_2());
|
||||
}
|
||||
public void Test_parse_fld(String src, Dbmeta_fld_itm expd_fld) {
|
||||
rdr.Init_by_src(Bry_.new_u8(src));
|
||||
Dbmeta_fld_itm actl_fld = fld_parser.Parse_fld(rdr);
|
||||
Tfds.Eq(expd_fld.Name() , actl_fld.Name());
|
||||
Tfds.Eq(expd_fld.Type().Tid_ansi() , actl_fld.Type().Tid_ansi());
|
||||
Tfds.Eq(expd_fld.Nullable_tid() , actl_fld.Nullable_tid());
|
||||
Tfds.Eq(Object_.Xto_str_strict_or_empty(expd_fld.Default()), Object_.Xto_str_strict_or_empty(actl_fld.Default()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
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.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import org.junit.*;
|
||||
public class Dbmeta_parser__idx_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Dbmeta_parser__idx_fxt fxt = new Dbmeta_parser__idx_fxt();
|
||||
@Test public void Unique() {fxt.Test_parse("CREATE UNIQUE INDEX idx_1 ON tbl_1 (fld_1, fld_2, fld_3)" , fxt.Make_idx(Bool_.Y, "idx_1", "tbl_1", "fld_1", "fld_2", "fld_3"));}
|
||||
@Test public void Normal() {fxt.Test_parse("CREATE INDEX idx_1 ON tbl_1 (fld_1, fld_2, fld_3)" , fxt.Make_idx(Bool_.N, "idx_1", "tbl_1", "fld_1", "fld_2", "fld_3"));}
|
||||
@Test public void Fld_1() {fxt.Test_parse("CREATE INDEX idx_1 ON tbl_1 (fld_1)" , fxt.Make_idx(Bool_.N, "idx_1", "tbl_1", "fld_1"));}
|
||||
}
|
||||
class Dbmeta_parser__idx_fxt {
|
||||
private final Dbmeta_parser__idx parser = new Dbmeta_parser__idx();
|
||||
public void Clear() {}
|
||||
public Dbmeta_idx_itm Make_idx(boolean unique, String idx_name, String tbl_name, String... fld_names) {return new Dbmeta_idx_itm(unique, tbl_name, idx_name, Dbmeta_idx_itm.To_fld_ary(fld_names));}
|
||||
public void Test_parse(String src, Dbmeta_idx_itm expd) {
|
||||
Dbmeta_idx_itm actl = parser.Parse(Bry_.new_u8(src));
|
||||
Tfds.Eq_bool(expd.Unique(), actl.Unique());
|
||||
Tfds.Eq_str(expd.Name(), actl.Name());
|
||||
Tfds.Eq_str(expd.Tbl(), actl.Tbl());
|
||||
Tfds.Eq_bool(Bool_.Y, Dbmeta_idx_fld.Ary_eq(expd.Flds, actl.Flds));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
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.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import org.junit.*; import gplx.dbs.engines.sqlite.*;
|
||||
public class Dbmeta_parser__tbl_tst {
|
||||
@Before public void init() {fxt.Clear();} private Dbmeta_parser__tbl_fxt fxt = new Dbmeta_parser__tbl_fxt();
|
||||
@Test public void Test_parse() {
|
||||
fxt.Test_parse("CREATE TABLE tbl_1 (fld_1 int, fld_2 int)", fxt.Make_tbl("tbl_1", "fld_1", "fld_2"));
|
||||
}
|
||||
@Test public void Test_smoke() {
|
||||
fxt.Test_parse(String_.Concat_lines_nl_skip_last
|
||||
( "CREATE TABLE page"
|
||||
, "( page_id integer NOT NULL PRIMARY KEY"
|
||||
, ", page_namespace integer NOT NULL"
|
||||
, ", page_title varchar(255) NOT NULL"
|
||||
, ", page_is_redirect integer NOT NULL"
|
||||
, ", page_touched varchar(14) NOT NULL"
|
||||
, ", page_len integer NOT NULL"
|
||||
, ", page_random_int integer NOT NULL"
|
||||
, ", page_text_db_id integer NOT NULL"
|
||||
, ", page_html_db_id integer NOT NULL DEFAULT -1"
|
||||
, ", page_redirect_id integer NOT NULL DEFAULT -1"
|
||||
, ");"
|
||||
), fxt.Make_tbl("page", "page_id", "page_namespace", "page_title", "page_is_redirect", "page_touched", "page_len", "page_random_int", "page_text_db_id", "page_html_db_id", "page_redirect_id"));
|
||||
}
|
||||
}
|
||||
class Dbmeta_parser__tbl_fxt {
|
||||
private final Dbmeta_parser__tbl tbl_parser = new Dbmeta_parser__tbl();
|
||||
public void Clear() {}
|
||||
public Dbmeta_tbl_itm Make_tbl(String tbl_name, String... fld_names) {
|
||||
int len = fld_names.length;
|
||||
Dbmeta_fld_itm[] flds = new Dbmeta_fld_itm[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
flds[i] = new Dbmeta_fld_itm(fld_names[i], new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__int, Sqlite_tid.Tid_int, Bry_.new_a7("int"), Int_.Min_value, Int_.Min_value));
|
||||
return Dbmeta_tbl_itm.New(tbl_name, flds);
|
||||
}
|
||||
public void Test_parse(String src, Dbmeta_tbl_itm expd_tbl) {
|
||||
Dbmeta_tbl_itm actl_tbl = tbl_parser.Parse(Bry_.new_u8(src));
|
||||
Tfds.Eq(expd_tbl.Name(), actl_tbl.Name());
|
||||
Tfds.Eq_ary_str(To_str_ary(expd_tbl.Flds()), To_str_ary(actl_tbl.Flds()));
|
||||
}
|
||||
private static String[] To_str_ary(Dbmeta_fld_mgr fld_mgr) {
|
||||
int len = fld_mgr.Len();
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
rv[i] = fld_mgr.Get_at(i).Name();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
50
140_dbs/src/gplx/dbs/metas/parsers/Sql_bry_rdr_tst.java
Normal file
50
140_dbs/src/gplx/dbs/metas/parsers/Sql_bry_rdr_tst.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
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.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import org.junit.*;
|
||||
public class Sql_bry_rdr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Sql_bry_rdr_fxt fxt = new Sql_bry_rdr_fxt();
|
||||
@Test public void Skip_ws() {
|
||||
fxt.Test_skip_ws("a", 0); // char
|
||||
fxt.Test_skip_ws("\ta", 1); // tab
|
||||
fxt.Test_skip_ws("\na", 1); // \n
|
||||
fxt.Test_skip_ws("\ra", 1); // \r
|
||||
fxt.Test_skip_ws(" a", 1); // space
|
||||
fxt.Test_skip_ws("\t\n\r a", 4); // multi
|
||||
fxt.Test_skip_ws("", 0); // eos
|
||||
}
|
||||
@Test public void Read_sql_identifier() {
|
||||
fxt.Test_read_sql_identifier("a", "a"); // one
|
||||
fxt.Test_read_sql_identifier("abc_1", "abc_1"); // many
|
||||
fxt.Test_read_sql_identifier("[abc_1]", "abc_1"); // bracket
|
||||
fxt.Test_read_sql_identifier(" a ", "a"); // ws
|
||||
fxt.Test_read_sql_identifier("", null); // eos
|
||||
fxt.Test_read_sql_identifier("!@#", null); // sym
|
||||
}
|
||||
}
|
||||
class Sql_bry_rdr_fxt {
|
||||
private final Sql_bry_rdr rdr = new Sql_bry_rdr();
|
||||
public void Clear() {}
|
||||
public void Test_skip_ws(String src, int expd_pos) {
|
||||
rdr.Init_by_src(Bry_.new_u8(src));
|
||||
rdr.Skip_ws();
|
||||
Tfds.Eq(expd_pos, rdr.Pos());
|
||||
}
|
||||
public void Test_read_sql_identifier(String src, String expd) {
|
||||
rdr.Init_by_src(Bry_.new_u8(src));
|
||||
Tfds.Eq(expd, String_.new_u8(rdr.Read_sql_identifier()));
|
||||
}
|
||||
}
|
||||
42
140_dbs/src/gplx/dbs/qrys/Db_qry_dml_tst.java
Normal file
42
140_dbs/src/gplx/dbs/qrys/Db_qry_dml_tst.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
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.qrys; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.criterias.*;
|
||||
public class Db_qry_dml_tst {
|
||||
@Test public void Delete_basic() {
|
||||
tst_XtoSql(Db_qry_delete.new_("tbl0", Db_crt_.New_eq("fld0", "val0"))
|
||||
, "DELETE FROM tbl0 WHERE fld0 = 'val0'");
|
||||
}
|
||||
@Test public void Insert_basic() {
|
||||
tst_XtoSql(new Db_qry_insert("tbl0").Val_int("id", 0).Val_str("name", "me").Val_date("time", DateAdp_.parse_gplx("2007-12-23"))
|
||||
, "INSERT INTO tbl0 (id, name, time) VALUES (0, 'me', '2007-12-23 00:00:00.000')");
|
||||
}
|
||||
@Test public void Update_basic() {
|
||||
Db_qry_update qry = new Db_qry_update();
|
||||
qry.From_("tbl0");
|
||||
qry.Where_(Db_crt_.New_eq("id", 0)).Val_str("name", "me");
|
||||
tst_XtoSql(qry, "UPDATE tbl0 SET name='me' WHERE id = 0");
|
||||
}
|
||||
@Test public void Update_all() {
|
||||
Db_qry_update qry = new Db_qry_update();
|
||||
qry.From_("tbl0");
|
||||
qry.Val_int("id", 1).Val_str("name", "me").Val_date("startTime", DateAdp_.parse_gplx("2007-12-23"));
|
||||
qry.Where_(Criteria_.And(Db_crt_.New_eq("id", 0), Db_crt_.New_mt("startTime", DateAdp_.parse_gplx("2005-01-01"))));
|
||||
tst_XtoSql(qry, "UPDATE tbl0 SET id=1, name='me', startTime='2007-12-23 00:00:00.000' WHERE (id = 0 AND startTime > '2005-01-01 00:00:00.000')");
|
||||
}
|
||||
void tst_XtoSql(Db_qry qry, String expd) {Tfds.Eq(expd, qry.To_sql__exec(gplx.dbs.sqls.Sql_qry_wtr_.New__basic()));}
|
||||
}
|
||||
87
140_dbs/src/gplx/dbs/qrys/Db_qry_select_tst.java
Normal file
87
140_dbs/src/gplx/dbs/qrys/Db_qry_select_tst.java
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
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.qrys; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*; import gplx.dbs.sqls.*;
|
||||
public class Db_qry_select_tst {
|
||||
@Before public void setup() {
|
||||
cmd = new Db_qry__select_cmd();
|
||||
} Db_qry__select_cmd cmd; String expd;
|
||||
@Test public void Basic() {
|
||||
cmd.Cols_("fld0", "fld1").From_("tbl0");
|
||||
expd = "SELECT fld0, fld1 FROM tbl0";
|
||||
|
||||
tst_XtoStr(cmd, expd);
|
||||
}
|
||||
@Test public void OrderDoesNotMatter() {
|
||||
cmd.From_("tbl0").Cols_("fld0", "fld1");
|
||||
expd = "SELECT fld0, fld1 FROM tbl0";
|
||||
|
||||
tst_XtoStr(cmd, expd);
|
||||
}
|
||||
@Test public void DefaultAllFields() {
|
||||
cmd.From_("tbl0");
|
||||
expd = "SELECT * FROM tbl0";
|
||||
|
||||
tst_XtoStr(cmd, expd);
|
||||
}
|
||||
@Test public void Where() {
|
||||
cmd.From_("tbl0").Where_(Db_crt_.New_eq("fld0", 0));
|
||||
expd = "SELECT * FROM tbl0 WHERE fld0 = 0";
|
||||
|
||||
tst_XtoStr(cmd, expd);
|
||||
}
|
||||
@Test public void Join() {
|
||||
cmd.From_("tbl0").Join_("tbl1", "t1", Db_qry_.New_join__join("fld1", "tbl0", "fld0"));
|
||||
expd = "SELECT * FROM tbl0 INNER JOIN tbl1 t1 ON tbl0.fld0 = t1.fld1";
|
||||
|
||||
tst_XtoStr(cmd, expd);
|
||||
}
|
||||
@Test public void OrderBy() {
|
||||
cmd.From_("tbl0").Order_("fld0", true);
|
||||
expd = "SELECT * FROM tbl0 ORDER BY fld0";
|
||||
|
||||
tst_XtoStr(cmd, expd);
|
||||
}
|
||||
@Test public void OrderByMany() {
|
||||
cmd.From_("tbl0").Order_asc_many_("fld0", "fld1");
|
||||
expd = "SELECT * FROM tbl0 ORDER BY fld0, fld1";
|
||||
|
||||
tst_XtoStr(cmd, expd);
|
||||
}
|
||||
@Test public void Limit() {
|
||||
cmd.From_("tbl0").Limit_(10);
|
||||
expd = "SELECT * FROM tbl0 LIMIT 10";
|
||||
|
||||
tst_XtoStr(cmd, expd);
|
||||
}
|
||||
// @Test public void GroupBy() {
|
||||
// cmd.From_("tbl0").groupBy_("fld0", "fld1");
|
||||
// expd = "SELECT fld0, fld1 FROM tbl0 GROUP BY fld0, fld1";
|
||||
// Tfds.Eq(cmd.To_str(), expd);
|
||||
// }
|
||||
// @Test public void Union() {
|
||||
// cmd.From_("tbl0").select("fld0").union_(qry2.from("tbl1").select("fld0"));
|
||||
// cmd.From_("tbl0").select("fld0").union_().from("tbl1").select("fld0"); // feasible, but will be bad later when trying to access Db_qry__select_cmd props
|
||||
// expd = "SELECT fld0 FROM tbl0 UNION SELECT fld0 FROM tbl1";
|
||||
// Tfds.Eq(cmd.To_str(), expd);
|
||||
// }
|
||||
// @Test public void Having() {
|
||||
// cmd.From_("tbl0").groupBy_("fld0", "fld1");
|
||||
// expd = "SELECT fld0, fld1 FROM tbl0 GROUP BY fld0, fld1 HAVING Count(fld0) > 1";
|
||||
// Tfds.Eq(cmd.To_str(), expd);
|
||||
// }
|
||||
void tst_XtoStr(Db_qry qry, String expd) {Tfds.Eq(expd, cmd.To_sql__exec(Sql_qry_wtr_.New__basic()));}
|
||||
}
|
||||
46
140_dbs/src/gplx/dbs/qrys/Db_qry_sql_tst.java
Normal file
46
140_dbs/src/gplx/dbs/qrys/Db_qry_sql_tst.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
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.qrys; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*; import gplx.dbs.sqls.*;
|
||||
public class Db_qry_sql_tst {
|
||||
@Before public void init() {fxt.Clear();} private Db_qry_sql_fxt fxt = new Db_qry_sql_fxt();
|
||||
@Test public void Insert() {
|
||||
fxt.Test_qry
|
||||
( Db_qry_insert.new_("tbl", "k1", "k2", "k3", "k4", "k5", "k6", "k7", "k8", "k9")
|
||||
, Object_.Ary(123, Bool_.Y, 1.23d, 123L, 123f, Byte_ascii.Num_1, "123", DateAdp_.parse_iso8561("1981-04-05T14:30:30"), Decimal_adp_.parse("1.23"))
|
||||
, "INSERT INTO tbl (k1, k2, k3, k4, k5, k6, k7, k8, k9) VALUES (123, 1, 1.23, 123, 123, 1, '123', '1981-04-05 14:30:30.000', 1.23)"
|
||||
);
|
||||
}
|
||||
@Test public void Update() {
|
||||
fxt.Test_qry
|
||||
( Db_qry_update.New("tbl", String_.Ary("k1", "k2"), "k3", "k4")
|
||||
, Object_.Ary("v3", "v4", "v1", "v2")
|
||||
, "UPDATE tbl SET k3='v3', k4='v4' WHERE (k1 = 'v1' AND k2 = 'v2')"
|
||||
);
|
||||
}
|
||||
@Test public void Delete() {
|
||||
fxt.Test_qry
|
||||
( Db_qry_delete.new_("tbl", String_.Ary("k1", "k2"))
|
||||
, Object_.Ary("v1", "v2")
|
||||
, "DELETE FROM tbl WHERE (k1 = 'v1' AND k2 = 'v2')"
|
||||
);
|
||||
}
|
||||
}
|
||||
class Db_qry_sql_fxt {
|
||||
private final Sql_qry_wtr qry_wtr = Sql_qry_wtr_.New__sqlite();
|
||||
public void Clear() {}
|
||||
public void Test_qry(Db_qry qry, Object[] vals, String expd) {Tfds.Eq(expd, Db_qry_sql.Gen_sql(qry_wtr, qry, vals));}
|
||||
}
|
||||
27
140_dbs/src/gplx/dbs/qrys/Db_stmt_sql_tst.java
Normal file
27
140_dbs/src/gplx/dbs/qrys/Db_stmt_sql_tst.java
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
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.qrys; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*;
|
||||
public class Db_stmt_sql_tst {
|
||||
@Before public void init() {}
|
||||
@Test public void Basic() {
|
||||
Db_stmt_sql stmt = new Db_stmt_sql();
|
||||
stmt.Parse(null, "UPDATE tbl_0 SET col_0 = ? WHERE col_1 = ?");
|
||||
stmt.Add("col_0", "1");
|
||||
stmt.Add("col_1", "2");
|
||||
Tfds.Eq("UPDATE tbl_0 SET col_0 = 1 WHERE col_1 = 2", stmt.Xto_sql());
|
||||
}
|
||||
}
|
||||
42
140_dbs/src/gplx/dbs/sqls/itms/Db_obj_ary_tst.java
Normal file
42
140_dbs/src/gplx/dbs/sqls/itms/Db_obj_ary_tst.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
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.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
import org.junit.*; import gplx.core.strings.*; import gplx.dbs.sqls.*;
|
||||
import gplx.dbs.sqls.wtrs.*;
|
||||
public class Db_obj_ary_tst {
|
||||
@Before public void init() {} private Db_obj_ary_fxt fxt = new Db_obj_ary_fxt();
|
||||
@Test public void Int() {
|
||||
fxt.Init_fld("fld_0", Type_adp_.Tid__int).Init_fld("fld_1", Type_adp_.Tid__int).Init_vals(1, 10).Init_vals(2, 20).Test_sql("(fld_0=1 AND fld_1=10) OR (fld_0=2 AND fld_1=20)");
|
||||
}
|
||||
@Test public void Str() {
|
||||
fxt.Init_fld("fld_0", Type_adp_.Tid__int).Init_fld("fld_1", Type_adp_.Tid__str).Init_vals(1, "a").Init_vals(2, "b").Test_sql("(fld_0=1 AND fld_1='a') OR (fld_0=2 AND fld_1='b')");
|
||||
}
|
||||
}
|
||||
class Db_obj_ary_fxt {
|
||||
private final Db_obj_ary_crt crt = new Db_obj_ary_crt();
|
||||
private final Sql_wtr_ctx ctx = new Sql_wtr_ctx(false);
|
||||
public Db_obj_ary_fxt Init_fld(String name, int tid) {flds_list.Add(new Db_obj_ary_fld(name, tid)); return this;} private List_adp flds_list = List_adp_.New();
|
||||
public Db_obj_ary_fxt Init_vals(Object... ary) {vals_list.Add(ary); return this;} private List_adp vals_list = List_adp_.New();
|
||||
public Db_obj_ary_fxt Test_sql(String expd) {
|
||||
Sql_core_wtr cmd_wtr = (Sql_core_wtr)Sql_qry_wtr_.New__basic();
|
||||
crt.Flds_((Db_obj_ary_fld[])flds_list.To_ary_and_clear(Db_obj_ary_fld.class));
|
||||
crt.Vals_((Object[][])vals_list.To_ary_and_clear(Object[].class));
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
cmd_wtr.Where_wtr().Bld_where__db_obj(bfr, ctx, crt);
|
||||
Tfds.Eq(expd, bfr.To_str_and_clear());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
34
140_dbs/src/gplx/dbs/sqls/wtrs/Sql_core_wtr_fxt.java
Normal file
34
140_dbs/src/gplx/dbs/sqls/wtrs/Sql_core_wtr_fxt.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
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 gplx.core.criterias.*;
|
||||
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();
|
||||
public Sql_core_wtr_fxt Sql_wtr_(Sql_qry_wtr v) {sql_wtr = v; return this;} private Sql_qry_wtr sql_wtr = Sql_qry_wtr_.New__sqlite();
|
||||
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());
|
||||
}
|
||||
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());
|
||||
}
|
||||
public void Test__qry(Db_qry qry, String expd) {
|
||||
Tfds.Eq_str_lines(expd, sql_wtr.To_sql_str(qry, Bool_.N));
|
||||
}
|
||||
}
|
||||
31
140_dbs/src/gplx/dbs/sqls/wtrs/Sql_from_wtr_tst.java
Normal file
31
140_dbs/src/gplx/dbs/sqls/wtrs/Sql_from_wtr_tst.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
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.*;
|
||||
public class Sql_from_wtr_tst {
|
||||
private final Sql_core_wtr_fxt fxt = new Sql_core_wtr_fxt();
|
||||
@Test public void Abrv() {
|
||||
fxt.Test__qry(Db_qry_.select_().Cols_all_().From_("tbl", "t"), "SELECT * FROM tbl t");
|
||||
}
|
||||
@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() {
|
||||
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");
|
||||
}
|
||||
}
|
||||
97
140_dbs/src/gplx/dbs/sqls/wtrs/Sql_qry_wtr__ansi__tst.java
Normal file
97
140_dbs/src/gplx/dbs/sqls/wtrs/Sql_qry_wtr__ansi__tst.java
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
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.*; import gplx.dbs.sqls.*;
|
||||
public class Sql_qry_wtr__ansi__tst {
|
||||
Sql_qry_wtr sqlWtr = Sql_qry_wtr_.New__basic();
|
||||
@Test public void Insert() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.insert_("people").Val_int("id", 1).Val_str("name", "me")
|
||||
, "INSERT INTO people (id, name) VALUES (1, 'me')"
|
||||
);
|
||||
}
|
||||
@Test public void Delete() {
|
||||
Criteria crt = Db_crt_.New_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_.New_eq("id", 1)).Val_str("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").Order_("name", false)
|
||||
, "SELECT * FROM people ORDER BY name DESC"
|
||||
);
|
||||
}
|
||||
@Test public void SelectWhere() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.select_().From_("people").Where_(Db_crt_.New_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", Db_qry_.New_join__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").Val_int("id", 1).Val_str("name", "me")
|
||||
, "INSERT INTO people (id, name) VALUES (?, ?)"
|
||||
, true
|
||||
);
|
||||
|
||||
tst_XtoSql
|
||||
( Db_qry_.delete_("people", Db_crt_.New_eq("id", 1))
|
||||
, "DELETE FROM people WHERE id = ?"
|
||||
, true
|
||||
);
|
||||
|
||||
tst_XtoSql
|
||||
( Db_qry_.update_("people", Db_crt_.New_eq("id", 1)).Val_str("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.To_sql_str(cmd, prepare));}
|
||||
}
|
||||
59
140_dbs/src/gplx/dbs/sqls/wtrs/Sql_qry_wtr__iosql__tst.java
Normal file
59
140_dbs/src/gplx/dbs/sqls/wtrs/Sql_qry_wtr__iosql__tst.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
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.strings.*;
|
||||
import gplx.core.criterias.*; /*Criteria_base*/
|
||||
import gplx.core.ios.*; import gplx.dbs.sqls.*; import gplx.dbs.sqls.wtrs.*;
|
||||
public class Sql_qry_wtr__iosql__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_fld.new_(fld, crt);}
|
||||
String fld;
|
||||
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)Sql_qry_wtr_.New__basic()).Where_wtr();
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
where_wtr.Bld_where_elem(bfr, ctx, crt);
|
||||
Tfds.Eq(expd, bfr.To_str_and_clear());
|
||||
}
|
||||
}
|
||||
66
140_dbs/src/gplx/dbs/sqls/wtrs/Sql_schema_wtr_tst.java
Normal file
66
140_dbs/src/gplx/dbs/sqls/wtrs/Sql_schema_wtr_tst.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
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.*;
|
||||
public class Sql_schema_wtr_tst {
|
||||
@Before public void setup() {} private final Sql_schema_wtr_fxt fxt = new Sql_schema_wtr_fxt();
|
||||
@Test public void Idx_unique() {
|
||||
fxt.Test_create_idx(Dbmeta_idx_itm.new_unique_by_tbl("tbl_name", "idx_name", "fld_1", "fld_2")
|
||||
, "CREATE UNIQUE INDEX IF NOT EXISTS tbl_name__idx_name ON tbl_name (fld_1, fld_2);"
|
||||
);
|
||||
}
|
||||
@Test public void Tbl_basic() {
|
||||
Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
flds.Add_int_pkey("fld_int_pkey");
|
||||
flds.Add_bool("fld_bool");
|
||||
flds.Add_short("fld_short");
|
||||
flds.Add_int("fld_int");
|
||||
flds.Add_long("fld_long");
|
||||
flds.Add_float("fld_float");
|
||||
flds.Add_double("fld_double");
|
||||
flds.Add_str("fld_str", 123);
|
||||
flds.Add_text("fld_text");
|
||||
flds.Add_bry("fld_bry");
|
||||
fxt.Test_create_tbl(Dbmeta_tbl_itm.New("tbl_name", flds.To_fld_ary())
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( "CREATE TABLE IF NOT EXISTS tbl_name"
|
||||
, "( fld_int_pkey integer NOT NULL PRIMARY KEY"
|
||||
, ", fld_bool boolean NOT NULL"
|
||||
, ", fld_short smallint NOT NULL"
|
||||
, ", fld_int integer NOT NULL"
|
||||
, ", fld_long bigint NOT NULL"
|
||||
, ", fld_float float NOT NULL"
|
||||
, ", fld_double double NOT NULL"
|
||||
, ", fld_str varchar(123) NOT NULL"
|
||||
, ", fld_text text NOT NULL"
|
||||
, ", fld_bry blob NOT NULL"
|
||||
, ");"
|
||||
));
|
||||
}
|
||||
@Test public void Tbl_alter_tbl_add() {
|
||||
Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
flds.Add_int_dflt("fld_int", -1);
|
||||
flds.Add_str_dflt("fld_str", 255, "a");
|
||||
fxt.Test_alter_tbl_add("tbl_name", flds.Get_by("fld_int"), "ALTER TABLE tbl_name ADD fld_int integer NOT NULL DEFAULT -1;");
|
||||
fxt.Test_alter_tbl_add("tbl_name", flds.Get_by("fld_str"), "ALTER TABLE tbl_name ADD fld_str varchar(255) NOT NULL DEFAULT 'a';");
|
||||
}
|
||||
}
|
||||
class Sql_schema_wtr_fxt {
|
||||
private Sql_schema_wtr sqlbldr = Sql_qry_wtr_.New__sqlite().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, Dbmeta_fld_itm fld, String expd) {Tfds.Eq_str_lines(expd, sqlbldr.Bld_alter_tbl_add(tbl, fld));}
|
||||
}
|
||||
26
140_dbs/src/gplx/dbs/sqls/wtrs/Sql_select_wtr_tst.java
Normal file
26
140_dbs/src/gplx/dbs/sqls/wtrs/Sql_select_wtr_tst.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
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.*;
|
||||
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() {
|
||||
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() {
|
||||
fxt.Test__qry(Db_qry_.select_tbl_("tbl").Limit_(20).Offset_(1), "SELECT * FROM tbl LIMIT 20 OFFSET 1");
|
||||
}
|
||||
}
|
||||
37
140_dbs/src/gplx/dbs/sqls/wtrs/Sql_val_wtr_tst.java
Normal file
37
140_dbs/src/gplx/dbs/sqls/wtrs/Sql_val_wtr_tst.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
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.*;
|
||||
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 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'");}
|
||||
}
|
||||
53
140_dbs/src/gplx/dbs/sqls/wtrs/Sql_where_wtr_tst.java
Normal file
53
140_dbs/src/gplx/dbs/sqls/wtrs/Sql_where_wtr_tst.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
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))");
|
||||
}
|
||||
}
|
||||
32
140_dbs/src/gplx/dbs/sys/Db_sys_mgr_tst.java
Normal file
32
140_dbs/src/gplx/dbs/sys/Db_sys_mgr_tst.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
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.sys; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*;
|
||||
public class Db_sys_mgr_tst {
|
||||
private final Db_sys_mgr_fxt fxt = new Db_sys_mgr_fxt();
|
||||
@Test public void FetchNextId() {
|
||||
fxt.Test__autonum_next("tbl_1.fld", 1); // default to "1" on first creation
|
||||
fxt.Test__autonum_next("tbl_1.fld", 2); // read "2" from db
|
||||
}
|
||||
}
|
||||
class Db_sys_mgr_fxt {
|
||||
private final Db_sys_mgr sys_mgr;
|
||||
public Db_sys_mgr_fxt() {
|
||||
Db_conn conn = Db_conn_pool.Instance.Get_or_new(Db_conn_info_.mem_("test"));
|
||||
sys_mgr = new Db_sys_mgr(conn);
|
||||
}
|
||||
public void Test__autonum_next(String key, int expd) {Tfds.Eq_int(expd, sys_mgr.Autonum_next(key));}
|
||||
}
|
||||
29
140_dbs/src/gplx/dbs/utls/Db_cmd_backup_tst.java
Normal file
29
140_dbs/src/gplx/dbs/utls/Db_cmd_backup_tst.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
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.utls; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*;
|
||||
public class Db_cmd_backup_tst {
|
||||
@Test public void Basic() {
|
||||
Datetime_now.Manual_y_();
|
||||
Db_cmd_backup bkpWkr = Db_cmd_backup.new_()
|
||||
.ExeUrl_(Io_url_.new_any_("C:\\mysql\\mysqldump.exe"))
|
||||
.BkpDir_(Io_url_.new_any_("C:\\bkp\\"))
|
||||
.Usr_("username")
|
||||
.Pwd_("password")
|
||||
.DbName_("dbname").InitVars();
|
||||
Tfds.Eq("\"C:\\mysql\\mysqldump.exe\" -u username -ppassword dbname > C:\\bkp\\dbname_20010101_0000.sql", bkpWkr.CmdText());
|
||||
}
|
||||
}
|
||||
54
140_dbs/src/gplx/dbs/utls/PoolIds_tst.java
Normal file
54
140_dbs/src/gplx/dbs/utls/PoolIds_tst.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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.utls; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*;
|
||||
public class PoolIds_tst {
|
||||
@Before public void setup() {
|
||||
conn = Db_conn_pool.Instance.Get_or_new(Db_conn_info_.Test);
|
||||
Db_qry_fxt.DeleteAll(conn, PoolIds.Tbl_Name);
|
||||
mgr = PoolIds.Instance;
|
||||
}
|
||||
@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(conn, url, expd);
|
||||
}
|
||||
void tst_Fetch(String url, int expd) {
|
||||
int actl = mgr.FetchNext(conn, url);
|
||||
Tfds.Eq(expd, actl);
|
||||
}
|
||||
Db_conn conn;
|
||||
PoolIds mgr;
|
||||
}
|
||||
Reference in New Issue
Block a user