1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Embeddable: Fix if_exists (restore)

This commit is contained in:
gnosygnu
2016-11-24 08:58:55 -05:00
parent fcbdf8bbd8
commit 81dc7ea4ea
1351 changed files with 88510 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs; import gplx.*;
import gplx.core.stores.*;
import gplx.dbs.engines.sqlite.*; import gplx.dbs.engines.mysql.*; import gplx.dbs.engines.postgres.*; import gplx.core.gfo_ndes.*;
public class Db_conn_fxt implements Rls_able {
public Db_conn Conn() {return conn;} public Db_conn_fxt Conn_(Db_conn v) {conn = v; return this;} Db_conn conn;
public void DmlAffectedAvailable_(boolean v) {dmlAffectedAvailable = v;} private boolean dmlAffectedAvailable = true;
public void ini_DeleteAll(String tbl) {conn.Exec_qry(Db_qry_.delete_tbl_(tbl));}
public void tst_ExecDml(int expd, Db_qry qry) {
int actl = conn.Exec_qry(qry);
if (dmlAffectedAvailable)
Tfds.Eq(expd, actl, "Exec_qry failed: sql={0}", qry.To_sql__exec(conn.Engine().Sql_wtr()));
}
public void tst_ExecRdrTbl(int expd, String tblName) {tst_ExecRdr(expd, Db_qry_.select_tbl_(tblName));}
public void tst_ExecRdr(int expd, Db_qry qry) {
DataRdr rdr = DataRdr_.Null;
try {
rdr = conn.Exec_qry_as_old_rdr(qry);
tbl = GfoNde_.rdr_(rdr);
}
catch (Exception e) {Err_.Noop(e); rdr.Rls();}
Tfds.Eq(expd, tbl.Subs().Count(), "Exec_qry_as_rdr failed: sql={0}", qry.To_sql__exec(conn.Engine().Sql_wtr()));
} GfoNde tbl;
public GfoNde tst_RowAry(int index, Object... expdValAry) {
GfoNde record = tbl.Subs().FetchAt_asGfoNde(index);
Object[] actlValAry = new Object[expdValAry.length];
for (int i = 0; i < actlValAry.length; i++)
actlValAry[i] = record.ReadAt(i);
Tfds.Eq_ary(actlValAry, expdValAry);
return record;
}
public void Rls() {conn.Rls_conn();}
public static Db_conn Mysql() {return Db_conn_pool.Instance.Get_or_new(Mysql_conn_info.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
public static Db_conn Tdb(String fileName) {return Db_conn_pool.Instance.Get_or_new(Db_conn_info_.tdb_(Tfds.RscDir.GenSubDir_nest("140_dbs", "tdbs").GenSubFil(fileName)));}
public static Db_conn Postgres() {return Db_conn_pool.Instance.Get_or_new(Postgres_conn_info.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
public static Db_conn Sqlite() {return Db_conn_pool.Instance.Get_or_new(Sqlite_conn_info.load_(Tfds.RscDir.GenSubFil_nest("140_dbs", "sqlite", "unit_tests.db")));}
public static final boolean SkipPostgres = Tfds.SkipDb || true;
}

View File

@@ -0,0 +1,33 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs; import gplx.*;
import gplx.core.gfo_ndes.*;
public class GfoNdeTstr {
public static void tst_ValsByCol(GfoNde nde, String fld, Object... expdAry) {
List_adp expd = List_adp_.New();
for (int i = 0; i < expdAry.length; i++) {
expd.Add(Object_.Xto_str_strict_or_empty(expdAry[i]));
}
List_adp actl = List_adp_.New();
for (int i = 0; i < nde.Subs().Count(); i++) {
GfoNde sub = nde.Subs().FetchAt_asGfoNde(i);
actl.Add(Object_.Xto_str_strict_or_empty(sub.Read(fld)));
}
Tfds.Eq_ary(expd.To_str_ary(), actl.To_str_ary());
}
}

View File

@@ -0,0 +1,129 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.engines; import gplx.*; import gplx.dbs.*;
import org.junit.*; import gplx.dbs.qrys.*;
public class db_CrudOps_tst {
CrudOpsFxt fx = new CrudOpsFxt();
@Test public void Mysql() {if (Tfds.SkipDb) return;
fx.RunAll(Db_conn_fxt.Mysql());
}
@Test public void Tdb() {if (Tfds.SkipDb) return;
fx.RunAll(Db_conn_fxt.Tdb("100_dbs_crud_ops.dsv"));
}
@Test public void Postgres() {if (Db_conn_fxt.SkipPostgres) return;
fx.RunAll(Db_conn_fxt.Postgres());
}
@Test public void Sqlite() {if (Tfds.SkipDb) return;
fx.Fx().DmlAffectedAvailable_(false);
fx.RunAll(Db_conn_fxt.Sqlite());
}
}
class CrudOpsFxt {
public Db_conn_fxt Fx() {return fx;} Db_conn_fxt fx = new Db_conn_fxt();
void Init() {fx.ini_DeleteAll("dbs_crud_ops");}
public void RunAll(Db_conn conn) {
fx.Conn_(conn);
Insert_hook();
UpdateOne_hook();
UpdateMany_hook();
DeleteOne_hook();
DeleteMany_hook();
SelectLike_hook();
SelectLikeForFileName_hook();
InsertUnicode_hook();
Backslash_hook();
fx.Rls();
}
public void Insert_hook() {
this.Init();
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "John Doe"));
fx.tst_ExecRdrTbl(1, "dbs_crud_ops");
fx.tst_RowAry(0, 1, "John Doe");
}
public void UpdateOne_hook() {
this.Init();
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "John Doe"));
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 2).Val_str("name", "John Doe"));
fx.tst_ExecDml(1, Db_qry_.update_common_("dbs_crud_ops", Db_crt_.New_eq("id", 2), Keyval_.new_("name", "Jane Smith")));
fx.tst_ExecRdrTbl(2, "dbs_crud_ops");
fx.tst_RowAry(0, 1, "John Doe");
fx.tst_RowAry(1, 2, "Jane Smith");
}
public void UpdateMany_hook() {
this.Init();
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "John Doe"));
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 2).Val_str("name", "John Doe"));
fx.tst_ExecDml(2, Db_qry_.update_common_("dbs_crud_ops", Db_crt_.New_eq("name", "John Doe"), Keyval_.new_("name", "Jane Smith")));
fx.tst_ExecRdrTbl(2, "dbs_crud_ops");
fx.tst_RowAry(0, 1, "Jane Smith");
fx.tst_RowAry(1, 2, "Jane Smith");
}
public void DeleteOne_hook() {
this.Init();
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "John Doe"));
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 2).Val_str("name", "Jane Smith"));
fx.tst_ExecDml(1, Db_qry_.delete_("dbs_crud_ops", Db_crt_.New_eq("id", 2)));
fx.tst_ExecRdrTbl(1, "dbs_crud_ops");
fx.tst_RowAry(0, 1, "John Doe");
}
public void DeleteMany_hook() {
this.Init();
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "John Doe"));
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 2).Val_str("name", "Jane Smith"));
fx.tst_ExecDml(2, Db_qry_.delete_tbl_("dbs_crud_ops"));
fx.tst_ExecRdrTbl(0, "dbs_crud_ops");
}
public void SelectLike_hook() {
this.Init();
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "John Doe"));
fx.tst_ExecRdr(1, Db_qry_.select_cols_("dbs_crud_ops", Db_crt_.New_like("name", "John%")));
fx.tst_RowAry(0, 1, "John Doe");
}
public void SelectLikeForFileName_hook() {
this.Init();
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "file%"));
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "file|%"));
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 1).Val_str("name", "file test"));
fx.tst_ExecRdr(1, Db_qry_.select_cols_("dbs_crud_ops", Db_crt_.New_like("name", "file|%")));
fx.tst_RowAry(0, 1, "file%");
}
public void InsertUnicode_hook() {
this.Init();
String val = "Ω";
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 3).Val_obj_type("name", val, Db_val_type.Tid_nvarchar));
Db_qry__select_cmd select = Db_qry_.select_val_("dbs_crud_ops", "name", Db_crt_.New_eq("id", 3));
Tfds.Eq(val, ExecRdr_val(select));
fx.tst_ExecDml(1, Db_qry_.update_("dbs_crud_ops", Db_crt_.Wildcard).Val_obj_type("name", val + "a", Db_val_type.Tid_nvarchar));
Tfds.Eq(val + "a", ExecRdr_val(select));
}
public void Backslash_hook() {
this.Init();
String val = "\\";
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Val_int("id", 3).Val_str("name", val));
Tfds.Eq(val, ExecRdr_val(Db_qry_.select_val_("dbs_crud_ops", "name", Db_crt_.New_eq("id", 3))));
Tfds.Eq(val, ExecRdr_val(Db_qry_.select_val_("dbs_crud_ops", "name", Db_crt_.New_eq("name", "\\"))));
}
String ExecRdr_val(Db_qry__select_cmd select) {return (String)Db_qry_.Exec_as_obj(fx.Conn(), select);}
}

View File

@@ -0,0 +1,79 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.engines; import gplx.*; import gplx.dbs.*;
import org.junit.*; import gplx.core.type_xtns.*; import gplx.core.stores.*;
public class db_DataTypes_tst {
DataTypes_base_fxt fx = new DataTypes_base_fxt();
@Test public void Mysql() {if (Tfds.SkipDb) return;
fx.Select_FloatStr_("0.333333");
fx.RunAll(Db_conn_fxt.Mysql());
}
@Test public void Tdb() {if (Tfds.SkipDb) return;
fx.Select_FloatStr_(Float_.To_str(Float_.Div(1, 3)));
fx.RunAll(Db_conn_fxt.Tdb("110_dbs_multiple_data_types.dsv"));
}
@Test public void Postgres() {if (Db_conn_fxt.SkipPostgres) return;
fx.Select_FloatStr_("0.33333334");
fx.RunAll(Db_conn_fxt.Postgres());
}
@Test public void Sqlite() {if (Tfds.SkipDb) return;
fx.Select_FloatStr_("0.33333334");
fx.RunAll(Db_conn_fxt.Sqlite());
}
/*
DROP TABLE dbs_multiple_data_types;
CREATE TABLE dbs_multiple_data_types (
unique_id int
, full_name varchar(255)
, is_active bit
, last_update timestamp
, quantity float(24)
, amount decimal(12, 3)
);
INSERT INTO dbs_multiple_data_types VALUES (1, 'John Doe', B'1', '3/30/2006 10:22 PM', 0.333333343, 12.345);
*/
}
class DataTypes_base_fxt {
public Db_conn Conn() {return conn;} Db_conn conn;
public DataTypes_base_fxt() {}
public void Rls() {conn.Rls_conn();}
public String Select_FloatStr() {return select_FloatStr;} public DataTypes_base_fxt Select_FloatStr_(String v) {select_FloatStr = v; return this;} private String select_FloatStr;
public void RunAll(Db_conn conn) {
this.conn = conn;
this.Select_hook(select_FloatStr);
conn.Rls_conn();
}
public void Select_hook(String floatStr) {
DataRdr rdr = conn.Exec_qry_as_old_rdr(Db_qry_.select_tbl_("dbs_multiple_data_types"));
rdr.MoveNextPeer();
Tfds.Eq(rdr.ReadInt("unique_id"), 1);
Tfds.Eq(rdr.ReadStr("full_name"), "John Doe");
Tfds.Eq(rdr.ReadBool("is_active"), true);
Tfds.Eq_date(rdr.ReadDate("last_update"), DateAdp_.parse_gplx("2006-03-30 22:22:00.000"));
Tfds.Eq(floatStr, Object_.Xto_str_strict_or_empty(rdr.ReadFloat("quantity")));
Tfds.Eq_decimal(rdr.ReadDecimal("amount"), Decimal_adp_.parts_(12, 345));
}
public void UpdateDate_hook() {
conn.Exec_qry(Db_qry_.update_("dbs_multiple_data_types", Db_crt_.New_eq("unique_id", 1)).Val_obj("last_update", DateAdpClassXtn.Instance.XtoDb(DateAdp_.parse_gplx("20091115 220000.000"))));
DataRdr rdr = conn.Exec_qry_as_old_rdr(Db_qry_.select_tbl_("dbs_multiple_data_types"));
rdr.MoveNextPeer();
Tfds.Eq_date(rdr.ReadDate("last_update"), DateAdp_.parse_gplx("20091115 220000.000"));
}
}

View File

@@ -0,0 +1,95 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.groupBys; import gplx.*; import gplx.dbs.*;
import org.junit.*; import gplx.dbs.qrys.*; import gplx.core.gfo_ndes.*; import gplx.core.stores.*;
public abstract class GroupBys_base_tst {
protected abstract Db_conn provider_();
protected Db_conn conn;
@Before public void setup() {
conn = provider_();
Db_qry_.delete_tbl_("dbs_group_bys").Exec_qry(conn);
}
@After public void teardown() {
conn.Rls_conn();
}
protected void GroupBy_1fld_hook() {
conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 1));
conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 2));
DataRdr rdr = conn.Exec_qry_as_old_rdr
(Db_qry_.select_().From_("dbs_group_bys")
.Cols_("key1")
.GroupBy_("key1"));
GfoNde nde = GfoNde_.rdr_(rdr);
GfoNdeTstr.tst_ValsByCol(nde, "key1", "a");
}
protected void GroupBy_2fld_hook() {
conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_str("key2", "b").Val_int("val_int", 1));
conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_str("key2", "b").Val_int("val_int", 2));
DataRdr rdr = conn.Exec_qry_as_old_rdr
(Db_qry_.select_().From_("dbs_group_bys")
.Cols_("key1", "key2")
.GroupBy_("key1", "key2"));
GfoNde nde = GfoNde_.rdr_(rdr);
GfoNdeTstr.tst_ValsByCol(nde, "key1", "a");
GfoNdeTstr.tst_ValsByCol(nde, "key2", "b");
}
protected void MinMax_hook(boolean min) {
conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 1));
conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 2));
Db_qry__select_cmd qry = Db_qry_.select_().From_("dbs_group_bys")
.Cols_("key1")
.GroupBy_("key1");
int expd = min ? 1 : 2;
if (min)
qry.Cols_groupBy_min("val_int", "val_int_func");
else
qry.Cols_groupBy_max("val_int", "val_int_func");
DataRdr rdr = conn.Exec_qry_as_old_rdr(qry);
GfoNde nde = GfoNde_.rdr_(rdr);
GfoNdeTstr.tst_ValsByCol(nde, "key1", "a");
GfoNdeTstr.tst_ValsByCol(nde, "val_int_func", expd);
}
protected void Count_hook() {
conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 10));
conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 20));
DataRdr rdr = conn.Exec_qry_as_old_rdr
(Db_qry_.select_().From_("dbs_group_bys")
.Cols_("key1").Cols_groupBy_count("val_int", "val_int_func")
.GroupBy_("key1"));
GfoNde nde = GfoNde_.rdr_(rdr);
GfoNdeTstr.tst_ValsByCol(nde, "key1", "a");
GfoNdeTstr.tst_ValsByCol(nde, "val_int_func", 2);
}
protected void Sum_hook() {
conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 10));
conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 20));
DataRdr rdr = conn.Exec_qry_as_old_rdr
(Db_qry_.select_().From_("dbs_group_bys")
.Cols_("key1").Cols_groupBy_sum("val_int", "val_int_func")
.GroupBy_("key1"));
GfoNde nde = GfoNde_.rdr_(rdr);
GfoNdeTstr.tst_ValsByCol(nde, "key1", "a");
GfoNdeTstr.tst_ValsByCol(nde, "val_int_func", 30);
}
}

View File

@@ -0,0 +1,28 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.groupBys; import gplx.*; import gplx.dbs.*;
import org.junit.*;
public class GroupBys_mysql_tst extends GroupBys_base_tst {
@Override protected Db_conn provider_() {return Db_conn_fxt.Mysql();}
@Test public void GroupBy_1fld() {super.GroupBy_1fld_hook();}
@Test public void GroupBy_2fld() {super.GroupBy_2fld_hook();}
@Test public void Min() {super.MinMax_hook(true);}
@Test public void Max() {super.MinMax_hook(false);}
@Test public void Count() {super.Count_hook();}
@Test public void Sum() {super.Sum_hook();}
}

View File

@@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.groupBys; import gplx.*; import gplx.dbs.*;
import org.junit.*;
public class GroupBys_tdb_tst extends GroupBys_base_tst {
@Override protected Db_conn provider_() {return Db_conn_fxt.Tdb("130_dbs_group_bys.dsv");}
@Test public void GroupBy_1fld() {super.GroupBy_1fld_hook();}
@Test public void GroupBy_2fld() {super.GroupBy_2fld_hook();}
@Test public void Min() {super.MinMax_hook(true);}
@Test public void Max() {super.MinMax_hook(false);}
@Test public void Count() {super.Count_hook();}
@Test public void Sum() {super.Sum_hook();}
// Avg, CountDistinct
}

View File

@@ -0,0 +1,60 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.insertIntos; import gplx.*; import gplx.dbs.*;
import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.dbs.qrys.*; import gplx.core.stores.*;
public abstract class InsertIntos_base_tst {
protected abstract Db_conn provider_();
protected Db_conn conn;
@Before public void setup() {
conn = provider_();
conn.Exec_qry(Db_qry_delete.new_("dbs_group_bys"));
conn.Exec_qry(Db_qry_delete.new_("dbs_insert_intos"));
}
@After public void teardown() {
conn.Rls_conn();
}
protected void Select_hook() {
conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 1));
conn.Exec_qry
(Db_qry_.insert_("dbs_insert_intos")
.Cols_("key1", "val_int")
.Select_
( new Db_qry__select_cmd().Cols_("key1", "val_int").From_("dbs_group_bys")
)
);
DataRdr rdr = conn.Exec_qry_as_old_rdr(new Db_qry__select_cmd().Cols_("key1", "val_int").From_("dbs_insert_intos"));
GfoNde nde = GfoNde_.rdr_(rdr);
GfoNdeTstr.tst_ValsByCol(nde, "key1", "a");
}
protected void GroupBy_hook() {
conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 1));
conn.Exec_qry(Db_qry_.insert_("dbs_group_bys").Val_str("key1", "a").Val_int("val_int", 2));
conn.Exec_qry
(Db_qry_.insert_("dbs_insert_intos")
.Cols_("key1", "val_int")
.Select_
( new Db_qry__select_cmd().Cols_("key1").Cols_groupBy_sum("val_int", "val_int_func")
.From_("dbs_group_bys").GroupBy_("key1")
));
DataRdr rdr = conn.Exec_qry_as_old_rdr(new Db_qry__select_cmd().Cols_("key1", "val_int").From_("dbs_insert_intos"));
GfoNde nde = GfoNde_.rdr_(rdr);
GfoNdeTstr.tst_ValsByCol(nde, "val_int", 3);
}
}

View File

@@ -0,0 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.insertIntos; import gplx.*; import gplx.dbs.*;
import org.junit.*;
public class InsertIntos_mysql_tst extends InsertIntos_base_tst {
@Override protected Db_conn provider_() {return Db_conn_fxt.Mysql();}
@Test public void Select() {super.Select_hook();}
@Test public void GroupBy() {super.GroupBy_hook();}
}

View File

@@ -0,0 +1,24 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.insertIntos; import gplx.*; import gplx.dbs.*;
import org.junit.*;
public class InsertIntos_tdb_tst extends InsertIntos_base_tst {
@Override protected Db_conn provider_() {return Db_conn_fxt.Tdb("140_dbs_insert_intos.dsv");}
@Test public void Select() {super.Select_hook();}
@Test public void GroupBy() {super.GroupBy_hook();}
}

View File

@@ -0,0 +1,44 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.joins; import gplx.*; import gplx.dbs.*;
import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.dbs.qrys.*; import gplx.dbs.sqls.*; import gplx.core.stores.*;
public abstract class Joins_base_tst {
protected Db_conn conn;
@Before public void setup() {
conn = provider_();
Db_qry_delete.new_("dbs_crud_ops").Exec_qry(conn);
Db_qry_delete.new_("dbs_join1").Exec_qry(conn);
}
@After public void teardown() {
conn.Rls_conn();
}
protected void InnerJoin_hook() {
conn.Exec_qry(new Db_qry_insert("dbs_crud_ops").Val_int("id", 0).Val_str("name", "me"));
conn.Exec_qry(new Db_qry_insert("dbs_crud_ops").Val_int("id", 1).Val_str("name", "you"));
conn.Exec_qry(new Db_qry_insert("dbs_join1").Val_int("join_id", 0).Val_str("join_data", "data0"));
conn.Exec_qry(new Db_qry_insert("dbs_join1").Val_int("join_id", 1).Val_str("join_data", "data1"));
Db_qry__select_cmd select = new Db_qry__select_cmd().From_("dbs_crud_ops").Join_("dbs_join1", "j1", Db_qry_.New_join__join("join_id", "dbs_crud_ops", "id")).Cols_("id", "name", "join_data");
DataRdr rdr = conn.Exec_qry_as_old_rdr(select);
GfoNde table = GfoNde_.rdr_(rdr);
Tfds.Eq(table.Subs().Count(), 2);
Tfds.Eq(table.Subs().FetchAt_asGfoNde(0).Read("join_data"), "data0");
Tfds.Eq(table.Subs().FetchAt_asGfoNde(1).Read("join_data"), "data1");
}
protected abstract Db_conn provider_();
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.joins; import gplx.*; import gplx.dbs.*;
import org.junit.*;
public class Joins_tdb_tst extends Joins_base_tst {
@Override protected Db_conn provider_() {return Db_conn_fxt.Tdb("120_dbs_joins.dsv");}
@Test public void InnerJoin() {
try {
InnerJoin_hook();
}
catch (Exception exc) {
if (String_.Has(Err_.Message_lang(exc), "joins not supported for tdbs")) return;
}
Tfds.Fail("'joins not supported for tdbs' error not thrown");
}
}

View File

@@ -0,0 +1,52 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.orderBys; import gplx.*; import gplx.dbs.*;
import org.junit.*; import gplx.dbs.qrys.*;
public abstract class OrderBys_base_tst {
@Before public void setup() {
conn = provider_();
fx.Conn_(conn);
Db_qry_delete.new_("dbs_crud_ops").Exec_qry(conn);
} protected Db_conn_fxt fx = new Db_conn_fxt();
@After public void teardown() {conn.Rls_conn();}
protected abstract Db_conn provider_(); protected Db_conn conn;
protected void Basic_hook() {
fx.tst_ExecDml(1, new Db_qry_insert("dbs_crud_ops").Val_int("id", 1).Val_str("name", "you"));
fx.tst_ExecDml(1, new Db_qry_insert("dbs_crud_ops").Val_int("id", 0).Val_str("name", "me"));
fx.tst_ExecRdr(2, new Db_qry__select_cmd().From_("dbs_crud_ops").Order_("id", true));
fx.tst_RowAry(0, 0, "me");
fx.tst_RowAry(1, 1, "you");
fx.tst_ExecRdr(2, new Db_qry__select_cmd().From_("dbs_crud_ops").Order_("id", false));
fx.tst_RowAry(0, 1, "you");
fx.tst_RowAry(1, 0, "me");
}
protected void SameVals_hook() {
fx.tst_ExecDml(1, new Db_qry_insert("dbs_crud_ops").Val_int("id", 0).Val_str("name", "me"));
fx.tst_ExecDml(1, new Db_qry_insert("dbs_crud_ops").Val_int("id", 0).Val_str("name", "you"));
fx.tst_ExecRdr(2, new Db_qry__select_cmd().From_("dbs_crud_ops").Order_("id", true));
fx.tst_RowAry(0, 0, "me");
fx.tst_RowAry(1, 0, "you");
fx.tst_ExecRdr(2, new Db_qry__select_cmd().From_("dbs_crud_ops").Order_("id", false));
fx.tst_RowAry(0, 0, "me");
fx.tst_RowAry(1, 0, "you");
}
}

View File

@@ -0,0 +1,38 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.orderBys; import gplx.*; import gplx.dbs.*;
import org.junit.*;
public class OrderBys_tdb_tst extends OrderBys_base_tst {
@Override protected Db_conn provider_() {return Db_conn_fxt.Tdb("120_dbs_joins.dsv");}
@Test public void Basic() {
Basic_hook();
}
@Test public void SameVals() {
SameVals_hook();
}
}
//namespace gplx.dbs.crudOps {
// import org.junit.*;
// public class CrudOps_tdb_tst {
// @Before public void setup() {fx = new CrudOpsFxt(Db_conn_fxt.Tdb("100_dbs_crud_ops.dsv"));} CrudOpsFxt fx;
// @Test public void FlushToDisk() {
// fx.Fx().tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Arg_("id", 2).Arg_("name", "you"));
// Db_qry_flush.new_("dbs_crud_ops").Exec_qry(fx.Fx().Conn());
// }
// }
//}