mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.2.4.1
This commit is contained in:
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.criterias.*; import gplx.dbs.sqls.*;
|
||||
public class AnsiSqlWtr_tst {
|
||||
Sql_qry_wtr sqlWtr = Sql_qry_wtr_.new_ansi();
|
||||
@Test public void Insert() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.insert_("people").Arg_("id", 1).Arg_("name", "me")
|
||||
, "INSERT INTO people (id, name) VALUES (1, 'me')"
|
||||
);
|
||||
}
|
||||
@Test public void Delete() {
|
||||
Criteria crt = Db_crt_.eq_("id", 1);
|
||||
tst_XtoSql
|
||||
( Db_qry_.delete_("people", crt)
|
||||
, "DELETE FROM people WHERE id=1"
|
||||
);
|
||||
}
|
||||
@Test public void Update() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.update_("people", Db_crt_.eq_("id", 1)).Arg_("name", "me")
|
||||
, "UPDATE people SET name='me' WHERE id=1"
|
||||
);
|
||||
}
|
||||
@Test public void SelectAll() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.select_().From_("people")
|
||||
, "SELECT * FROM people"
|
||||
);
|
||||
}
|
||||
@Test public void SelectFlds() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.select_().Cols_("id", "name").From_("people")
|
||||
, "SELECT id, name FROM people"
|
||||
);
|
||||
}
|
||||
@Test public void SelectOrderBy() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.select_().From_("people").OrderBy_("name", false)
|
||||
, "SELECT * FROM people ORDER BY name DESC"
|
||||
);
|
||||
}
|
||||
@Test public void SelectWhere() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.select_().From_("people").Where_(Db_crt_.eq_("id", 1))
|
||||
, "SELECT * FROM people WHERE id=1"
|
||||
);
|
||||
}
|
||||
@Test public void Select_From_Alias() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.select_().From_("people", "p")
|
||||
, "SELECT * FROM people p"
|
||||
);
|
||||
}
|
||||
@Test public void Select_Join_Alias() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.select_().From_("people", "p").Join_("roles", "r", Sql_join_itm.same_("p", "id"))
|
||||
, "SELECT * FROM people p INNER JOIN roles r ON p.id=r.id"
|
||||
);
|
||||
}
|
||||
@Test public void Prepare() {
|
||||
tst_XtoSql
|
||||
( Db_qry_.insert_("people").Arg_("id", 1).Arg_("name", "me")
|
||||
, "INSERT INTO people (id, name) VALUES (?, ?)"
|
||||
, true
|
||||
);
|
||||
|
||||
tst_XtoSql
|
||||
( Db_qry_.delete_("people", Db_crt_.eq_("id", 1))
|
||||
, "DELETE FROM people WHERE id=?"
|
||||
, true
|
||||
);
|
||||
|
||||
tst_XtoSql
|
||||
( Db_qry_.update_("people", Db_crt_.eq_("id", 1)).Arg_("name", "me")
|
||||
, "UPDATE people SET name=? WHERE id=?"
|
||||
, true
|
||||
);
|
||||
}
|
||||
void tst_XtoSql(Db_qry cmd, String expd) {tst_XtoSql(cmd, expd, false);}
|
||||
void tst_XtoSql(Db_qry cmd, String expd, boolean prepare) {Tfds.Eq(expd, sqlWtr.Xto_str(cmd, prepare));}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ 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.dbs.engines.sqlite.*;
|
||||
import gplx.dbs.engines.sqlite.*; import gplx.dbs.engines.mysql.*; import gplx.dbs.engines.postgres.*;
|
||||
public class Db_conn_fxt implements RlsAble {
|
||||
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;
|
||||
@@ -46,10 +46,9 @@ public class Db_conn_fxt implements RlsAble {
|
||||
}
|
||||
public void Rls() {conn.Conn_term();}
|
||||
|
||||
public static Db_conn Mysql() {return Db_conn_.new_and_open_(Db_url__mysql.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_conn Tdb(String fileName) {return Db_conn_.new_and_open_(Db_url_.tdb_(Tfds.RscDir.GenSubDir_nest("140_dbs", "tdbs").GenSubFil(fileName)));}
|
||||
public static Db_conn Postgres() {return Db_conn_.new_and_open_(Db_url__postgres.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_conn Sqlite() {return Db_conn_.new_and_open_(Db_url__sqlite.load_(Tfds.RscDir.GenSubFil_nest("140_dbs", "sqlite", "unit_tests.db")));}
|
||||
// public static Db_conn Mssql() {return MssqlConnectUrl.WindowsAuth(".", "unit_tests");
|
||||
public static Db_conn Mysql() {return Db_conn_pool.I.Get_or_new(Mysql_url.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_conn Tdb(String fileName) {return Db_conn_pool.I.Get_or_new(Db_url_.tdb_(Tfds.RscDir.GenSubDir_nest("140_dbs", "tdbs").GenSubFil(fileName)));}
|
||||
public static Db_conn Postgres() {return Db_conn_pool.I.Get_or_new(Postgres_url.new_("127.0.0.1", "unit_tests", "gplx_user", "gplx_password"));}
|
||||
public static Db_conn Sqlite() {return Db_conn_pool.I.Get_or_new(Sqlite_url.load_(Tfds.RscDir.GenSubFil_nest("140_dbs", "sqlite", "unit_tests.db")));}
|
||||
public static final boolean SkipPostgres = Tfds.SkipDb || true;
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.criterias.*;
|
||||
public class Db_crt_tst {
|
||||
@Before public void setup() {
|
||||
row = GfoNde_.vals_(GfoFldList_.new_().Add("id", IntClassXtn._).Add("name", StringClassXtn._), Object_.Ary(1, "me"));
|
||||
}
|
||||
@Test public void EqualTest() {
|
||||
crt = Db_crt_.eq_("id", 1);
|
||||
tst_Match(true, row, crt);
|
||||
}
|
||||
@Test public void EqualFalseTest() {
|
||||
crt = Db_crt_.eq_("id", 2);
|
||||
tst_Match(false, row, crt);
|
||||
}
|
||||
@Test public void AndCompositeTest() {
|
||||
crt = Criteria_.And(Db_crt_.eq_("id", 1), Db_crt_.eq_("name", "me"));
|
||||
tst_Match(true, row, crt);
|
||||
|
||||
crt = Criteria_.And(Db_crt_.eq_("id", 1), Db_crt_.eq_("name", "you"));
|
||||
tst_Match(false, row, crt);
|
||||
}
|
||||
@Test public void OrCompositeTest() {
|
||||
crt = Criteria_.Or(Db_crt_.eq_("id", 1), Db_crt_.eq_("name", "you"));
|
||||
tst_Match(true, row, crt);
|
||||
|
||||
crt = Criteria_.Or(Db_crt_.eq_("id", 2), Db_crt_.eq_("name", "you"));
|
||||
tst_Match(false, row, crt);
|
||||
}
|
||||
|
||||
void tst_Match(boolean epxd, GfoNde row, Criteria crt) {
|
||||
boolean actl = crt.Matches(row);
|
||||
Tfds.Eq(epxd, actl);
|
||||
}
|
||||
GfoNde row; Criteria crt;
|
||||
}
|
||||
@@ -16,6 +16,7 @@ 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.dbs.qrys.*;
|
||||
public class Db_qry_fxt {
|
||||
public static void Insert_kvo(Db_conn conn, String tblName, KeyValList kvList) {
|
||||
Db_qry_insert qry = Db_qry_.insert_(tblName);
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import org.junit.*; import gplx.core.strings.*;
|
||||
import gplx.core.criterias.*; /*Criteria_base*/
|
||||
import gplx.ios.*; import gplx.dbs.sqls.*;
|
||||
public class IoSqlCriteriaWriter_tst {
|
||||
@Test public void Type() {
|
||||
fld = IoItm_base_.Prop_Type;
|
||||
tst_Write("type=1", ioCrt_(fld, Criteria_.eq_(IoItmDir.Type_Dir)));
|
||||
tst_Write("type=2", ioCrt_(fld, Criteria_.eq_(IoItmFil.Type_Fil)));
|
||||
}
|
||||
@Test public void Ext() {
|
||||
fld = IoItm_base_.Prop_Ext;
|
||||
tst_Write("ext='.txt'", ioCrt_(fld, Criteria_.eq_(".txt")));
|
||||
tst_Write("ext IN ('.txt', '.xml', '.html')", ioCrt_(fld, Criteria_.in_(".txt", ".xml", ".html")));
|
||||
tst_Write("ext NOT IN ('.dll', '.exe')", ioCrt_(fld, Criteria_.inn_(".dll", ".exe")));
|
||||
}
|
||||
@Test public void Title() {
|
||||
fld = IoItm_base_.Prop_Title;
|
||||
tst_Write("title='bin'", ioCrt_(fld, Criteria_.eq_("bin")));
|
||||
tst_Write("title NOT IN ('bin', 'obj')", ioCrt_(fld, Criteria_.inn_("bin", "obj")));
|
||||
}
|
||||
@Test public void Url() {
|
||||
fld = IoItm_base_.Prop_Path;
|
||||
tst_Write("url='C:\\fil.txt'", ioCrt_(fld, Criteria_.eq_("C:\\fil.txt")));
|
||||
tst_Write("url IOMATCH '*.txt'", ioCrt_(fld, Criteria_ioMatch.parse_(true, "*.txt", false)));
|
||||
}
|
||||
@Test public void Binary() {
|
||||
// parentheses around lhs and rhs
|
||||
tst_Write(
|
||||
"(type=1 OR type=2)"
|
||||
, Criteria_.Or
|
||||
( ioCrt_(IoItm_base_.Prop_Type, Criteria_.eq_(IoItmDir.Type_Dir)), ioCrt_(IoItm_base_.Prop_Type, Criteria_.eq_(IoItmFil.Type_Fil))
|
||||
));
|
||||
}
|
||||
Criteria ioCrt_(String fld, Criteria crt) {return Criteria_fld.new_(fld, crt);}
|
||||
String fld;
|
||||
void tst_Write(String expd, Criteria crt) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
Sql_qry_wtr_ansi whereWtr = (Sql_qry_wtr_ansi)Sql_qry_wtr_.new_ansi();
|
||||
whereWtr.Bld_where_val(sb, crt);
|
||||
Tfds.Eq(expd, sb.XtoStr());
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import org.junit.*;
|
||||
public class PoolIds_tst {
|
||||
@Before public void setup() {
|
||||
conn = Db_conn_pool_old._.Get_or_new(Db_url_.Test);
|
||||
Db_qry_fxt.DeleteAll(conn, PoolIds.Tbl_Name);
|
||||
mgr = PoolIds._;
|
||||
}
|
||||
@Test public void FetchNextId() {
|
||||
tst_Fetch("/test0", 0);
|
||||
}
|
||||
@Test public void ChangeNextId_Insert() {
|
||||
run_Change("/test0", 1);
|
||||
|
||||
tst_Fetch("/test0", 1);
|
||||
}
|
||||
@Test public void ChangeNextId_Update() {
|
||||
run_Change("/test0", 0);
|
||||
run_Change("/test0", 1);
|
||||
|
||||
tst_Fetch("/test0", 1);
|
||||
}
|
||||
@Test public void FetchNextId_Multiple() {
|
||||
run_Change("/test0", 0);
|
||||
run_Change("/test1", 1);
|
||||
|
||||
tst_Fetch("/test0", 0);
|
||||
tst_Fetch("/test1", 1);
|
||||
}
|
||||
void run_Change(String url, int expd) {
|
||||
mgr.Commit(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;
|
||||
}
|
||||
129
140_dbs/tst/gplx/dbs/engines/db_CrudOps_tst.java
Normal file
129
140_dbs/tst/gplx/dbs/engines/db_CrudOps_tst.java
Normal 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").Arg_("id", 1).Arg_("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").Arg_("id", 1).Arg_("name", "John Doe"));
|
||||
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Arg_("id", 2).Arg_("name", "John Doe"));
|
||||
|
||||
fx.tst_ExecDml(1, Db_qry_.update_common_("dbs_crud_ops", Db_crt_.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").Arg_("id", 1).Arg_("name", "John Doe"));
|
||||
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Arg_("id", 2).Arg_("name", "John Doe"));
|
||||
|
||||
fx.tst_ExecDml(2, Db_qry_.update_common_("dbs_crud_ops", Db_crt_.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").Arg_("id", 1).Arg_("name", "John Doe"));
|
||||
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Arg_("id", 2).Arg_("name", "Jane Smith"));
|
||||
|
||||
fx.tst_ExecDml(1, Db_qry_.delete_("dbs_crud_ops", Db_crt_.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").Arg_("id", 1).Arg_("name", "John Doe"));
|
||||
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Arg_("id", 2).Arg_("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").Arg_("id", 1).Arg_("name", "John Doe"));
|
||||
|
||||
fx.tst_ExecRdr(1, Db_qry_.select_cols_("dbs_crud_ops", Db_crt_.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").Arg_("id", 1).Arg_("name", "file%"));
|
||||
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Arg_("id", 1).Arg_("name", "file|%"));
|
||||
fx.tst_ExecDml(1, Db_qry_.insert_("dbs_crud_ops").Arg_("id", 1).Arg_("name", "file test"));
|
||||
|
||||
fx.tst_ExecRdr(1, Db_qry_.select_cols_("dbs_crud_ops", Db_crt_.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").Arg_("id", 3).Arg_obj_type_("name", val, Db_val_type.Tid_nvarchar));
|
||||
Db_qry_select select = Db_qry_.select_val_("dbs_crud_ops", "name", Db_crt_.eq_("id", 3));
|
||||
Tfds.Eq(val, ExecRdr_val(select));
|
||||
|
||||
fx.tst_ExecDml(1, Db_qry_.update_("dbs_crud_ops", Db_crt_.Wildcard).Arg_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").Arg_("id", 3).Arg_("name", val));
|
||||
Tfds.Eq(val, ExecRdr_val(Db_qry_.select_val_("dbs_crud_ops", "name", Db_crt_.eq_("id", 3))));
|
||||
Tfds.Eq(val, ExecRdr_val(Db_qry_.select_val_("dbs_crud_ops", "name", Db_crt_.eq_("name", "\\"))));
|
||||
}
|
||||
String ExecRdr_val(Db_qry_select select) {return (String)select.ExecRdr_val(fx.Conn());}
|
||||
}
|
||||
79
140_dbs/tst/gplx/dbs/engines/db_DataTypes_tst.java
Normal file
79
140_dbs/tst/gplx/dbs/engines/db_DataTypes_tst.java
Normal 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.*;
|
||||
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_.Xto_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.Conn_term();}
|
||||
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.Conn_term();
|
||||
}
|
||||
public void Select_hook(String floatStr) {
|
||||
DataRdr rdr = Db_qry_.select_tbl_("dbs_multiple_data_types").Exec_qry_as_rdr(conn);
|
||||
|
||||
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"), DecimalAdp_.parts_(12, 345));
|
||||
}
|
||||
public void UpdateDate_hook() {
|
||||
conn.Exec_qry(Db_qry_.update_("dbs_multiple_data_types", Db_crt_.eq_("unique_id", 1)).Arg_obj_("last_update", DateAdpClassXtn._.XtoDb(DateAdp_.parse_gplx("20091115 220000.000"))));
|
||||
|
||||
DataRdr rdr = Db_qry_.select_tbl_("dbs_multiple_data_types").Exec_qry_as_rdr(conn);
|
||||
rdr.MoveNextPeer();
|
||||
Tfds.Eq_date(rdr.ReadDate("last_update"), DateAdp_.parse_gplx("20091115 220000.000"));
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ 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 org.junit.*; import gplx.dbs.qrys.*;
|
||||
public abstract class GroupBys_base_tst {
|
||||
protected abstract Db_conn provider_();
|
||||
protected Db_conn conn;
|
||||
|
||||
@@ -16,7 +16,7 @@ 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 org.junit.*; import gplx.dbs.qrys.*;
|
||||
public abstract class InsertIntos_base_tst {
|
||||
protected abstract Db_conn provider_();
|
||||
protected Db_conn conn;
|
||||
|
||||
@@ -16,7 +16,7 @@ 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.dbs.sqls.*;
|
||||
import org.junit.*; import gplx.dbs.qrys.*; import gplx.dbs.sqls.*;
|
||||
public abstract class Joins_base_tst {
|
||||
protected Db_conn conn;
|
||||
@Before public void setup() {
|
||||
|
||||
@@ -16,7 +16,7 @@ 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 org.junit.*; import gplx.dbs.qrys.*;
|
||||
public abstract class OrderBys_base_tst {
|
||||
@Before public void setup() {
|
||||
conn = provider_();
|
||||
|
||||
Reference in New Issue
Block a user