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

Refactor: @Test whitespace clean-up and other corelib changes

This commit is contained in:
gnosygnu
2021-11-28 08:16:54 -05:00
parent 2a4abd8f75
commit b0082fd231
1059 changed files with 23816 additions and 21909 deletions

View File

@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="tst"/>
<classpathentry kind="src" path="/100_core"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry combineaccessrules="false" kind="src" path="/110_gfml"/>
<classpathentry kind="lib" path="lib/mysql-connector-java-5.1.12-bin.jar"/>
<classpathentry kind="lib" path="lib/postgresql-8.4-701.jdbc4.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/sqlite-jdbc-3.18.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -1,23 +1,23 @@
/*
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
*/
/*
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() {
@Test public void Basic() {
Db_qry__select_cmd qry = Db_qry_.select_()
.Cols_w_tbl_("t1", "fld_1")
.Cols_w_tbl_("t2", "fld_2")

View File

@@ -1,25 +1,25 @@
/*
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
*/
/*
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() {
@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
@@ -30,7 +30,7 @@ public class Db_conn_info_tst {
Tfds.Eq_ary_str(expd, mock.Kvs());
}
}
class Db_conn_info_mock extends Db_conn_info__base {
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";

View File

@@ -18,6 +18,7 @@ import gplx.core.criterias.*;
public class Db_crt_ {
public static final Criteria Wildcard = Criteria_.All;
public static Criteria New_and (Criteria lhs, Criteria rhs) {return Criteria_.And(lhs, rhs);}
public static Criteria New_or (Criteria lhs, Criteria rhs) {return Criteria_.Or(lhs, rhs);}
public static Criteria_fld New_eq (String key, Object val) {return Criteria_fld.new_(key, Criteria_.eq_(val));}
public static Criteria_fld New_eq (String pre, String key, Object val) {return Criteria_fld.new_(pre, key, Criteria_.eq_(val));}
public static Criteria_fld New_eq_not (String key, Object val) {return Criteria_fld.new_(key, Criteria_.eqn_(val));}

View File

@@ -1,40 +1,40 @@
/*
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
*/
/*
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() {
@Test public void EqualTest() {
crt = Db_crt_.New_eq("id", 1);
tst_Match(true, row, crt);
}
@Test public void EqualFalseTest() {
@Test public void EqualFalseTest() {
crt = Db_crt_.New_eq("id", 2);
tst_Match(false, row, crt);
}
@Test public void AndCompositeTest() {
@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() {
@Test public void OrCompositeTest() {
crt = Criteria_.Or(Db_crt_.New_eq("id", 1), Db_crt_.New_eq("name", "you"));
tst_Match(true, row, crt);

View File

@@ -1,18 +1,18 @@
/*
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
*/
/*
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.*;
public class Dbmeta_fld_list {
private final Ordered_hash flds = Ordered_hash_.New();
@@ -31,6 +31,7 @@ public class Dbmeta_fld_list {
public String Add_int_dflt(String name, int dflt) {return Add(Dbmeta_fld_itm.new_int(name).Default_(dflt));}
public String Add_int_null(String name) {return Add(Dbmeta_fld_itm.new_int(name).Nullable_y_());}
public String Add_long(String name) {return Add(Dbmeta_fld_itm.new_long(name));}
public String Add_long_null(String name) {return Add(Dbmeta_fld_itm.new_long(name).Nullable_y_());}
public String Add_float(String name) {return Add(Dbmeta_fld_itm.new_float(name));}
public String Add_double(String name) {return Add(Dbmeta_fld_itm.new_double(name));}
public String Add_text(String name) {return Add(Dbmeta_fld_itm.new_text(name));}

View File

@@ -1,45 +1,45 @@
/*
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
*/
/*
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() {
@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() {
@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() {
@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() {
@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() {
@Test public void Basic() {
fxt.Init__tbl__old
( Object_.Ary(1, "A")
, Object_.Ary(2, "B")

View File

@@ -1,24 +1,24 @@
/*
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
*/
/*
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() {
@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"
@@ -28,7 +28,7 @@ public class Gfdb_diff_cmd_sql_bldr_tst {
, "AND k.diff_uid BETWEEN 0 AND 99;"
));
}
@Test public void Update() {
@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"
@@ -38,7 +38,7 @@ public class Gfdb_diff_cmd_sql_bldr_tst {
, "AND k.diff_uid BETWEEN 0 AND 99;"
));
}
@Test public void Delete() {
@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"

View File

@@ -1,22 +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.engines; import gplx.*; import gplx.dbs.*;
import java.sql.*;
import gplx.core.stores.*;
import gplx.dbs.engines.*; import gplx.dbs.metas.*; import gplx.dbs.qrys.*; import gplx.dbs.sqls.*; import gplx.dbs.sqls.wtrs.*; import gplx.dbs.conn_props.*; import gplx.dbs.qrys.bats.*;
/*
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; import gplx.Err_;
import gplx.Gfo_usr_dlg;
import gplx.Gfo_usr_dlg_;
import gplx.Io_url;
import gplx.Keyval;
import gplx.core.stores.DataRdr;
import gplx.dbs.Db_conn;
import gplx.dbs.Db_conn_info;
import gplx.dbs.Db_qry;
import gplx.dbs.Db_qry_;
import gplx.dbs.Db_rdr;
import gplx.dbs.Db_rdr__basic;
import gplx.dbs.Db_stmt;
import gplx.dbs.Dbmeta_fld_itm;
import gplx.dbs.Dbmeta_idx_itm;
import gplx.dbs.Dbmeta_tbl_itm;
import gplx.dbs.conn_props.Db_conn_props_mgr;
import gplx.dbs.metas.Dbmeta_tbl_mgr;
import gplx.dbs.qrys.Db_qry_sql;
import gplx.dbs.qrys.Db_stmt_cmd;
import gplx.dbs.qrys.bats.Db_batch_mgr;
import gplx.dbs.sqls.Sql_qry_wtr;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public abstract class Db_engine_sql_base implements Db_engine {
@gplx.Internal protected void Ctor(Db_conn_info conn_info) {this.conn_info = conn_info;}
public abstract String Tid();
@@ -27,12 +51,14 @@ public abstract class Db_engine_sql_base implements Db_engine {
public abstract Db_engine New_clone(Db_conn_info conn_info);
public Db_rdr Exec_as_rdr__rls_manual(Object rdr_obj, String sql) {return New_rdr(null, rdr_obj, sql);}
public Db_rdr Exec_as_rdr__rls_auto(Db_stmt stmt, Object rdr_obj, String sql) {return New_rdr(stmt, rdr_obj, sql);}
@gplx.Virtual public Db_rdr New_rdr_clone() {return new Db_rdr__basic();}
@gplx.Virtual public Db_stmt Stmt_by_qry(Db_qry qry) {return new Db_stmt_cmd(this, qry);}
@gplx.Virtual public void Txn_bgn(String name) {Exec_as_obj(Db_qry_sql.xtn_("BEGIN TRANSACTION;"));}
@gplx.Virtual public String Txn_end() {Exec_as_obj(Db_qry_sql.xtn_("COMMIT TRANSACTION;")); batch_mgr.Txn_end().Run(this); return "";}
@gplx.Virtual public void Txn_cxl() {Exec_as_obj(Db_qry_sql.xtn_("ROLLBACK TRANSACTION;"));}
@gplx.Virtual public void Txn_sav() {
public Db_rdr New_rdr_clone() {return new Db_rdr__basic();}
public Db_stmt Stmt_by_qry(Db_qry qry) {return new Db_stmt_cmd(this, qry);}
protected String Txn_bgn_str() {return "BEGIN TRANSACTION;";}
protected String Txn_end_str() {return "COMMIT TRANSACTION;";}
public void Txn_bgn(String name) {Exec_as_obj(Db_qry_sql.xtn_(this.Txn_bgn_str()));}
public String Txn_end() {Exec_as_obj(Db_qry_sql.xtn_(this.Txn_end_str())); batch_mgr.Txn_end().Run(this); return "";}
public void Txn_cxl() {Exec_as_obj(Db_qry_sql.xtn_("ROLLBACK TRANSACTION;"));}
public void Txn_sav() {
String txn_name = this.Txn_end();
this.Txn_bgn(txn_name);
}
@@ -68,7 +94,7 @@ public abstract class Db_engine_sql_base implements Db_engine {
}
this.Meta_mgr().Load_all();
}
@gplx.Virtual public void Meta_idx_delete(String idx) {
public void Meta_idx_delete(String idx) {
if (Meta_idx_exists(idx)) Exec_as_int("DROP INDEX " + idx);
}
public void Meta_fld_append(String tbl, Dbmeta_fld_itm fld) {
@@ -82,14 +108,14 @@ public abstract class Db_engine_sql_base implements Db_engine {
}
this.Meta_mgr().Load_all();
}
@gplx.Virtual public boolean Meta_tbl_exists(String tbl) {return false;}
@gplx.Virtual public boolean Meta_fld_exists(String tbl, String fld) {return false;}
@gplx.Virtual public boolean Meta_idx_exists(String idx) {return false;}
public boolean Meta_tbl_exists(String tbl) {return false;}
public boolean Meta_fld_exists(String tbl, String fld) {return false;}
public boolean Meta_idx_exists(String idx) {return false;}
public abstract Dbmeta_tbl_mgr Meta_mgr();
@gplx.Virtual public void Env_db_attach(String alias, Io_url db_url) {}
@gplx.Virtual public void Env_db_attach(String alias, Db_conn db_url) {}
@gplx.Virtual public void Env_db_detach(String alias) {}
@gplx.Virtual public DataRdr New_rdr(ResultSet rdr, String sql) {return gplx.core.stores.Db_data_rdr_.new_(rdr, sql);}
public void Env_db_attach(String alias, Io_url db_url) {}
public void Env_db_attach(String alias, Db_conn db_url) {}
public void Env_db_detach(String alias) {}
public DataRdr New_rdr(ResultSet rdr, String sql) {return gplx.core.stores.Db_data_rdr_.new_(rdr, sql);}
private Db_rdr New_rdr(Db_stmt stmt, Object rdr, String sql) {
Db_rdr__basic rv = (Db_rdr__basic)New_rdr_clone();
rv.Ctor(stmt, (ResultSet)rdr, sql);

View File

@@ -1,23 +1,23 @@
/*
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
*/
/*
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() {
@Test public void Basic() {
fxt.Exec__create_tbl("tbl_1", "fld_1");
fxt.Exec__insert("tbl_1"
, String_.Ary("a_1")
@@ -51,7 +51,7 @@ public class Mem_exec_select_tst {
, String_.Ary("a_2")
);
}
@Test public void Join__single() {
@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"
@@ -83,7 +83,7 @@ public class Mem_exec_select_tst {
, String_.Ary("a_2", "1a_2", "2a_2")
);
}
@Test public void Join__many() {
@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"

View File

@@ -13,15 +13,26 @@ 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.mysql; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
import gplx.core.stores.*; import gplx.dbs.engines.*; import gplx.dbs.sqls.*; import gplx.dbs.metas.*;
package gplx.dbs.engines.mysql;
import gplx.Err_;
import gplx.core.stores.DataRdr;
import gplx.core.stores.Db_data_rdr;
import gplx.dbs.Db_conn_info;
import gplx.dbs.engines.Db_engine;
import gplx.dbs.engines.Db_engine_sql_base;
import gplx.dbs.metas.Dbmeta_tbl_mgr;
import gplx.dbs.sqls.Sql_qry_wtr;
import gplx.dbs.sqls.Sql_qry_wtr_;
import gplx.dbs.wkrs.SqlWkrMgr;
import java.sql.*;
import java.sql.Connection;
import java.sql.ResultSet;
public class Mysql_engine extends Db_engine_sql_base {
@Override public String Tid() {return Mysql_conn_info.Tid_const;}
@Override public Sql_qry_wtr Sql_wtr() {return Sql_qry_wtr_.New__mysql();}
@Override public void CtorConn(SqlWkrMgr wkrMgr) {}
@Override protected String Txn_bgn_str() {return "START TRANSACTION;";}
@Override protected String Txn_end_str() {return "COMMIT;";}
@Override public Db_engine New_clone(Db_conn_info connectInfo) {
Mysql_engine rv = new Mysql_engine();
rv.Ctor(connectInfo);

View File

@@ -13,17 +13,44 @@ 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.sqlite; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
import java.sql.*;
import gplx.core.stores.*; import gplx.dbs.engines.*; import gplx.dbs.engines.sqlite.*; import gplx.dbs.metas.*; import gplx.dbs.sqls.*;
import gplx.dbs.qrys.*;
import gplx.core.consoles.Console_adp_;
import gplx.core.consoles.Console_adp__sys;
package gplx.dbs.engines.sqlite; import gplx.Bool_;
import gplx.Byte_;
import gplx.DateAdp;
import gplx.DateAdp_;
import gplx.Decimal_adp;
import gplx.Decimal_adp_;
import gplx.Err_;
import gplx.Float_;
import gplx.Gfo_usr_dlg_;
import gplx.Int_;
import gplx.Io_mgr;
import gplx.Io_url;
import gplx.Keyval;
import gplx.Keyval_;
import gplx.Long_;
import gplx.String_;
import gplx.Type_;
import gplx.core.ios.IoItmFil;
import gplx.core.stores.DataRdr;
import gplx.core.stores.Db_data_rdr;
import gplx.dbs.Db_conn;
import gplx.dbs.Db_conn_info;
import gplx.dbs.Db_qry;
import gplx.dbs.Db_rdr;
import gplx.dbs.Db_rdr__basic;
import gplx.dbs.Db_stmt;
import gplx.dbs.Dbmeta_fld_itm;
import gplx.dbs.engines.Db_engine;
import gplx.dbs.engines.Db_engine_sql_base;
import gplx.dbs.metas.Dbmeta_tbl_mgr;
import gplx.dbs.sqls.Sql_qry_wtr_;
import gplx.dbs.wkrs.SqlWkrMgr;
import gplx.dbs.wkrs.randoms.SqliteRandomWkr;
import org.sqlite.SQLiteConnection;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Sqlite_engine extends Db_engine_sql_base {
private final Sqlite_txn_mgr txn_mgr; private final Sqlite_schema_mgr schema_mgr;
Sqlite_engine() {
@@ -138,13 +165,28 @@ class Sqlite_rdr extends Db_data_rdr { @Override public float ReadFloat(String
@Override public Decimal_adp ReadDecimal(String key) {return ReadDecimalOr(key, null);}
@Override public Decimal_adp ReadDecimalOr(String key, Decimal_adp or) {
Object val = Read(key);
Double d = ((Double)val);
return val == null ? or : Decimal_adp_.double_(d);
if (val == null) return or;
if (Type_.Eq_by_obj(val, Double.class)) {
return Decimal_adp_.double_((Double)val);
}
else if (Type_.Eq_by_obj(val, Integer.class)) { // 2021-09-16|needed for gfds
return Decimal_adp_.int_((Integer)val);
}
else {
throw Err_.New("sqlite decimal must be either double or int; val={0}", val);
}
}
@Override public DateAdp ReadDate(String key) {return ReadDateOr(key, null);}
@Override public DateAdp ReadDateOr(String key, DateAdp or) {
Object val = Read(key);
return val == null ? or : DateAdp_.parse_fmt((String)val, "M/dd/yyyy hh:mm tt");
if (val == null) return or;
String valStr = (String)val;
try {
return DateAdp_.parse_fmt(valStr, "M/dd/yyyy hh:mm tt");
}
catch (Exception exc) { // 2021-09-16|needed for gfds
return DateAdp_.parse_fmt(valStr, "yyyy-MM-dd hh:mm:ss");
}
}
@Override public boolean ReadBool(String key) {return ReadBoolOr(key, false);}
@Override public boolean ReadBoolOr(String key, boolean or) {

View File

@@ -1,20 +1,21 @@
/*
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.sqlite; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
import gplx.core.primitives.*; import gplx.dbs.qrys.*; import gplx.dbs.utls.*; import gplx.dbs.engines.*; import gplx.dbs.engines.sqlite.*;
/*
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.sqlite; import gplx.*; import gplx.dbs.*;
import gplx.dbs.qrys.*;
public class Sqlite_engine_ {
public static void Db_attach(Db_conn p, String alias, String url) {
String s = String_.Format("ATTACH '{0}' AS {1};", url, alias);
@@ -74,5 +75,6 @@ public class Sqlite_engine_ {
public static String X_date_to_str(DateAdp v) {return v == Date_null ? "" : v.XtoStr_fmt_iso_8561();}
public static final DateAdp Date_null = null;
public static final byte Wildcard_byte = Byte_ascii.Hash;
public static final String Wildcard_str = "%";
public static int Read_only_detection = Io_mgr.Read_only__basic__file;
}

View File

@@ -13,18 +13,18 @@ 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);
}
}
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);
}
}

View File

@@ -1,18 +1,18 @@
/*
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
*/
/*
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*/
@@ -24,7 +24,7 @@ public class TdbDbLoadMgr_tst {
}
TdbDatabase db; TdbDbLoadMgr loadMgr = TdbDbLoadMgr.new_(); TdbDbSaveMgr saveMgr = TdbDbSaveMgr.new_();
DataRdr rdr; DataWtr wtr;
@Test public void ReadDbFiles() {
@Test public void ReadDbFiles() {
String raw = String_.Concat_lines_crlf
( "=======DIF======================, ,\" \",//"
, "_files, ,\" \",#"
@@ -45,7 +45,7 @@ public class TdbDbLoadMgr_tst {
db.Files().DataObj_Wtr(wtr);
Tfds.Eq(wtr.To_str(), raw);
}
@Test public void ReadDbTbls() {
@Test public void ReadDbTbls() {
String raw = String_.Concat_lines_crlf
( "=======DIF======================, ,\" \",//"
, "_tables, ,\" \",#"
@@ -66,7 +66,7 @@ public class TdbDbLoadMgr_tst {
db.Tables().DataObj_Wtr(wtr);
Tfds.Eq(wtr.To_str(), raw);
}
@Test public void ReadTbl() {
@Test public void ReadTbl() {
String raw = String_.Concat_lines_crlf
( "=======DIF======================, ,\" \",//"
, "tbl0, ,\" \",#"

View File

@@ -1,18 +1,18 @@
/*
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
*/
/*
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.*;
@@ -22,7 +22,7 @@ public class TdbDbSaveMgr_tst {
db = TdbDatabase.new_(dbInfo);
wtr.Clear();
} TdbDatabase db; TdbDbSaveMgr saveMgr = TdbDbSaveMgr.new_(); DataWtr wtr = DsvDataWtr_.new_();
@Test public void WriteDbFils() {
@Test public void WriteDbFils() {
String expd = String_.Concat_lines_crlf
( ""
, ""
@@ -38,7 +38,7 @@ public class TdbDbSaveMgr_tst {
String actl = wtr.To_str();
Tfds.Eq(expd, actl);
}
@Test public void WriteDbTbls() {
@Test public void WriteDbTbls() {
String expd = String_.Concat_lines_crlf
( ""
, ""
@@ -53,7 +53,7 @@ public class TdbDbSaveMgr_tst {
String actl = wtr.To_str();
Tfds.Eq(expd, actl);
}
@Test public void WriteTbl() {
@Test public void WriteTbl() {
String expd = String_.Concat_lines_crlf
( ""
, ""

View File

@@ -1,18 +1,18 @@
/*
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
*/
/*
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.*;
@@ -23,7 +23,7 @@ public class TdbFlush_tst {
}
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() {
@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);
@@ -31,7 +31,7 @@ public class TdbFlush_tst {
engine.FlushAll();
fx_io.tst_Exists(true, dbPath);
}
@Test public void IgnoreFlushedDb() {
@Test public void IgnoreFlushedDb() {
engine.FlushAll();
fx_io.tst_Exists(true, dbPath);
fx_io.run_UpdateFilModifiedTime(dbPath, time);
@@ -39,7 +39,7 @@ public class TdbFlush_tst {
engine.FlushAll();
fx_io.tst_QueryFilModified(true, dbPath, time);
}
@Test public void FlushNewTbl() {
@Test public void FlushNewTbl() {
engine.FlushAll();
fx_engine.run_MakeTbl(engine, "tbl0", TdbFile.MainFileId);
fx_io.run_UpdateFilModifiedTime(dbPath, time);
@@ -47,7 +47,7 @@ public class TdbFlush_tst {
engine.FlushAll();
fx_io.tst_QueryFilModified(false, dbPath, time);
}
@Test public void IgnoreFlushedTbl() {
@Test public void IgnoreFlushedTbl() {
fx_engine.run_MakeTbl(engine, "tbl0", TdbFile.MainFileId);
engine.FlushAll();
fx_io.run_UpdateFilModifiedTime(dbPath, time);
@@ -55,7 +55,7 @@ public class TdbFlush_tst {
engine.FlushAll();
fx_io.tst_QueryFilModified(true, dbPath, time);
}
@Test public void FlushDirtyTbl() {
@Test public void FlushDirtyTbl() {
fx_engine.run_MakeTbl(engine, "tbl0", TdbFile.MainFileId);
engine.FlushAll();
fx_io.run_UpdateFilModifiedTime(dbPath, time);
@@ -64,7 +64,7 @@ public class TdbFlush_tst {
engine.FlushAll();
fx_io.tst_QueryFilModified(false, dbPath, time);
}
@Test public void FlushDirtyFilOnly() {
@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());

View File

@@ -1,30 +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
*/
/*
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() {
@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() {
@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));
@@ -33,7 +33,7 @@ public class Dbmeta_parser__fld_tst {
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() {
@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));
}
}

View File

@@ -1,25 +1,25 @@
/*
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
*/
/*
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"));}
@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();

View File

@@ -1,26 +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
*/
/*
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() {
@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() {
@Test public void Test_smoke() {
fxt.Test_parse(String_.Concat_lines_nl_skip_last
( "CREATE TABLE page"
, "( page_id integer NOT NULL PRIMARY KEY"

View File

@@ -1,23 +1,23 @@
/*
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
*/
/*
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() {
@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
@@ -26,7 +26,7 @@ public class Sql_bry_rdr_tst {
fxt.Test_skip_ws("\t\n\r a", 4); // multi
fxt.Test_skip_ws("", 0); // eos
}
@Test public void Read_sql_identifier() {
@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

View File

@@ -1,21 +1,21 @@
/*
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
*/
/*
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 gplx.core.criterias.*;
import gplx.dbs.sqls.*; import gplx.dbs.sqls.itms.*;
import gplx.dbs.sqls.itms.*;
public class Db_qry__select_cmd implements Db_qry {
public int Tid() {return Db_qry_.Tid_select;}
public boolean Exec_is_rdr() {return Bool_.Y;}
@@ -30,6 +30,7 @@ public class Db_qry__select_cmd implements Db_qry {
}
public Db_qry__select_cmd Join_(String name, String alias, Sql_join_fld... join_flds) {return Join_(Sql_tbl_itm.Tid__inner, Sql_tbl_itm.Db__null , name, alias, join_flds);}
public Db_qry__select_cmd Join_(String db, String name, String alias, Sql_join_fld... join_flds) {return Join_(Sql_tbl_itm.Tid__inner, db , name, alias, join_flds);}
public Db_qry__select_cmd Join_(int join_tid, String name, String alias, Sql_join_fld... join_flds) {return Join_(join_tid, Sql_tbl_itm.Db__null, name, alias, join_flds);}
public Db_qry__select_cmd Join_(int join_tid, String db, String name, String alias, Sql_join_fld... join_flds) {
if (from == null) throw Err_.new_("sql_qry", "super table is not defined");
from.Tbls.Add(new Sql_tbl_itm(join_tid, db, name, alias, join_flds));
@@ -107,5 +108,5 @@ public class Db_qry__select_cmd implements Db_qry {
}
public String To_sql__exec(gplx.dbs.sqls.Sql_qry_wtr wtr) {return wtr.To_sql_str(this, Bool_.N);}
public String To_sql__prep(gplx.dbs.sqls.Sql_qry_wtr wtr) {return wtr.To_sql_str(this, Bool_.Y);}
public String To_sql__prep(gplx.dbs.sqls.Sql_qry_wtr wtr) {return wtr.To_sql_str(this, Bool_.Y);}
}

View File

@@ -1,37 +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
*/
/*
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() {
@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() {
@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() {
@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() {
@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"));

View File

@@ -1,84 +1,84 @@
/*
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
*/
/*
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() {
@Test public void Basic() {
cmd.Cols_("fld0", "fld1").From_("tbl0");
expd = "SELECT fld0, fld1 FROM tbl0";
tst_XtoStr(cmd, expd);
}
@Test public void OrderDoesNotMatter() {
@Test public void OrderDoesNotMatter() {
cmd.From_("tbl0").Cols_("fld0", "fld1");
expd = "SELECT fld0, fld1 FROM tbl0";
tst_XtoStr(cmd, expd);
}
@Test public void DefaultAllFields() {
@Test public void DefaultAllFields() {
cmd.From_("tbl0");
expd = "SELECT * FROM tbl0";
tst_XtoStr(cmd, expd);
}
@Test public void Where() {
@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() {
@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() {
@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() {
@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() {
@Test public void Limit() {
cmd.From_("tbl0").Limit_(10);
expd = "SELECT * FROM tbl0 LIMIT 10";
tst_XtoStr(cmd, expd);
}
// @Test public void GroupBy() {
// @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() {
// @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() {
// @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);

View File

@@ -1,37 +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
*/
/*
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() {
@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() {
@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() {
@Test public void Delete() {
fxt.Test_qry
( Db_qry_delete.new_("tbl", String_.Ary("k1", "k2"))
, Object_.Ary("v1", "v2")

View File

@@ -1,6 +1,6 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
Copyright (C) 2012-2021 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.
@@ -13,164 +13,279 @@ 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 java.sql.*;
import gplx.dbs.engines.*; import gplx.dbs.sqls.*; import gplx.core.stores.*;
public class Db_stmt_cmd implements Db_stmt {
private static final String Key_na = ""; // key is not_available; only called by procs with signature of Val(<type> v);
private Db_engine engine;
private PreparedStatement stmt = null;
private String sql; private int val_idx = 0;
public Db_stmt_cmd(Db_engine engine, Db_qry qry) {Ctor_stmt(engine, qry);}
public void Ctor_stmt(Db_engine engine, Db_qry qry) {
this.engine = engine;
sql = qry.Tid() == Db_qry_.Tid_select_in_tbl ? ((Db_qry__select_in_tbl)qry).To_sql__exec(engine.Sql_wtr()) : engine.Sql_wtr().To_sql_str(qry, true);
Reset_stmt();
}
public Db_stmt Reset_stmt() {
stmt = (PreparedStatement)engine.Stmt_by_sql(sql);
return this;
}
public Db_stmt Crt_bool_as_byte(String k, boolean v) {return Add_byte_by_bool(Bool_.Y, k, v);}
public Db_stmt Val_bool_as_byte(String k, boolean v) {return Add_byte_by_bool(Bool_.N, k, v);}
public Db_stmt Val_bool_as_byte(boolean v) {return Add_byte_by_bool(Bool_.N, Key_na, v);}
private Db_stmt Add_byte_by_bool(boolean where, String k, boolean v) {return Add_byte(where, k, v ? Bool_.Y_byte : Bool_.N_byte);}
public Db_stmt Crt_byte(String k, byte v) {return Add_byte(Bool_.Y, k, v);}
public Db_stmt Val_byte(String k, byte v) {return Add_byte(Bool_.N, k, v);}
public Db_stmt Val_byte(byte v) {return Add_byte(Bool_.N, Key_na, v);}
private Db_stmt Add_byte(boolean where, String k, byte v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setByte(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "byte", "val", v, "sql", sql);}
return this;
}
public Db_stmt Crt_int(String k, int v) {return Add_int(Bool_.Y, k, v);}
public Db_stmt Val_int_by_bool(String k, boolean v) {return Add_int(Bool_.N, k, v ? 1 : 0);}
public Db_stmt Val_int(String k, int v) {return Add_int(Bool_.N, k, v);}
public Db_stmt Val_int(int v) {return Add_int(Bool_.N, Key_na, v);}
private Db_stmt Add_int(boolean where, String k, int v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setInt(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "int", "val", v, "sql", sql);}
return this;
}
public Db_stmt Crt_long(String k, long v) {return Add_long(Bool_.Y, k, v);}
public Db_stmt Val_long(String k, long v) {return Add_long(Bool_.N, k, v);}
public Db_stmt Val_long(long v) {return Add_long(Bool_.N, Key_na, v);}
private Db_stmt Add_long(boolean where, String k, long v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setLong(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "long", "val", v, "sql", sql);}
return this;
}
public Db_stmt Crt_float(String k, float v) {return Add_float(Bool_.Y, k, v);}
public Db_stmt Val_float(String k, float v) {return Add_float(Bool_.N, k, v);}
public Db_stmt Val_float(float v) {return Add_float(Bool_.N, Key_na, v);}
private Db_stmt Add_float(boolean where, String k, float v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setFloat(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "float", "val", v, "sql", sql);}
return this;
}
public Db_stmt Crt_double(String k, double v) {return Add_double(Bool_.Y, k, v);}
public Db_stmt Val_double(String k, double v) {return Add_double(Bool_.N, k, v);}
public Db_stmt Val_double(double v) {return Add_double(Bool_.N, Key_na, v);}
private Db_stmt Add_double(boolean where, String k, double v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setDouble(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "double", "val", v, "sql", sql);}
return this;
}
public Db_stmt Crt_decimal(String k, Decimal_adp v) {return Add_decimal(Bool_.Y, k, v);}
public Db_stmt Val_decimal(String k, Decimal_adp v) {return Add_decimal(Bool_.N, k, v);}
public Db_stmt Val_decimal(Decimal_adp v) {return Add_decimal(Bool_.N, Key_na, v);}
private Db_stmt Add_decimal(boolean where, String k, Decimal_adp v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setBigDecimal(++val_idx, v.Under_as_native());} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v, "sql", sql);}
return this;
}
public Db_stmt Crt_bry(String k, byte[] v) {return Add_bry(Bool_.Y, k, v);}
public Db_stmt Val_bry(String k, byte[] v) {return Add_bry(Bool_.N, k, v);}
public Db_stmt Val_bry(byte[] v) {return Add_bry(Bool_.N, Key_na, v);}
private Db_stmt Add_bry(boolean where, String k, byte[] v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setBytes(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "byte[]", v.length, sql);}
return this;
}
public Db_stmt Crt_bry_as_str(String k, byte[] v) {return Add_bry_as_str(Bool_.Y, k, v);}
public Db_stmt Val_bry_as_str(String k, byte[] v) {return Add_bry_as_str(Bool_.N, k, v);}
public Db_stmt Val_bry_as_str(byte[] v) {return Add_bry_as_str(Bool_.N, Key_na, v);}
private Db_stmt Add_bry_as_str(boolean where, String k, byte[] v) {return Add_str(where, k, String_.new_u8(v));}
public Db_stmt Crt_str(String k, String v) {return Add_str(Bool_.Y, k, v);}
public Db_stmt Val_str(String k, String v) {return Add_str(Bool_.N, k, v);}
public Db_stmt Val_str(String v) {return Add_str(Bool_.N, Key_na, v);}
@gplx.Virtual protected Db_stmt Add_str(boolean where, String k, String v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setString(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "String", "val", v, "sql", sql);}
return this;
}
public Db_stmt Crt_date(String k, DateAdp v) {return Add_date(Bool_.Y, k, v);}
public Db_stmt Val_date(String k, DateAdp v) {return Add_date(Bool_.N, k, v);}
@gplx.Virtual protected Db_stmt Add_date(boolean where, String k, DateAdp v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setTimestamp(++val_idx, new java.sql.Timestamp(v.UnderDateTime().getTime().getTime()));} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "date", "val", v, "sql", sql);}
return this;
}
public Db_stmt Crt_text(String k, String v) {return Add_text(Bool_.Y, k, v);}
public Db_stmt Val_text(String k, String v) {return Add_text(Bool_.N, k, v);}
private Db_stmt Add_text(boolean where, String k, String v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {stmt.setString(++val_idx, v);} catch (Exception e) {this.Rls(); throw Err_.new_exc(e, "db", "failed to add value", "type", "text", "val", v, "sql", sql);}
return this;
}
public Db_stmt Val_rdr_(gplx.core.ios.streams.Io_stream_rdr v, long rdr_len) {
try {stmt.setBinaryStream(++val_idx, (java.io.InputStream)v.Under(), (int)rdr_len);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);}
return this;
}
public boolean Exec_insert() {
try {boolean rv = stmt.execute(); return rv;}
catch (Exception e) {
this.Rls();
Reset_stmt();
throw Err_.new_exc(e, "db_stmt", "insert failed", "url", engine.Conn_info().Db_api(), "sql", sql);
}
}
public int Exec_update() {
try {int rv = stmt.executeUpdate(); return rv;}
catch (Exception e) {
this.Rls();
Reset_stmt();
throw Err_.new_exc(e, "db_stmt", "update failed", "url", engine.Conn_info().Db_api(), "sql", sql);
}
}
public int Exec_delete() {
try {int rv = stmt.executeUpdate(); return rv;}
catch (Exception e) {
this.Rls();
Reset_stmt();
throw Err_.new_exc(e, "db_stmt", "delete failed", "url", engine.Conn_info().Db_api(), "sql", sql);
}
}
public DataRdr Exec_select() {
try {DataRdr rv = engine.New_rdr(stmt.executeQuery(), sql); return rv;} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql);}
}
public Db_rdr Exec_select__rls_auto() {
try {return engine.Exec_as_rdr__rls_auto(this, stmt.executeQuery(), sql);} catch (Exception e) {throw Err_.new_exc(e, "db", "select failed", "sql", sql);}
}
public Db_rdr Exec_select__rls_manual() {
try {return engine.Exec_as_rdr__rls_manual(stmt.executeQuery(), sql);} catch (Exception e) {throw Err_.new_exc(e, "db", "select failed", "sql", sql);}
}
public Object Exec_select_val() {
try {Object rv = DataRdr_.Read_1st_row_and_1st_fld(engine.New_rdr(stmt.executeQuery(), sql)); return rv;} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sql);}
}
public Db_stmt Clear() {
val_idx = 0;
try {stmt.clearBatch();}
catch (Exception e) {throw Err_.new_exc(e, "db", "failed to clear parameters", "sql", sql);}
return this;
}
public void Rls() {
if (stmt == null) return; // Null instance
try {
if (stmt.getConnection().isClosed()) return; // do not close stmt if connection is already closed; throws null error; DATE:2015-02-11
stmt.close();
stmt = null;
}
catch (Exception e) {throw Err_.new_exc(e, "db", "failed to close command", "sql", sql);}
}
}
package gplx.dbs.qrys;
import gplx.Bool_;
import gplx.DateAdp;
import gplx.Decimal_adp;
import gplx.Err_;
import gplx.String_;
import gplx.core.stores.DataRdr;
import gplx.core.stores.DataRdr_;
import gplx.dbs.Db_qry;
import gplx.dbs.Db_qry_;
import gplx.dbs.Db_rdr;
import gplx.dbs.Db_stmt;
import gplx.dbs.Dbmeta_fld_itm;
import gplx.dbs.engines.Db_engine;
import gplx.objects.lists.GfoListBase;
import java.sql.PreparedStatement;
public class Db_stmt_cmd implements Db_stmt {
private static final String Key_na = ""; // key is not_available; only called by procs with signature of Val(<type> v);
private Db_engine engine;
private PreparedStatement stmt = null;
private String sql;
private int val_idx = 0;
private final GfoListBase<Object> paramList = new GfoListBase<>();
public Db_stmt_cmd(Db_engine engine, Db_qry qry) {Ctor_stmt(engine, qry);}
public void Ctor_stmt(Db_engine engine, Db_qry qry) {
this.engine = engine;
sql = qry.Tid() == Db_qry_.Tid_select_in_tbl ? ((Db_qry__select_in_tbl)qry).To_sql__exec(engine.Sql_wtr()) : engine.Sql_wtr().To_sql_str(qry, true);
Reset_stmt();
}
public Db_stmt Reset_stmt() {
stmt = (PreparedStatement)engine.Stmt_by_sql(sql);
return this;
}
public Db_stmt Crt_bool_as_byte(String k, boolean v) {return Add_byte_by_bool(Bool_.Y, k, v);}
public Db_stmt Val_bool_as_byte(String k, boolean v) {return Add_byte_by_bool(Bool_.N, k, v);}
public Db_stmt Val_bool_as_byte(boolean v) {return Add_byte_by_bool(Bool_.N, Key_na, v);}
private Db_stmt Add_byte_by_bool(boolean where, String k, boolean v) {return Add_byte(where, k, v ? Bool_.Y_byte : Bool_.N_byte);}
public Db_stmt Crt_byte(String k, byte v) {return Add_byte(Bool_.Y, k, v);}
public Db_stmt Val_byte(String k, byte v) {return Add_byte(Bool_.N, k, v);}
public Db_stmt Val_byte(byte v) {return Add_byte(Bool_.N, Key_na, v);}
private Db_stmt Add_byte(boolean where, String k, byte v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {
stmt.setByte(++val_idx, v);
paramList.Add(v);
} catch (Exception e) {
this.Rls();
throw Err_.new_exc(e, "db", "failed to add value", "type", "byte", "val", v, "sql", sql);
}
return this;
}
public Db_stmt Crt_int(String k, int v) {return Add_int(Bool_.Y, k, v);}
public Db_stmt Val_int_by_bool(String k, boolean v) {return Add_int(Bool_.N, k, v ? 1 : 0);}
public Db_stmt Val_int(String k, int v) {return Add_int(Bool_.N, k, v);}
public Db_stmt Val_int(int v) {return Add_int(Bool_.N, Key_na, v);}
private Db_stmt Add_int(boolean where, String k, int v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {
stmt.setInt(++val_idx, v);
paramList.Add(v);
} catch (Exception e) {
this.Rls();
throw Err_.new_exc(e, "db", "failed to add value", "type", "int", "val", v, "sql", sql);
}
return this;
}
public Db_stmt Crt_long(String k, long v) {return Add_long(Bool_.Y, k, v);}
public Db_stmt Val_long(String k, long v) {return Add_long(Bool_.N, k, v);}
public Db_stmt Val_long(long v) {return Add_long(Bool_.N, Key_na, v);}
private Db_stmt Add_long(boolean where, String k, long v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {
stmt.setLong(++val_idx, v);
paramList.Add(v);
} catch (Exception e) {
this.Rls();
throw Err_.new_exc(e, "db", "failed to add value", "type", "long", "val", v, "sql", sql);
}
return this;
}
public Db_stmt Crt_float(String k, float v) {return Add_float(Bool_.Y, k, v);}
public Db_stmt Val_float(String k, float v) {return Add_float(Bool_.N, k, v);}
public Db_stmt Val_float(float v) {return Add_float(Bool_.N, Key_na, v);}
private Db_stmt Add_float(boolean where, String k, float v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {
stmt.setFloat(++val_idx, v);
paramList.Add(v);
} catch (Exception e) {
this.Rls();
throw Err_.new_exc(e, "db", "failed to add value", "type", "float", "val", v, "sql", sql);
}
return this;
}
public Db_stmt Crt_double(String k, double v) {return Add_double(Bool_.Y, k, v);}
public Db_stmt Val_double(String k, double v) {return Add_double(Bool_.N, k, v);}
public Db_stmt Val_double(double v) {return Add_double(Bool_.N, Key_na, v);}
private Db_stmt Add_double(boolean where, String k, double v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {
stmt.setDouble(++val_idx, v);
paramList.Add(v);
} catch (Exception e) {
this.Rls();
throw Err_.new_exc(e, "db", "failed to add value", "type", "double", "val", v, "sql", sql);
}
return this;
}
public Db_stmt Crt_decimal(String k, Decimal_adp v) {return Add_decimal(Bool_.Y, k, v);}
public Db_stmt Val_decimal(String k, Decimal_adp v) {return Add_decimal(Bool_.N, k, v);}
public Db_stmt Val_decimal(Decimal_adp v) {return Add_decimal(Bool_.N, Key_na, v);}
private Db_stmt Add_decimal(boolean where, String k, Decimal_adp v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {
stmt.setBigDecimal(++val_idx, v.Under_as_native());
paramList.Add(v);
} catch (Exception e) {
this.Rls();
throw Err_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v, "sql", sql);
}
return this;
}
public Db_stmt Crt_bry(String k, byte[] v) {return Add_bry(Bool_.Y, k, v);}
public Db_stmt Val_bry(String k, byte[] v) {return Add_bry(Bool_.N, k, v);}
public Db_stmt Val_bry(byte[] v) {return Add_bry(Bool_.N, Key_na, v);}
private Db_stmt Add_bry(boolean where, String k, byte[] v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {
stmt.setBytes(++val_idx, v);
paramList.Add(v);
} catch (Exception e) {
this.Rls();
throw Err_.new_exc(e, "db", "failed to add value", "type", "byte[]", v.length, sql);
}
return this;
}
public Db_stmt Crt_bry_as_str(String k, byte[] v) {return Add_bry_as_str(Bool_.Y, k, v);}
public Db_stmt Val_bry_as_str(String k, byte[] v) {return Add_bry_as_str(Bool_.N, k, v);}
public Db_stmt Val_bry_as_str(byte[] v) {return Add_bry_as_str(Bool_.N, Key_na, v);}
private Db_stmt Add_bry_as_str(boolean where, String k, byte[] v) {return Add_str(where, k, String_.new_u8(v));}
public Db_stmt Crt_str(String k, String v) {return Add_str(Bool_.Y, k, v);}
public Db_stmt Val_str(String k, String v) {return Add_str(Bool_.N, k, v);}
public Db_stmt Val_str(String v) {return Add_str(Bool_.N, Key_na, v);}
protected Db_stmt Add_str(boolean where, String k, String v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {
stmt.setString(++val_idx, v);
paramList.Add(v);
} catch (Exception e) {
this.Rls();
throw Err_.new_exc(e, "db", "failed to add value", "type", "String", "val", v, "sql", sql);
}
return this;
}
public Db_stmt Crt_date(String k, DateAdp v) {return Add_date(Bool_.Y, k, v);}
public Db_stmt Val_date(String k, DateAdp v) {return Add_date(Bool_.N, k, v);}
protected Db_stmt Add_date(boolean where, String k, DateAdp v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {
stmt.setTimestamp(++val_idx, new java.sql.Timestamp(v.UnderDateTime().getTime().getTime()));
paramList.Add(v);
} catch (Exception e) {
this.Rls();
throw Err_.new_exc(e, "db", "failed to add value", "type", "date", "val", v, "sql", sql);
}
return this;
}
public Db_stmt Crt_text(String k, String v) {return Add_text(Bool_.Y, k, v);}
public Db_stmt Val_text(String k, String v) {return Add_text(Bool_.N, k, v);}
private Db_stmt Add_text(boolean where, String k, String v) {
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
try {
stmt.setString(++val_idx, v);
paramList.Add(v);
} catch (Exception e) {
this.Rls();
throw Err_.new_exc(e, "db", "failed to add value", "type", "text", "val", v, "sql", sql);
}
return this;
}
public Db_stmt Val_rdr_(gplx.core.ios.streams.Io_stream_rdr v, long rdr_len) {
try {
stmt.setBinaryStream(++val_idx, (java.io.InputStream)v.Under(), (int)rdr_len);
} catch (Exception e) {
// DATE:2021-07-16: shouldn't there be a this.Rls()?
throw Err_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);
}
return this;
}
public boolean Exec_insert() {
try {boolean rv = stmt.execute(); return rv;}
catch (Exception e) {
String sqlStr = ToSqlStr();
this.Rls();
Reset_stmt();
throw Err_.new_exc(e, "db_stmt", "insert failed", "url", engine.Conn_info().Db_api(), "sql", sqlStr);
}
}
public int Exec_update() {
try {int rv = stmt.executeUpdate(); return rv;}
catch (Exception e) {
String sqlStr = ToSqlStr();
this.Rls();
Reset_stmt();
throw Err_.new_exc(e, "db_stmt", "update failed", "url", engine.Conn_info().Db_api(), "sql", sqlStr);
}
}
public int Exec_delete() {
try {int rv = stmt.executeUpdate(); return rv;}
catch (Exception e) {
String sqlStr = ToSqlStr();
this.Rls();
Reset_stmt();
throw Err_.new_exc(e, "db_stmt", "delete failed", "url", engine.Conn_info().Db_api(), "sql", sqlStr);
}
}
public DataRdr Exec_select() {
try {
DataRdr rv = engine.New_rdr(stmt.executeQuery(), sql); return rv;
} catch (Exception e) {
String sqlStr = ToSqlStr();
// DATE:2021-07-16: this needs a this.Rls() / Reset_stmt
throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sqlStr);
}
}
public Db_rdr Exec_select__rls_auto() {
try {
return engine.Exec_as_rdr__rls_auto(this, stmt.executeQuery(), sql);
} catch (Exception e) {
String sqlStr = ToSqlStr();
// DATE:2021-07-16: this needs a this.Rls() / Reset_stmt
throw Err_.new_exc(e, "db", "select failed", "sql", sqlStr);
}
}
public Db_rdr Exec_select__rls_manual() {
try {
return engine.Exec_as_rdr__rls_manual(stmt.executeQuery(), sql);
} catch (Exception e) {
String sqlStr = ToSqlStr();
// DATE:2021-07-16: this needs a this.Rls() / Reset_stmt
throw Err_.new_exc(e, "db", "select failed", "sql", sqlStr);
}
}
public Object Exec_select_val() {
try {
Object rv = DataRdr_.Read_1st_row_and_1st_fld(engine.New_rdr(stmt.executeQuery(), sql)); return rv;
} catch (Exception e) {
String sqlStr = ToSqlStr();
// DATE:2021-07-16: this needs a this.Rls() / Reset_stmt
throw Err_.new_exc(e, "db", "failed to exec prepared statement", "sql", sqlStr);
}
}
public Db_stmt Clear() {
val_idx = 0;
paramList.Clear();
try {stmt.clearBatch();}
catch (Exception e) {throw Err_.new_exc(e, "db", "failed to clear parameters", "sql", sql);}
return this;
}
public void Rls() {
this.Clear(); // DATE:2021-07-16: added this.Clear();
if (stmt == null) return; // Null instance
try {
if (stmt.getConnection().isClosed()) return; // do not close stmt if connection is already closed; throws null error; DATE:2015-02-11
stmt.close();
stmt = null;
}
catch (Exception e) {throw Err_.new_exc(e, "db", "failed to close command", "sql", sql);}
}
public String ToSqlStr() {
return Db_val_type.ToSqlStr(sql, paramList);
}
}

View File

@@ -13,15 +13,15 @@ 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());
}
}
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());
}
}

View File

@@ -1,6 +1,6 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
Copyright (C) 2012-2021 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.
@@ -13,22 +13,96 @@ 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.*;
package gplx.dbs.qrys;
import gplx.Bry_find_;
import gplx.DateAdp_;
import gplx.Decimal_adp_;
import gplx.Object_;
import gplx.String_;
import gplx.objects.lists.GfoListBase;
import gplx.objects.primitives.Bool_;
import gplx.objects.primitives.Byte_;
import gplx.objects.primitives.Char_;
import gplx.objects.primitives.Double_;
import gplx.objects.primitives.Float_;
import gplx.objects.primitives.Int_;
import gplx.objects.primitives.Long_;
import gplx.objects.primitives.Short_;
import gplx.objects.strings.bfrs.GfoStringBuilder;
import gplx.objects.types.Type_;
public class Db_val_type {
public static final byte // not serialized
Tid_null = 0
, Tid_bool = 1
, Tid_byte = 2
, Tid_int32 = 3
, Tid_int64 = 4
, Tid_date = 5
, Tid_decimal = 6
, Tid_float = 7
, Tid_double = 8
, Tid_bry = 9
, Tid_varchar = 10
, Tid_nvarchar = 11
, Tid_rdr = 12
, Tid_text = 13
;
}
public static final byte // not serialized
Tid_null = 0
, Tid_bool = 1
, Tid_byte = 2
, Tid_int32 = 3
, Tid_int64 = 4
, Tid_date = 5
, Tid_decimal = 6
, Tid_float = 7
, Tid_double = 8
, Tid_bry = 9
, Tid_varchar = 10
, Tid_nvarchar = 11
, Tid_rdr = 12
, Tid_text = 13
, Tid_int16 = 14
, Tid_char = 15
, Tid_unknown = 16
;
public static int ToTypeId(Object o) {
Class<?> type = o.getClass();
if (Type_.Eq(type, Int_.Cls_ref_type)) return Tid_int32;
else if (Type_.Eq(type, String_.Cls_ref_type)) return Tid_nvarchar;
else if (Type_.Eq(type, byte[].class)) return Tid_nvarchar;
else if (Type_.Eq(type, Bool_.Cls_ref_type)) return Tid_bool;
else if (Type_.Eq(type, Byte_.Cls_ref_type)) return Tid_byte;
else if (Type_.Eq(type, Long_.Cls_ref_type)) return Tid_int64;
else if (Type_.Eq(type, Double_.Cls_ref_type)) return Tid_double;
else if (Type_.Eq(type, Decimal_adp_.Cls_ref_type)) return Tid_decimal;
else if (Type_.Eq(type, DateAdp_.Cls_ref_type)) return Tid_date;
else if (Type_.Eq(type, Float_.Cls_ref_type)) return Tid_float;
else if (Type_.Eq(type, Short_.Cls_ref_type)) return Tid_int16;
else if (Type_.Eq(type, Char_.Cls_ref_type)) return Tid_char;
else return Tid_unknown;
}
public static String ToSqlStr(String sql, GfoListBase<Object> paramList) {
try {
GfoStringBuilder sb = new GfoStringBuilder();
int oldPos = 0;
int paramIdx = 0;
while (true) {
int newPos = String_.FindFwd(sql, "?", oldPos);
if (newPos == Bry_find_.Not_found) break;
if (paramIdx == paramList.Len()) break;
sb.AddMid(sql, oldPos, newPos);
Object paramObj = paramList.GetAt(paramIdx++);
String paramStr = Object_.Xto_str_loose_or(paramObj, "");
boolean quote = false;
switch (ToTypeId(paramObj)) {
case Tid_char:
case Tid_bry:
case Tid_varchar:
case Tid_nvarchar:
case Tid_date:
quote = true;
break;
}
if (quote) {
sb.Add('\'');
sb.Add(String_.Replace(paramStr, "'", "\\'"));
sb.Add('\'');
} else {
sb.Add(paramStr);
}
oldPos = newPos + 1;
}
sb.AddMid(sql, oldPos);
return sb.ToStr();
} catch (Exception exc) {
return "FAILED TO INTERPOLATE:" + sql;
}
}
}

View File

@@ -1,27 +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
*/
/*
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() {
@Test public void Int() {
fxt.Init_fld("fld_0", Type_ids_.Id__int).Init_fld("fld_1", Type_ids_.Id__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() {
@Test public void Str() {
fxt.Init_fld("fld_0", Type_ids_.Id__int).Init_fld("fld_1", Type_ids_.Id__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')");
}
}

View File

@@ -1,29 +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
*/
/*
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() {
@Test public void Abrv() {
fxt.Test__qry(Db_qry_.select_().Cols_all_().From_("tbl", "t"), "SELECT * FROM tbl t");
}
@Test public void Db() {
@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() {
@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");

View File

@@ -1,79 +1,79 @@
/*
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
*/
/*
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() {
@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() {
@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() {
@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() {
@Test public void SelectAll() {
tst_XtoSql
( Db_qry_.select_().From_("people")
, "SELECT * FROM people"
);
}
@Test public void SelectFlds() {
@Test public void SelectFlds() {
tst_XtoSql
( Db_qry_.select_().Cols_("id", "name").From_("people")
, "SELECT id, name FROM people"
);
}
@Test public void SelectOrderBy() {
@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() {
@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() {
@Test public void Select_From_Alias() {
tst_XtoSql
( Db_qry_.select_().From_("people", "p")
, "SELECT * FROM people p"
);
}
@Test public void Select_Join_Alias() {
@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() {
@Test public void Prepare() {
tst_XtoSql
( Db_qry_.insert_("people").Val_int("id", 1).Val_str("name", "me")
, "INSERT INTO people (id, name) VALUES (?, ?)"

View File

@@ -1,45 +1,45 @@
/*
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
*/
/*
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() {
@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() {
@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() {
@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() {
@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() {
@Test public void Binary() {
// parentheses around lhs and rhs
tst_Write(
"(type = 1 OR type = 2)"

View File

@@ -1,28 +1,28 @@
/*
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
*/
/*
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() {
@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() {
@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");
@@ -50,7 +50,7 @@ public class Sql_schema_wtr_tst {
, ");"
));
}
@Test public void Tbl_alter_tbl_add() {
@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");

View File

@@ -13,14 +13,14 @@ 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");
}
}
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");
}
}

View File

@@ -1,37 +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
*/
/*
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'");}
@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'");}
}

View File

@@ -1,47 +1,47 @@
/*
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
*/
/*
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() {
@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() {
@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() {
@Test public void Nested() {
fxt.Test__where
( Criteria_.Or
( Db_crt_.New_eq("id", 1)

View File

@@ -1,23 +1,23 @@
/*
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
*/
/*
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() {
@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
}

View File

@@ -13,17 +13,17 @@ 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());
}
}
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());
}
}

View File

@@ -0,0 +1,5 @@
package gplx.gfdbs.cores;
public interface GfdbCloseAble {
void Close();
}

View File

@@ -0,0 +1,5 @@
package gplx.gfdbs.cores;
public interface GfdbConnInfo {
String ConnStr();
}

View File

@@ -0,0 +1,11 @@
package gplx.gfdbs.cores;
import gplx.Io_url;
public class GfdbConnInfoSqlite implements GfdbConnInfo {
public GfdbConnInfoSqlite(Io_url dbFilPath) {
this.dbFilPath = dbFilPath;
}
public String ConnStr() {return null;}
public Io_url DbFilPath() {return dbFilPath;} private Io_url dbFilPath;
}

View File

@@ -0,0 +1,7 @@
package gplx.gfdbs.cores;
public interface GfdbItm<K, I> {
void CtorByItm(I itm);
GfdbState DbState(); void DbStateSet(GfdbState v);
K ToPkey();
}

View File

@@ -0,0 +1,5 @@
package gplx.gfdbs.cores;
public interface GfdbItmFactory<I> {
I NewByDb();
}

View File

@@ -0,0 +1,14 @@
package gplx.gfdbs.cores;
import gplx.dbs.Db_rdr;
import gplx.dbs.Db_stmt;
import gplx.dbs.Dbmeta_fld_list;
public interface GfdbMeta<I> extends GfdbItmFactory<I> {
String TblName();
Dbmeta_fld_list Flds();
String[] Pkeys();
void SaveStmtPkeys(Db_stmt stmt, I itm);
void SaveStmtVals(GfdbState state, Db_stmt stmt, I itm);
void LoadItm(Db_rdr rdr, I itm);
}

View File

@@ -0,0 +1,19 @@
package gplx.gfdbs.cores;
import gplx.dbs.Db_stmt;
import gplx.dbs.Dbmeta_fld_list;
public abstract class GfdbMetaBase<I> implements GfdbMeta<I> {
public GfdbMetaBase(String tblName) {
this.tblName = tblName;
CtorFlds();
this.pkeys = CtorPkeys();
}
@Override public String TblName() {return tblName;} private final String tblName;
@Override public Dbmeta_fld_list Flds() {return flds;} protected final Dbmeta_fld_list flds = new Dbmeta_fld_list();
@Override public String[] Pkeys() {return pkeys;} protected String[] pkeys;
@Override public abstract void SaveStmtPkeys(Db_stmt stmt, I itm);
@Override public abstract void SaveStmtVals(GfdbState state, Db_stmt stmt, I itm);
protected abstract void CtorFlds();
protected abstract String[] CtorPkeys();
}

View File

@@ -0,0 +1,11 @@
package gplx.gfdbs.cores;
public enum GfdbState {
Noop, // = 0
Insert,// = 1
Update,// = 2
Delete,// = 3
;
public int ToDb() {return this.ordinal();}
public static GfdbState ByDb(int id) {return GfdbState.values()[id];}
}

View File

@@ -0,0 +1,47 @@
package gplx.gfdbs.cores;
import gplx.Err_;
import gplx.dbs.Db_conn;
import gplx.dbs.Dbmeta_idx_itm;
import gplx.dbs.Dbmeta_tbl_itm;
import gplx.dbs.qrys.Db_qry_delete;
import gplx.gfdbs.cores.cmds.GfdbModifyCmd;
import gplx.gfdbs.cores.cmds.GfdbSelectCmd;
import gplx.gfdbs.cores.cmds.GfoDbSelectWkrAll;
import gplx.gfdbs.cores.txns.GfdbTxnMgr;
public class GfdbTbl<I, M extends GfdbMeta<I>> implements GfdbCloseAble {
protected final Db_conn conn;
protected final M meta;
public GfdbTbl(Db_conn conn, GfdbTxnMgr txnMgr, M meta) {
this.conn = conn;
this.meta = meta;
this.insertCmd = new GfdbModifyCmd<>(conn, txnMgr, meta, GfdbState.Insert);
this.updateCmd = new GfdbModifyCmd<>(conn, txnMgr, meta, GfdbState.Update);
this.deleteCmd = new GfdbModifyCmd<>(conn, txnMgr, meta, GfdbState.Delete);
this.selectAllCmd = new GfdbSelectCmd<>(conn, meta, new GfoDbSelectWkrAll<>(meta));
}
public M Meta() {return meta;}
public void CreateTbl() {
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(meta.TblName(), meta.Flds(), Dbmeta_idx_itm.new_unique_by_tbl(meta.TblName(), "pkey", meta.Pkeys())));
}
public GfdbModifyCmd<I> InsertCmd() {return insertCmd;} private final GfdbModifyCmd<I> insertCmd;
public GfdbModifyCmd<I> UpdateCmd() {return updateCmd;} private final GfdbModifyCmd<I> updateCmd;
public GfdbModifyCmd<I> DeleteCmd() {return deleteCmd;} private final GfdbModifyCmd<I> deleteCmd;
public GfdbSelectCmd<I> SelectAllCmd() {return selectAllCmd;} private final GfdbSelectCmd<I> selectAllCmd;
public GfdbModifyCmd<I> ModifyCmd(GfdbState dbState) {
switch (dbState) {
case Insert: return insertCmd;
case Update: return updateCmd;
case Delete: return deleteCmd;
default: throw Err_.new_unhandled_default(dbState);
}
}
public void DeleteAll() {conn.Stmt_new(Db_qry_delete.new_all_(meta.TblName())).Exec_delete();}
@Override public void Close() {
insertCmd.Close();
updateCmd.Close();
deleteCmd.Close();
selectAllCmd.Close();
}
}

View File

@@ -0,0 +1,34 @@
package gplx.gfdbs.cores.cfgs;
import gplx.Type_;
import gplx.gfdbs.cores.GfdbState;
import gplx.gfdbs.cores.GfdbItm;
public class GfdbCfgItm implements GfdbItm<String, GfdbCfgItm> {
@Override public void CtorByItm(GfdbCfgItm itm) {this.Ctor(itm.key, itm.val);}
public GfdbCfgItm Ctor(String key, String val) {
this.key = key;
this.val = val;
return this;
}
@Override public GfdbState DbState() {return dbState;} private GfdbState dbState = GfdbState.Noop; @Override public void DbStateSet(GfdbState v) {this.dbState = v;}
@Override public String ToPkey() {
return key;
}
public String Key() {return key;} private String key;
public String Val() {return val;} private String val;
public void ValSet(String v) {this.val = v; this.dbState = GfdbState.Update;}
public int ValAdd(int add) {
Integer valInt = Integer.parseInt(val);
valInt += add;
this.ValSet(valInt.toString());
return valInt;
}
@Override public String toString() {return Type_.SimpleName_by_obj(this) + toStringItm();}
protected String toStringItm() {
return "|dbState=" + dbState.name()
+ "|key=" + key
+ "|val=" + val
;
}
}

View File

@@ -0,0 +1,32 @@
package gplx.gfdbs.cores.cfgs;
import gplx.dbs.Db_rdr;
import gplx.dbs.Db_stmt;
import gplx.gfdbs.cores.GfdbState;
import gplx.gfdbs.cores.GfdbMetaBase;
public class GfdbCfgMeta extends GfdbMetaBase<GfdbCfgItm> {
public GfdbCfgMeta() {super(GfdbCfgMeta.TBL_CORE_CFG);}
public String Key() {return key;} private String key;
public String Val() {return val;} private String val;
@Override protected void CtorFlds() {
this.key = flds.Add_str_pkey("cfg_key", 1024);
this.val = flds.Add_str("cfg_val", 1024);
}
@Override protected String[] CtorPkeys() {return new String[] {key};}
@Override public void SaveStmtPkeys(Db_stmt stmt, GfdbCfgItm itm) {stmt.Crt_str(this.Key(), itm.Key());}
@Override public void SaveStmtVals(GfdbState state, Db_stmt stmt, GfdbCfgItm itm) {
if (state == GfdbState.Insert) {
stmt.Val_str(this.Key(), itm.Key());
}
stmt.Val_str(this.Val(), itm.Val());
}
@Override public GfdbCfgItm NewByDb() {return new GfdbCfgItm();}
@Override public void LoadItm(Db_rdr rdr, GfdbCfgItm itm) {
itm.Ctor
( rdr.Read_str(key)
, rdr.Read_str(val)
);
}
public static final String TBL_CORE_CFG = "core_cfg";
}

View File

@@ -0,0 +1,32 @@
package gplx.gfdbs.cores.cfgs;
import gplx.dbs.Db_conn;
import gplx.dbs.Db_crt_;
import gplx.dbs.Db_qry;
import gplx.dbs.Db_qry_;
import gplx.dbs.Db_rdr;
import gplx.gfdbs.cores.cmds.GfoDbSelectWkr;
import gplx.dbs.engines.sqlite.Sqlite_engine_;
public class GfdbCfgSelectWildcardWkr implements GfoDbSelectWkr<GfdbCfgItm> {
private final GfdbCfgMeta meta;
public GfdbCfgSelectWildcardWkr(GfdbCfgMeta meta) {
this.meta = meta;
}
@Override public Db_rdr NewRdr(Db_conn conn, Object... args) {
Db_qry qry = Db_qry_.select_()
.Cols_all_()
.From_(meta.TblName())
.Where_
(
Db_crt_.New_like(meta.Key(), "")
);
String keyPattern = (String)args[0];
return conn.Stmt_new(qry).Clear()
.Crt_str(meta.Key(), keyPattern + Sqlite_engine_.Wildcard_str)
.Exec_select__rls_auto();
}
@Override public void ItmLoad(Db_rdr rdr, GfdbCfgItm itm) {
meta.LoadItm(rdr, itm);
}
}

View File

@@ -0,0 +1,18 @@
package gplx.gfdbs.cores.cfgs;
import gplx.dbs.Db_conn;
import gplx.gfdbs.cores.GfdbTbl;
import gplx.gfdbs.cores.cmds.GfdbSelectCmd;
import gplx.gfdbs.cores.txns.GfdbTxnMgr;
public class GfdbCfgTbl extends GfdbTbl<GfdbCfgItm, GfdbCfgMeta> {
public GfdbCfgTbl(GfdbTxnMgr txnMgr, Db_conn conn, GfdbCfgMeta meta) {
super(conn, txnMgr, meta);
this.selectWildcardCmd = new GfdbSelectCmd<>(conn, meta, new GfdbCfgSelectWildcardWkr(meta));
}
public GfdbSelectCmd<GfdbCfgItm> SelectWildcardCmd() {return selectWildcardCmd;} private final GfdbSelectCmd<GfdbCfgItm> selectWildcardCmd;
@Override public void Close() {
super.Close();
selectWildcardCmd.Close();
}
}

View File

@@ -0,0 +1,35 @@
package gplx.gfdbs.cores.cfgs;
import gplx.gfdbs.cores.txns.GfdbTxnSub;
import gplx.gfdbs.cores.wkrs.GfdbListWkr;
import gplx.gfdbs.cores.wkrs.GfdbListWkrUtl;
import gplx.objects.lists.GfoIndexedList;
public class GfdbIdMgr implements GfdbTxnSub {
private final GfoIndexedList<String, GfdbCfgItm> regy = new GfoIndexedList<>();
private final GfdbListWkr<String, GfdbCfgItm> dbListWkr;
private boolean load = true;
private static final String ID_MGR_PREFIX = "idMgr.";
public GfdbIdMgr(GfdbCfgTbl coreCfgTbl) {
this.dbListWkr = GfdbListWkrUtl.NewByTbl(regy, coreCfgTbl, coreCfgTbl.SelectWildcardCmd(), ID_MGR_PREFIX);
}
public void Reg(String tblName) {
String key = ToCfgTblKey(tblName);
GfdbCfgItm itm = new GfdbCfgItm().Ctor(key, "0");
regy.Add(key, itm);
}
@Override public void WhenTxnSav() {
dbListWkr.Save();
}
public int Next(String tblName) {
if (load) {
load = false;
dbListWkr.Load();
}
GfdbCfgItm itm = regy.GetByOrFail(ToCfgTblKey(tblName));
return itm.ValAdd(1);
}
private String ToCfgTblKey(String tblName) {return ID_MGR_PREFIX + tblName;}
}

View File

@@ -0,0 +1,63 @@
package gplx.gfdbs.cores.cmds;
import gplx.dbs.Db_conn;
import gplx.dbs.Db_stmt;
import gplx.dbs.Db_stmt_;
import gplx.gfdbs.cores.GfdbCloseAble;
import gplx.gfdbs.cores.GfdbMeta;
import gplx.gfdbs.cores.txns.GfdbTxnMgr;
import gplx.gfdbs.cores.GfdbState;
public class GfdbModifyCmd<I> implements GfdbCloseAble {
private final Db_conn conn;
private final GfdbTxnMgr txnMgr;
private Db_stmt stmt;
public GfdbModifyCmd(Db_conn conn, GfdbTxnMgr txnMgr, GfdbMeta<I> meta, GfdbState dbState) {
this.conn = conn;
this.txnMgr = txnMgr;
this.meta = meta;
this.dbState = dbState;
}
public GfdbMeta<I> Meta() {return meta;} private final GfdbMeta<I> meta;
public GfdbState DbState() {return dbState;} private final GfdbState dbState;
public void ExecObject(Object o) {Exec((I)o);}
public void Exec(I itm) {
if (stmt == null) {
StmtMake();
}
else {
stmt.Clear();
}
if (dbState != GfdbState.Delete) {
meta.SaveStmtVals(dbState, stmt, itm);
}
StmtWhere(itm);
StmtExec();
txnMgr.SaveCheck();
}
private void StmtMake() {
switch (dbState) {
case Insert: stmt = conn.Stmt_insert(meta.TblName(), meta.Flds()); break;
case Delete: stmt = conn.Stmt_delete(meta.TblName(), meta.Pkeys()); break;
case Update: stmt = conn.Stmt_update_exclude(meta.TblName(), meta.Flds(), meta.Pkeys()); break;
}
}
private void StmtWhere(I itm) {
switch (dbState) {
case Delete:
case Update:
meta.SaveStmtPkeys(stmt, itm);
break;
}
}
private void StmtExec() {
switch (dbState) {
case Insert: stmt.Exec_insert(); break;
case Update: stmt.Exec_update(); break;
case Delete: stmt.Exec_delete(); break;
}
}
@Override public void Close() {
stmt = Db_stmt_.Rls(stmt);
}
}

View File

@@ -0,0 +1,50 @@
package gplx.gfdbs.cores.cmds;
import gplx.dbs.Db_conn;
import gplx.dbs.Db_rdr;
import gplx.dbs.Db_rdr_;
import gplx.gfdbs.cores.GfdbCloseAble;
import gplx.gfdbs.cores.GfdbItmFactory;
import gplx.objects.lists.GfoListBase;
public class GfdbSelectCmd<I> implements GfdbCloseAble, GfdbSelectList<I> {
private final Db_conn conn;
private final GfdbItmFactory<I> itmFactory;
private final GfoDbSelectWkr<I> wkr;
public GfdbSelectCmd(Db_conn conn, GfdbItmFactory<I> itmFactory, GfoDbSelectWkr<I> wkr) {
this.conn = conn;
this.itmFactory = itmFactory;
this.wkr = wkr;
}
public GfoListBase<I> Select(Object... args) {
GfoListBase<I> list = new GfoListBase<>();
Db_rdr rdr = Db_rdr_.Empty;
try {
rdr = wkr.NewRdr(conn, args);
while (rdr.Move_next()) {
I itm = itmFactory.NewByDb();
wkr.ItmLoad(rdr, itm);
list.Add(itm);
}
}
finally {rdr.Rls();}
return list;
}
public I SelectOne(Object... args) {
Db_rdr rdr = Db_rdr_.Empty;
try {
rdr = wkr.NewRdr(conn, args);
if (rdr.Move_next()) {
I itm = itmFactory.NewByDb();
wkr.ItmLoad(rdr, itm);
return itm;
}
else {
return null;
}
}
finally {rdr.Rls();}
}
@Override public void Close() {}
}

View File

@@ -0,0 +1,8 @@
package gplx.gfdbs.cores.cmds;
import gplx.gfdbs.cores.GfdbCloseAble;
import gplx.objects.lists.GfoListBase;
public interface GfdbSelectList<I> extends GfdbCloseAble {
GfoListBase<I> Select(Object... args);
}

View File

@@ -0,0 +1,24 @@
package gplx.gfdbs.cores.cmds;
import gplx.gfdbs.cores.GfdbTbl;
import gplx.gfdbs.cores.GfdbMeta;
import gplx.gfdbs.cores.GfdbState;
import gplx.objects.lists.GfoIndexedList;
public class GfoDbModifyCmdHash {
private final GfoIndexedList<String, GfdbModifyCmd<Object>> hash = new GfoIndexedList<>();
public <I extends Object> GfoDbModifyCmdHash Add(GfdbModifyCmd<I> cmd) {
hash.Add(ToKey(cmd.Meta().TblName(), cmd.DbState()), (GfdbModifyCmd<Object>)cmd);
return this;
}
public <I, G extends GfdbMeta<I>> GfoDbModifyCmdHash AddTbl(GfdbTbl<I, G> tbl) {
Add((GfdbModifyCmd<Object>)tbl.InsertCmd());
Add((GfdbModifyCmd<Object>)tbl.UpdateCmd());
Add((GfdbModifyCmd<Object>)tbl.DeleteCmd());
return this;
}
private String ToKey(String type, GfdbState state) {
return type + "|" + state.name();
}
}

View File

@@ -0,0 +1,9 @@
package gplx.gfdbs.cores.cmds;
import gplx.dbs.Db_conn;
import gplx.dbs.Db_rdr;
public interface GfoDbSelectWkr<I> {
Db_rdr NewRdr(Db_conn conn, Object... args);
void ItmLoad(Db_rdr rdr, I itm);
}

View File

@@ -0,0 +1,18 @@
package gplx.gfdbs.cores.cmds;
import gplx.dbs.Db_conn;
import gplx.dbs.Db_rdr;
import gplx.dbs.Db_stmt;
import gplx.gfdbs.cores.GfdbMeta;
public class GfoDbSelectWkrAll<I, M extends GfdbMeta<I>> implements GfoDbSelectWkr<I> {
private final M meta;
public GfoDbSelectWkrAll(M meta) {
this.meta = meta;
}
@Override public Db_rdr NewRdr(Db_conn conn, Object... args) {
Db_stmt stmt = conn.Stmt_select_all(meta.TblName(), meta.Flds());
return stmt.Exec_select__rls_auto();
}
@Override public void ItmLoad(Db_rdr rdr, I itm) {meta.LoadItm(rdr, itm);}
}

View File

@@ -0,0 +1,30 @@
package gplx.gfdbs.cores.cmds;
import gplx.Err_;
import gplx.dbs.Db_conn;
import gplx.dbs.Db_rdr;
import gplx.dbs.Db_stmt;
import gplx.dbs.Dbmeta_fld_itm;
import gplx.gfdbs.cores.GfdbMeta;
import gplx.dbs.stmts.Db_stmt_arg_list;
public class GfoDbSelectWkrOne<I, M extends GfdbMeta<I>> implements GfoDbSelectWkr<I> {
private final M meta;
private final String[] pkeyCols;
public GfoDbSelectWkrOne(M meta, String... pkeyCols) {
this.meta = meta;
this.pkeyCols = pkeyCols;
}
@Override public Db_rdr NewRdr(Db_conn conn, Object... pkeyVals) {
Db_stmt stmt = conn.Stmt_select(meta.TblName(), meta.Flds(), pkeyCols);
if (pkeyCols.length != pkeyVals.length) throw Err_.new_wo_type("pkey lengths don't match");
for (int i = 0; i < pkeyCols.length; i++) {
String pkeyCol = pkeyCols[i];
Dbmeta_fld_itm pkeyFld = meta.Flds().Get_by(pkeyCol);
Db_stmt_arg_list.Fill_crt(stmt, pkeyFld.Type().Tid_ansi(), pkeyCol, pkeyVals[i]);
}
return stmt.Exec_select__rls_auto();
}
@Override public void ItmLoad(Db_rdr rdr, I itm) {meta.LoadItm(rdr, itm);}
}

View File

@@ -0,0 +1,59 @@
package gplx.gfdbs.cores.txns;
import gplx.dbs.Db_conn;
import gplx.gfdbs.cores.GfdbCloseAble;
import gplx.objects.lists.GfoListBase;
public class GfdbTxnMgr {
private final GfdbCloseAble dbMgr;
private final Db_conn conn;
private final GfoListBase<GfdbTxnSub> subs = new GfoListBase<>();
private boolean enabled = true;
private int saveEveryN = 1000;
private int n;
public GfdbTxnMgr(GfdbCloseAble dbMgr, Db_conn conn) {
this.dbMgr = dbMgr;
this.conn = conn;
}
public void SaveEveryNSet(int v) {this.saveEveryN = v;}
public void EnabledSet(boolean v) {this.enabled = v;}
public GfoListBase<GfdbTxnSub> Subs() {return subs;}
public GfdbTxnMgr Bgn(String name) {
if (enabled) {
conn.Txn_bgn(name);
}
return this;
}
public GfdbTxnMgr RegSub(GfdbTxnSub... subArray) {
for (GfdbTxnSub sub : subArray)
subs.Add(sub);
return this;
}
public void Cancel() {
conn.Txn_cxl();
}
public void SaveCheck() {
if ((n++ % saveEveryN) == 0) {
this.SaveForce();
}
}
public void SaveForce() {
this.SubsSave();
if (enabled) {
conn.Txn_sav();
}
}
public void End() {
this.SubsSave();
if (enabled) {
conn.Txn_end();
}
dbMgr.Close();
n = 0;
}
private void SubsSave() {
for (GfdbTxnSub sub : subs) {
sub.WhenTxnSav();
}
}
}

View File

@@ -0,0 +1,5 @@
package gplx.gfdbs.cores.txns;
public interface GfdbTxnSub {
void WhenTxnSav();
}

View File

@@ -0,0 +1,65 @@
package gplx.gfdbs.cores.wkrs;
import gplx.gfdbs.cores.GfdbState;
import gplx.gfdbs.cores.GfdbItm;
import gplx.gfdbs.cores.cmds.GfdbModifyCmd;
import gplx.gfdbs.cores.cmds.GfdbSelectCmd;
import gplx.objects.lists.GfoIndexedList;
import gplx.objects.lists.GfoListBase;
public class GfdbListWkr<K, I extends GfdbItm<K, I>> {
private final GfoIndexedList<K, I> regy;
private final GfdbModifyCmd<I> insertCmd;
private final GfdbModifyCmd<I> updateCmd;
private final GfdbModifyCmd<I> deleteCmd;
private final GfdbSelectCmd<I> selectCmd;
private final Object[] selectArgs;
public GfdbListWkr(GfoIndexedList<K, I> regy,
GfdbModifyCmd<I> insertCmd, GfdbModifyCmd<I> updateCmd, GfdbModifyCmd<I> deleteCmd,
GfdbSelectCmd<I> selectCmd, Object[] selectArgs) {
this.regy = regy;
this.selectCmd = selectCmd;
this.selectArgs = selectArgs;
this.insertCmd = insertCmd;
this.updateCmd = updateCmd;
this.deleteCmd = deleteCmd;
}
public void Load() {
GfoListBase<I> dbList = selectCmd.Select(selectArgs);
for (I regyItm : regy) {
regyItm.DbStateSet(GfdbState.Insert);
}
for (I dbItm : dbList) {
K key = dbItm.ToPkey();
I regyItm = regy.GetByOrNull(key);
if (regyItm == null) {
dbItm.DbStateSet(GfdbState.Delete);
}
else {
regyItm.CtorByItm(dbItm);
regyItm.DbStateSet(GfdbState.Update);
dbItm.DbStateSet(GfdbState.Noop);
}
}
for (I itm : regy) {
SaveItm(itm);
}
for (I itm : dbList) {
SaveItm(itm);
}
}
public void Save() {
for (I itm : regy) {
SaveItm(itm);
}
}
private void SaveItm(I itm) {
GfdbState itmState = itm.DbState();
itm.DbStateSet(GfdbState.Noop);
switch (itmState) {
case Insert: insertCmd.Exec(itm); break;
case Update: updateCmd.Exec(itm); break;
case Delete: deleteCmd.Exec(itm); break;
}
}
}

View File

@@ -0,0 +1,14 @@
package gplx.gfdbs.cores.wkrs;
import gplx.gfdbs.cores.GfdbItm;
import gplx.gfdbs.cores.GfdbMeta;
import gplx.gfdbs.cores.GfdbTbl;
import gplx.gfdbs.cores.cmds.GfdbSelectCmd;
import gplx.objects.lists.GfoIndexedList;
public class GfdbListWkrUtl {
public static <K, I extends GfdbItm<K, I>, M extends GfdbMeta<I>, T extends GfdbTbl<I, M>>
GfdbListWkr<K, I> NewByTbl(GfoIndexedList<K, I> regy, T tbl, GfdbSelectCmd<I> selectCmd, Object... selectArgs) {
return new GfdbListWkr<>(regy, tbl.InsertCmd(), tbl.UpdateCmd(), tbl.DeleteCmd(), selectCmd, selectArgs);
}
}

View File

@@ -1,18 +1,18 @@
/*
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
*/
/*
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*/
@@ -40,13 +40,13 @@ public class DbMaprMgr_tst {
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() {
@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() {
@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));
@@ -58,13 +58,13 @@ public class DbMaprMgr_tst {
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() {
@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() {
@Test public void Save_subs() {
disc = MockDisc.new_().Id_(1).Name_("disc");
title = MockTitle.new_().Id_(2).Name_("title").Disc_(disc);
@@ -72,7 +72,7 @@ public class DbMaprMgr_tst {
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() {
@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);
@@ -88,7 +88,7 @@ public class DbMaprMgr_tst {
, Db_mock_row.vals_only_(1, 2, null, 5, "subtitle")
);
}
@Test public void Load_root() {
@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);
@@ -97,7 +97,7 @@ public class DbMaprMgr_tst {
Tfds.Eq("name", disc.Name());
Tfds.Eq(0, disc.Titles().Count());
}
@Test public void Load_subs() {
@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"));
@@ -110,7 +110,7 @@ public class DbMaprMgr_tst {
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() {
@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"));

View File

@@ -1,32 +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
*/
/*
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; 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;
@Test public void Mysql() {if (Tfds.SkipDb) return;
fx.RunAll(Db_conn_fxt.Mysql());
}
@Test public void Tdb() {if (Tfds.SkipDb) return;
@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;
@Test public void Postgres() {if (Db_conn_fxt.SkipPostgres) return;
fx.RunAll(Db_conn_fxt.Postgres());
}
@Test public void Sqlite() {if (Tfds.SkipDb) return;
@Test public void Sqlite() {if (Tfds.SkipDb) return;
fx.Fx().DmlAffectedAvailable_(false);
fx.RunAll(Db_conn_fxt.Sqlite());
}

View File

@@ -1,35 +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
*/
/*
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; 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;
@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;
@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;
@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;
@Test public void Sqlite() {if (Tfds.SkipDb) return;
fx.Select_FloatStr_("0.33333334");
fx.RunAll(Db_conn_fxt.Sqlite());
}

View File

@@ -13,14 +13,14 @@ 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.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();}
}
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

@@ -13,15 +13,15 @@ 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.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
}
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

@@ -13,10 +13,10 @@ 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.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();}
}
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

@@ -13,10 +13,10 @@ 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.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();}
}
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

@@ -13,17 +13,17 @@ 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.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");
}
}
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

@@ -1,26 +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
*/
/*
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.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() {
@Test public void Basic() {
Basic_hook();
}
@Test public void SameVals() {
@Test public void SameVals() {
SameVals_hook();
}
}
@@ -28,7 +28,7 @@ public class OrderBys_tdb_tst extends OrderBys_base_tst {
// 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() {
// @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());
// }

View File

@@ -0,0 +1,29 @@
package gplx.dbs.qrys;
import gplx.Byte_;
import gplx.DateAdp_;
import gplx.Decimal_adp_;
import gplx.core.tests.Gftest;
import gplx.objects.lists.GfoListBase;
import org.junit.Test;
public class Db_val_typeTest {
@Test public void Numbers() {
TestToSqlStr
("ABC true 1 2 3 4.0 5 6 XYZ"
,"ABC ? ? ? ? ? ? ? XYZ"
, true, Byte_.By_int(1), 2, (long)3, (float)4, (double)5, Decimal_adp_.int_(6)
);
}
@Test public void Strings() {
TestToSqlStr
("ABC 'abc' 'a\\'\"c' 'xyz' 'x\\'\"z' '2021-01-02 03:04:05.006' XYZ"
,"ABC ? ? ? ? ? XYZ"
, "abc", "a'\"c", "xyz", "x'\"z", DateAdp_.new_(2021, 1, 2, 3, 4, 5, 6)
);
}
private void TestToSqlStr(String expd, String sql, Object... paramArray) {
String actl = Db_val_type.ToSqlStr(sql, new GfoListBase<>().AddMany(paramArray));
Gftest.Eq__str(expd, actl);
}
}

View File

@@ -1,18 +1,18 @@
/*
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
*/
/*
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 {
@@ -21,21 +21,21 @@ public class PoolIds_tst {
Db_qry_fxt.DeleteAll(conn, PoolIds.Tbl_Name);
mgr = PoolIds.Instance;
}
@Test public void FetchNextId() {
@Test public void FetchNextId() {
tst_Fetch("/test0", 0);
}
@Test public void ChangeNextId_Insert() {
@Test public void ChangeNextId_Insert() {
run_Change("/test0", 1);
tst_Fetch("/test0", 1);
}
@Test public void ChangeNextId_Update() {
@Test public void ChangeNextId_Update() {
run_Change("/test0", 0);
run_Change("/test0", 1);
tst_Fetch("/test0", 1);
}
@Test public void FetchNextId_Multiple() {
@Test public void FetchNextId_Multiple() {
run_Change("/test0", 0);
run_Change("/test1", 1);