mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Refactor: Refactor baselib; merge Array_ and Bool_
This commit is contained in:
@@ -15,7 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs;
|
||||
|
||||
import gplx.Bool_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.Double_;
|
||||
import gplx.Err_;
|
||||
import gplx.Gfo_log_;
|
||||
@@ -133,8 +133,8 @@ public class Db_conn {
|
||||
public Db_rdr Exec_rdr(String sql) {return this.Stmt_sql(sql).Exec_select__rls_auto();}
|
||||
public void Exec_delete_all(String tbl) {Stmt_delete(tbl).Exec_delete();}
|
||||
public int Exec_sql_args(String sql, Object... args) {return this.Exec_qry(Db_qry_sql.dml_(String_.Format(sql, args)));}
|
||||
public int Exec_sql_plog_ntx(String msg, String sql) {return Exec_sql_plog(Bool_.N, msg, sql);}
|
||||
public int Exec_sql_plog_txn(String msg, String sql) {return Exec_sql_plog(Bool_.Y, msg, sql);}
|
||||
public int Exec_sql_plog_ntx(String msg, String sql) {return Exec_sql_plog(BoolUtl.N, msg, sql);}
|
||||
public int Exec_sql_plog_txn(String msg, String sql) {return Exec_sql_plog(BoolUtl.Y, msg, sql);}
|
||||
public int Exec_sql_plog(boolean txn, String msg, String sql) {
|
||||
Gfo_usr_dlg_.Instance.Plog_many("", "", msg);
|
||||
if (txn) this.Txn_bgn(msg);
|
||||
|
||||
@@ -14,6 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public abstract class Db_conn_info__base implements Db_conn_info {
|
||||
public Db_conn_info__base(String raw, String db_api, String database) {this.raw = raw; this.db_api = db_api; this.database = database;}
|
||||
public abstract String Key();
|
||||
@@ -28,7 +29,7 @@ public abstract class Db_conn_info__base implements Db_conn_info {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
String itm = ary[i];
|
||||
bfr.Add_str_u8(itm);
|
||||
bfr.Add_byte(i % 2 == 0 ? Byte_ascii.Eq : Byte_ascii.Semic);
|
||||
bfr.Add_byte(i % 2 == 0 ? AsciiByte.Eq : AsciiByte.Semic);
|
||||
}
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
|
||||
@@ -13,7 +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; import gplx.*;
|
||||
package gplx.dbs;
|
||||
import gplx.Bry_;
|
||||
import gplx.Byte_;
|
||||
import gplx.Double_;
|
||||
import gplx.Float_;
|
||||
import gplx.Int_;
|
||||
import gplx.Io_url_;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.Long_;
|
||||
import gplx.String_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Db_conn_utl {
|
||||
public static Db_conn Conn__new(String url_rel) {
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
@@ -32,7 +43,7 @@ public class Db_conn_utl {
|
||||
String fld_name = fld.Name();
|
||||
Object val = row[j];
|
||||
switch (fld.Type().Tid()) {
|
||||
case DbmetaFldType.TidBool: stmt.Val_bool_as_byte (fld_name, Bool_.Cast(val)); break;
|
||||
case DbmetaFldType.TidBool: stmt.Val_bool_as_byte (fld_name, BoolUtl.Cast(val)); break;
|
||||
case DbmetaFldType.TidByte: stmt.Val_byte (fld_name, Byte_.Cast(val)); break;
|
||||
case DbmetaFldType.TidInt: stmt.Val_int (fld_name, Int_.Cast(val)); break;
|
||||
case DbmetaFldType.TidLong: stmt.Val_long (fld_name, Long_.cast(val)); break;
|
||||
|
||||
@@ -13,17 +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; import gplx.*;
|
||||
public class Db_mock_row {
|
||||
public int Idx() {return idx;} public Db_mock_row Idx_(int val) {idx = val; return this;} int idx = -1;
|
||||
public Db_mock_cell[] Dat() {return dat;} Db_mock_cell[] dat = null;
|
||||
public static Db_mock_row vals_only_(Object... ary) {
|
||||
Db_mock_row rv = new Db_mock_row();
|
||||
int len = Array_.Len(ary);
|
||||
rv.dat = new Db_mock_cell[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv.dat[i] = Db_mock_cell.new_().Val_(ary[i]);
|
||||
return rv;
|
||||
}
|
||||
public static Db_mock_row new_() {return new Db_mock_row();} Db_mock_row() {}
|
||||
}
|
||||
package gplx.dbs;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
public class Db_mock_row {
|
||||
public int Idx() {return idx;} public Db_mock_row Idx_(int val) {idx = val; return this;} int idx = -1;
|
||||
public Db_mock_cell[] Dat() {return dat;} Db_mock_cell[] dat = null;
|
||||
public static Db_mock_row vals_only_(Object... ary) {
|
||||
Db_mock_row rv = new Db_mock_row();
|
||||
int len = ArrayUtl.Len(ary);
|
||||
rv.dat = new Db_mock_cell[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv.dat[i] = Db_mock_cell.new_().Val_(ary[i]);
|
||||
return rv;
|
||||
}
|
||||
public static Db_mock_row new_() {return new Db_mock_row();} Db_mock_row() {}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
/*
|
||||
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 gplx.dbs.qrys.*; import gplx.core.gfo_ndes.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Db_qry_fxt {
|
||||
public static void Insert_kvo(Db_conn conn, String tblName, Keyval_list kvList) {
|
||||
Db_qry_insert qry = Db_qry_.insert_(tblName);
|
||||
@@ -37,12 +39,12 @@ public class Db_qry_fxt {
|
||||
}
|
||||
public static void tst_Select(Db_conn conn, String tblName, Db_mock_row... expdAry) {
|
||||
GfoNde nde = Db_qry_fxt.SelectAll(conn, tblName);
|
||||
int len = Array_.Len(expdAry);
|
||||
int len = ArrayUtl.Len(expdAry);
|
||||
for (int i = 0; i < len; i++) {
|
||||
Db_mock_row expdRow = expdAry[i];
|
||||
int actlIdx = (expdRow.Idx() == -1) ? i : expdRow.Idx();
|
||||
GfoNde actlNde = nde.Subs().FetchAt_asGfoNde(actlIdx);
|
||||
int fldLen = Array_.Len(expdRow.Dat());
|
||||
int fldLen = ArrayUtl.Len(expdRow.Dat());
|
||||
for (int j = 0; j < fldLen; j++) {
|
||||
Db_mock_cell expdDat = expdRow.Dat()[j];
|
||||
Object actlVal = expdDat.Fld() == null ? actlNde.ReadAt(j) : actlNde.Read(expdDat.Fld());
|
||||
@@ -56,7 +58,7 @@ public class Db_qry_fxt {
|
||||
while (rdr.Move_next()) {
|
||||
for (int i = 0; i < cols_len; ++i) {
|
||||
bfr.Add_obj(rdr.Read_at(i));
|
||||
bfr.Add_byte(i == cols_len - 1 ? Byte_ascii.Nl : Byte_ascii.Pipe);
|
||||
bfr.Add_byte(i == cols_len - 1 ? AsciiByte.Nl : AsciiByte.Pipe);
|
||||
}
|
||||
}
|
||||
rdr.Rls();
|
||||
|
||||
@@ -13,7 +13,20 @@ 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.*;
|
||||
package gplx.dbs;
|
||||
import gplx.Bry_;
|
||||
import gplx.Byte_;
|
||||
import gplx.DateAdp;
|
||||
import gplx.DateAdp_;
|
||||
import gplx.Double_;
|
||||
import gplx.Err_;
|
||||
import gplx.Float_;
|
||||
import gplx.Int_;
|
||||
import gplx.Io_url;
|
||||
import gplx.Long_;
|
||||
import gplx.Object_;
|
||||
import gplx.String_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import java.sql.ResultSet;
|
||||
public class Db_rdr__basic implements Db_rdr {
|
||||
protected ResultSet rdr;
|
||||
@@ -34,7 +47,7 @@ public class Db_rdr__basic implements Db_rdr {
|
||||
public float Read_float(String k) {try {return Float_.cast(rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Float_.Cls_val_name);}}
|
||||
public double Read_double(String k) {try {return Double_.cast(rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Double_.Cls_val_name);}}
|
||||
public byte Read_byte(String k) {try {return Byte_.Cast(rdr.getObject(k));} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Byte_.Cls_val_name);}}
|
||||
public boolean Read_bool_by_byte(String k) {try {return Byte_.Cast(rdr.getObject(k)) == 1;} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Bool_.Cls_val_name);}}
|
||||
public boolean Read_bool_by_byte(String k) {try {return Byte_.Cast(rdr.getObject(k)) == 1;} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", BoolUtl.ClsValName);}}
|
||||
public int Fld_len() {try {return rdr.getMetaData().getColumnCount();} catch (Exception e) {throw Err_.new_exc(e, "db", "field count failed", "sql", sql);}}
|
||||
public Object Read_obj(String k) {try {return rdr.getObject(k);} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "key", k, "type", Object_.Cls_val_name);}}
|
||||
public Object Read_at(int i) {try {return rdr.getObject(i + 1);} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "idx", i, "type", Object_.Cls_val_name);}}
|
||||
|
||||
@@ -1,19 +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; import gplx.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Db_sql_ {
|
||||
public static String Make_by_fmt(String[] lines, Object... args) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
@@ -32,7 +34,7 @@ public class Db_sql_ {
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
byte b = raw[i];
|
||||
if (b == Byte_ascii.Apos) {
|
||||
if (b == AsciiByte.Apos) {
|
||||
if (bfr == null) {
|
||||
dirty = true;
|
||||
bfr = Bry_bfr_.New();
|
||||
@@ -50,10 +52,10 @@ public class Db_sql_ {
|
||||
}
|
||||
public static String Prep_in_from_ary(Object ary) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
int len = Array_.Len(ary);
|
||||
int len = ArrayUtl.Len(ary);
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (i != 0) bfr.Add_byte(Byte_ascii.Comma);
|
||||
bfr.Add_byte(Byte_ascii.Question);
|
||||
if (i != 0) bfr.Add_byte(AsciiByte.Comma);
|
||||
bfr.Add_byte(AsciiByte.Question);
|
||||
}
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
|
||||
@@ -13,8 +13,25 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.dbs.qrys.*;
|
||||
package gplx.dbs;
|
||||
import gplx.Bry_;
|
||||
import gplx.Byte_;
|
||||
import gplx.Double_;
|
||||
import gplx.Err;
|
||||
import gplx.Err_;
|
||||
import gplx.Float_;
|
||||
import gplx.Int_;
|
||||
import gplx.Long_;
|
||||
import gplx.String_;
|
||||
import gplx.Type_ids_;
|
||||
import gplx.dbs.qrys.Db_qry__select_cmd;
|
||||
import gplx.dbs.qrys.Db_qry__select_in_tbl;
|
||||
import gplx.dbs.qrys.Db_qry_delete;
|
||||
import gplx.dbs.qrys.Db_qry_insert;
|
||||
import gplx.dbs.qrys.Db_qry_sql;
|
||||
import gplx.dbs.qrys.Db_qry_update;
|
||||
import gplx.dbs.qrys.Db_stmt_sql;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Db_stmt_ {
|
||||
public static final Db_stmt Null = new Db_stmt_sql();
|
||||
public static Db_stmt new_insert_(Db_conn conn, String tbl, String... flds) {
|
||||
@@ -60,7 +77,7 @@ public class Db_stmt_ {
|
||||
public static void Val_by_obj(Db_stmt stmt, String key, Object val) {
|
||||
int tid = Type_ids_.To_id_by_obj(val);
|
||||
switch (tid) {
|
||||
case Type_ids_.Id__bool: stmt.Val_bool_as_byte (key, Bool_.Cast(val)); break;
|
||||
case Type_ids_.Id__bool: stmt.Val_bool_as_byte (key, BoolUtl.Cast(val)); break;
|
||||
case Type_ids_.Id__byte: stmt.Val_byte (key, Byte_.Cast(val)); break;
|
||||
case Type_ids_.Id__int: stmt.Val_int (key, Int_.Cast(val)); break;
|
||||
case Type_ids_.Id__long: stmt.Val_long (key, Long_.cast(val)); break;
|
||||
|
||||
@@ -16,7 +16,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
package gplx.dbs;
|
||||
import gplx.Err_;
|
||||
import gplx.Type_ids_;
|
||||
import gplx.objects.strings.String_;
|
||||
import gplx.objects.strings.StringUtl;
|
||||
public class DbmetaFldType {
|
||||
public DbmetaFldType(int tid, String name, int len1, int len2) {
|
||||
this.tid = tid;
|
||||
@@ -30,7 +30,7 @@ public class DbmetaFldType {
|
||||
public int Len2() {return len2;} private final int len2; // scaling
|
||||
public boolean Eq(DbmetaFldType comp) {
|
||||
return tid == comp.tid
|
||||
&& String_.Eq(name, comp.name)
|
||||
&& StringUtl.Eq(name, comp.name)
|
||||
&& len1 == comp.len1
|
||||
&& len2 == comp.len2;
|
||||
}
|
||||
|
||||
@@ -13,8 +13,11 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.dbs.metas.*; import gplx.dbs.sqls.*;
|
||||
package gplx.dbs;
|
||||
import gplx.String_;
|
||||
import gplx.dbs.metas.Dbmeta_idx_fld;
|
||||
import gplx.dbs.sqls.SqlQryWtr;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Dbmeta_idx_itm {
|
||||
public Dbmeta_idx_itm(boolean unique, String tbl, String name, Dbmeta_idx_fld[] flds) {
|
||||
this.tbl = tbl; this.name = name; this.unique = unique; this.Flds = flds;
|
||||
@@ -30,14 +33,14 @@ public class Dbmeta_idx_itm {
|
||||
&& tbl == comp.tbl
|
||||
&& Dbmeta_idx_fld.Ary_eq(Flds, comp.Flds);
|
||||
}
|
||||
public static Dbmeta_idx_itm new_unique_by_name (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.Y, tbl, name, To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_normal_by_name (String tbl, String name, Dbmeta_idx_fld... flds) {return new Dbmeta_idx_itm(Bool_.N, tbl, name, flds);}
|
||||
public static Dbmeta_idx_itm new_normal_by_name (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.N, tbl, name, To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_unique_by_tbl (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.Y, tbl, Bld_idx_name(tbl, name), To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_normal_by_tbl (String tbl, String name, Dbmeta_idx_fld... flds) {return new Dbmeta_idx_itm(Bool_.N, tbl, Bld_idx_name(tbl, name), flds);}
|
||||
public static Dbmeta_idx_itm new_normal_by_tbl (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.N, tbl, Bld_idx_name(tbl, name), To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_unique_by_tbl_wo_null (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.Y, tbl, Bld_idx_name(tbl, name), To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_normal_by_tbl_wo_null (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(Bool_.N, tbl, Bld_idx_name(tbl, name), To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_unique_by_name (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(BoolUtl.Y, tbl, name, To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_normal_by_name (String tbl, String name, Dbmeta_idx_fld... flds) {return new Dbmeta_idx_itm(BoolUtl.N, tbl, name, flds);}
|
||||
public static Dbmeta_idx_itm new_normal_by_name (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(BoolUtl.N, tbl, name, To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_unique_by_tbl (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(BoolUtl.Y, tbl, Bld_idx_name(tbl, name), To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_normal_by_tbl (String tbl, String name, Dbmeta_idx_fld... flds) {return new Dbmeta_idx_itm(BoolUtl.N, tbl, Bld_idx_name(tbl, name), flds);}
|
||||
public static Dbmeta_idx_itm new_normal_by_tbl (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(BoolUtl.N, tbl, Bld_idx_name(tbl, name), To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_unique_by_tbl_wo_null (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(BoolUtl.Y, tbl, Bld_idx_name(tbl, name), To_fld_ary(flds));}
|
||||
public static Dbmeta_idx_itm new_normal_by_tbl_wo_null (String tbl, String name, String... flds) {return new Dbmeta_idx_itm(BoolUtl.N, tbl, Bld_idx_name(tbl, name), To_fld_ary(flds));}
|
||||
public static String Bld_idx_name(String tbl, String suffix) {return String_.Concat(tbl, "__", suffix);}
|
||||
public static final Dbmeta_idx_itm[] Ary_empty = new Dbmeta_idx_itm[0];
|
||||
public static Dbmeta_idx_fld[] To_fld_ary(String[] ary) {
|
||||
|
||||
@@ -14,15 +14,17 @@ 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; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Gfdb_rdr_utl_ {
|
||||
public static int Compare(DbmetaFldItm[] flds, int len, Db_rdr lhs_rdr, Db_rdr rhs_rdr) {
|
||||
int comp = CompareAble_.Same;
|
||||
int comp = CompareAbleUtl.Same;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
DbmetaFldItm fld = flds[i];
|
||||
String fld_name = fld.Name();
|
||||
int tid = fld.Type().Tid();
|
||||
switch (tid) {
|
||||
case DbmetaFldType.TidBool: comp = Bool_.Compare (lhs_rdr.Read_bool_by_byte(fld_name), rhs_rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case DbmetaFldType.TidBool: comp = BoolUtl.Compare (lhs_rdr.Read_bool_by_byte(fld_name), rhs_rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case DbmetaFldType.TidByte: comp = Byte_.Compare (lhs_rdr.Read_byte(fld_name) , rhs_rdr.Read_byte(fld_name)); break;
|
||||
case DbmetaFldType.TidInt: comp = Int_.Compare (lhs_rdr.Read_int(fld_name) , rhs_rdr.Read_int(fld_name)); break;
|
||||
case DbmetaFldType.TidLong: comp = Long_.Compare (lhs_rdr.Read_long(fld_name) , rhs_rdr.Read_long(fld_name)); break;
|
||||
@@ -32,9 +34,9 @@ public class Gfdb_rdr_utl_ {
|
||||
case DbmetaFldType.TidBry: comp = Bry_.Compare (lhs_rdr.Read_bry(fld_name) , rhs_rdr.Read_bry(fld_name)); break;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
if (comp != CompareAble_.Same) return comp;
|
||||
if (comp != CompareAbleUtl.Same) return comp;
|
||||
}
|
||||
return CompareAble_.Same;
|
||||
return CompareAbleUtl.Same;
|
||||
}
|
||||
public static void Stmt_args(Db_stmt stmt, DbmetaFldItm[] flds, int bgn, int end, Db_rdr rdr) {
|
||||
for (int i = bgn; i < end; ++i) {
|
||||
|
||||
@@ -13,7 +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.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
package gplx.dbs.diffs.builds;
|
||||
import gplx.Err_;
|
||||
import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.dbs.diffs.Gfdb_diff_tbl;
|
||||
import gplx.dbs.diffs.Gfdb_rdr_utl_;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
class Gfdb_diff_rdr_comparer {
|
||||
private Db_rdr old_rdr, new_rdr;
|
||||
private boolean old_rdr_move, new_rdr_move;
|
||||
@@ -21,8 +28,8 @@ class Gfdb_diff_rdr_comparer {
|
||||
private DbmetaFldItm[] key_flds; private int key_flds_len;
|
||||
public void Init_rdrs(Gfdb_diff_tbl tbl, Db_rdr old_rdr, Db_rdr new_rdr) {
|
||||
this.old_rdr = old_rdr; this.new_rdr = new_rdr;
|
||||
this.old_rdr_move = new_rdr_move = Bool_.Y;
|
||||
this.old_rdr_done = new_rdr_done = Bool_.N;
|
||||
this.old_rdr_move = new_rdr_move = BoolUtl.Y;
|
||||
this.old_rdr_done = new_rdr_done = BoolUtl.N;
|
||||
this.key_flds = tbl.Keys; key_flds_len = key_flds.length;
|
||||
}
|
||||
public int Compare() {
|
||||
@@ -40,14 +47,14 @@ class Gfdb_diff_rdr_comparer {
|
||||
else {
|
||||
int comp = Gfdb_rdr_utl_.Compare(key_flds, key_flds_len, old_rdr, new_rdr);
|
||||
switch (comp) {
|
||||
case CompareAble_.Same: // old == cur; move both
|
||||
case CompareAbleUtl.Same: // old == cur; move both
|
||||
old_rdr_move = new_rdr_move = true;
|
||||
return Gfdb_diff_rdr_comparer.Rslt__same;
|
||||
case CompareAble_.Less: // old < cur; EX: old == 2; cur == 3
|
||||
case CompareAbleUtl.Less: // old < cur; EX: old == 2; cur == 3
|
||||
old_rdr_move = true;
|
||||
new_rdr_move = false;
|
||||
return Gfdb_diff_rdr_comparer.Rslt__new_missing;
|
||||
case CompareAble_.More: // old > cur; EX: old == 4; cur == 3
|
||||
case CompareAbleUtl.More: // old > cur; EX: old == 4; cur == 3
|
||||
old_rdr_move = false;
|
||||
new_rdr_move = true;
|
||||
return Gfdb_diff_rdr_comparer.Rslt__old_missing;
|
||||
|
||||
@@ -13,8 +13,9 @@ 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.*;
|
||||
package gplx.dbs.diffs.builds; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import gplx.dbs.diffs.itms.*;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
public class Gfdb_diff_wkr__db implements Gfdb_diff_wkr {
|
||||
private DbmetaFldItm[] val_flds; private int val_flds_len;
|
||||
private Gfdb_diff_tbl tbl; private Db_rdr old_rdr, new_rdr;
|
||||
@@ -40,7 +41,7 @@ public class Gfdb_diff_wkr__db implements Gfdb_diff_wkr {
|
||||
public void Handle_old_missing() {Insert(Gdif_db_.Tid__insert, ++uid, new_rdr, tbl.Flds);}
|
||||
public void Handle_new_missing() {Insert(Gdif_db_.Tid__delete, ++uid, old_rdr, tbl.Flds);}
|
||||
public void Handle_same() {
|
||||
if (Gfdb_rdr_utl_.Compare(val_flds, val_flds_len, old_rdr, new_rdr) != CompareAble_.Same)
|
||||
if (Gfdb_rdr_utl_.Compare(val_flds, val_flds_len, old_rdr, new_rdr) != CompareAbleUtl.Same)
|
||||
Insert(Gdif_db_.Tid__update, ++uid, new_rdr, tbl.Flds);
|
||||
}
|
||||
private void Insert(byte dif_type, int uid, Db_rdr rdr, DbmetaFldItm[] flds) {
|
||||
|
||||
@@ -13,13 +13,28 @@ 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.*;
|
||||
package gplx.dbs.engines.mems;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Io_mgr;
|
||||
import gplx.Io_url_;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.Tfds;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_conn_bldr;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.DbmetaFldList;
|
||||
import gplx.dbs.Dbmeta_tbl_itm;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
class Mem_db_fxt {
|
||||
public Mem_db_fxt() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
}
|
||||
public Db_conn Make_conn(String url) {return Db_conn_bldr.Instance.Get_or_autocreate(Bool_.Y, Io_url_.mem_fil_(url));}
|
||||
public Db_conn Make_conn(String url) {return Db_conn_bldr.Instance.Get_or_autocreate(BoolUtl.Y, Io_url_.mem_fil_(url));}
|
||||
public Dbmeta_tbl_itm Exec__create_tbl(Db_conn conn, String tbl, String... fld_names) {
|
||||
DbmetaFldList flds = new DbmetaFldList();
|
||||
int len = fld_names.length;
|
||||
|
||||
@@ -13,9 +13,28 @@ 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.core.criterias.*;
|
||||
import gplx.dbs.qrys.*; import gplx.dbs.sqls.itms.*;
|
||||
package gplx.dbs.engines.mems; import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Err_;
|
||||
import gplx.Hash_adp_bry;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.String_;
|
||||
import gplx.core.criterias.Criteria;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.qrys.Db_qry__select_cmd;
|
||||
import gplx.dbs.qrys.Db_qry__select_in_tbl;
|
||||
import gplx.dbs.sqls.itms.Sql_join_fld;
|
||||
import gplx.dbs.sqls.itms.Sql_order_fld;
|
||||
import gplx.dbs.sqls.itms.Sql_select_clause;
|
||||
import gplx.dbs.sqls.itms.Sql_select_fld;
|
||||
import gplx.dbs.sqls.itms.Sql_select_fld_list;
|
||||
import gplx.dbs.sqls.itms.Sql_tbl_itm;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
public class Mem_exec_select {
|
||||
private final Mem_engine engine;
|
||||
private final List_adp tmp_where_rows = List_adp_.New();
|
||||
@@ -52,17 +71,17 @@ public class Mem_exec_select {
|
||||
Mem_row[] rslt_rows = (Mem_row[])tmp_where_rows.ToAryAndClear(Mem_row.class);
|
||||
if (qry2 != null) {
|
||||
if (qry2.Order() != null && qry2.Order().Flds().length > 0)
|
||||
Array_.Sort(rslt_rows, new Mem_sorter(qry2.Order().Flds()));
|
||||
ArrayUtl.Sort(rslt_rows, new Mem_sorter(qry2.Order().Flds()));
|
||||
int offset = qry2.Offset();
|
||||
if (offset != Db_qry__select_cmd.Offset__disabled) {
|
||||
Mem_row[] trg_rows = new Mem_row[rslt_rows.length - offset];
|
||||
Array_.Copy_to(rslt_rows, offset, trg_rows, 0, trg_rows.length);
|
||||
ArrayUtl.CopyTo(rslt_rows, offset, trg_rows, 0, trg_rows.length);
|
||||
rslt_rows = trg_rows;
|
||||
}
|
||||
int limit = qry2.Limit();
|
||||
if (limit != Db_qry__select_cmd.Limit__disabled) {
|
||||
Mem_row[] trg_rows = new Mem_row[limit];
|
||||
Array_.Copy_to(rslt_rows, 0, trg_rows, 0, limit);
|
||||
ArrayUtl.CopyTo(rslt_rows, 0, trg_rows, 0, limit);
|
||||
rslt_rows = trg_rows;
|
||||
}
|
||||
rslt_rows = Mem_exec_.Rows__select_flds(rslt_rows, qry2.Cols());
|
||||
@@ -70,7 +89,7 @@ public class Mem_exec_select {
|
||||
return new Mem_rdr(select, rslt_rows);
|
||||
}
|
||||
}
|
||||
class Mem_sorter implements gplx.core.lists.ComparerAble {
|
||||
class Mem_sorter implements ComparerAble {
|
||||
private final Sql_order_fld[] flds;
|
||||
public Mem_sorter(Sql_order_fld[] flds) {
|
||||
this.flds = flds;
|
||||
@@ -83,10 +102,10 @@ class Mem_sorter implements gplx.core.lists.ComparerAble {
|
||||
Sql_order_fld fld = flds[i];
|
||||
Object lhs_val = lhs.Get_by(fld.Name);
|
||||
Object rhs_val = rhs.Get_by(fld.Name);
|
||||
int comp = CompareAble_.Compare_obj(lhs_val, rhs_val);
|
||||
if (comp != CompareAble_.Same) return comp * (fld.Sort == Sql_order_fld.Sort__dsc ? -1 : 1);
|
||||
int comp = CompareAbleUtl.Compare_obj(lhs_val, rhs_val);
|
||||
if (comp != CompareAbleUtl.Same) return comp * (fld.Sort == Sql_order_fld.Sort__dsc ? -1 : 1);
|
||||
}
|
||||
return CompareAble_.Same;
|
||||
return CompareAbleUtl.Same;
|
||||
}
|
||||
}
|
||||
class Mem_exec_ {
|
||||
@@ -97,7 +116,7 @@ class Mem_exec_ {
|
||||
int rhs_rows_len = rhs_rows.length;
|
||||
for (int i = 0; i < rhs_rows_len; ++i) {
|
||||
Mem_row rhs_row = rhs_rows[i];
|
||||
byte[] rhs_key = Rows__bld_key(bfr, Bool_.N, tbl_alias, rhs_row, join_flds, join_flds_len);
|
||||
byte[] rhs_key = Rows__bld_key(bfr, BoolUtl.N, tbl_alias, rhs_row, join_flds, join_flds_len);
|
||||
List_adp rhs_list = (List_adp)rhs_hash.Get_by_bry(rhs_key);
|
||||
if (rhs_list == null) {
|
||||
rhs_list = List_adp_.New();
|
||||
@@ -109,7 +128,7 @@ class Mem_exec_ {
|
||||
int lhs_len = lhs_rows.length;
|
||||
for (int i = 0; i < lhs_len; ++i) {
|
||||
Mem_row lhs_row = lhs_rows[i];
|
||||
byte[] lhs_key = Rows__bld_key(bfr, Bool_.Y, tbl_alias, lhs_row, join_flds, join_flds_len);
|
||||
byte[] lhs_key = Rows__bld_key(bfr, BoolUtl.Y, tbl_alias, lhs_row, join_flds, join_flds_len);
|
||||
List_adp rhs_list = (List_adp)rhs_hash.Get_by_bry(lhs_key);
|
||||
if (rhs_list == null) {
|
||||
switch (join_tid) {
|
||||
|
||||
@@ -13,8 +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.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import org.junit.*; import gplx.dbs.sqls.itms.*;
|
||||
package gplx.dbs.engines.mems;
|
||||
import gplx.String_;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_null;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.Db_qry_;
|
||||
import gplx.dbs.sqls.itms.Sql_tbl_itm;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Test;
|
||||
public class Mem_exec_select_tst {
|
||||
private final Mem_db_fxt__single fxt = new Mem_db_fxt__single();
|
||||
@Test public void Basic() {
|
||||
@@ -33,7 +40,7 @@ public class Mem_exec_select_tst {
|
||||
);
|
||||
|
||||
// order by
|
||||
fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_().Order_("fld_1", Bool_.N)
|
||||
fxt.Test__select(Db_qry_.select_().From_("tbl_1").Cols_all_().Order_("fld_1", BoolUtl.N)
|
||||
, String_.Ary("a_2")
|
||||
, String_.Ary("a_1")
|
||||
, String_.Ary("a_0")
|
||||
|
||||
@@ -13,8 +13,22 @@ 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 gplx.core.stores.*;
|
||||
package gplx.dbs.engines.mems;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.DateAdp;
|
||||
import gplx.Decimal_adp;
|
||||
import gplx.Err_;
|
||||
import gplx.Ordered_hash;
|
||||
import gplx.Ordered_hash_;
|
||||
import gplx.String_;
|
||||
import gplx.core.stores.DataRdr;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.dbs.engines.Db_engine;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Mem_stmt implements Db_stmt {
|
||||
private static final String Key_na = ""; // key is not_available; only called by procs with signature of Val(<type> v);
|
||||
private final Ordered_hash val_list = Ordered_hash_.New();
|
||||
@@ -32,79 +46,79 @@ public class Mem_stmt implements Db_stmt {
|
||||
return this;
|
||||
}
|
||||
public void Rls() {this.Clear();}
|
||||
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);}
|
||||
public Db_stmt Crt_bool_as_byte(String k, boolean v) {return Add_byte_by_bool(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_bool_as_byte(String k, boolean v) {return Add_byte_by_bool(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_bool_as_byte(boolean v) {return Add_byte_by_bool(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_byte_by_bool(boolean where, String k, boolean v) {return Add_byte(where, k, v ? BoolUtl.YByte : BoolUtl.NByte);}
|
||||
public Db_stmt Crt_byte(String k, byte v) {return Add_byte(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_byte(String k, byte v) {return Add_byte(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_byte(byte v) {return Add_byte(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_byte(boolean where, String k, byte v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "byte", "val", v);}
|
||||
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);}
|
||||
public Db_stmt Crt_int(String k, int v) {return Add_int(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_int_by_bool(String k, boolean v) {return Add_int(BoolUtl.N, k, v ? 1 : 0);}
|
||||
public Db_stmt Val_int(String k, int v) {return Add_int(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_int(int v) {return Add_int(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_int(boolean where, String k, int v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "int", "val", v);}
|
||||
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);}
|
||||
public Db_stmt Crt_long(String k, long v) {return Add_long(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_long(String k, long v) {return Add_long(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_long(long v) {return Add_long(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_long(boolean where, String k, long v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "long", "val", v);}
|
||||
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);}
|
||||
public Db_stmt Crt_float(String k, float v) {return Add_float(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_float(String k, float v) {return Add_float(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_float(float v) {return Add_float(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_float(boolean where, String k, float v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "float", "val", v);}
|
||||
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);}
|
||||
public Db_stmt Crt_double(String k, double v) {return Add_double(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_double(String k, double v) {return Add_double(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_double(double v) {return Add_double(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_double(boolean where, String k, double v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "double", "val", v);}
|
||||
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);}
|
||||
public Db_stmt Crt_decimal(String k, Decimal_adp v) {return Add_decimal(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_decimal(String k, Decimal_adp v) {return Add_decimal(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_decimal(Decimal_adp v) {return Add_decimal(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_decimal(boolean where, String k, Decimal_adp v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v);}
|
||||
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);}
|
||||
public Db_stmt Crt_bry(String k, byte[] v) {return Add_bry(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_bry(String k, byte[] v) {return Add_bry(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_bry(byte[] v) {return Add_bry(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_bry(boolean where, String k, byte[] v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "byte[]", "val", v.length);}
|
||||
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);}
|
||||
public Db_stmt Crt_bry_as_str(String k, byte[] v) {return Add_bry_as_str(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_bry_as_str(String k, byte[] v) {return Add_bry_as_str(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_bry_as_str(byte[] v) {return Add_bry_as_str(BoolUtl.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);}
|
||||
public Db_stmt Crt_str(String k, String v) {return Add_str(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_str(String k, String v) {return Add_str(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_str(String v) {return Add_str(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_str(boolean where, String k, String v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "String", "val", v);}
|
||||
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);}
|
||||
public Db_stmt Crt_date(String k, DateAdp v) {return Add_date(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_date(String k, DateAdp v) {return Add_date(BoolUtl.N, k, v);}
|
||||
private Db_stmt Add_date(boolean where, String k, DateAdp v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "date", "val", v);}
|
||||
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);}
|
||||
public Db_stmt Crt_text(String k, String v) {return Add_text(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_text(String k, String v) {return Add_text(BoolUtl.N, k, v);}
|
||||
private Db_stmt Add_text(boolean where, String k, String v) {
|
||||
try {Add(k, where, v);} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "text", "val", v);}
|
||||
return this;
|
||||
@@ -113,7 +127,7 @@ public class Mem_stmt implements Db_stmt {
|
||||
try {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
gplx.core.ios.streams.Io_stream_rdr_.Load_all_to_bfr(bfr, v);
|
||||
Add("", Bool_.N, bfr.To_str_and_clear());
|
||||
Add("", BoolUtl.N, bfr.To_str_and_clear());
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "rdr", "val", v);}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ 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.Bool_;
|
||||
package gplx.dbs.engines.sqlite; import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.Byte_;
|
||||
import gplx.DateAdp;
|
||||
import gplx.DateAdp_;
|
||||
@@ -130,7 +130,7 @@ class Db_rdr__sqlite extends Db_rdr__basic { @Override public byte Read_byte(Str
|
||||
try {
|
||||
int val = rdr.getInt(k);
|
||||
return val == 1;
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "i", k, "type", Bool_.Cls_val_name);}
|
||||
} catch (Exception e) {throw Err_.new_exc(e, "db", "read failed", "i", k, "type", BoolUtl.ClsValName);}
|
||||
}
|
||||
@Override public long Read_long(String k) {
|
||||
try {
|
||||
|
||||
@@ -15,7 +15,7 @@ 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.*;
|
||||
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
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,7 +74,7 @@ public class Sqlite_engine_ {
|
||||
public static final boolean Supports_indexed_by = true;
|
||||
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 byte Wildcard_byte = AsciiByte.Hash;
|
||||
public static final String Wildcard_str = "%";
|
||||
public static int Read_only_detection = Io_mgr.Read_only__basic__file;
|
||||
}
|
||||
|
||||
@@ -13,8 +13,13 @@ 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.*;
|
||||
package gplx.dbs.engines.sqlite;
|
||||
import gplx.Int_;
|
||||
import gplx.String_;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.Db_qry_;
|
||||
import gplx.dbs.sqls.SqlQryWtr;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Sqlite_pragma implements Db_qry {
|
||||
private final String sql;
|
||||
public Sqlite_pragma(boolean parens, String key, String val) {
|
||||
@@ -27,22 +32,22 @@ public class Sqlite_pragma implements Db_qry {
|
||||
public String ToSqlExec(SqlQryWtr wtr) {return sql;}
|
||||
|
||||
public static final String Const__journal_mode = "journal_mode", Const__journal_mode__wal = "wal", Const__journal_mode__off = "off";
|
||||
public static Sqlite_pragma New__journal__delete() {return new Sqlite_pragma(Bool_.N, Const__journal_mode , "delete");} // default
|
||||
public static Sqlite_pragma New__journal__truncate() {return new Sqlite_pragma(Bool_.N, Const__journal_mode , "truncate");}
|
||||
public static Sqlite_pragma New__journal__persist() {return new Sqlite_pragma(Bool_.N, Const__journal_mode , "persist");}
|
||||
public static Sqlite_pragma New__journal__memory() {return new Sqlite_pragma(Bool_.N, Const__journal_mode , "memory");}
|
||||
public static Sqlite_pragma New__journal__wal() {return new Sqlite_pragma(Bool_.N, Const__journal_mode , Const__journal_mode__wal);}
|
||||
public static Sqlite_pragma New__journal__off() {return new Sqlite_pragma(Bool_.N, Const__journal_mode , Const__journal_mode__off);}
|
||||
public static Sqlite_pragma New__synchronous__off() {return new Sqlite_pragma(Bool_.N, "synchronous" , "off");}
|
||||
public static Sqlite_pragma New__synchronous__normal() {return new Sqlite_pragma(Bool_.N, "synchronous" , "normal");} // default if WAL
|
||||
public static Sqlite_pragma New__synchronous__full() {return new Sqlite_pragma(Bool_.N, "synchronous" , "full");} // default otherwise
|
||||
public static Sqlite_pragma New__synchronous__extra() {return new Sqlite_pragma(Bool_.N, "synchronous" , "extra");}
|
||||
public static Sqlite_pragma New__wal_autocheckpoint(int v) {return new Sqlite_pragma(Bool_.N, "wal_auto_checkpoint", Int_.To_str(v));} // default is 1000
|
||||
public static Sqlite_pragma New__wal_checkpoint__passive() {return new Sqlite_pragma(Bool_.Y, "wal_checkpoint" , "passive");}
|
||||
public static Sqlite_pragma New__wal_checkpoint__full() {return new Sqlite_pragma(Bool_.Y, "wal_checkpoint" , "full");}
|
||||
public static Sqlite_pragma New__wal_checkpoint__restart() {return new Sqlite_pragma(Bool_.Y, "wal_checkpoint" , "restart");}
|
||||
public static Sqlite_pragma New__wal_checkpoint__truncate() {return new Sqlite_pragma(Bool_.Y, "wal_checkpoint" , "truncate");}
|
||||
public static Sqlite_pragma New__locking_mode__normal() {return new Sqlite_pragma(Bool_.N, "locking_mode" , "normal");} // default
|
||||
public static Sqlite_pragma New__locking_mode__exclusive() {return new Sqlite_pragma(Bool_.N, "locking_mode" , "exclusive");}
|
||||
public static Sqlite_pragma New__page_size(int v) {return new Sqlite_pragma(Bool_.N, "page_size" , Int_.To_str(v));} // default is 1024
|
||||
public static Sqlite_pragma New__journal__delete() {return new Sqlite_pragma(BoolUtl.N, Const__journal_mode , "delete");} // default
|
||||
public static Sqlite_pragma New__journal__truncate() {return new Sqlite_pragma(BoolUtl.N, Const__journal_mode , "truncate");}
|
||||
public static Sqlite_pragma New__journal__persist() {return new Sqlite_pragma(BoolUtl.N, Const__journal_mode , "persist");}
|
||||
public static Sqlite_pragma New__journal__memory() {return new Sqlite_pragma(BoolUtl.N, Const__journal_mode , "memory");}
|
||||
public static Sqlite_pragma New__journal__wal() {return new Sqlite_pragma(BoolUtl.N, Const__journal_mode , Const__journal_mode__wal);}
|
||||
public static Sqlite_pragma New__journal__off() {return new Sqlite_pragma(BoolUtl.N, Const__journal_mode , Const__journal_mode__off);}
|
||||
public static Sqlite_pragma New__synchronous__off() {return new Sqlite_pragma(BoolUtl.N, "synchronous" , "off");}
|
||||
public static Sqlite_pragma New__synchronous__normal() {return new Sqlite_pragma(BoolUtl.N, "synchronous" , "normal");} // default if WAL
|
||||
public static Sqlite_pragma New__synchronous__full() {return new Sqlite_pragma(BoolUtl.N, "synchronous" , "full");} // default otherwise
|
||||
public static Sqlite_pragma New__synchronous__extra() {return new Sqlite_pragma(BoolUtl.N, "synchronous" , "extra");}
|
||||
public static Sqlite_pragma New__wal_autocheckpoint(int v) {return new Sqlite_pragma(BoolUtl.N, "wal_auto_checkpoint", Int_.To_str(v));} // default is 1000
|
||||
public static Sqlite_pragma New__wal_checkpoint__passive() {return new Sqlite_pragma(BoolUtl.Y, "wal_checkpoint" , "passive");}
|
||||
public static Sqlite_pragma New__wal_checkpoint__full() {return new Sqlite_pragma(BoolUtl.Y, "wal_checkpoint" , "full");}
|
||||
public static Sqlite_pragma New__wal_checkpoint__restart() {return new Sqlite_pragma(BoolUtl.Y, "wal_checkpoint" , "restart");}
|
||||
public static Sqlite_pragma New__wal_checkpoint__truncate() {return new Sqlite_pragma(BoolUtl.Y, "wal_checkpoint" , "truncate");}
|
||||
public static Sqlite_pragma New__locking_mode__normal() {return new Sqlite_pragma(BoolUtl.N, "locking_mode" , "normal");} // default
|
||||
public static Sqlite_pragma New__locking_mode__exclusive() {return new Sqlite_pragma(BoolUtl.N, "locking_mode" , "exclusive");}
|
||||
public static Sqlite_pragma New__page_size(int v) {return new Sqlite_pragma(BoolUtl.N, "page_size" , Int_.To_str(v));} // default is 1024
|
||||
}
|
||||
|
||||
@@ -13,13 +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.sqlite; import gplx.*;
|
||||
import gplx.dbs.engines.*;
|
||||
import gplx.dbs.qrys.*;
|
||||
package gplx.dbs.engines.sqlite;
|
||||
import gplx.Gfo_usr_dlg_;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.String_;
|
||||
import gplx.dbs.engines.Db_engine;
|
||||
import gplx.dbs.qrys.Db_qry_sql;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Sqlite_txn_mgr {
|
||||
private final List_adp txn_list = List_adp_.New();
|
||||
public Sqlite_txn_mgr(Db_engine engine) {this.engine = engine;} private final Db_engine engine;
|
||||
private boolean pragma_needed = Bool_.Y, txn_started = Bool_.N; // NOTE: txns only support 1 level; SQLite fails when nesting transactions; DATE:2015-03-11
|
||||
private boolean pragma_needed = BoolUtl.Y, txn_started = BoolUtl.N; // NOTE: txns only support 1 level; SQLite fails when nesting transactions; DATE:2015-03-11
|
||||
public void Txn_bgn(String name) {
|
||||
if (String_.Len_eq_0(name)) name = "unnamed";
|
||||
if (pragma_needed) {
|
||||
|
||||
@@ -1,24 +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
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import gplx.core.lists.*; /*GfoNde*/ import gplx.dbs.qrys.*;
|
||||
/*
|
||||
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.dbs.*; import gplx.dbs.engines.*;
|
||||
import gplx.dbs.qrys.*;
|
||||
import gplx.objects.arrays.ArrayUtl;
|
||||
class TdbFlushWkr implements Db_qryWkr {
|
||||
public Object Exec(Db_engine engineObj, Db_qry cmdObj) {
|
||||
TdbEngine engine = TdbEngine.cast(engineObj); Db_qry_flush cmd = Db_qry_flush.cast(cmdObj);
|
||||
if (Array_.Len(cmd.TableNames()) == 0)
|
||||
if (ArrayUtl.Len(cmd.TableNames()) == 0)
|
||||
engine.FlushAll();
|
||||
else {
|
||||
for (String tblName : cmd.TableNames()) {
|
||||
|
||||
@@ -16,7 +16,8 @@ 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 gplx.core.criterias.*; import gplx.core.gfo_ndes.*; import gplx.dbs.qrys.*;
|
||||
import gplx.dbs.sqls.itms.*;
|
||||
import gplx.core.lists.*; /*ComparerAble*/ import gplx.core.stores.*; /*GfoNdeRdr*/
|
||||
import gplx.core.stores.*; /*GfoNdeRdr*/
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
class TdbSelectWkr implements Db_qryWkr {
|
||||
public Object Exec(Db_engine engineObj, Db_qry cmdObj) {
|
||||
TdbEngine engine = TdbEngine.cast(engineObj); Db_qry__select_cmd cmd = (Db_qry__select_cmd)cmdObj;
|
||||
|
||||
@@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.metas.parsers; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.core.brys.*; import gplx.core.btries.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
abstract class Dbmeta_fld_wkr__base {
|
||||
private byte[] hook;
|
||||
private final Btrie_slim_mgr words_trie = Btrie_slim_mgr.ci_a7();
|
||||
@@ -127,9 +128,9 @@ class Dbmeta_fld_wkr__default extends Dbmeta_fld_wkr__base {
|
||||
}
|
||||
byte b = src[pos]; ++pos;
|
||||
switch (b) {
|
||||
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr:
|
||||
case Byte_ascii.Paren_end:
|
||||
case Byte_ascii.Comma:
|
||||
case AsciiByte.Space: case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr:
|
||||
case AsciiByte.ParenEnd:
|
||||
case AsciiByte.Comma:
|
||||
end = pos - 1;
|
||||
loop = false;
|
||||
break;
|
||||
|
||||
@@ -15,7 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.metas.parsers; import gplx.Bry_;
|
||||
import gplx.Bry_find_;
|
||||
import gplx.Byte_ascii;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import gplx.Err_;
|
||||
import gplx.Int_;
|
||||
import gplx.String_;
|
||||
@@ -36,12 +36,12 @@ public class Dbmeta_parser__fld {
|
||||
rdr.Skip_ws();
|
||||
if (rdr.Pos() == src_len) return fld; // eos
|
||||
switch (src[rdr.Pos()]) {
|
||||
case Byte_ascii.Comma: return fld;
|
||||
case Byte_ascii.Paren_end: return fld;
|
||||
case Byte_ascii.Dash:
|
||||
case AsciiByte.Comma: return fld;
|
||||
case AsciiByte.ParenEnd: return fld;
|
||||
case AsciiByte.Dash:
|
||||
int nxt_pos = rdr.Pos() + 1;
|
||||
if (src[nxt_pos] == Byte_ascii.Dash) {
|
||||
nxt_pos = Bry_find_.Find_fwd(src, Byte_ascii.Nl, nxt_pos);
|
||||
if (src[nxt_pos] == AsciiByte.Dash) {
|
||||
nxt_pos = Bry_find_.Find_fwd(src, AsciiByte.Nl, nxt_pos);
|
||||
rdr.Move_to(nxt_pos + 1);
|
||||
}
|
||||
else {
|
||||
@@ -67,13 +67,13 @@ public class Dbmeta_parser__fld {
|
||||
int paren_itms_count = type_itm.Paren_itms_count();
|
||||
int len_1 = Int_.Min_value, len_2 = Int_.Min_value;
|
||||
if (paren_itms_count > 0) {
|
||||
rdr.Skip_ws().Chk(Byte_ascii.Paren_bgn);
|
||||
rdr.Skip_ws().Chk(AsciiByte.ParenBgn);
|
||||
len_1 = rdr.Skip_ws().Read_int_to_non_num(); if (len_1 == Int_.Min_value) rdr.Err_wkr().Fail("invalid fld len_1");
|
||||
if (paren_itms_count == 2) {
|
||||
rdr.Skip_ws().Chk(Byte_ascii.Comma);
|
||||
rdr.Skip_ws().Chk(AsciiByte.Comma);
|
||||
len_2 = rdr.Skip_ws().Read_int_to_non_num(); if (len_2 == Int_.Min_value) rdr.Err_wkr().Fail("invalid fld len_2");
|
||||
}
|
||||
rdr.Skip_ws().Chk(Byte_ascii.Paren_end);
|
||||
rdr.Skip_ws().Chk(AsciiByte.ParenEnd);
|
||||
}
|
||||
return new DbmetaFldType(type_itm.Tid_ansi(), String_.new_u8(type_itm.Word()), len_1, len_2);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ 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.Bool_;
|
||||
package gplx.dbs.metas.parsers; import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.Bry_;
|
||||
import gplx.Int_;
|
||||
import gplx.Object_;
|
||||
@@ -35,10 +35,10 @@ public class Dbmeta_parser__fld_tst {
|
||||
fxt.Test_parse_fld("name_1 int" , fxt.Make_fld("name_1", DbmetaFldType.TidInt, DbmetaFldItm.NullableUnspecified));
|
||||
fxt.Test_parse_fld("name_1 int null" , fxt.Make_fld("name_1", DbmetaFldType.TidInt, DbmetaFldItm.NullableNull));
|
||||
fxt.Test_parse_fld("name_1 int not null" , fxt.Make_fld("name_1", DbmetaFldType.TidInt, DbmetaFldItm.NullableNotNull));
|
||||
fxt.Test_parse_fld("name_1 int not null autoincrement" , fxt.Make_fld("name_1", DbmetaFldType.TidInt, DbmetaFldItm.NullableNotNull, Bool_.N, Bool_.Y));
|
||||
fxt.Test_parse_fld("name_1 int not null primary key" , fxt.Make_fld("name_1", DbmetaFldType.TidInt, DbmetaFldItm.NullableNotNull, Bool_.Y, Bool_.N));
|
||||
fxt.Test_parse_fld("name_1 int not null default -1" , fxt.Make_fld("name_1", DbmetaFldType.TidInt, DbmetaFldItm.NullableNotNull, Bool_.Y, Bool_.N, -1));
|
||||
fxt.Test_parse_fld("name_1 varchar(3) not null default 'abc'" , fxt.Make_fld("name_1", DbmetaFldType.TidStr, DbmetaFldItm.NullableNotNull, Bool_.Y, Bool_.N, "abc"));
|
||||
fxt.Test_parse_fld("name_1 int not null autoincrement" , fxt.Make_fld("name_1", DbmetaFldType.TidInt, DbmetaFldItm.NullableNotNull, BoolUtl.N, BoolUtl.Y));
|
||||
fxt.Test_parse_fld("name_1 int not null primary key" , fxt.Make_fld("name_1", DbmetaFldType.TidInt, DbmetaFldItm.NullableNotNull, BoolUtl.Y, BoolUtl.N));
|
||||
fxt.Test_parse_fld("name_1 int not null default -1" , fxt.Make_fld("name_1", DbmetaFldType.TidInt, DbmetaFldItm.NullableNotNull, BoolUtl.Y, BoolUtl.N, -1));
|
||||
fxt.Test_parse_fld("name_1 varchar(3) not null default 'abc'" , fxt.Make_fld("name_1", DbmetaFldType.TidStr, DbmetaFldItm.NullableNotNull, BoolUtl.Y, BoolUtl.N, "abc"));
|
||||
}
|
||||
@Test public void Comment() {
|
||||
fxt.Test_parse_fld("name_1 int --a\n" , fxt.Make_fld("name_1", DbmetaFldType.TidInt, DbmetaFldItm.NullableUnspecified));
|
||||
|
||||
@@ -15,6 +15,7 @@ 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 gplx.core.btries.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Dbmeta_parser__idx {
|
||||
private final Sql_bry_rdr rdr = new Sql_bry_rdr();
|
||||
private final List_adp tmp_list = List_adp_.New();
|
||||
@@ -31,14 +32,14 @@ public class Dbmeta_parser__idx {
|
||||
byte[] idx_name = rdr.Read_sql_identifier();
|
||||
rdr.Skip_ws().Chk_trie_val(trie, Tid__on);
|
||||
byte[] tbl_name = rdr.Read_sql_identifier();
|
||||
rdr.Skip_ws().Chk(Byte_ascii.Paren_bgn);
|
||||
rdr.Skip_ws().Chk(AsciiByte.ParenBgn);
|
||||
while (true) {
|
||||
byte[] fld_bry = rdr.Read_sql_identifier(); if (fld_bry == null) throw Err_.new_("db", "index parse failed; index field is not an identifier", "src", src);
|
||||
// TODO_OLD: check for ASC / DESC
|
||||
Dbmeta_idx_fld fld_itm = new Dbmeta_idx_fld(String_.new_u8(fld_bry), Dbmeta_idx_fld.Sort_tid__none);
|
||||
tmp_list.Add(fld_itm);
|
||||
byte sym = rdr.Skip_ws().Read_byte();
|
||||
if (sym == Byte_ascii.Paren_end) break;
|
||||
if (sym == AsciiByte.ParenEnd) break;
|
||||
}
|
||||
return new Dbmeta_idx_itm(unique, String_.new_u8(tbl_name), String_.new_u8(idx_name), (Dbmeta_idx_fld[])tmp_list.ToAryAndClear(Dbmeta_idx_fld.class));
|
||||
}
|
||||
|
||||
@@ -13,13 +13,19 @@ 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.*;
|
||||
package gplx.dbs.metas.parsers;
|
||||
import gplx.Bry_;
|
||||
import gplx.Tfds;
|
||||
import gplx.dbs.Dbmeta_idx_itm;
|
||||
import gplx.dbs.metas.Dbmeta_idx_fld;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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(BoolUtl.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(BoolUtl.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(BoolUtl.N, "idx_1", "tbl_1", "fld_1"));}
|
||||
}
|
||||
class Dbmeta_parser__idx_fxt {
|
||||
private final Dbmeta_parser__idx parser = new Dbmeta_parser__idx();
|
||||
@@ -30,6 +36,6 @@ class Dbmeta_parser__idx_fxt {
|
||||
Tfds.Eq_bool(expd.Unique(), actl.Unique());
|
||||
Tfds.Eq_str(expd.Name(), actl.Name());
|
||||
Tfds.Eq_str(expd.Tbl(), actl.Tbl());
|
||||
Tfds.Eq_bool(Bool_.Y, Dbmeta_idx_fld.Ary_eq(expd.Flds, actl.Flds));
|
||||
Tfds.Eq_bool(BoolUtl.Y, Dbmeta_idx_fld.Ary_eq(expd.Flds, actl.Flds));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.metas.parsers; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Dbmeta_parser__tbl {
|
||||
private final Sql_bry_rdr rdr = new Sql_bry_rdr();
|
||||
private final Dbmeta_parser__fld fld_parser = new Dbmeta_parser__fld();
|
||||
@@ -23,17 +24,17 @@ public class Dbmeta_parser__tbl {
|
||||
rdr.Skip_ws().Chk_trie_val(trie, Tid__create);
|
||||
rdr.Skip_ws().Chk_trie_val(trie, Tid__table);
|
||||
byte[] tbl_name = rdr.Read_sql_identifier();
|
||||
rdr.Skip_ws().Chk(Byte_ascii.Paren_bgn);
|
||||
rdr.Skip_ws().Chk(AsciiByte.ParenBgn);
|
||||
Dbmeta_tbl_itm rv = Dbmeta_tbl_itm.New(String_.new_u8(tbl_name));
|
||||
boolean loop = true;
|
||||
while (loop) {
|
||||
DbmetaFldItm fld = fld_parser.Parse_fld(rdr); if (fld == null) rdr.Err_wkr().Fail("unknown field", "src", src);
|
||||
rv.Flds().Add(fld);
|
||||
int pos = rdr.Pos();
|
||||
byte b = pos == rdr.Src_end() ? Byte_ascii.Null : src[pos];
|
||||
byte b = pos == rdr.Src_end() ? AsciiByte.Null : src[pos];
|
||||
switch (b) {
|
||||
case Byte_ascii.Comma: rdr.Move_by_one(); break;
|
||||
case Byte_ascii.Paren_end: rdr.Move_by_one(); loop = false; break;
|
||||
case AsciiByte.Comma: rdr.Move_by_one(); break;
|
||||
case AsciiByte.ParenEnd: rdr.Move_by_one(); loop = false; break;
|
||||
default: rdr.Err_wkr().Fail("premature end of flds"); break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +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
|
||||
*/
|
||||
package gplx.dbs.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
/*
|
||||
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.core.brys.*;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Sql_bry_rdr extends Bry_rdr { public byte[] Read_sql_identifier() {
|
||||
this.Skip_ws();
|
||||
int bgn = pos, end = -1;
|
||||
if (pos == src_end) return null;
|
||||
if (src[pos] == Byte_ascii.Brack_bgn) { // EX: [name with space]
|
||||
if (src[pos] == AsciiByte.BrackBgn) { // EX: [name with space]
|
||||
bgn = ++pos; // set bgn after [
|
||||
end = this.Find_fwd_lr(Byte_ascii.Brack_end);
|
||||
end = this.Find_fwd_lr(AsciiByte.BrackEnd);
|
||||
}
|
||||
else {
|
||||
this.Skip_alpha_num_under(); // ASSUME: identifier is ASCII and alpha / num / underscore
|
||||
@@ -31,24 +32,24 @@ public class Sql_bry_rdr extends Bry_rdr { public byte[] Read_sql_identifier()
|
||||
return Bry_.Mid(src, bgn, end);
|
||||
}
|
||||
@Override public Bry_rdr Skip_ws() {
|
||||
byte b_0 = pos < src_end ? src[pos] : Byte_ascii.Null;
|
||||
byte bgn_1 = Byte_ascii.Null;
|
||||
byte b_0 = pos < src_end ? src[pos] : AsciiByte.Null;
|
||||
byte bgn_1 = AsciiByte.Null;
|
||||
byte[] end_bry = null;
|
||||
switch (b_0) {
|
||||
case Byte_ascii.Dash: bgn_1 = Byte_ascii.Dash; end_bry = Comm_end_line; break;
|
||||
case Byte_ascii.Slash: bgn_1 = Byte_ascii.Star; end_bry = Comm_end_multi; break;
|
||||
case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr: case Byte_ascii.Space:
|
||||
case AsciiByte.Dash: bgn_1 = AsciiByte.Dash; end_bry = Comm_end_line; break;
|
||||
case AsciiByte.Slash: bgn_1 = AsciiByte.Star; end_bry = Comm_end_multi; break;
|
||||
case AsciiByte.Tab: case AsciiByte.Nl: case AsciiByte.Cr: case AsciiByte.Space:
|
||||
++pos;
|
||||
return super.Skip_ws();
|
||||
default:
|
||||
return this;
|
||||
}
|
||||
byte b_1 = pos + 1 < src_end ? src[pos + 1] : Byte_ascii.Null;
|
||||
byte b_1 = pos + 1 < src_end ? src[pos + 1] : AsciiByte.Null;
|
||||
if (b_1 != bgn_1) return this;
|
||||
int end_pos = Bry_find_.Find_fwd(src, end_bry, pos + 2, src_end);
|
||||
if (end_pos == Bry_find_.Not_found) return this;
|
||||
pos = end_pos + end_bry.length;
|
||||
return super.Skip_ws();
|
||||
}
|
||||
private static final byte[] Comm_end_line = Byte_ascii.Nl_bry, Comm_end_multi = Bry_.new_a7("*/");
|
||||
private static final byte[] Comm_end_line = AsciiByte.NlBry, Comm_end_multi = Bry_.new_a7("*/");
|
||||
}
|
||||
|
||||
@@ -13,13 +13,27 @@ 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.*;
|
||||
package gplx.dbs.qrys;
|
||||
import gplx.Err_;
|
||||
import gplx.Int_;
|
||||
import gplx.core.criterias.Criteria;
|
||||
import gplx.core.criterias.Criteria_;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.Db_qry_;
|
||||
import gplx.dbs.sqls.SqlQryWtr;
|
||||
import gplx.dbs.sqls.itms.*;
|
||||
import gplx.dbs.sqls.itms.Sql_from_clause;
|
||||
import gplx.dbs.sqls.itms.Sql_group_clause;
|
||||
import gplx.dbs.sqls.itms.Sql_join_fld;
|
||||
import gplx.dbs.sqls.itms.Sql_order_clause;
|
||||
import gplx.dbs.sqls.itms.Sql_order_fld;
|
||||
import gplx.dbs.sqls.itms.Sql_select_clause;
|
||||
import gplx.dbs.sqls.itms.Sql_select_fld;
|
||||
import gplx.dbs.sqls.itms.Sql_tbl_itm;
|
||||
import gplx.dbs.sqls.itms.Sql_where_clause;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Db_qry__select_cmd implements Db_qry {
|
||||
public int Tid() {return Db_qry_.Tid_select;}
|
||||
public boolean ReturnsRdr() {return Bool_.Y;}
|
||||
public boolean ReturnsRdr() {return BoolUtl.Y;}
|
||||
public String BaseTable() {return from.Base_tbl.Name;}
|
||||
public Sql_from_clause From() {return from;} private Sql_from_clause from;
|
||||
public Db_qry__select_cmd From_(String tbl) {return From_(tbl, Sql_tbl_itm.Alias__null);}
|
||||
@@ -62,10 +76,10 @@ public class Db_qry__select_cmd implements Db_qry {
|
||||
return this;
|
||||
}
|
||||
public Sql_order_clause Order() {return order;} private Sql_order_clause order = null;
|
||||
public Db_qry__select_cmd Order_asc_(String fld) {return Order_(fld, Bool_.Y);}
|
||||
public Db_qry__select_cmd Order_(String fld) {return Order_(Sql_order_fld.Tbl__null, fld, Bool_.Y);}
|
||||
public Db_qry__select_cmd Order_asc_(String fld) {return Order_(fld, BoolUtl.Y);}
|
||||
public Db_qry__select_cmd Order_(String fld) {return Order_(Sql_order_fld.Tbl__null, fld, BoolUtl.Y);}
|
||||
public Db_qry__select_cmd Order_(String fld, boolean asc) {return Order_(Sql_order_fld.Tbl__null, fld, asc);}
|
||||
public Db_qry__select_cmd Order_(String tbl, String fld) {return Order_(tbl, fld, Bool_.Y);}
|
||||
public Db_qry__select_cmd Order_(String tbl, String fld) {return Order_(tbl, fld, BoolUtl.Y);}
|
||||
public Db_qry__select_cmd Order_(String tbl, String fld, boolean asc) {
|
||||
if (order == null) order = new Sql_order_clause();
|
||||
Sql_order_fld item = new Sql_order_fld(tbl, fld, asc ? Sql_order_fld.Sort__nil : Sql_order_fld.Sort__dsc);
|
||||
@@ -108,6 +122,6 @@ public class Db_qry__select_cmd implements Db_qry {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String ToSqlExec(SqlQryWtr wtr) {return wtr.ToSqlStr(this, Bool_.N);}
|
||||
public String To_sql__prep(SqlQryWtr wtr) {return wtr.ToSqlStr(this, Bool_.Y);}
|
||||
public String ToSqlExec(SqlQryWtr wtr) {return wtr.ToSqlStr(this, BoolUtl.N);}
|
||||
public String To_sql__prep(SqlQryWtr wtr) {return wtr.ToSqlStr(this, BoolUtl.Y);}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,19 @@ 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.*;
|
||||
package gplx.dbs.qrys;
|
||||
import gplx.core.criterias.Criteria;
|
||||
import gplx.core.criterias.Criteria_;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_crt_;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.Db_qry_;
|
||||
import gplx.dbs.sqls.SqlQryWtr;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Db_qry_delete implements Db_qry {
|
||||
Db_qry_delete(String base_table, Criteria where) {this.base_table = base_table; this.where = where;}
|
||||
public int Tid() {return Db_qry_.Tid_delete;}
|
||||
public boolean ReturnsRdr() {return Bool_.N;}
|
||||
public boolean ReturnsRdr() {return BoolUtl.N;}
|
||||
public String BaseTable() {return base_table;} private final String base_table;
|
||||
public String ToSqlExec(SqlQryWtr wtr) {return wtr.ToSqlStr(this, false);}
|
||||
public Criteria Where() {return where;} private final Criteria where;
|
||||
|
||||
@@ -15,6 +15,8 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.qrys; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.dbs.sqls.*;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Db_qry_sql implements Db_qry {
|
||||
public int Tid() {return Db_qry_.Tid_sql;}
|
||||
public boolean ReturnsRdr() {return isReader;} private boolean isReader;
|
||||
@@ -42,7 +44,7 @@ public class Db_qry_sql implements Db_qry {
|
||||
int args_idx = 0, args_len = args.length, pos = 0;
|
||||
Bry_bfr bfr = Bry_bfr_.New_w_size(src_len);
|
||||
while (pos < src_len) {
|
||||
int question_pos = Bry_find_.Find_fwd(src, Byte_ascii.Question, pos);
|
||||
int question_pos = Bry_find_.Find_fwd(src, AsciiByte.Question, pos);
|
||||
if (question_pos == Bry_find_.Not_found)
|
||||
question_pos = src_len;
|
||||
bfr.Add_mid(src, pos, question_pos);
|
||||
@@ -57,8 +59,8 @@ public class Db_qry_sql implements Db_qry {
|
||||
Class<?> val_type = val.getClass();
|
||||
if (Type_.Eq(val_type, Int_.Cls_ref_type))
|
||||
bfr.Add_int_variable(Int_.Cast(val));
|
||||
else if (Type_.Eq(val_type, Bool_.Cls_ref_type))
|
||||
bfr.Add_int_fixed(1, Bool_.To_int(Bool_.Cast(val))); // NOTE: save boolean to 0 or 1, b/c (a) db may not support bit datatype (sqllite) and (b) avoid i18n issues with "true"/"false"
|
||||
else if (Type_.Eq(val_type, BoolUtl.ClsRefType))
|
||||
bfr.Add_int_fixed(1, BoolUtl.ToInt(BoolUtl.Cast(val))); // NOTE: save boolean to 0 or 1, b/c (a) db may not support bit datatype (sqllite) and (b) avoid i18n issues with "true"/"false"
|
||||
else if (Type_.Eq(val_type, Double_.Cls_ref_type))
|
||||
bfr.Add_double(Double_.cast(val));
|
||||
else if (Type_.Eq(val_type, Long_.Cls_ref_type))
|
||||
@@ -73,7 +75,7 @@ public class Db_qry_sql implements Db_qry {
|
||||
bfr.Add_str_a7(Decimal_adp_.cast(val).To_str());
|
||||
else {
|
||||
byte[] val_bry = Bry_.new_u8(Object_.Xto_str_strict_or_null(val));
|
||||
val_bry = Bry_.Replace(val_bry, Byte_ascii.Apos_bry, Bry_escape_apos);
|
||||
val_bry = Bry_.Replace(val_bry, AsciiByte.AposBry, Bry_escape_apos);
|
||||
bfr.Add_byte_apos().Add(val_bry).Add_byte_apos();
|
||||
}
|
||||
} private static final byte[] Bry_null = Bry_.new_u8("NULL"), Bry_escape_apos = Bry_.new_a7("''");
|
||||
|
||||
@@ -13,14 +13,25 @@ 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.*;
|
||||
package gplx.dbs.qrys;
|
||||
import gplx.DateAdp_;
|
||||
import gplx.Decimal_adp_;
|
||||
import gplx.Object_;
|
||||
import gplx.String_;
|
||||
import gplx.Tfds;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.sqls.SqlQryWtr;
|
||||
import gplx.dbs.sqls.SqlQryWtrUtl;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
public class Db_qry_sql_tst {
|
||||
@Before public void init() {fxt.Clear();} private Db_qry_sql_fxt fxt = new Db_qry_sql_fxt();
|
||||
@Test public void Insert() {
|
||||
fxt.Test_qry
|
||||
( Db_qry_insert.new_("tbl", "k1", "k2", "k3", "k4", "k5", "k6", "k7", "k8", "k9")
|
||||
, Object_.Ary(123, Bool_.Y, 1.23d, 123L, 123f, Byte_ascii.Num_1, "123", DateAdp_.parse_iso8561("1981-04-05T14:30:30"), Decimal_adp_.parse("1.23"))
|
||||
, Object_.Ary(123, BoolUtl.Y, 1.23d, 123L, 123f, AsciiByte.Num1, "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)"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.qrys;
|
||||
|
||||
import gplx.Bool_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.DateAdp;
|
||||
import gplx.Decimal_adp;
|
||||
import gplx.Err_;
|
||||
@@ -49,13 +49,13 @@ public class Db_stmt_cmd implements Db_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);}
|
||||
public Db_stmt Crt_bool_as_byte(String k, boolean v) {return Add_byte_by_bool(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_bool_as_byte(String k, boolean v) {return Add_byte_by_bool(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_bool_as_byte(boolean v) {return Add_byte_by_bool(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_byte_by_bool(boolean where, String k, boolean v) {return Add_byte(where, k, v ? BoolUtl.YByte : BoolUtl.NByte);}
|
||||
public Db_stmt Crt_byte(String k, byte v) {return Add_byte(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_byte(String k, byte v) {return Add_byte(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_byte(byte v) {return Add_byte(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_byte(boolean where, String k, byte v) {
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
@@ -67,10 +67,10 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
}
|
||||
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);}
|
||||
public Db_stmt Crt_int(String k, int v) {return Add_int(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_int_by_bool(String k, boolean v) {return Add_int(BoolUtl.N, k, v ? 1 : 0);}
|
||||
public Db_stmt Val_int(String k, int v) {return Add_int(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_int(int v) {return Add_int(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_int(boolean where, String k, int v) {
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
@@ -82,9 +82,9 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
}
|
||||
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);}
|
||||
public Db_stmt Crt_long(String k, long v) {return Add_long(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_long(String k, long v) {return Add_long(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_long(long v) {return Add_long(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_long(boolean where, String k, long v) {
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
@@ -96,9 +96,9 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
}
|
||||
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);}
|
||||
public Db_stmt Crt_float(String k, float v) {return Add_float(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_float(String k, float v) {return Add_float(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_float(float v) {return Add_float(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_float(boolean where, String k, float v) {
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
@@ -110,9 +110,9 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
}
|
||||
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);}
|
||||
public Db_stmt Crt_double(String k, double v) {return Add_double(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_double(String k, double v) {return Add_double(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_double(double v) {return Add_double(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_double(boolean where, String k, double v) {
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
@@ -124,9 +124,9 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
}
|
||||
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);}
|
||||
public Db_stmt Crt_decimal(String k, Decimal_adp v) {return Add_decimal(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_decimal(String k, Decimal_adp v) {return Add_decimal(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_decimal(Decimal_adp v) {return Add_decimal(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_decimal(boolean where, String k, Decimal_adp v) {
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
@@ -138,9 +138,9 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
}
|
||||
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);}
|
||||
public Db_stmt Crt_bry(String k, byte[] v) {return Add_bry(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_bry(String k, byte[] v) {return Add_bry(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_bry(byte[] v) {return Add_bry(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_bry(boolean where, String k, byte[] v) {
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
@@ -152,13 +152,13 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
}
|
||||
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);}
|
||||
public Db_stmt Crt_bry_as_str(String k, byte[] v) {return Add_bry_as_str(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_bry_as_str(String k, byte[] v) {return Add_bry_as_str(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_bry_as_str(byte[] v) {return Add_bry_as_str(BoolUtl.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);}
|
||||
public Db_stmt Crt_str(String k, String v) {return Add_str(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_str(String k, String v) {return Add_str(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_str(String v) {return Add_str(BoolUtl.N, Key_na, v);}
|
||||
protected Db_stmt Add_str(boolean where, String k, String v) {
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
@@ -170,8 +170,8 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
}
|
||||
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);}
|
||||
public Db_stmt Crt_date(String k, DateAdp v) {return Add_date(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_date(String k, DateAdp v) {return Add_date(BoolUtl.N, k, v);}
|
||||
protected Db_stmt Add_date(boolean where, String k, DateAdp v) {
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
@@ -183,8 +183,8 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
}
|
||||
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);}
|
||||
public Db_stmt Crt_text(String k, String v) {return Add_text(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_text(String k, String v) {return Add_text(BoolUtl.N, k, v);}
|
||||
private Db_stmt Add_text(boolean where, String k, String v) {
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
|
||||
@@ -13,9 +13,36 @@ 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.brys.fmtrs.*; import gplx.core.stores.*;
|
||||
import gplx.dbs.engines.*;
|
||||
package gplx.dbs.qrys;
|
||||
import gplx.Bry_;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Bry_find_;
|
||||
import gplx.Byte_;
|
||||
import gplx.DateAdp;
|
||||
import gplx.Decimal_adp;
|
||||
import gplx.Double_;
|
||||
import gplx.Err_;
|
||||
import gplx.Float_;
|
||||
import gplx.Int_;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.Long_;
|
||||
import gplx.Object_;
|
||||
import gplx.String_;
|
||||
import gplx.Type_;
|
||||
import gplx.core.brys.fmtrs.Bry_fmtr;
|
||||
import gplx.core.stores.DataRdr;
|
||||
import gplx.core.stores.DataRdr_;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.Db_rdr_;
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.dbs.engines.Db_engine;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Db_stmt_sql implements Db_stmt {// used for formatting SQL statements; not used for actual insert into database
|
||||
private static final String Key_na = ""; // key is not_available; only called by procs with signature of Val(<type> v);
|
||||
private final List_adp args = List_adp_.New();
|
||||
@@ -24,79 +51,79 @@ public class Db_stmt_sql implements Db_stmt {// used for formatting SQL statemen
|
||||
public void Ctor_stmt(Db_engine engine, Db_qry qry) {}
|
||||
public Db_conn Conn() {return conn;} public void Conn_(Db_conn v) {this.conn = v;} Db_conn conn;
|
||||
public Db_stmt Reset_stmt() {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);}
|
||||
public Db_stmt Crt_bool_as_byte(String k, boolean v) {return Add_byte_by_bool(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_bool_as_byte(String k, boolean v) {return Add_byte_by_bool(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_bool_as_byte(boolean v) {return Add_byte_by_bool(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_byte_by_bool(boolean where, String k, boolean v) {return Add_byte(where, k, v ? BoolUtl.YByte : BoolUtl.NByte);}
|
||||
public Db_stmt Crt_byte(String k, byte v) {return Add_byte(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_byte(String k, byte v) {return Add_byte(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_byte(byte v) {return Add_byte(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_byte(boolean where, String k, byte v) {
|
||||
try {Add(k, Byte_.To_str(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "byte", "val", v);}
|
||||
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);}
|
||||
public Db_stmt Crt_int(String k, int v) {return Add_int(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_int_by_bool(String k, boolean v) {return Add_int(BoolUtl.N, k, v ? 1 : 0);}
|
||||
public Db_stmt Val_int(String k, int v) {return Add_int(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_int(int v) {return Add_int(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_int(boolean where, String k, int v) {
|
||||
try {Add(k, Int_.To_str(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "int", "val", v);}
|
||||
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);}
|
||||
public Db_stmt Crt_long(String k, long v) {return Add_long(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_long(String k, long v) {return Add_long(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_long(long v) {return Add_long(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_long(boolean where, String k, long v) {
|
||||
try {Add(k, Long_.To_str(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "long", "val", v);}
|
||||
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);}
|
||||
public Db_stmt Crt_float(String k, float v) {return Add_float(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_float(String k, float v) {return Add_float(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_float(float v) {return Add_float(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_float(boolean where, String k, float v) {
|
||||
try {Add(k, Float_.To_str(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "float", "val", v);}
|
||||
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);}
|
||||
public Db_stmt Crt_double(String k, double v) {return Add_double(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_double(String k, double v) {return Add_double(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_double(double v) {return Add_double(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_double(boolean where, String k, double v) {
|
||||
try {Add(k, Double_.To_str(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "double", "val", v);}
|
||||
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);}
|
||||
public Db_stmt Crt_decimal(String k, Decimal_adp v) {return Add_decimal(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_decimal(String k, Decimal_adp v) {return Add_decimal(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_decimal(Decimal_adp v) {return Add_decimal(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_decimal(boolean where, String k, Decimal_adp v) {
|
||||
try {Add(k, v.To_str());} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "decimal", "val", v);}
|
||||
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);}
|
||||
public Db_stmt Crt_bry(String k, byte[] v) {return Add_bry(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_bry(String k, byte[] v) {return Add_bry(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_bry(byte[] v) {return Add_bry(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_bry(boolean where, String k, byte[] v) {// HACK: convert to String b/c tdb does not support byte[]
|
||||
try {Add(k, Val_str_wrap(String_.new_u8(v)));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "byte[]", "val", v.length);}
|
||||
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);}
|
||||
public Db_stmt Crt_bry_as_str(String k, byte[] v) {return Add_bry_as_str(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_bry_as_str(String k, byte[] v) {return Add_bry_as_str(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_bry_as_str(byte[] v) {return Add_bry_as_str(BoolUtl.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);}
|
||||
public Db_stmt Crt_str(String k, String v) {return Add_str(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_str(String k, String v) {return Add_str(BoolUtl.N, k, v);}
|
||||
public Db_stmt Val_str(String v) {return Add_str(BoolUtl.N, Key_na, v);}
|
||||
private Db_stmt Add_str(boolean where, String k, String v) {
|
||||
try {Add(k, Val_str_wrap(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "String", "val", v);}
|
||||
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);}
|
||||
public Db_stmt Crt_date(String k, DateAdp v) {return Add_date(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_date(String k, DateAdp v) {return Add_date(BoolUtl.N, k, v);}
|
||||
private Db_stmt Add_date(boolean where, String k, DateAdp v) {
|
||||
try {Add(k, Val_str_wrap(v.XtoStr_fmt_iso_8561()));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "date", "val", v);}
|
||||
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);}
|
||||
public Db_stmt Crt_text(String k, String v) {return Add_text(BoolUtl.Y, k, v);}
|
||||
public Db_stmt Val_text(String k, String v) {return Add_text(BoolUtl.N, k, v);}
|
||||
private Db_stmt Add_text(boolean where, String k, String v) {
|
||||
try {Add(k, Val_str_wrap(v));} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to add value", "type", "text", "val", v);}
|
||||
return this;
|
||||
@@ -157,11 +184,11 @@ public class Db_stmt_sql implements Db_stmt {// used for formatting SQL statemen
|
||||
int arg_idx = 0; int pos_prv = 0;
|
||||
tmp_bfr.Clear();
|
||||
while (true) {
|
||||
int pos_cur = Bry_find_.Find_fwd(sql_bry, Byte_ascii.Question, pos_prv); if (pos_cur == Bry_find_.Not_found) break;
|
||||
int pos_cur = Bry_find_.Find_fwd(sql_bry, AsciiByte.Question, pos_prv); if (pos_cur == Bry_find_.Not_found) break;
|
||||
tmp_bfr.Add_mid(sql_bry, pos_prv, pos_cur);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Tilde).Add_byte(Byte_ascii.Curly_bgn);
|
||||
tmp_bfr.Add_byte(AsciiByte.Tilde).Add_byte(AsciiByte.CurlyBgn);
|
||||
tmp_bfr.Add_int_variable(arg_idx++);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Curly_end);
|
||||
tmp_bfr.Add_byte(AsciiByte.CurlyEnd);
|
||||
pos_prv = pos_cur + 1;
|
||||
}
|
||||
tmp_bfr.Add_mid(sql_bry, pos_prv, sql_bry.length);
|
||||
|
||||
@@ -21,16 +21,16 @@ 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_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.primitives.ByteUtl;
|
||||
import gplx.objects.primitives.CharUtl;
|
||||
import gplx.objects.primitives.DoubleUtl;
|
||||
import gplx.objects.primitives.FloatUtl;
|
||||
import gplx.objects.primitives.IntUtl;
|
||||
import gplx.objects.primitives.LongUtl;
|
||||
import gplx.objects.primitives.ShortUtl;
|
||||
import gplx.objects.strings.bfrs.GfoStrBldr;
|
||||
import gplx.objects.types.TypeUtl;
|
||||
|
||||
public class Db_val_type {
|
||||
public static final byte // not serialized
|
||||
@@ -54,23 +54,23 @@ public class Db_val_type {
|
||||
;
|
||||
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;
|
||||
if (TypeUtl.Eq(type, IntUtl.ClsRefType)) return Tid_int32;
|
||||
else if (TypeUtl.Eq(type, String_.Cls_ref_type)) return Tid_nvarchar;
|
||||
else if (TypeUtl.Eq(type, byte[].class)) return Tid_nvarchar;
|
||||
else if (TypeUtl.Eq(type, BoolUtl.ClsRefType)) return Tid_bool;
|
||||
else if (TypeUtl.Eq(type, ByteUtl.ClsRefType)) return Tid_byte;
|
||||
else if (TypeUtl.Eq(type, LongUtl.ClsRefType)) return Tid_int64;
|
||||
else if (TypeUtl.Eq(type, DoubleUtl.ClsRefType)) return Tid_double;
|
||||
else if (TypeUtl.Eq(type, Decimal_adp_.Cls_ref_type)) return Tid_decimal;
|
||||
else if (TypeUtl.Eq(type, DateAdp_.Cls_ref_type)) return Tid_date;
|
||||
else if (TypeUtl.Eq(type, FloatUtl.ClsRefType)) return Tid_float;
|
||||
else if (TypeUtl.Eq(type, ShortUtl.ClsRefType)) return Tid_int16;
|
||||
else if (TypeUtl.Eq(type, CharUtl.ClsRefType)) return Tid_char;
|
||||
else return Tid_unknown;
|
||||
}
|
||||
public static String ToSqlStr(String sql, GfoListBase<Object> paramList) {
|
||||
try {
|
||||
GfoStringBuilder sb = new GfoStringBuilder();
|
||||
GfoStrBldr sb = new GfoStrBldr();
|
||||
int oldPos = 0;
|
||||
int paramIdx = 0;
|
||||
while (true) {
|
||||
@@ -91,9 +91,9 @@ public class Db_val_type {
|
||||
break;
|
||||
}
|
||||
if (quote) {
|
||||
sb.Add('\'');
|
||||
sb.AddChar('\'');
|
||||
sb.Add(String_.Replace(paramStr, "'", "\\'"));
|
||||
sb.Add('\'');
|
||||
sb.AddChar('\'');
|
||||
} else {
|
||||
sb.Add(paramStr);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ 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;
|
||||
import gplx.Byte_ascii;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import gplx.String_;
|
||||
import gplx.dbs.sqls.wtrs.Sql_core_wtr;
|
||||
import gplx.dbs.sqls.wtrs.Sql_core_wtr__mysql;
|
||||
@@ -24,7 +24,7 @@ public class SqlQryWtrUtl {
|
||||
public static SqlQryWtr NewMysql() {return new Sql_core_wtr__mysql();}
|
||||
public static SqlQryWtr NewSqlite() {return new Sql_core_wtr__sqlite();}
|
||||
|
||||
public static final byte Like_wildcard = Byte_ascii.Percent;
|
||||
public static final byte Like_wildcard = AsciiByte.Percent;
|
||||
public static String QuoteArg(String s) { // only for constructing DEBUG SQL strings
|
||||
return "'" + String_.Replace(s, "'", "''") + "'";
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ 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.*;
|
||||
package gplx.dbs.sqls.itms;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Sql_order_fld {
|
||||
public Sql_order_fld(String tbl, String name, byte sort) {this.Tbl = tbl; this.Name = name; this.Sort = sort;}
|
||||
public final String Tbl;
|
||||
@@ -31,5 +32,5 @@ public class Sql_order_fld {
|
||||
}
|
||||
|
||||
public static final String Tbl__null = null;
|
||||
public static final byte Sort__asc = Bool_.Y_byte, Sort__dsc = Bool_.N_byte, Sort__nil = Bool_.__byte;
|
||||
public static final byte Sort__asc = BoolUtl.YByte, Sort__dsc = BoolUtl.NByte, Sort__nil = BoolUtl.NullByte;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
/*
|
||||
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.*;
|
||||
/*
|
||||
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.core.gfo_ndes.*;
|
||||
import gplx.core.lists.*;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.objects.lists.ComparerAble;
|
||||
public class Sql_order_fld_sorter implements ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
GfoNde lhs = (GfoNde)lhsObj; GfoNde rhs = (GfoNde)rhsObj;
|
||||
@@ -23,12 +24,12 @@ public class Sql_order_fld_sorter implements ComparerAble {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
item = items[i];
|
||||
lhsData = lhs.Read(item.Name); rhsData = rhs.Read(item.Name);
|
||||
int compare = CompareAble_.Compare_obj(lhsData, rhsData);
|
||||
if (compare == CompareAble_.Same) continue;
|
||||
int compare = CompareAbleUtl.Compare_obj(lhsData, rhsData);
|
||||
if (compare == CompareAbleUtl.Same) continue;
|
||||
int ascendingVal = item.Sort == Sql_order_fld.Sort__dsc ? -1 : 1;
|
||||
return compare * ascendingVal;
|
||||
}
|
||||
return CompareAble_.Same;
|
||||
return CompareAbleUtl.Same;
|
||||
}
|
||||
Sql_order_fld[] items;
|
||||
public static ComparerAble new_(Sql_order_fld[] items) {
|
||||
|
||||
@@ -13,8 +13,9 @@ 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 gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
|
||||
package gplx.dbs.sqls.itms; import gplx.*;
|
||||
import gplx.core.type_xtns.*;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
public abstract class Sql_select_fld {
|
||||
public Sql_select_fld(String tbl, String fld, String alias) {
|
||||
this.Tbl = tbl; this.Fld = fld; this.Alias = alias;
|
||||
@@ -31,8 +32,8 @@ public abstract class Sql_select_fld {
|
||||
public static Sql_select_fld Wildcard = Sql_select_fld_wild.Instance;
|
||||
public static Sql_select_fld New_count (String tbl, String fld, String alias) {return new Sql_select_fld_count(tbl, fld, alias);}
|
||||
public static Sql_select_fld New_sum (String tbl, String fld, String alias) {return new Sql_select_fld_sum(tbl, fld, alias);}
|
||||
public static Sql_select_fld New_min (String tbl, String fld, String alias) {return new Sql_select_fld_minMax(CompareAble_.Less, tbl, fld, alias);}
|
||||
public static Sql_select_fld New_max (String tbl, String fld, String alias) {return new Sql_select_fld_minMax(CompareAble_.More, tbl, fld, alias);}
|
||||
public static Sql_select_fld New_min (String tbl, String fld, String alias) {return new Sql_select_fld_minMax(CompareAbleUtl.Less, tbl, fld, alias);}
|
||||
public static Sql_select_fld New_max (String tbl, String fld, String alias) {return new Sql_select_fld_minMax(CompareAbleUtl.More, tbl, fld, alias);}
|
||||
public static String Bld_tbl_w_fld(String tbl, String fld) {return tbl == null ? fld : tbl + "." + fld;}
|
||||
|
||||
// tdb related functions
|
||||
|
||||
@@ -13,8 +13,9 @@ 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.*;
|
||||
package gplx.dbs.sqls.itms; import gplx.*;
|
||||
import gplx.core.type_xtns.*;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
abstract class Sql_select_fld_func extends Sql_select_fld { public Sql_select_fld_func(String tbl, String fld, String alias) {super(tbl, fld, alias);}
|
||||
public abstract String XtoSql_functionName();
|
||||
@Override public String To_fld_sql() {
|
||||
@@ -41,10 +42,10 @@ class Sql_select_fld_minMax extends Sql_select_fld_func { private final int com
|
||||
public Sql_select_fld_minMax(int compareType, String tbl, String fld, String alias) {super(tbl, fld, alias);
|
||||
this.compareType = compareType;
|
||||
}
|
||||
@Override public String XtoSql_functionName() {return compareType == CompareAble_.Less ? "MIN" : "MAX";}
|
||||
@Override public String XtoSql_functionName() {return compareType == CompareAbleUtl.Less ? "MIN" : "MAX";}
|
||||
@Override public Object GroupBy_eval(Object groupByVal, Object curVal, ClassXtn type) {
|
||||
if (groupByVal == null) return curVal;
|
||||
int compareVal = CompareAble_.Compare_obj(curVal, groupByVal);
|
||||
int compareVal = CompareAbleUtl.Compare_obj(curVal, groupByVal);
|
||||
return compareVal * compareType > 0 ? curVal : groupByVal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
package gplx.dbs.sqls.wtrs;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Byte_ascii;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import gplx.Err_;
|
||||
import gplx.Keyval;
|
||||
import gplx.dbs.Db_qry;
|
||||
@@ -31,8 +31,8 @@ import gplx.dbs.sqls.SqlQryWtr;
|
||||
import gplx.dbs.sqls.itms.Sql_select_fld;
|
||||
public class Sql_core_wtr implements SqlQryWtr {
|
||||
private final Bry_bfr bfr = Bry_bfr_.New_w_size(64);
|
||||
public byte[] Seq__nl = Byte_ascii.Space_bry;
|
||||
public byte Seq__quote = Byte_ascii.Apos, Seq__escape = Byte_ascii.Backslash;
|
||||
public byte[] Seq__nl = AsciiByte.SpaceBry;
|
||||
public byte Seq__quote = AsciiByte.Apos, Seq__escape = AsciiByte.Backslash;
|
||||
public Sql_core_wtr() {
|
||||
this.val_wtr = Make__val_wtr();
|
||||
this.from_wtr = Make__from_wtr();
|
||||
|
||||
@@ -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.sqls.wtrs; import gplx.Bool_;
|
||||
package gplx.dbs.sqls.wtrs; import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Byte_ascii;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import gplx.Err_;
|
||||
import gplx.Object_;
|
||||
import gplx.String_;
|
||||
@@ -56,7 +56,7 @@ public class Sql_schema_wtr {
|
||||
int len = flds.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
DbmetaFldItm fld = flds.Get_at(i);
|
||||
tmp_bfr.Add_byte(i == 0 ? Byte_ascii.Paren_bgn : Byte_ascii.Comma).Add_byte_space();
|
||||
tmp_bfr.Add_byte(i == 0 ? AsciiByte.ParenBgn : AsciiByte.Comma).Add_byte_space();
|
||||
Bld_fld(tmp_bfr, fld);
|
||||
tmp_bfr.Add_byte_nl();
|
||||
}
|
||||
@@ -82,9 +82,9 @@ public class Sql_schema_wtr {
|
||||
}
|
||||
if (fld.DefaultVal() != DbmetaFldItm.DefaultValNull) {
|
||||
tmp_bfr.Add_str_a7("DEFAULT ");
|
||||
boolean quote = Bool_.N;
|
||||
boolean quote = BoolUtl.N;
|
||||
switch (fld.Type().Tid()) {
|
||||
case DbmetaFldType.TidStr: case DbmetaFldType.TidText: quote = Bool_.Y; break;
|
||||
case DbmetaFldType.TidStr: case DbmetaFldType.TidText: quote = BoolUtl.Y; break;
|
||||
}
|
||||
if (quote) tmp_bfr.Add_byte_apos();
|
||||
tmp_bfr.Add_str_u8(Object_.Xto_str_strict_or_null(fld.DefaultVal()));
|
||||
@@ -104,7 +104,7 @@ public class Sql_schema_wtr {
|
||||
case DbmetaFldType.TidLong: tmp_bfr.Add_str_a7("bigint"); break;
|
||||
case DbmetaFldType.TidFloat: tmp_bfr.Add_str_a7("float"); break;
|
||||
case DbmetaFldType.TidDouble: tmp_bfr.Add_str_a7("double"); break;
|
||||
case DbmetaFldType.TidStr: tmp_bfr.Add_str_a7("varchar(").Add_int_variable(len).Add_byte(Byte_ascii.Paren_end); break;
|
||||
case DbmetaFldType.TidStr: tmp_bfr.Add_str_a7("varchar(").Add_int_variable(len).Add_byte(AsciiByte.ParenEnd); break;
|
||||
case DbmetaFldType.TidText: tmp_bfr.Add_str_a7("text"); break;
|
||||
case DbmetaFldType.TidBry: tmp_bfr.Add_str_a7("blob"); break;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
|
||||
@@ -13,13 +13,29 @@ 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.*;
|
||||
package gplx.dbs.sqls.wtrs;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Byte_;
|
||||
import gplx.DateAdp;
|
||||
import gplx.DateAdp_;
|
||||
import gplx.Decimal_adp;
|
||||
import gplx.Decimal_adp_;
|
||||
import gplx.Double_;
|
||||
import gplx.Float_;
|
||||
import gplx.Int_;
|
||||
import gplx.Long_;
|
||||
import gplx.Object_;
|
||||
import gplx.Short_;
|
||||
import gplx.String_;
|
||||
import gplx.Type_ids_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
public class Sql_val_wtr {
|
||||
// private final Bry_bfr tmp_bfr = Bry_bfr_.New(32);
|
||||
public byte Seq__quote = Byte_ascii.Apos, Seq__escape = Byte_ascii.Backslash;
|
||||
public byte Seq__quote = AsciiByte.Apos, Seq__escape = AsciiByte.Backslash;
|
||||
public void Bld_val(Bry_bfr bfr, Sql_wtr_ctx ctx, Object val) {
|
||||
if (ctx.Mode_is_prep) {
|
||||
bfr.Add_byte(Byte_ascii.Question);
|
||||
bfr.Add_byte(AsciiByte.Question);
|
||||
return;
|
||||
}
|
||||
if (val == null) {
|
||||
@@ -28,7 +44,7 @@ public class Sql_val_wtr {
|
||||
}
|
||||
int tid_type = Type_ids_.To_id_by_type(val.getClass());
|
||||
switch (tid_type) {
|
||||
case Type_ids_.Id__bool: Bld_val__bool (bfr, Bool_.Cast(val)); break;
|
||||
case Type_ids_.Id__bool: Bld_val__bool (bfr, BoolUtl.Cast(val)); break;
|
||||
case Type_ids_.Id__byte: Bld_val__byte (bfr, Byte_.Cast(val)); break;
|
||||
case Type_ids_.Id__short: Bld_val__short (bfr, Short_.cast(val)); break;
|
||||
case Type_ids_.Id__int: Bld_val__int (bfr, Int_.Cast(val)); break;
|
||||
|
||||
@@ -14,8 +14,8 @@ 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.Bry_bfr;
|
||||
import gplx.Byte_ascii;
|
||||
import gplx.CompareAble_;
|
||||
import gplx.objects.strings.AsciiByte;
|
||||
import gplx.objects.lists.CompareAbleUtl;
|
||||
import gplx.Err_;
|
||||
import gplx.Object_;
|
||||
import gplx.String_;
|
||||
@@ -95,8 +95,8 @@ public class Sql_where_wtr {
|
||||
private void Bld_where__comp(Bry_bfr bfr, Sql_wtr_ctx ctx, Criteria_comp crt) {
|
||||
int comp_tid = crt.Comp_mode();
|
||||
bfr.Add_byte_space();
|
||||
bfr.Add_byte(comp_tid < CompareAble_.Same ? Byte_ascii.Angle_bgn : Byte_ascii.Angle_end);
|
||||
if (comp_tid % 2 == CompareAble_.Same) bfr.Add_byte_eq();
|
||||
bfr.Add_byte(comp_tid < CompareAbleUtl.Same ? AsciiByte.AngleBgn : AsciiByte.AngleEnd);
|
||||
if (comp_tid % 2 == CompareAbleUtl.Same) bfr.Add_byte_eq();
|
||||
bfr.Add_byte_space();
|
||||
val_wtr.Bld_val(bfr, ctx, crt.Val());
|
||||
}
|
||||
@@ -117,12 +117,12 @@ public class Sql_where_wtr {
|
||||
int len = crt.Ary_len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (i == 0)
|
||||
bfr.Add_byte(Byte_ascii.Paren_bgn);
|
||||
bfr.Add_byte(AsciiByte.ParenBgn);
|
||||
else
|
||||
bfr.Add_byte(Byte_ascii.Comma).Add_byte_space();
|
||||
bfr.Add_byte(AsciiByte.Comma).Add_byte_space();
|
||||
val_wtr.Bld_val(bfr, ctx, ary[i]);
|
||||
}
|
||||
bfr.Add_byte(Byte_ascii.Paren_end);
|
||||
bfr.Add_byte(AsciiByte.ParenEnd);
|
||||
}
|
||||
private void Bld_where__iomatch(Bry_bfr bfr, Sql_wtr_ctx ctx, Criteria_ioMatch crt) {
|
||||
bfr.Add_str_a7(crt.Neg() ? " NOT IOMATCH " : " IOMATCH ");
|
||||
|
||||
@@ -13,15 +13,28 @@ 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.stmts; import gplx.*; import gplx.dbs.*;
|
||||
package gplx.dbs.stmts;
|
||||
import gplx.Bry_;
|
||||
import gplx.Byte_;
|
||||
import gplx.Double_;
|
||||
import gplx.Err_;
|
||||
import gplx.Float_;
|
||||
import gplx.Int_;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.Long_;
|
||||
import gplx.String_;
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.DbmetaFldType;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Db_stmt_arg_list {
|
||||
private final List_adp list = List_adp_.New();
|
||||
public void Clear() {list.Clear();}
|
||||
public int Len() {return list.Len();}
|
||||
public Db_stmt_arg Get_at(int i) {return (Db_stmt_arg)list.Get_at(i);}
|
||||
public Db_stmt_arg_list Crt_int (String key, int val) {return Add(Bool_.Y, DbmetaFldType.TidInt, key, val);}
|
||||
public Db_stmt_arg_list Crt_str_by_bry (String key, byte[] val) {return Add(Bool_.Y, DbmetaFldType.TidStr, key, String_.new_u8(val));}
|
||||
public Db_stmt_arg_list Crt_str (String key, String val) {return Add(Bool_.Y, DbmetaFldType.TidStr, key, val);}
|
||||
public Db_stmt_arg_list Crt_int (String key, int val) {return Add(BoolUtl.Y, DbmetaFldType.TidInt, key, val);}
|
||||
public Db_stmt_arg_list Crt_str_by_bry (String key, byte[] val) {return Add(BoolUtl.Y, DbmetaFldType.TidStr, key, String_.new_u8(val));}
|
||||
public Db_stmt_arg_list Crt_str (String key, String val) {return Add(BoolUtl.Y, DbmetaFldType.TidStr, key, val);}
|
||||
public Db_stmt_arg_list Add(boolean crt, int tid, String key, Object val) {list.Add(new Db_stmt_arg(crt, tid, key, val)); return this;}
|
||||
public void Fill(Db_stmt stmt) {
|
||||
int len = list.Len();
|
||||
@@ -36,7 +49,7 @@ public class Db_stmt_arg_list {
|
||||
}
|
||||
public static void Fill_crt(Db_stmt stmt, int tid, String key, Object val) {
|
||||
switch (tid) {
|
||||
case DbmetaFldType.TidBool: stmt.Crt_bool_as_byte (key, Bool_.Cast(val)); break;
|
||||
case DbmetaFldType.TidBool: stmt.Crt_bool_as_byte (key, BoolUtl.Cast(val)); break;
|
||||
case DbmetaFldType.TidByte: stmt.Crt_byte (key, Byte_.Cast(val)); break;
|
||||
case DbmetaFldType.TidInt: stmt.Crt_int (key, Int_.Cast(val)); break;
|
||||
case DbmetaFldType.TidLong: stmt.Crt_long (key, Long_.cast(val)); break;
|
||||
@@ -50,7 +63,7 @@ public class Db_stmt_arg_list {
|
||||
}
|
||||
public static void Fill_val(Db_stmt stmt, int tid, String key, Object val) {
|
||||
switch (tid) {
|
||||
case DbmetaFldType.TidBool: stmt.Val_bool_as_byte (key, Bool_.Cast(val)); break;
|
||||
case DbmetaFldType.TidBool: stmt.Val_bool_as_byte (key, BoolUtl.Cast(val)); break;
|
||||
case DbmetaFldType.TidByte: stmt.Val_byte (key, Byte_.Cast(val)); break;
|
||||
case DbmetaFldType.TidInt: stmt.Val_int (key, Int_.Cast(val)); break;
|
||||
case DbmetaFldType.TidLong: stmt.Val_long (key, Long_.cast(val)); break;
|
||||
|
||||
@@ -13,8 +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.stmts; import gplx.*; import gplx.dbs.*;
|
||||
package gplx.dbs.stmts;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.Bry_fmt;
|
||||
import gplx.Int_;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.DbmetaFldType;
|
||||
import gplx.dbs.sqls.SqlQryWtrUtl;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Db_stmt_mgr {
|
||||
private final List_adp fmt_list = List_adp_.New();
|
||||
private final Db_stmt_arg_list arg_list = new Db_stmt_arg_list();
|
||||
@@ -27,11 +37,11 @@ public class Db_stmt_mgr {
|
||||
}
|
||||
public void Add_crt_str(String key, String val) {
|
||||
fmt_list.Add(mode_is_stmt ? stmt_arg_placeholder : SqlQryWtrUtl.QuoteArg(val));
|
||||
arg_list.Add(Bool_.Y, DbmetaFldType.TidStr, key, val);
|
||||
arg_list.Add(BoolUtl.Y, DbmetaFldType.TidStr, key, val);
|
||||
}
|
||||
public void Add_crt_int(String key, int val) {
|
||||
fmt_list.Add(mode_is_stmt ? stmt_arg_placeholder : Int_.To_str(val));
|
||||
arg_list.Add(Bool_.Y, DbmetaFldType.TidInt, key, val);
|
||||
arg_list.Add(BoolUtl.Y, DbmetaFldType.TidInt, key, val);
|
||||
}
|
||||
public void Write_fmt(Bry_fmt fmt) {
|
||||
fmt.Bld_many(bfr, (Object[])fmt_list.ToAryAndClear(Object.class));
|
||||
|
||||
@@ -13,8 +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.utls; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.dbs.stmts.*;
|
||||
package gplx.dbs.utls;
|
||||
import gplx.Hash_adp;
|
||||
import gplx.Hash_adp_;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.dbs.DbmetaFldList;
|
||||
import gplx.dbs.stmts.Db_stmt_arg_list;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
public class Db_tbl__crud_ {
|
||||
public static boolean Upsert(Db_conn conn, String tbl_name, DbmetaFldList flds, String[] crt_cols, Object... objs) {
|
||||
// init
|
||||
@@ -23,7 +33,7 @@ public class Db_tbl__crud_ {
|
||||
|
||||
// check if exists
|
||||
Db_stmt select_stmt = conn.Stmt_select(tbl_name, crt_cols, crt_cols);
|
||||
Add_arg(select_stmt, flds, crt_cols, objs, Bool_.Y, 0);
|
||||
Add_arg(select_stmt, flds, crt_cols, objs, BoolUtl.Y, 0);
|
||||
Db_rdr rdr = select_stmt.Exec_select__rls_auto();
|
||||
boolean exists = rdr.Move_next();
|
||||
rdr.Rls();
|
||||
@@ -32,8 +42,8 @@ public class Db_tbl__crud_ {
|
||||
// update
|
||||
if (exists) {
|
||||
Db_stmt update_stmt = conn.Stmt_update(tbl_name, crt_cols, val_cols);
|
||||
Add_arg(update_stmt, flds, val_cols, objs, Bool_.N, crt_cols_len);
|
||||
Add_arg(update_stmt, flds, crt_cols, objs, Bool_.Y, 0);
|
||||
Add_arg(update_stmt, flds, val_cols, objs, BoolUtl.N, crt_cols_len);
|
||||
Add_arg(update_stmt, flds, crt_cols, objs, BoolUtl.Y, 0);
|
||||
update_stmt.Exec_update();
|
||||
update_stmt.Rls();
|
||||
return false;
|
||||
@@ -41,8 +51,8 @@ public class Db_tbl__crud_ {
|
||||
// insert
|
||||
else {
|
||||
Db_stmt insert_stmt = conn.Stmt_insert(tbl_name, flds);
|
||||
Add_arg(insert_stmt, flds, crt_cols, objs, Bool_.N, 0);
|
||||
Add_arg(insert_stmt, flds, val_cols, objs, Bool_.N, crt_cols_len);
|
||||
Add_arg(insert_stmt, flds, crt_cols, objs, BoolUtl.N, 0);
|
||||
Add_arg(insert_stmt, flds, val_cols, objs, BoolUtl.N, crt_cols_len);
|
||||
insert_stmt.Exec_insert();
|
||||
insert_stmt.Rls();
|
||||
return true;
|
||||
|
||||
@@ -13,8 +13,16 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
import gplx.core.criterias.*;
|
||||
package gplx.dbs.sqls.wtrs;
|
||||
import gplx.Bry_bfr;
|
||||
import gplx.Bry_bfr_;
|
||||
import gplx.String_;
|
||||
import gplx.Tfds;
|
||||
import gplx.core.criterias.Criteria;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.sqls.SqlQryWtr;
|
||||
import gplx.dbs.sqls.SqlQryWtrUtl;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
class Sql_core_wtr_fxt {
|
||||
private final Sql_core_wtr__sqlite wtr = new Sql_core_wtr__sqlite();
|
||||
private final Sql_wtr_ctx ctx = new Sql_wtr_ctx(false);
|
||||
@@ -29,6 +37,6 @@ class Sql_core_wtr_fxt {
|
||||
Tfds.Eq_str_lines(String_.Concat_lines_nl_skip_last(expd), bfr.To_str_and_clear());
|
||||
}
|
||||
public void Test__qry(Db_qry qry, String expd) {
|
||||
Tfds.Eq_str_lines(expd, sql_wtr.ToSqlStr(qry, Bool_.N));
|
||||
Tfds.Eq_str_lines(expd, sql_wtr.ToSqlStr(qry, BoolUtl.N));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,13 +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.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
import org.junit.*;
|
||||
package gplx.dbs.sqls.wtrs;
|
||||
import gplx.Byte_;
|
||||
import gplx.DateAdp_;
|
||||
import gplx.Decimal_adp_;
|
||||
import gplx.Short_;
|
||||
import gplx.objects.primitives.BoolUtl;
|
||||
import org.junit.Test;
|
||||
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 Bool__n() {fxt.Test__val(BoolUtl.N , "0");}
|
||||
@Test public void Bool__y() {fxt.Test__val(BoolUtl.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");}
|
||||
|
||||
@@ -1,53 +1,55 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.sqls.wtrs; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
import org.junit.*; import gplx.core.criterias.*;
|
||||
public class Sql_where_wtr_tst {
|
||||
private final Sql_core_wtr_fxt fxt = new Sql_core_wtr_fxt();
|
||||
@Test public void Eq() {fxt.Test__where(Db_crt_.New_eq ("fld", 1) , "fld = 1");}
|
||||
@Test public void Eq_not() {fxt.Test__where(Db_crt_.New_eq_not ("fld", 1) , "fld != 1");}
|
||||
@Test public void Eq_pre() {fxt.Test__where(Db_crt_.New_eq ("a", "fld", 1) , "a.fld = 1");}
|
||||
@Test public void Lt() {fxt.Test__where(Db_crt_.New_lt ("fld", 1) , "fld < 1");}
|
||||
@Test public void Lte() {fxt.Test__where(Db_crt_.New_lte ("fld", 1) , "fld <= 1");}
|
||||
@Test public void Mt() {fxt.Test__where(Db_crt_.New_mt ("fld", 1) , "fld > 1");}
|
||||
@Test public void Mte() {fxt.Test__where(Db_crt_.New_mte ("fld", 1) , "fld >= 1");}
|
||||
@Test public void Between() {fxt.Test__where(Db_crt_.New_between ("fld", 1, 3) , "fld BETWEEN 1 AND 3");}
|
||||
@Test public void In() {fxt.Test__where(Db_crt_.New_in ("fld", 1, 2, 3) , "fld IN (1, 2, 3)");}
|
||||
@Test public void Like() {fxt.Test__where(Db_crt_.New_like ("fld", "A%") , "fld LIKE 'A%' ESCAPE '|'");}
|
||||
@Test public void And__subs__2() {
|
||||
fxt.Test__where
|
||||
( Criteria_.And
|
||||
( Db_crt_.New_eq("id", 1)
|
||||
, Db_crt_.New_eq("name", "me")
|
||||
), "(id = 1 AND name = 'me')");
|
||||
}
|
||||
@Test public void Or__subs__2() {
|
||||
fxt.Test__where
|
||||
( Criteria_.Or
|
||||
( Db_crt_.New_eq("id", 1)
|
||||
, Db_crt_.New_eq("name", "me")
|
||||
), "(id = 1 OR name = 'me')");
|
||||
}
|
||||
@Test public void Nested() {
|
||||
fxt.Test__where
|
||||
( Criteria_.Or
|
||||
( Db_crt_.New_eq("id", 1)
|
||||
, Criteria_.And
|
||||
( Db_crt_.New_eq("name", "me")
|
||||
, Db_crt_.New_eq("id", 2))
|
||||
), "(id = 1 OR (name = 'me' AND id = 2))");
|
||||
}
|
||||
}
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
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.
|
||||
|
||||
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.core.criterias.Criteria_;
|
||||
import gplx.dbs.Db_crt_;
|
||||
import org.junit.Test;
|
||||
public class Sql_where_wtr_tst {
|
||||
private final Sql_core_wtr_fxt fxt = new Sql_core_wtr_fxt();
|
||||
@Test public void Eq() {fxt.Test__where(Db_crt_.New_eq ("fld", 1) , "fld = 1");}
|
||||
@Test public void Eq_not() {fxt.Test__where(Db_crt_.New_eq_not ("fld", 1) , "fld != 1");}
|
||||
@Test public void Eq_pre() {fxt.Test__where(Db_crt_.New_eq ("a", "fld", 1) , "a.fld = 1");}
|
||||
@Test public void Lt() {fxt.Test__where(Db_crt_.New_lt ("fld", 1) , "fld < 1");}
|
||||
@Test public void Lte() {fxt.Test__where(Db_crt_.New_lte ("fld", 1) , "fld <= 1");}
|
||||
@Test public void Mt() {fxt.Test__where(Db_crt_.New_mt ("fld", 1) , "fld > 1");}
|
||||
@Test public void Mte() {fxt.Test__where(Db_crt_.New_mte ("fld", 1) , "fld >= 1");}
|
||||
@Test public void Between() {fxt.Test__where(Db_crt_.New_between ("fld", 1, 3) , "fld BETWEEN 1 AND 3");}
|
||||
@Test public void In() {fxt.Test__where(Db_crt_.New_in ("fld", 1, 2, 3) , "fld IN (1, 2, 3)");}
|
||||
@Test public void Like() {fxt.Test__where(Db_crt_.New_like ("fld", "A%") , "fld LIKE 'A%' ESCAPE '|'");}
|
||||
@Test public void And__subs__2() {
|
||||
fxt.Test__where
|
||||
( Criteria_.And
|
||||
( Db_crt_.New_eq("id", 1)
|
||||
, Db_crt_.New_eq("name", "me")
|
||||
), "(id = 1 AND name = 'me')");
|
||||
}
|
||||
@Test public void Or__subs__2() {
|
||||
fxt.Test__where
|
||||
( Criteria_.Or
|
||||
( Db_crt_.New_eq("id", 1)
|
||||
, Db_crt_.New_eq("name", "me")
|
||||
), "(id = 1 OR name = 'me')");
|
||||
}
|
||||
@Test public void Nested() {
|
||||
fxt.Test__where
|
||||
( Criteria_.Or
|
||||
( Db_crt_.New_eq("id", 1)
|
||||
, Criteria_.And
|
||||
( Db_crt_.New_eq("name", "me")
|
||||
, Db_crt_.New_eq("id", 2))
|
||||
), "(id = 1 OR (name = 'me' AND id = 2))");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user