mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Refactor: Refactor Dbmeta classes; Rename methods of list and hash classes
This commit is contained in:
@@ -13,16 +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.core.srls; import gplx.*; import gplx.core.*;
|
||||
import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
public class Dbmeta_dat_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public Dbmeta_dat_mgr Clear() {hash.Clear(); return this;}
|
||||
public int Len() {return hash.Count();}
|
||||
public Dbmeta_dat_itm Get_at(int idx) {return (Dbmeta_dat_itm)hash.Get_at(idx);}
|
||||
public Dbmeta_dat_mgr Add_int(String key, int val) {
|
||||
Dbmeta_dat_itm itm = new Dbmeta_dat_itm(Dbmeta_fld_tid.Tid__int, key, val);
|
||||
hash.Add(key, itm);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
package gplx.core.srls; import gplx.*;
|
||||
import gplx.dbs.*;
|
||||
public class Dbmeta_dat_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public Dbmeta_dat_mgr Clear() {hash.Clear(); return this;}
|
||||
public int Len() {return hash.Len();}
|
||||
public Dbmeta_dat_itm Get_at(int idx) {return (Dbmeta_dat_itm)hash.Get_at(idx);}
|
||||
public Dbmeta_dat_mgr Add_int(String key, int val) {
|
||||
Dbmeta_dat_itm itm = new Dbmeta_dat_itm(DbmetaFldType.TidInt, key, val);
|
||||
hash.Add(key, itm);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.stores; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.stores; import gplx.*;
|
||||
public class DbMaprItm {
|
||||
public String TableName() {return tableName;} public DbMaprItm TableName_(String val) {tableName = val; return this;} private String tableName;
|
||||
public Ordered_hash Flds() {return flds;} Ordered_hash flds = Ordered_hash_.New();
|
||||
@@ -23,7 +23,7 @@ public class DbMaprItm {
|
||||
|
||||
public DbMaprItm Flds_add(String objProp, String dbFld) {flds.Add(objProp, DbMaprArg.new_(objProp, dbFld)); return this;}
|
||||
public DbMaprItm ContextFlds_add(String s) {
|
||||
DbMaprArg arg = (DbMaprArg)flds.Get_by(s);
|
||||
DbMaprArg arg = (DbMaprArg)flds.GetByOrNull(s);
|
||||
contextFlds.Add(arg.ObjProp(), arg);
|
||||
return this;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class DbMaprItm {
|
||||
}
|
||||
throw Err_.new_missing_key(find);
|
||||
}
|
||||
public DbMaprArg Flds_get(String key) {return (DbMaprArg)flds.Get_by(key);}
|
||||
public DbMaprArg Flds_get(String key) {return (DbMaprArg)flds.GetByOrNull(key);}
|
||||
SrlObj proto; String key; List_adp subs = List_adp_.New();
|
||||
public static DbMaprItm proto_(SrlObj proto, String key, String tableName) {
|
||||
DbMaprItm rv = new DbMaprItm();
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.stores; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.stores; import gplx.*;
|
||||
public class DbMaprMgr {
|
||||
public DbMaprArg[] RootIndexFlds() {return rootIndexFlds;} public DbMaprMgr RootIndexFlds_(DbMaprArg... val) {rootIndexFlds = val; return this;} DbMaprArg[] rootIndexFlds;
|
||||
public DbMaprItm Root() {return root;} public DbMaprMgr Root_(DbMaprItm v) {root = v; return this;} DbMaprItm root;
|
||||
@@ -24,7 +24,7 @@ public class DbMaprMgr {
|
||||
for (Object argObj : mapr.ContextFlds()) {
|
||||
DbMaprArg arg = (DbMaprArg)argObj;
|
||||
Object contextVal = Gfo_invk_.Invk_by_key((Gfo_invk)gobj, arg.ObjProp());
|
||||
this.ContextVars().Add_if_dupe_use_nth(arg.DbFld(), contextVal);
|
||||
this.ContextVars().AddIfDupeUseNth(arg.DbFld(), contextVal);
|
||||
}
|
||||
this.OwnerStack().Add(gobj);
|
||||
this.MaprStack().Add(mapr);
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.stores; import gplx.*; import gplx.core.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.core.stores; import gplx.*;
|
||||
import gplx.core.criterias.*; import gplx.dbs.*; import gplx.core.gfo_ndes.*;
|
||||
public class DbMaprRdr extends DataRdr_base implements SrlMgr {
|
||||
@Override public String NameOfNode() {return "DbMaprRdr";}
|
||||
@Override public Object StoreRoot(SrlObj subProto, String key) {
|
||||
mgr = (DbMaprMgr)this.EnvVars().Get_by_or_fail(DbMaprWtr.Key_Mgr);
|
||||
mgr = (DbMaprMgr)this.EnvVars().GetByOrFail(DbMaprWtr.Key_Mgr);
|
||||
DbMaprItm rootMapr = mgr.Root();
|
||||
|
||||
GfoNde tbl = GetTbl(rootMapr, rootCrt); int subsCount = tbl.Subs().Count(); if (subsCount == 0) return null; if (subsCount > 1) throw Err_.new_wo_type("criteria returned > 1 row", "criteria", rootCrt.To_str(), "subsCount", subsCount);
|
||||
@@ -29,7 +29,7 @@ public class DbMaprRdr extends DataRdr_base implements SrlMgr {
|
||||
return root;
|
||||
}
|
||||
@Override public void SrlList(String subPropKey, List_adp list, SrlObj subProto, String itmKey) {
|
||||
DbMaprItm curMapr = (DbMaprItm)mgr.MaprStack().Get_at_last();
|
||||
DbMaprItm curMapr = (DbMaprItm)mgr.MaprStack().GetAtLast();
|
||||
DbMaprItm subMapr = curMapr.Subs_get(subPropKey);
|
||||
list.Clear();
|
||||
|
||||
@@ -56,7 +56,7 @@ public class DbMaprRdr extends DataRdr_base implements SrlMgr {
|
||||
}
|
||||
List_adp GetIdxFlds(DbMaprMgr mgr, DbMaprItm curMapr) {
|
||||
List_adp rv = List_adp_.New();
|
||||
int maprStackCount = mgr.MaprStack().Count() - 0; // -1 b/c current is added to stack
|
||||
int maprStackCount = mgr.MaprStack().Len() - 0; // -1 b/c current is added to stack
|
||||
for (int i = 0; i < maprStackCount; i ++) {
|
||||
DbMaprItm mapr = (DbMaprItm)mgr.MaprStack().Get_at(i);
|
||||
SrlObj gobj = (SrlObj)mgr.OwnerStack().Get_at(i);
|
||||
@@ -74,7 +74,7 @@ public class DbMaprRdr extends DataRdr_base implements SrlMgr {
|
||||
}
|
||||
GfoNde GetTbl(DbMaprItm mapr, Criteria crit) {
|
||||
String key = mapr.TableName();
|
||||
GfoNde tblByRootCrt = GfoNde_.as_(tables.Get_by(key));
|
||||
GfoNde tblByRootCrt = GfoNde_.as_(tables.GetByOrNull(key));
|
||||
if (tblByRootCrt == null) {
|
||||
DataRdr dbRdr = null;
|
||||
try {
|
||||
@@ -96,8 +96,8 @@ public class DbMaprRdr extends DataRdr_base implements SrlMgr {
|
||||
rowStack.Add(tbl.Subs().FetchAt_asGfoNde(i));
|
||||
}
|
||||
@Override public Object Read(String key) {
|
||||
DbMaprItm mapr = (DbMaprItm)mgr.MaprStack().Get_at_last();
|
||||
GfoNde row = (GfoNde)rowStack.Get_at_last();
|
||||
DbMaprItm mapr = (DbMaprItm)mgr.MaprStack().GetAtLast();
|
||||
GfoNde row = (GfoNde)rowStack.GetAtLast();
|
||||
DbMaprArg arg = mapr.Flds_get(key);
|
||||
Object dbVal = null; try {dbVal = row.Read(arg.DbFld());} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to read dbVal from row", "key", key, "fld", arg.DbFld());}
|
||||
return dbVal;
|
||||
|
||||
@@ -13,20 +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.core.stores; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.stores; import gplx.*;
|
||||
import gplx.core.criterias.*; import gplx.core.gfo_ndes.*;
|
||||
import gplx.dbs.*; import gplx.dbs.qrys.*;
|
||||
public class DbMaprWtr extends DataWtr_base implements DataWtr {
|
||||
public void InitWtr(String key, Object val) {}
|
||||
@Override public Object StoreRoot(SrlObj root, String key) {
|
||||
mgr = (DbMaprMgr)this.EnvVars().Get_by_or_fail(DbMaprWtr.Key_Mgr);
|
||||
mgr = (DbMaprMgr)this.EnvVars().GetByOrFail(DbMaprWtr.Key_Mgr);
|
||||
DbMaprWtrUtl.PurgeObjTree(root, mgr, conn);
|
||||
WriteGfoObj(root, mgr.Root());
|
||||
mgr.Clear();
|
||||
return null;
|
||||
}
|
||||
@Override public void SrlList(String subPropKey, List_adp list, SrlObj subProto, String itmKey) {
|
||||
DbMaprItm ownerMapr = (DbMaprItm)mgr.MaprStack().Get_at_last();
|
||||
DbMaprItm ownerMapr = (DbMaprItm)mgr.MaprStack().GetAtLast();
|
||||
DbMaprItm subMapr = ownerMapr.Subs_get(subPropKey);
|
||||
|
||||
for (Object subObj : list) {
|
||||
@@ -43,7 +43,7 @@ public class DbMaprWtr extends DataWtr_base implements DataWtr {
|
||||
mgr.EnvStack_del(mapr, gobj);
|
||||
}
|
||||
void WriteContextFlds() {
|
||||
int maprStackCount = mgr.MaprStack().Count() - 1; // -1 b/c current is added to stack
|
||||
int maprStackCount = mgr.MaprStack().Len() - 1; // -1 b/c current is added to stack
|
||||
for (int i = 0; i < maprStackCount; i ++) {
|
||||
DbMaprItm mapr = (DbMaprItm)mgr.MaprStack().Get_at(i);
|
||||
SrlObj gobj = (SrlObj)mgr.OwnerStack().Get_at(i);
|
||||
@@ -60,7 +60,7 @@ public class DbMaprWtr extends DataWtr_base implements DataWtr {
|
||||
insertCmd = null;
|
||||
}
|
||||
@Override public void WriteData(String name, Object val) {
|
||||
DbMaprItm ownerMapr = (DbMaprItm)mgr.MaprStack().Get_at_last();
|
||||
DbMaprItm ownerMapr = (DbMaprItm)mgr.MaprStack().GetAtLast();
|
||||
String fld = ""; try {fld = ownerMapr.Flds_get(name).DbFld();} catch (Exception e) {throw Err_.new_exc(e, "db", "failed to fetch fld from mapr", "key", name);}
|
||||
WriteDataVal(fld, val);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class Db_attach_mgr {
|
||||
}
|
||||
public String Resolve_sql(String sql) {
|
||||
attach_list.Clear();
|
||||
int hash_len = links_hash.Count();
|
||||
int hash_len = links_hash.Len();
|
||||
for (int i = 0; i < hash_len; ++i) {
|
||||
Db_attach_itm attach_itm = (Db_attach_itm)links_hash.Get_at(i);
|
||||
String tkn = "<" + attach_itm.Key + ">";
|
||||
@@ -86,7 +86,7 @@ public class Db_attach_mgr {
|
||||
}
|
||||
public String Test__attach_sql() {return attached_sql;} private String attached_sql;
|
||||
public String[] Test__attach_list_keys() {
|
||||
int rv_len = attach_list.Count();
|
||||
int rv_len = attach_list.Len();
|
||||
String[] rv = new String[rv_len];
|
||||
for (int i = 0; i < rv_len; ++i) {
|
||||
Db_attach_itm itm = (Db_attach_itm)attach_list.Get_at(i);
|
||||
@@ -98,12 +98,12 @@ public class Db_attach_mgr {
|
||||
attach_list.Clear();
|
||||
SqlQryWtr sql_wtr = main_conn.Engine().Sql_wtr();
|
||||
List_adp from_tbls = from_itm.Tbls;
|
||||
int from_tbls_len = from_tbls.Count();
|
||||
int from_tbls_len = from_tbls.Len();
|
||||
for (int i = 0; i < from_tbls_len; ++i) {
|
||||
Sql_tbl_itm from_tbl = (Sql_tbl_itm)from_tbls.Get_at(i);
|
||||
String from_tbl_db = from_tbl.Db;
|
||||
if (String_.Eq(Sql_tbl_itm.Db__null, from_tbl_db)) continue; // tbl does not have db defined; only "tbl" not "db.tbl"; skip
|
||||
Db_attach_itm attach_itm = (Db_attach_itm)links_hash.Get_by(from_tbl_db); if (attach_itm == null) throw Err_.new_("dbs", "qry defines an unknown database for attach_wkr", "from_tbl_db", from_tbl_db, "sql", qry.To_sql__exec(sql_wtr));
|
||||
Db_attach_itm attach_itm = (Db_attach_itm)links_hash.GetByOrNull(from_tbl_db); if (attach_itm == null) throw Err_.new_("dbs", "qry defines an unknown database for attach_wkr", "from_tbl_db", from_tbl_db, "sql", qry.ToSqlExec(sql_wtr));
|
||||
if (attach_itm.Url.Eq(main_conn_url)) // attach_db same as conn; blank db, so "tbl", not "db.tbl"
|
||||
from_tbl.Db_enabled = false;
|
||||
else
|
||||
|
||||
@@ -78,8 +78,8 @@ public class Db_conn {
|
||||
public void Meta_idx_create(Gfo_usr_dlg usr_dlg, Dbmeta_idx_itm... idxs) {engine.Meta_idx_create(usr_dlg, idxs);}
|
||||
public void Meta_idx_delete(String idx) {engine.Meta_idx_delete(idx);}
|
||||
public void Meta_idx_delete(String tbl, String suffix) {engine.Meta_idx_delete(tbl + "__" + suffix);}
|
||||
public void Meta_fld_append(String tbl, Dbmeta_fld_itm fld) {engine.Meta_fld_append(tbl, fld);}
|
||||
public void Meta_fld_assert(String tbl, String fld, Dbmeta_fld_tid tid, Object dflt) {if (!Meta_fld_exists(tbl, fld)) this.Meta_fld_append(tbl, new Dbmeta_fld_itm(fld, tid).Default_(dflt));}
|
||||
public void Meta_fld_append(String tbl, DbmetaFldItm fld) {engine.Meta_fld_append(tbl, fld);}
|
||||
public void Meta_fld_assert(String tbl, String fld, DbmetaFldType tid, Object dflt) {if (!Meta_fld_exists(tbl, fld)) this.Meta_fld_append(tbl, new DbmetaFldItm(fld, tid).DefaultValSet(dflt));}
|
||||
public boolean Meta_tbl_exists(String tbl) {return engine.Meta_tbl_exists(tbl);}
|
||||
public boolean Meta_fld_exists(String tbl, String fld) {return engine.Meta_fld_exists(tbl, fld);}
|
||||
public boolean Meta_idx_exists(String idx) {return engine.Meta_idx_exists(idx);}
|
||||
@@ -94,7 +94,7 @@ public class Db_conn {
|
||||
}
|
||||
if (dirty) this.Meta_mgr().Load_all();
|
||||
}
|
||||
public String Meta_fld_append_if_missing(String tbl_name, Dbmeta_fld_list flds, Dbmeta_fld_itm fld) {
|
||||
public String Meta_fld_append_if_missing(String tbl_name, DbmetaFldList flds, DbmetaFldItm fld) {
|
||||
String fld_name = fld.Name();
|
||||
// if fld doesn't exist, add it; NOTE: need to check if tbl exists first else meta_fld not available
|
||||
if ( this.Meta_tbl_exists(tbl_name)
|
||||
@@ -102,7 +102,7 @@ public class Db_conn {
|
||||
try {this.Meta_fld_append(tbl_name, fld);}
|
||||
catch (Exception e) {
|
||||
Gfo_log_.Instance.Warn("failed to append fld", "conn", this.Conn_info().Db_api(), "tbl", tbl_name, "fld", fld_name, "err", Err_.Message_gplx_log(e));
|
||||
fld_name = Dbmeta_fld_itm.Key_null;
|
||||
fld_name = DbmetaFldItm.KeyNull;
|
||||
}
|
||||
}
|
||||
// if fld does exist, or tbl doesn't exist, just add fld to collection
|
||||
@@ -113,15 +113,15 @@ public class Db_conn {
|
||||
return fld_name;
|
||||
}
|
||||
public Dbmeta_tbl_mgr Meta_mgr() {return engine.Meta_mgr();}
|
||||
public Db_stmt Stmt_insert(String tbl, Dbmeta_fld_list flds) {return engine.Stmt_by_qry(Db_qry_insert.new_(tbl, flds.To_str_ary_wo_autonum()));}
|
||||
public Db_stmt Stmt_insert(String tbl, DbmetaFldList flds) {return engine.Stmt_by_qry(Db_qry_insert.new_(tbl, flds.ToStrAryWoAutonum()));}
|
||||
public Db_stmt Stmt_insert(String tbl, String... cols) {return engine.Stmt_by_qry(Db_qry_insert.new_(tbl, cols));}
|
||||
public Db_stmt Stmt_update(String tbl, String[] where, String... cols) {return engine.Stmt_by_qry(Db_qry_update.New(tbl, where, cols));}
|
||||
public Db_stmt Stmt_update_exclude(String tbl, Dbmeta_fld_list flds, String... where) {return engine.Stmt_by_qry(Db_qry_update.New(tbl, where, flds.To_str_ary_exclude(where)));}
|
||||
public Db_stmt Stmt_update_exclude(String tbl, DbmetaFldList flds, String... where) {return engine.Stmt_by_qry(Db_qry_update.New(tbl, where, flds.ToStrAryExclude(where)));}
|
||||
public Db_stmt Stmt_delete(String tbl, String... where) {return engine.Stmt_by_qry(Db_qry_delete.new_(tbl, where));}
|
||||
public Db_stmt Stmt_select_all(String tbl, Dbmeta_fld_list flds) {return engine.Stmt_by_qry(Db_qry__select_in_tbl.new_(tbl, String_.Ary_empty, flds.To_str_ary(), null));}
|
||||
public Db_stmt Stmt_select_all(String tbl, DbmetaFldList flds) {return engine.Stmt_by_qry(Db_qry__select_in_tbl.new_(tbl, String_.Ary_empty, flds.ToStrAry(), null));}
|
||||
public Db_stmt Stmt_select(String tbl, String[] cols, String... where) {return engine.Stmt_by_qry(Db_qry__select_in_tbl.new_(tbl, where, cols, null));}
|
||||
public Db_stmt Stmt_select(String tbl, Dbmeta_fld_list flds, String... where) {return engine.Stmt_by_qry(Db_qry__select_in_tbl.new_(tbl, where, flds.To_str_ary(), null));}
|
||||
public Db_stmt Stmt_select_order(String tbl, Dbmeta_fld_list flds, String[] where, String... orderbys) {return engine.Stmt_by_qry(Db_qry__select_in_tbl.new_(tbl, where, flds.To_str_ary(), orderbys));}
|
||||
public Db_stmt Stmt_select(String tbl, DbmetaFldList flds, String... where) {return engine.Stmt_by_qry(Db_qry__select_in_tbl.new_(tbl, where, flds.ToStrAry(), null));}
|
||||
public Db_stmt Stmt_select_order(String tbl, DbmetaFldList flds, String[] where, String... orderbys) {return engine.Stmt_by_qry(Db_qry__select_in_tbl.new_(tbl, where, flds.ToStrAry(), orderbys));}
|
||||
public Db_stmt Stmt_select_order(String tbl, String[] flds, String[] where, String... orderbys) {return engine.Stmt_by_qry(Db_qry__select_in_tbl.new_(tbl, where, flds, orderbys));}
|
||||
public Db_stmt Stmt_new(Db_qry qry) {return engine.Stmt_by_qry(qry);}
|
||||
public Db_stmt Stmt_sql(String sql) {return engine.Stmt_by_qry(Db_qry_sql.sql_(sql));}
|
||||
@@ -163,7 +163,7 @@ public class Db_conn {
|
||||
rls_list.Add(rls);
|
||||
}
|
||||
public void Rls_conn() {
|
||||
int len = rls_list.Count();
|
||||
int len = rls_list.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Rls_able itm = (Rls_able)rls_list.Get_at(i);
|
||||
itm.Rls();
|
||||
|
||||
@@ -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; import gplx.*;
|
||||
import gplx.dbs.engines.sqlite.*; import gplx.dbs.qrys.bats.*;
|
||||
import gplx.dbs.engines.sqlite.*;
|
||||
public interface Db_conn_bldr_wkr {
|
||||
void Clear_for_tests();
|
||||
boolean Exists(Io_url url);
|
||||
@@ -53,7 +53,7 @@ class Db_conn_bldr_wkr__mem implements Db_conn_bldr_wkr {
|
||||
}
|
||||
public Db_conn New(Io_url url) {
|
||||
String io_url_str = url.Xto_api();
|
||||
hash.Add_if_dupe_use_nth(io_url_str, io_url_str); // NOTE: tests can call New multiple times; don't fail if exists; just overwrite existing entry; DATE:2016-04-21
|
||||
hash.AddIfDupeUseNth(io_url_str, io_url_str); // NOTE: tests can call New multiple times; don't fail if exists; just overwrite existing entry; DATE:2016-04-21
|
||||
return Get_or_new(url);
|
||||
}
|
||||
private Db_conn Get_or_new(Io_url url) {
|
||||
|
||||
@@ -36,7 +36,7 @@ class Db_conn_info_pool {
|
||||
this.Add(Noop_conn_info.Instance).Add(Tdb_conn_info.Instance).Add(Mysql_conn_info.Instance).Add(Postgres_conn_info.Instance).Add(Sqlite_conn_info.Instance);
|
||||
this.Add(Mem_conn_info.Instance);
|
||||
}
|
||||
public Db_conn_info_pool Add(Db_conn_info itm) {regy.Add_if_dupe_use_nth(itm.Key(), itm); return this;}
|
||||
public Db_conn_info_pool Add(Db_conn_info itm) {regy.AddIfDupeUseNth(itm.Key(), itm); return this;}
|
||||
public Db_conn_info Parse(String raw) {// assume each pair has format of: name=val;
|
||||
try {
|
||||
Keyval_hash hash = new Keyval_hash();
|
||||
@@ -50,7 +50,7 @@ class Db_conn_info_pool {
|
||||
else
|
||||
hash.Add(kv[0], kv[1]);
|
||||
}
|
||||
Db_conn_info prototype = (Db_conn_info)regy.Get_by(url_tid);
|
||||
Db_conn_info prototype = (Db_conn_info)regy.GetByOrNull(url_tid);
|
||||
return prototype.New_self(raw, hash);
|
||||
}
|
||||
catch(Exception exc) {throw Err_.new_parse_exc(exc, Db_conn_info.class, raw);}
|
||||
@@ -79,7 +79,7 @@ class Db_conn_info_pool {
|
||||
hash.Add(Sqlite_conn_info.Cs__data_source, sqlite_url.Raw());
|
||||
hash.Add(Sqlite_conn_info.Cs__version , Sqlite_conn_info.Cs__version__3);
|
||||
}
|
||||
Db_conn_info prototype = (Db_conn_info)regy.Get_by(cs_tid);
|
||||
Db_conn_info prototype = (Db_conn_info)regy.GetByOrNull(cs_tid);
|
||||
return prototype.New_self(raw, hash);
|
||||
}
|
||||
public static final Db_conn_info_pool Instance = new Db_conn_info_pool();
|
||||
|
||||
@@ -22,9 +22,9 @@ public class Db_conn_pool { // PURPOSE: cache one connection per connection_stri
|
||||
public void Del(Db_conn_info url) {hash.Del(url.Db_api());}
|
||||
public Db_conn Get_or_new(String s) {return Get_or_new(Db_conn_info_.parse(s));}
|
||||
public Db_conn Get_or_new(Db_conn_info url) {
|
||||
Db_conn rv = (Db_conn)hash.Get_by(url.Db_api());
|
||||
Db_conn rv = (Db_conn)hash.GetByOrNull(url.Db_api());
|
||||
if (rv == null) {
|
||||
Db_engine prime = (Db_engine)prime_hash.Get_by(url.Key()); if (prime == null) Err_.new_wo_type("db engine prototype not found", "key", url.Key());
|
||||
Db_engine prime = (Db_engine)prime_hash.GetByOrNull(url.Key()); if (prime == null) Err_.new_wo_type("db engine prototype not found", "key", url.Key());
|
||||
Db_engine clone = prime.New_clone(url);
|
||||
rv = new Db_conn(clone);
|
||||
clone.Batch_mgr().Copy(clone.Tid(), batch_mgr);
|
||||
|
||||
@@ -1,46 +1,45 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.dbs.metas.*;
|
||||
public class Db_conn_utl {
|
||||
public static Db_conn Conn__new(String url_rel) {
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
return Db_conn_bldr.Instance.Get_or_new(Io_url_.mem_fil_("mem/" + url_rel)).Conn();
|
||||
}
|
||||
public static void Tbl__new(Db_conn conn, String tbl, Dbmeta_fld_itm[] flds, Object[]... rows) {
|
||||
public static void Tbl__new(Db_conn conn, String tbl, DbmetaFldItm[] flds, Object[]... rows) {
|
||||
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl, flds));
|
||||
int rows_len = rows.length;
|
||||
Db_stmt stmt = conn.Stmt_insert(tbl, Dbmeta_fld_itm.To_str_ary(flds));
|
||||
Db_stmt stmt = conn.Stmt_insert(tbl, DbmetaFldItm.ToStrAry(flds));
|
||||
for (int i = 0; i < rows_len; ++i) {
|
||||
Object[] row = rows[i];
|
||||
int dat_len = row.length;
|
||||
stmt.Clear();
|
||||
for (int j = 0; j < dat_len; ++j) {
|
||||
Dbmeta_fld_itm fld = flds[j];
|
||||
DbmetaFldItm fld = flds[j];
|
||||
String fld_name = fld.Name();
|
||||
Object val = row[j];
|
||||
switch (fld.Type().Tid_ansi()) {
|
||||
case Dbmeta_fld_tid.Tid__bool: stmt.Val_bool_as_byte (fld_name, Bool_.Cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__byte: stmt.Val_byte (fld_name, Byte_.Cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__int: stmt.Val_int (fld_name, Int_.Cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__long: stmt.Val_long (fld_name, Long_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__float: stmt.Val_float (fld_name, Float_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__double: stmt.Val_double (fld_name, Double_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__str: stmt.Val_str (fld_name, String_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__bry: stmt.Val_bry (fld_name, Bry_.cast(val)); break;
|
||||
switch (fld.Type().Tid()) {
|
||||
case DbmetaFldType.TidBool: stmt.Val_bool_as_byte (fld_name, Bool_.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;
|
||||
case DbmetaFldType.TidFloat: stmt.Val_float (fld_name, Float_.cast(val)); break;
|
||||
case DbmetaFldType.TidDouble: stmt.Val_double (fld_name, Double_.cast(val)); break;
|
||||
case DbmetaFldType.TidStr: stmt.Val_str (fld_name, String_.cast(val)); break;
|
||||
case DbmetaFldType.TidBry: stmt.Val_bry (fld_name, Bry_.cast(val)); break;
|
||||
}
|
||||
}
|
||||
stmt.Exec_insert();
|
||||
@@ -70,6 +69,6 @@ public class Db_conn_utl {
|
||||
rv.Add(row);
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
return (Object[][])rv.To_ary_and_clear(Object[].class);
|
||||
return (Object[][])rv.ToAryAndClear(Object[].class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class Db_crt_ {
|
||||
int len = ary.length;
|
||||
int crt_idx = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
String itm = ary[i]; if (itm == Dbmeta_fld_itm.Key_null) continue;
|
||||
String itm = ary[i]; if (itm == DbmetaFldItm.KeyNull) continue;
|
||||
Criteria crt = Db_crt_.New_eq(itm, null);
|
||||
rv = (crt_idx == 0) ? crt : Criteria_.And(rv, crt);
|
||||
++crt_idx;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
Copyright (C) 2012-2021 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
@@ -16,8 +16,8 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
package gplx.dbs;
|
||||
import gplx.dbs.sqls.SqlQryWtr;
|
||||
public interface Db_qry {
|
||||
int Tid();
|
||||
boolean Exec_is_rdr();
|
||||
String Base_table();
|
||||
String To_sql__exec(SqlQryWtr wtr);
|
||||
int Tid();
|
||||
boolean ReturnsRdr();
|
||||
String BaseTable();
|
||||
String ToSqlExec(SqlQryWtr wtr);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
Copyright (C) 2012-2021 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
@@ -22,14 +22,14 @@ import gplx.dbs.qrys.Db_qry_insert;
|
||||
import gplx.dbs.qrys.Db_qry_update;
|
||||
import gplx.dbs.sqls.itms.Sql_join_fld;
|
||||
public class Db_qry_ {
|
||||
public static Db_qry__select_cmd select_cols_(String tbl, Criteria crt, String... cols){return select_().From_(tbl).Where_(crt).Cols_(cols);}
|
||||
public static Db_qry__select_cmd select_val_(String tbl, String col, Criteria crt) {return select_().From_(tbl).Where_(crt).Cols_(col);}
|
||||
public static Db_qry__select_cmd select_cols_(String tbl, Criteria crt, String... cols) {return select_().From_(tbl).Where_(crt).Cols_(cols);}
|
||||
public static Db_qry__select_cmd select_val_(String tbl, String col, Criteria crt) {return select_().From_(tbl).Where_(crt).Cols_(col);}
|
||||
public static Db_qry__select_cmd select_tbl_(String tbl) {return select_().From_(tbl).Cols_all_();}
|
||||
public static Db_qry__select_cmd select_() {return new Db_qry__select_cmd();}
|
||||
public static Db_qry__select_cmd select_(String tbl, String... cols) {return new Db_qry__select_cmd().From_(tbl).Cols_(cols);}
|
||||
public static Db_qry_delete delete_(String tbl, Criteria crt) {return Db_qry_delete.new_(tbl, crt);}
|
||||
public static Db_qry_delete delete_tbl_(String tbl) {return Db_qry_delete.new_(tbl);}
|
||||
public static Db_qry_insert insert_(String tbl) {return new Db_qry_insert(tbl);}
|
||||
public static Db_qry__select_cmd select_() {return new Db_qry__select_cmd();}
|
||||
public static Db_qry__select_cmd select_(String tbl, String... cols) {return new Db_qry__select_cmd().From_(tbl).Cols_(cols);}
|
||||
public static Db_qry_delete delete_(String tbl, Criteria crt) {return Db_qry_delete.new_(tbl, crt);}
|
||||
public static Db_qry_delete delete_tbl_(String tbl) {return Db_qry_delete.new_(tbl);}
|
||||
public static Db_qry_insert insert_(String tbl) {return new Db_qry_insert(tbl);}
|
||||
public static Db_qry_insert insert_common_(String tbl, Keyval... pairs) {
|
||||
Db_qry_insert cmd = new Db_qry_insert(tbl);
|
||||
for (Keyval pair : pairs)
|
||||
@@ -58,9 +58,17 @@ public class Db_qry_ {
|
||||
gplx.core.stores.DataRdr rdr = conn.Exec_qry_as_old_rdr(qry);
|
||||
try {
|
||||
return rdr.MoveNextPeer() ? rdr.Read(qry.Cols().Flds.Get_at(0).Fld) : null; // NOTE: need to access from flds for tdb
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
|
||||
public static Db_qry as_(Object obj) {return obj instanceof Db_qry ? (Db_qry)obj : null;}
|
||||
public static final int Tid_insert = 0, Tid_delete = 1, Tid_update = 2, Tid_select = 3, Tid_sql = 4, Tid_select_in_tbl = 5, Tid_flush = 6, Tid_noop = 7, Tid_pragma = 8;
|
||||
public static final int
|
||||
Tid_insert = 0,
|
||||
Tid_delete = 1,
|
||||
Tid_update = 2,
|
||||
Tid_select = 3,
|
||||
Tid_sql = 4,
|
||||
Tid_select_in_tbl = 5,
|
||||
Tid_flush = 6,
|
||||
Tid_pragma = 8;
|
||||
}
|
||||
|
||||
@@ -1,76 +1,77 @@
|
||||
/*
|
||||
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.core.criterias.*;
|
||||
interface Db_sql_qry {
|
||||
String Tbl_main();
|
||||
}
|
||||
class Db_sql_qry__select {
|
||||
public Db_sql_qry__select(String from) {this.from = from;}
|
||||
public String From() {return from;} private final String from;
|
||||
public Db_sql_col[] Select() {return select;} private Db_sql_col[] select;
|
||||
// public Criteria Where() {return where;} private Criteria where;
|
||||
// public Db_sql_col[] Group_bys() {return group_bys;} private Db_sql_col[] group_bys;
|
||||
// public Db_sql_col[] Order_bys() {return order_bys;} private Db_sql_col[] order_bys;
|
||||
// public int Limit() {return limit;} private int limit;
|
||||
// public int Offset() {return offset;} private int offset;
|
||||
public Db_sql_qry__select Select_all_() {this.select = Db_sql_col_.Ary(new Db_sql_col__all(0, from)); return this;}
|
||||
public Db_sql_qry__select Select_flds_(String... ary) {this.select = Db_sql_col_bldr.Instance.new_fld_many(ary); return this;}
|
||||
public static Db_sql_qry__select new_(String from) {return new Db_sql_qry__select(from);}
|
||||
}
|
||||
class Db_sql_bldr {
|
||||
public void Test() {
|
||||
// Db_sql_qry__select qry = null;
|
||||
// qry = Db_sql_qry__select.new_("tbl").Select_all_();
|
||||
// qry = Db_sql_qry__select.new_("tbl").Select_flds_("fld1", "fld2");
|
||||
// qry = Db_sql_qry__select.new_("tbl").Select_flds_("fld1", "fld2").Where_("fld3");
|
||||
// , String_.Ary("col1", "col2"), String_.Ary("col3")).Limit_(10).;
|
||||
// Db_sql_qry__select qry = Db_sql_qry__select_.new_("tbl").Cols_("col1", "col2").Where_eq_one("col3").Limit_(10);
|
||||
}
|
||||
}
|
||||
interface Db_sql_col {
|
||||
int Ord();
|
||||
String Alias();
|
||||
}
|
||||
class Db_sql_col_ {
|
||||
public static Db_sql_col[] Ary(Db_sql_col... v) {return v;}
|
||||
}
|
||||
class Db_sql_col_bldr {
|
||||
private final List_adp tmp_list = List_adp_.New();
|
||||
public Db_sql_col[] new_fld_many(String[] ary) {
|
||||
tmp_list.Clear();
|
||||
int ord = -1;
|
||||
for (int i = 0; i < ary.length; ++i) {
|
||||
String fld_key = ary[i];
|
||||
if (fld_key == Dbmeta_fld_itm.Key_null) continue;
|
||||
Db_sql_col__name fld = new Db_sql_col__name(++ord, fld_key);
|
||||
tmp_list.Add(fld);
|
||||
}
|
||||
return (Db_sql_col[])tmp_list.To_ary_and_clear(Db_sql_col.class);
|
||||
}
|
||||
public static final Db_sql_col_bldr Instance = new Db_sql_col_bldr(); Db_sql_col_bldr() {}
|
||||
}
|
||||
class Db_sql_col__name {
|
||||
public Db_sql_col__name(int ord, String key) {this.ord = ord; this.key = key;}
|
||||
public int Ord() {return ord;} private final int ord;
|
||||
public String Key() {return key;} private final String key;
|
||||
}
|
||||
class Db_sql_col__all implements Db_sql_col {
|
||||
public Db_sql_col__all(int ord, String tbl) {this.ord = ord; this.tbl = tbl;}
|
||||
public int Ord() {return ord;} private final int ord;
|
||||
public String Tbl() {return tbl;} private final String tbl;
|
||||
public String Alias() {return "*";}
|
||||
}
|
||||
/*
|
||||
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;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
interface Db_sql_qry {
|
||||
String Tbl_main();
|
||||
}
|
||||
class Db_sql_qry__select {
|
||||
public Db_sql_qry__select(String from) {this.from = from;}
|
||||
public String From() {return from;} private final String from;
|
||||
public Db_sql_col[] Select() {return select;} private Db_sql_col[] select;
|
||||
// public Criteria Where() {return where;} private Criteria where;
|
||||
// public Db_sql_col[] Group_bys() {return group_bys;} private Db_sql_col[] group_bys;
|
||||
// public Db_sql_col[] Order_bys() {return order_bys;} private Db_sql_col[] order_bys;
|
||||
// public int Limit() {return limit;} private int limit;
|
||||
// public int Offset() {return offset;} private int offset;
|
||||
public Db_sql_qry__select Select_all_() {this.select = Db_sql_col_.Ary(new Db_sql_col__all(0, from)); return this;}
|
||||
public Db_sql_qry__select Select_flds_(String... ary) {this.select = Db_sql_col_bldr.Instance.new_fld_many(ary); return this;}
|
||||
public static Db_sql_qry__select new_(String from) {return new Db_sql_qry__select(from);}
|
||||
}
|
||||
class Db_sql_bldr {
|
||||
public void Test() {
|
||||
// Db_sql_qry__select qry = null;
|
||||
// qry = Db_sql_qry__select.new_("tbl").Select_all_();
|
||||
// qry = Db_sql_qry__select.new_("tbl").Select_flds_("fld1", "fld2");
|
||||
// qry = Db_sql_qry__select.new_("tbl").Select_flds_("fld1", "fld2").Where_("fld3");
|
||||
// , String_.Ary("col1", "col2"), String_.Ary("col3")).Limit_(10).;
|
||||
// Db_sql_qry__select qry = Db_sql_qry__select_.new_("tbl").Cols_("col1", "col2").Where_eq_one("col3").Limit_(10);
|
||||
}
|
||||
}
|
||||
interface Db_sql_col {
|
||||
int Ord();
|
||||
String Alias();
|
||||
}
|
||||
class Db_sql_col_ {
|
||||
public static Db_sql_col[] Ary(Db_sql_col... v) {return v;}
|
||||
}
|
||||
class Db_sql_col_bldr {
|
||||
private final List_adp tmp_list = List_adp_.New();
|
||||
public Db_sql_col[] new_fld_many(String[] ary) {
|
||||
tmp_list.Clear();
|
||||
int ord = -1;
|
||||
for (int i = 0; i < ary.length; ++i) {
|
||||
String fld_key = ary[i];
|
||||
if (fld_key == DbmetaFldItm.KeyNull) continue;
|
||||
Db_sql_col__name fld = new Db_sql_col__name(++ord, fld_key);
|
||||
tmp_list.Add(fld);
|
||||
}
|
||||
return (Db_sql_col[])tmp_list.ToAryAndClear(Db_sql_col.class);
|
||||
}
|
||||
public static final Db_sql_col_bldr Instance = new Db_sql_col_bldr(); Db_sql_col_bldr() {}
|
||||
}
|
||||
class Db_sql_col__name {
|
||||
public Db_sql_col__name(int ord, String key) {this.ord = ord; this.key = key;}
|
||||
public int Ord() {return ord;} private final int ord;
|
||||
public String Key() {return key;} private final String key;
|
||||
}
|
||||
class Db_sql_col__all implements Db_sql_col {
|
||||
public Db_sql_col__all(int ord, String tbl) {this.ord = ord; this.tbl = tbl;}
|
||||
public int Ord() {return ord;} private final int ord;
|
||||
public String Tbl() {return tbl;} private final String tbl;
|
||||
public String Alias() {return "*";}
|
||||
}
|
||||
|
||||
@@ -71,27 +71,27 @@ public class Db_stmt_ {
|
||||
default: throw Err_.new_unhandled_default(tid);
|
||||
}
|
||||
}
|
||||
public static void Insert_by_rdr(Dbmeta_fld_list flds, Db_rdr rdr, Db_stmt stmt) {
|
||||
public static void Insert_by_rdr(DbmetaFldList flds, Db_rdr rdr, Db_stmt stmt) {
|
||||
stmt.Clear();
|
||||
Fill_by_rdr(flds, rdr, stmt);
|
||||
stmt.Exec_insert();
|
||||
}
|
||||
private static void Fill_by_rdr(Dbmeta_fld_list flds, Db_rdr rdr, Db_stmt stmt) {
|
||||
private static void Fill_by_rdr(DbmetaFldList flds, Db_rdr rdr, Db_stmt stmt) {
|
||||
int flds_len = flds.Len();
|
||||
for (int i = 0; i < flds_len; i++) {
|
||||
Dbmeta_fld_itm fld = (Dbmeta_fld_itm)flds.Get_at(i);
|
||||
DbmetaFldItm fld = (DbmetaFldItm)flds.GetAt(i);
|
||||
String fld_name = fld.Name();
|
||||
int fld_tid = fld.Type().Tid_ansi();
|
||||
int fld_tid = fld.Type().Tid();
|
||||
if (fld.Autonum()) continue;
|
||||
switch (fld_tid) {
|
||||
case Dbmeta_fld_tid.Tid__bool: stmt.Val_bool_as_byte (fld_name, rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__byte: stmt.Val_byte (fld_name, rdr.Read_byte(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__int: stmt.Val_int (fld_name, rdr.Read_int(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__long: stmt.Val_long (fld_name, rdr.Read_long(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__float: stmt.Val_float (fld_name, rdr.Read_float(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__double: stmt.Val_double (fld_name, rdr.Read_double(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__str: stmt.Val_str (fld_name, rdr.Read_str(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__bry: stmt.Val_bry (fld_name, rdr.Read_bry(fld_name)); break;
|
||||
case DbmetaFldType.TidBool: stmt.Val_bool_as_byte (fld_name, rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case DbmetaFldType.TidByte: stmt.Val_byte (fld_name, rdr.Read_byte(fld_name)); break;
|
||||
case DbmetaFldType.TidInt: stmt.Val_int (fld_name, rdr.Read_int(fld_name)); break;
|
||||
case DbmetaFldType.TidLong: stmt.Val_long (fld_name, rdr.Read_long(fld_name)); break;
|
||||
case DbmetaFldType.TidFloat: stmt.Val_float (fld_name, rdr.Read_float(fld_name)); break;
|
||||
case DbmetaFldType.TidDouble: stmt.Val_double (fld_name, rdr.Read_double(fld_name)); break;
|
||||
case DbmetaFldType.TidStr: stmt.Val_str (fld_name, rdr.Read_str(fld_name)); break;
|
||||
case DbmetaFldType.TidBry: stmt.Val_bry (fld_name, rdr.Read_bry(fld_name)); break;
|
||||
default: throw Err_.new_unhandled_default_w_msg(fld_tid, fld_name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Db_stmt_bldr {
|
||||
private Db_conn conn; private Db_stmt create, update, delete;
|
||||
private String tbl_name; private String[] flds_keys, flds_vals, flds_all;
|
||||
public void Conn_(Db_conn v, String tbl_name, Dbmeta_fld_list flds, String... flds_keys) {
|
||||
Conn_(v, tbl_name, flds.To_str_ary(), flds.To_str_ary_exclude(flds_keys), flds_keys);
|
||||
public void Conn_(Db_conn v, String tbl_name, DbmetaFldList flds, String... flds_keys) {
|
||||
Conn_(v, tbl_name, flds.ToStrAry(), flds.ToStrAryExclude(flds_keys), flds_keys);
|
||||
}
|
||||
public void Conn_(Db_conn v, String tbl_name, String[] flds_vals, String... flds_keys) {
|
||||
Conn_(v, tbl_name, String_.Ary_add(flds_keys, flds_vals), flds_vals, flds_keys);
|
||||
|
||||
83
140_dbs/src/gplx/dbs/DbmetaFldItm.java
Normal file
83
140_dbs/src/gplx/dbs/DbmetaFldItm.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
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;
|
||||
import gplx.Int_;
|
||||
import gplx.Object_;
|
||||
import gplx.String_;
|
||||
public class DbmetaFldItm {
|
||||
public DbmetaFldItm(String name, DbmetaFldType type) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.primary = false;
|
||||
this.autonum = false;
|
||||
this.defaultVal = DefaultValNull;
|
||||
}
|
||||
public String Name() {return name;} private final String name;
|
||||
public DbmetaFldType Type() {return type;} private final DbmetaFldType type;
|
||||
public int Nullable() {return nullable;} public DbmetaFldItm NullableSet(int v) {nullable = v; return this;} private int nullable;
|
||||
public DbmetaFldItm NullableSetNull() {return NullableSet(NullableNull);}
|
||||
public boolean Primary() {return primary;} public DbmetaFldItm PrimarySetY() {primary = true; return this;} private boolean primary; public DbmetaFldItm PrimarySetN() {primary = false; return this;}
|
||||
public boolean Autonum() {return autonum;} public DbmetaFldItm AutonumSetY() {autonum = true; return this;} private boolean autonum;
|
||||
public Object DefaultVal() {return defaultVal;} public DbmetaFldItm DefaultValSet(Object v) {defaultVal = v; return this;} private Object defaultVal;
|
||||
public boolean Eq(DbmetaFldItm comp) {
|
||||
return String_.Eq(name, comp.name)
|
||||
&& type.Eq(comp.type)
|
||||
&& nullable == comp.nullable
|
||||
&& primary == comp.primary
|
||||
&& autonum == comp.autonum
|
||||
&& Object_.Eq(defaultVal, comp.defaultVal);
|
||||
}
|
||||
public static final int NullableUnspecified = 0, NullableNull = 1, NullableNotNull = 2;
|
||||
public static final Object DefaultValNull = null;
|
||||
public static final String KeyNull = null;
|
||||
public static final DbmetaFldItm[] AryEmpty = new DbmetaFldItm[0];
|
||||
|
||||
public static DbmetaFldItm NewBool(String name) {return new DbmetaFldItm(name, DbmetaFldType.ItmBool);}
|
||||
public static DbmetaFldItm NewByte(String name) {return new DbmetaFldItm(name, DbmetaFldType.ItmByte);}
|
||||
public static DbmetaFldItm NewShort(String name) {return new DbmetaFldItm(name, DbmetaFldType.ItmShort);}
|
||||
public static DbmetaFldItm NewInt(String name) {return new DbmetaFldItm(name, DbmetaFldType.ItmInt);}
|
||||
public static DbmetaFldItm NewLong(String name) {return new DbmetaFldItm(name, DbmetaFldType.ItmLong);}
|
||||
public static DbmetaFldItm NewFloat(String name) {return new DbmetaFldItm(name, DbmetaFldType.ItmFloat);}
|
||||
public static DbmetaFldItm NewDouble(String name) {return new DbmetaFldItm(name, DbmetaFldType.ItmDouble);}
|
||||
public static DbmetaFldItm NewText(String name) {return new DbmetaFldItm(name, DbmetaFldType.ItmText);}
|
||||
public static DbmetaFldItm NewBry(String name) {return new DbmetaFldItm(name, DbmetaFldType.ItmBry);}
|
||||
public static DbmetaFldItm NewStr(String name, int len) {return new DbmetaFldItm(name, DbmetaFldType.ItmStr(len));}
|
||||
public static String[] ToStrAry(DbmetaFldItm[] ary) {
|
||||
int len = ary.length;
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv[i] = ary[i].name;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static final String[] StrAryEmpty = String_.Ary_empty; // marker constant; should add overrides
|
||||
public static String Make_or_null(Db_conn conn, DbmetaFldList flds, String tbl_name, int fld_type, Object fld_dflt, String fld_name) {
|
||||
boolean tbl_exists = conn.Meta_tbl_exists(tbl_name);
|
||||
boolean fld_exists = true;
|
||||
if (tbl_exists) {
|
||||
fld_exists = conn.Meta_fld_exists(tbl_name, fld_name);
|
||||
if (!fld_exists) return DbmetaFldItm.KeyNull;
|
||||
}
|
||||
DbmetaFldItm fld = null;
|
||||
switch (fld_type) {
|
||||
case DbmetaFldType.TidInt: fld = DbmetaFldItm.NewInt(fld_name); break;
|
||||
}
|
||||
if (fld_dflt != null) fld.DefaultValSet(fld_dflt);
|
||||
flds.Add(fld);
|
||||
return fld.name;
|
||||
}
|
||||
public static String ToDoubleStrByInt(int v) {return Int_.To_str(v) + ".0";} // move
|
||||
}
|
||||
102
140_dbs/src/gplx/dbs/DbmetaFldList.java
Normal file
102
140_dbs/src/gplx/dbs/DbmetaFldList.java
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
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;
|
||||
import gplx.Hash_adp;
|
||||
import gplx.Hash_adp_;
|
||||
import gplx.List_adp;
|
||||
import gplx.List_adp_;
|
||||
import gplx.objects.lists.GfoIndexedList;
|
||||
public class DbmetaFldList {
|
||||
private final GfoIndexedList<String, DbmetaFldItm> flds = new GfoIndexedList<>();
|
||||
public void Clear() {flds.Clear();}
|
||||
public int Len() {return flds.Len();}
|
||||
public boolean Has(String key) {return flds.Has(key);}
|
||||
public DbmetaFldItm GetByOrNull(String name) {return flds.GetByOrNull(name);}
|
||||
public DbmetaFldItm GetAt(int idx) {return flds.GetAt(idx);}
|
||||
public void Del(String key) {flds.DelBy(key);}
|
||||
public void AddAt(int pos, DbmetaFldItm fld) {flds.AddAt(pos, fld.Name(), fld);}
|
||||
public String AddBool(String name) {return Add(DbmetaFldItm.NewBool(name));}
|
||||
public String AddByte(String name) {return Add(DbmetaFldItm.NewByte(name));}
|
||||
public String AddShort(String name) {return Add(DbmetaFldItm.NewShort(name));}
|
||||
public String AddInt(String name) {return Add(DbmetaFldItm.NewInt(name));}
|
||||
public String AddIntPkey(String name) {return Add(DbmetaFldItm.NewInt(name).PrimarySetY());}
|
||||
public String AddIntPkeyAutonum(String name) {return Add(DbmetaFldItm.NewInt(name).PrimarySetY().AutonumSetY());}
|
||||
public String AddIntDflt(String name, int dflt) {return Add(DbmetaFldItm.NewInt(name).DefaultValSet(dflt));}
|
||||
public String AddLong(String name) {return Add(DbmetaFldItm.NewLong(name));}
|
||||
public String AddLongNull(String name) {return Add(DbmetaFldItm.NewLong(name).NullableSetNull());}
|
||||
public String AddFloat(String name) {return Add(DbmetaFldItm.NewFloat(name));}
|
||||
public String AddDouble(String name) {return Add(DbmetaFldItm.NewDouble(name));}
|
||||
public String AddText(String name) {return Add(DbmetaFldItm.NewText(name));}
|
||||
public String AddBry(String name) {return Add(DbmetaFldItm.NewBry(name));}
|
||||
public String AddStr(String name, int len) {return Add(DbmetaFldItm.NewStr(name, len));}
|
||||
public String AddDate(String name) {return Add(DbmetaFldItm.NewStr(name, 32));}
|
||||
public String AddStrPkey(String name, int len) {return Add(DbmetaFldItm.NewStr(name, len).PrimarySetY());}
|
||||
public String AddStrNull(String name, int len) {return Add(DbmetaFldItm.NewStr(name, len).NullableSetNull());}
|
||||
public String AddStrDflt(String name, int len, String dflt) {return Add(DbmetaFldItm.NewStr(name, len).DefaultValSet(dflt));}
|
||||
public DbmetaFldList BldInt(String name) {AddInt(name); return this;}
|
||||
public DbmetaFldList BldStr(String name) {return BldStr(name, 255);}
|
||||
public DbmetaFldList BldStr(String name, int len) {AddStr(name, len); return this;}
|
||||
public String Add(DbmetaFldItm fld) {
|
||||
String name = fld.Name();
|
||||
flds.Add(name, fld);
|
||||
return name;
|
||||
}
|
||||
|
||||
public DbmetaFldList Clone() {
|
||||
DbmetaFldList rv = new DbmetaFldList();
|
||||
int len = this.Len();
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv.Add(this.GetAt(i));
|
||||
return rv;
|
||||
}
|
||||
public DbmetaFldItm[] ToFldAry() {return flds.ToAry(DbmetaFldItm.class);}
|
||||
public String[] ToStrAry() {
|
||||
int len = flds.Len();
|
||||
String[] strAry = new String[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
DbmetaFldItm fld = (DbmetaFldItm)flds.GetAt(i);
|
||||
strAry[i] = fld.Name();
|
||||
}
|
||||
return strAry;
|
||||
}
|
||||
public String[] ToStrAryWoAutonum() {
|
||||
int len = flds.Len();
|
||||
List_adp rv = List_adp_.New();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
DbmetaFldItm fld = (DbmetaFldItm)flds.GetAt(i);
|
||||
if (fld.Autonum()) continue;
|
||||
rv.Add(fld.Name());
|
||||
}
|
||||
return (String[])rv.ToAry(String.class);
|
||||
}
|
||||
public String[] ToStrAryExclude(String[] ary) {
|
||||
Hash_adp ary_hash = Hash_adp_.New();
|
||||
List_adp rv = List_adp_.New();
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; ++i) {
|
||||
String ary_itm = ary[i];
|
||||
ary_hash.Add(ary_itm, ary_itm);
|
||||
}
|
||||
int fld_len = flds.Len();
|
||||
for (int i = 0; i < fld_len; ++i) {
|
||||
DbmetaFldItm fld = (DbmetaFldItm)flds.GetAt(i);
|
||||
String fld_key = fld.Name();
|
||||
if (ary_hash.Has(fld_key)) continue;
|
||||
rv.Add(fld_key);
|
||||
}
|
||||
return rv.ToStrAry();
|
||||
}
|
||||
}
|
||||
97
140_dbs/src/gplx/dbs/DbmetaFldType.java
Normal file
97
140_dbs/src/gplx/dbs/DbmetaFldType.java
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
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;
|
||||
import gplx.Err_;
|
||||
import gplx.Type_ids_;
|
||||
import gplx.objects.strings.String_;
|
||||
public class DbmetaFldType {
|
||||
public DbmetaFldType(int tid, String name, int len1, int len2) {
|
||||
this.tid = tid;
|
||||
this.name = name;
|
||||
this.len1 = len1;
|
||||
this.len2 = len2;
|
||||
}
|
||||
public int Tid() {return tid;} private final int tid;
|
||||
public String Name() {return name;} private final String name;
|
||||
public int Len1() {return len1;} private final int len1; // length in bytes or precision
|
||||
public int Len2() {return len2;} private final int len2; // scaling
|
||||
public boolean Eq(DbmetaFldType comp) {
|
||||
return tid == comp.tid
|
||||
&& String_.Eq(name, comp.name)
|
||||
&& len1 == comp.len1
|
||||
&& len2 == comp.len2;
|
||||
}
|
||||
public static final int
|
||||
TidBool = 0,
|
||||
TidByte = 1,
|
||||
TidShort = 2,
|
||||
TidInt = 3,
|
||||
TidLong = 4,
|
||||
TidFloat = 5,
|
||||
TidDouble = 6,
|
||||
TidStr = 7,
|
||||
TidText = 8,
|
||||
TidBry = 9,
|
||||
TidDecimal = 10,
|
||||
TidDate = 11;
|
||||
public static final DbmetaFldType
|
||||
ItmBool = new DbmetaFldType(DbmetaFldType.TidBool, "bit", -1, -1),
|
||||
ItmByte = new DbmetaFldType(DbmetaFldType.TidByte, "tinyint", -1, -1),
|
||||
ItmShort = new DbmetaFldType(DbmetaFldType.TidShort, "smallint", -1, -1),
|
||||
ItmInt = new DbmetaFldType(DbmetaFldType.TidInt, "integer", -1, -1),
|
||||
ItmLong = new DbmetaFldType(DbmetaFldType.TidLong, "bigint", -1, -1),
|
||||
ItmFloat = new DbmetaFldType(DbmetaFldType.TidFloat, "float", -1, -1),
|
||||
ItmDouble = new DbmetaFldType(DbmetaFldType.TidDouble, "double", -1, -1),
|
||||
ItmText = new DbmetaFldType(DbmetaFldType.TidText, "text", -1, -1),
|
||||
ItmBry = new DbmetaFldType(DbmetaFldType.TidBry, "blob", -1, -1),
|
||||
ItmDate = new DbmetaFldType(DbmetaFldType.TidDate, "date", -1, -1);
|
||||
public static DbmetaFldType ItmStr(int len) {return new DbmetaFldType(DbmetaFldType.TidStr, "varchar", len, -1);}
|
||||
public static DbmetaFldType ItmDecimal(int len_1, int len_2) {return new DbmetaFldType(DbmetaFldType.TidDecimal, "decimal", len_1, len_2);}
|
||||
public static DbmetaFldType New(int tid, int len1) {
|
||||
switch (tid) {
|
||||
case DbmetaFldType.TidBool: return ItmBool;
|
||||
case DbmetaFldType.TidByte: return ItmByte;
|
||||
case DbmetaFldType.TidShort: return ItmShort;
|
||||
case DbmetaFldType.TidInt: return ItmInt;
|
||||
case DbmetaFldType.TidLong: return ItmLong;
|
||||
case DbmetaFldType.TidFloat: return ItmFloat;
|
||||
case DbmetaFldType.TidDouble: return ItmDouble;
|
||||
case DbmetaFldType.TidStr: return ItmStr(len1);
|
||||
case DbmetaFldType.TidText: return ItmText;
|
||||
case DbmetaFldType.TidBry: return ItmBry;
|
||||
case DbmetaFldType.TidDate: return ItmDate;
|
||||
case DbmetaFldType.TidDecimal: // return Itm__decimal(len1);
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public static int GetTypeIdByObj(Object o) {
|
||||
int type_id = Type_ids_.To_id_by_obj(o);
|
||||
switch (type_id) {
|
||||
case Type_ids_.Id__bool: return DbmetaFldType.TidBool;
|
||||
case Type_ids_.Id__byte: return DbmetaFldType.TidByte;
|
||||
case Type_ids_.Id__short: return DbmetaFldType.TidShort;
|
||||
case Type_ids_.Id__int: return DbmetaFldType.TidInt;
|
||||
case Type_ids_.Id__long: return DbmetaFldType.TidLong;
|
||||
case Type_ids_.Id__float: return DbmetaFldType.TidFloat;
|
||||
case Type_ids_.Id__double: return DbmetaFldType.TidDouble;
|
||||
case Type_ids_.Id__str: return DbmetaFldType.TidStr;
|
||||
case Type_ids_.Id__bry: return DbmetaFldType.TidBry;
|
||||
case Type_ids_.Id__date: return DbmetaFldType.TidDate;
|
||||
case Type_ids_.Id__decimal: return DbmetaFldType.TidDecimal;
|
||||
default: throw Err_.new_unhandled_default(type_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
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.metas.*;
|
||||
public class Dbmeta_fld_itm {
|
||||
public Dbmeta_fld_itm(String name, Dbmeta_fld_tid type) {
|
||||
this.name = name; this.type = type;
|
||||
this.primary = false; this.autonum = false; this.default_val = Default_value_null;
|
||||
}
|
||||
public String Name() {return name;} private final String name;
|
||||
public Dbmeta_fld_tid Type() {return type;} private final Dbmeta_fld_tid type;
|
||||
public int Nullable_tid() {return nullable_tid;} public Dbmeta_fld_itm Nullable_tid_(int v) {nullable_tid = v; return this;} private int nullable_tid;
|
||||
public Dbmeta_fld_itm Nullable_y_() {return Nullable_tid_(Nullable_null);}
|
||||
public boolean Primary() {return primary;} public Dbmeta_fld_itm Primary_y_() {primary = true; return this;} private boolean primary; public Dbmeta_fld_itm Primary_n_() {primary = false; return this;}
|
||||
public boolean Autonum() {return autonum;} public Dbmeta_fld_itm Autonum_y_() {autonum = true; return this;} private boolean autonum;
|
||||
public Object Default() {return default_val;} public Dbmeta_fld_itm Default_(Object v) {default_val = v; return this;} private Object default_val;
|
||||
public boolean Eq(Dbmeta_fld_itm comp) {
|
||||
return String_.Eq(name, comp.name)
|
||||
&& type.Eq(comp.type)
|
||||
&& nullable_tid == comp.nullable_tid
|
||||
&& primary == comp.primary
|
||||
&& autonum == comp.autonum
|
||||
&& Object_.Eq(default_val, comp.default_val);
|
||||
}
|
||||
|
||||
public static final int Nullable_unknown = 0, Nullable_null = 1, Nullable_not_null = 2;
|
||||
public static final Object Default_value_null = null;
|
||||
public static final String Key_null = null;
|
||||
public static final String[] Str_ary_empty = String_.Ary_empty;
|
||||
public static final Dbmeta_fld_itm[] Ary_empty = new Dbmeta_fld_itm[0];
|
||||
|
||||
public static Dbmeta_fld_itm new_bool(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__bool);}
|
||||
public static Dbmeta_fld_itm new_byte(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__byte);}
|
||||
public static Dbmeta_fld_itm new_short(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__short);}
|
||||
public static Dbmeta_fld_itm new_int(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__int);}
|
||||
public static Dbmeta_fld_itm new_long(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__long);}
|
||||
public static Dbmeta_fld_itm new_float(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__float);}
|
||||
public static Dbmeta_fld_itm new_double(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__double);}
|
||||
public static Dbmeta_fld_itm new_text(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__text);}
|
||||
public static Dbmeta_fld_itm new_bry(String name) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__bry);}
|
||||
public static Dbmeta_fld_itm new_str(String name, int len) {return new Dbmeta_fld_itm(name, Dbmeta_fld_tid.Itm__str(len));}
|
||||
public static String[] To_str_ary(Dbmeta_fld_itm[] ary) {
|
||||
int len = ary.length;
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv[i] = ary[i].name;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static String Make_or_null(Db_conn conn, Dbmeta_fld_list flds, String tbl_name, int fld_type, Object fld_dflt, String fld_name) {
|
||||
boolean tbl_exists = conn.Meta_tbl_exists(tbl_name);
|
||||
boolean fld_exists = true;
|
||||
if (tbl_exists) {
|
||||
fld_exists = conn.Meta_fld_exists(tbl_name, fld_name);
|
||||
if (!fld_exists) return Dbmeta_fld_itm.Key_null;
|
||||
}
|
||||
Dbmeta_fld_itm fld = null;
|
||||
switch (fld_type) {
|
||||
case Dbmeta_fld_tid.Tid__int: fld = Dbmeta_fld_itm.new_int(fld_name); break;
|
||||
}
|
||||
if (fld_dflt != null) fld.Default_(fld_dflt);
|
||||
flds.Add(fld);
|
||||
return fld.name;
|
||||
}
|
||||
public static String To_double_str_by_int(int v) {return Int_.To_str(v) + ".0";}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs; import gplx.*;
|
||||
public class Dbmeta_fld_list {
|
||||
private final Ordered_hash flds = Ordered_hash_.New();
|
||||
public void Clear() {flds.Clear(); str_ary = null; fld_ary = null;}
|
||||
public int Len() {return flds.Len();}
|
||||
public boolean Has(String key) {return flds.Has(key);}
|
||||
public Dbmeta_fld_itm Get_by(String name) {return (Dbmeta_fld_itm)flds.Get_by(name);}
|
||||
public Dbmeta_fld_itm Get_at(int idx) {return (Dbmeta_fld_itm)flds.Get_at(idx);}
|
||||
public String Add_bool(String name) {return Add(Dbmeta_fld_itm.new_bool(name));}
|
||||
public String Add_byte(String name) {return Add(Dbmeta_fld_itm.new_byte(name));}
|
||||
public String Add_short(String name) {return Add(Dbmeta_fld_itm.new_short(name));}
|
||||
public String Add_int(String name) {return Add(Dbmeta_fld_itm.new_int(name));}
|
||||
public String Add_int_pkey(String name) {return Add(Dbmeta_fld_itm.new_int(name).Primary_y_());}
|
||||
public String Add_int_pkey_autonum(String name) {return Add(Dbmeta_fld_itm.new_int(name).Primary_y_().Autonum_y_());}
|
||||
public String Add_int_autonum(String name) {return Add(Dbmeta_fld_itm.new_int(name).Autonum_y_());}
|
||||
public String Add_int_dflt(String name, int dflt) {return Add(Dbmeta_fld_itm.new_int(name).Default_(dflt));}
|
||||
public String Add_int_null(String name) {return Add(Dbmeta_fld_itm.new_int(name).Nullable_y_());}
|
||||
public String Add_long(String name) {return Add(Dbmeta_fld_itm.new_long(name));}
|
||||
public String Add_long_null(String name) {return Add(Dbmeta_fld_itm.new_long(name).Nullable_y_());}
|
||||
public String Add_float(String name) {return Add(Dbmeta_fld_itm.new_float(name));}
|
||||
public String Add_double(String name) {return Add(Dbmeta_fld_itm.new_double(name));}
|
||||
public String Add_text(String name) {return Add(Dbmeta_fld_itm.new_text(name));}
|
||||
public String Add_bry(String name) {return Add(Dbmeta_fld_itm.new_bry(name));}
|
||||
public String Add_str(String name, int len) {return Add(Dbmeta_fld_itm.new_str(name, len));}
|
||||
public String Add_date(String name) {return Add(Dbmeta_fld_itm.new_str(name, 32));}
|
||||
public String Add_str_pkey(String name, int len) {return Add(Dbmeta_fld_itm.new_str(name, len).Primary_y_());}
|
||||
public String Add_str_null(String name, int len) {return Add(Dbmeta_fld_itm.new_str(name, len).Nullable_y_());}
|
||||
public String Add_str_dflt(String name, int len, String dflt)
|
||||
{return Add(Dbmeta_fld_itm.new_str(name, len).Default_(dflt));}
|
||||
public Dbmeta_fld_list Bld_int(String name) {Add_int(name); return this;}
|
||||
public Dbmeta_fld_list Bld_str(String name) {return Bld_str(name, 255);}
|
||||
public Dbmeta_fld_list Bld_str(String name, int len){Add_str(name, len); return this;}
|
||||
|
||||
public String Add(Dbmeta_fld_itm fld) {
|
||||
fld_ary = null; str_ary = null;
|
||||
String name = fld.Name();
|
||||
flds.Add(name, fld);
|
||||
return name;
|
||||
}
|
||||
public void Del(String key) {
|
||||
fld_ary = null; str_ary = null;
|
||||
flds.Del(key);
|
||||
}
|
||||
public void Insert(int pos, Dbmeta_fld_itm fld) {
|
||||
fld_ary = null; str_ary = null;
|
||||
flds.Add_at(pos, fld);
|
||||
}
|
||||
|
||||
public Dbmeta_fld_list New_int(String name) {Add(Dbmeta_fld_itm.new_int(name)); return this;}
|
||||
public Dbmeta_fld_list New_fld(Dbmeta_fld_itm fld) {Add(fld); return this;}
|
||||
public Dbmeta_fld_list Clone() {
|
||||
Dbmeta_fld_list rv = new Dbmeta_fld_list();
|
||||
int len = this.Len();
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv.Add(this.Get_at(i));
|
||||
return rv;
|
||||
}
|
||||
public Dbmeta_fld_itm[] To_fld_ary() {if (fld_ary == null) fld_ary = (Dbmeta_fld_itm[])flds.To_ary(Dbmeta_fld_itm.class); return fld_ary;} private Dbmeta_fld_itm[] fld_ary;
|
||||
public String[] To_str_ary() {
|
||||
if (str_ary == null) {
|
||||
int len = flds.Len();
|
||||
this.str_ary = new String[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbmeta_fld_itm fld = (Dbmeta_fld_itm)flds.Get_at(i);
|
||||
str_ary[i] = fld.Name();
|
||||
}
|
||||
}
|
||||
return str_ary;
|
||||
} private String[] str_ary;
|
||||
public String[] To_str_ary_wo_autonum() {
|
||||
int len = flds.Count();
|
||||
List_adp rv = List_adp_.New();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbmeta_fld_itm fld = (Dbmeta_fld_itm)flds.Get_at(i);
|
||||
if (fld.Autonum()) continue;
|
||||
rv.Add(fld.Name());
|
||||
}
|
||||
return (String[])rv.To_ary(String.class);
|
||||
}
|
||||
public String[] To_str_ary_exclude(String[] ary) {
|
||||
Hash_adp ary_hash = Hash_adp_.New();
|
||||
List_adp rv = List_adp_.New();
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; ++i) {
|
||||
String ary_itm = ary[i];
|
||||
ary_hash.Add(ary_itm, ary_itm);
|
||||
}
|
||||
int fld_len = flds.Count();
|
||||
for (int i = 0; i < fld_len; ++i) {
|
||||
Dbmeta_fld_itm fld = (Dbmeta_fld_itm)flds.Get_at(i);
|
||||
String fld_key = fld.Name();
|
||||
if (ary_hash.Has(fld_key)) continue;
|
||||
rv.Add(fld_key);
|
||||
}
|
||||
return rv.To_str_ary();
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
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.engines.sqlite.*; // for Tid_sqlite; note that Tid_sqlite is not used, and only exists for doc purposes
|
||||
public class Dbmeta_fld_tid {
|
||||
public Dbmeta_fld_tid(int tid_ansi, int tid_sqlite, byte[] name, int len_1, int len_2) {
|
||||
this.tid_ansi = tid_ansi; this.tid_sqlite = tid_sqlite; this.name = name; this.len_1 = len_1; this.len_2 = len_2;
|
||||
}
|
||||
public int Tid_ansi() {return tid_ansi;} private final int tid_ansi;
|
||||
public int Tid_sqlite() {return tid_sqlite;} private final int tid_sqlite;
|
||||
public byte[] Name() {return name;} private final byte[] name;
|
||||
public int Len_1() {return len_1;} private final int len_1;
|
||||
public int Len_2() {return len_2;} private final int len_2;
|
||||
public boolean Eq(Dbmeta_fld_tid comp) {
|
||||
return tid_ansi == comp.tid_ansi
|
||||
&& tid_sqlite == comp.tid_sqlite
|
||||
&& Bry_.Eq(name, comp.name)
|
||||
&& len_1 == comp.len_1
|
||||
&& len_2 == comp.len_2;
|
||||
}
|
||||
|
||||
public static final int Tid__bool = 0, Tid__byte = 1, Tid__short = 2, Tid__int = 3, Tid__long = 4, Tid__float = 5, Tid__double = 6, Tid__str = 7, Tid__text = 8, Tid__bry = 9, Tid__decimal = 10, Tid__date = 11;
|
||||
public static final Dbmeta_fld_tid
|
||||
Itm__byte = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__byte , Sqlite_tid.Tid_int , Bry_.new_a7("tinyint") , -1, -1)
|
||||
, Itm__short = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__short , Sqlite_tid.Tid_int , Bry_.new_a7("smallint") , -1, -1)
|
||||
, Itm__int = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__int , Sqlite_tid.Tid_int , Bry_.new_a7("integer") , -1, -1)
|
||||
, Itm__long = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__long , Sqlite_tid.Tid_int , Bry_.new_a7("bigint") , -1, -1)
|
||||
, Itm__text = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__text , Sqlite_tid.Tid_text , Bry_.new_a7("text") , -1, -1)
|
||||
, Itm__bry = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__bry , Sqlite_tid.Tid_none , Bry_.new_a7("blob") , -1, -1)
|
||||
, Itm__float = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__float , Sqlite_tid.Tid_real , Bry_.new_a7("float") , -1, -1)
|
||||
, Itm__double = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__double , Sqlite_tid.Tid_real , Bry_.new_a7("double") , -1, -1)
|
||||
, Itm__numeric = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__decimal , Sqlite_tid.Tid_numeric , Bry_.new_a7("numeric") , -1, -1)
|
||||
, Itm__bool = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__bool , Sqlite_tid.Tid_numeric , Bry_.new_a7("bit") , -1, -1) // "bit" is not SQLITE
|
||||
, Itm__date = new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__date , Sqlite_tid.Tid_numeric , Bry_.new_a7("date") , -1, -1)
|
||||
;
|
||||
public static Dbmeta_fld_tid Itm__str (int len) {return new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__str , Sqlite_tid.Tid_text , Bry_.new_a7("varchar") , len, -1);}
|
||||
public static Dbmeta_fld_tid Itm__decimal (int len_1, int len_2) {return new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__decimal , Sqlite_tid.Tid_numeric , Bry_.new_a7("decimal") , len_1, len_2);}
|
||||
public static Dbmeta_fld_tid New(int tid, int len1) {
|
||||
switch (tid) {
|
||||
case Dbmeta_fld_tid.Tid__bool: return Itm__bool;
|
||||
case Dbmeta_fld_tid.Tid__byte: return Itm__byte;
|
||||
case Dbmeta_fld_tid.Tid__short: return Itm__short;
|
||||
case Dbmeta_fld_tid.Tid__int: return Itm__int;
|
||||
case Dbmeta_fld_tid.Tid__long: return Itm__long;
|
||||
case Dbmeta_fld_tid.Tid__float: return Itm__float;
|
||||
case Dbmeta_fld_tid.Tid__double: return Itm__double;
|
||||
case Dbmeta_fld_tid.Tid__str: return Itm__str(len1);
|
||||
case Dbmeta_fld_tid.Tid__text: return Itm__text;
|
||||
case Dbmeta_fld_tid.Tid__bry: return Itm__bry;
|
||||
case Dbmeta_fld_tid.Tid__date: return Itm__date;
|
||||
case Dbmeta_fld_tid.Tid__decimal: // return Itm__decimal(len1);
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public static int Get_by_obj(Object o) {
|
||||
int type_id = Type_ids_.To_id_by_obj(o);
|
||||
switch (type_id) {
|
||||
case Type_ids_.Id__bool: return Dbmeta_fld_tid.Tid__bool;
|
||||
case Type_ids_.Id__byte: return Dbmeta_fld_tid.Tid__byte;
|
||||
case Type_ids_.Id__short: return Dbmeta_fld_tid.Tid__short;
|
||||
case Type_ids_.Id__int: return Dbmeta_fld_tid.Tid__int;
|
||||
case Type_ids_.Id__long: return Dbmeta_fld_tid.Tid__long;
|
||||
case Type_ids_.Id__float: return Dbmeta_fld_tid.Tid__float;
|
||||
case Type_ids_.Id__double: return Dbmeta_fld_tid.Tid__double;
|
||||
case Type_ids_.Id__str: return Dbmeta_fld_tid.Tid__str;
|
||||
case Type_ids_.Id__bry: return Dbmeta_fld_tid.Tid__bry;
|
||||
case Type_ids_.Id__date: return Dbmeta_fld_tid.Tid__date;
|
||||
case Type_ids_.Id__decimal: return Dbmeta_fld_tid.Tid__decimal;
|
||||
default: throw Err_.new_unhandled_default(type_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,9 +21,9 @@ public class Dbmeta_tbl_itm {
|
||||
public Dbmeta_fld_mgr Flds() {return flds;} private final Dbmeta_fld_mgr flds = new Dbmeta_fld_mgr();
|
||||
public String To_sql_create(SqlQryWtr sql_wtr) {return sql_wtr.Schema_wtr().Bld_create_tbl(this);}
|
||||
|
||||
public static Dbmeta_tbl_itm New(String name, Dbmeta_fld_list flds, Dbmeta_idx_itm... idxs) {return New(name, flds.To_fld_ary(), idxs);}
|
||||
public static Dbmeta_tbl_itm New(String name, Dbmeta_fld_itm... flds) {return New(name, flds, Dbmeta_idx_itm.Ary_empty);}
|
||||
public static Dbmeta_tbl_itm New(String name, Dbmeta_fld_itm[] flds, Dbmeta_idx_itm... idxs) {
|
||||
public static Dbmeta_tbl_itm New(String name, DbmetaFldList flds, Dbmeta_idx_itm... idxs) {return New(name, flds.ToFldAry(), idxs);}
|
||||
public static Dbmeta_tbl_itm New(String name, DbmetaFldItm... flds) {return New(name, flds, Dbmeta_idx_itm.Ary_empty);}
|
||||
public static Dbmeta_tbl_itm New(String name, DbmetaFldItm[] flds, Dbmeta_idx_itm... idxs) {
|
||||
Dbmeta_tbl_itm rv = new Dbmeta_tbl_itm();
|
||||
rv.name = name;
|
||||
if (flds != null) {
|
||||
|
||||
@@ -13,12 +13,12 @@ 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.conn_props; import gplx.*; import gplx.dbs.*;
|
||||
package gplx.dbs.conn_props; import gplx.*;
|
||||
public class Db_conn_props_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public boolean Has(String key) {return hash.Has(key);}
|
||||
public boolean Match(String key, String expd_val) {
|
||||
String actl_val = (String)hash.Get_by(key);
|
||||
String actl_val = (String)hash.GetByOrNull(key);
|
||||
return actl_val == null ? false : String_.Eq(expd_val,actl_val);
|
||||
}
|
||||
public void Add(String key, String val) {hash.Add(key, val);}
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.dbs.metas.*;
|
||||
public class Gfdb_diff_tbl {
|
||||
public Gfdb_diff_tbl(String name, Dbmeta_fld_itm[] flds, Dbmeta_fld_itm[] keys, Dbmeta_fld_itm[] vals) {
|
||||
public Gfdb_diff_tbl(String name, DbmetaFldItm[] flds, DbmetaFldItm[] keys, DbmetaFldItm[] vals) {
|
||||
this.Name = name; this.Flds = flds; this.Keys = keys; this.Vals = vals;
|
||||
}
|
||||
public final String Name;
|
||||
public final Dbmeta_fld_itm[] Flds;
|
||||
public final Dbmeta_fld_itm[] Keys;
|
||||
public final Dbmeta_fld_itm[] Vals;
|
||||
public final DbmetaFldItm[] Flds;
|
||||
public final DbmetaFldItm[] Keys;
|
||||
public final DbmetaFldItm[] Vals;
|
||||
public Db_rdr Make_rdr(Db_conn conn) {
|
||||
Db_stmt stmt = conn.Stmt_select_order(Name, Dbmeta_fld_itm.To_str_ary(Flds), Dbmeta_fld_itm.Str_ary_empty, Dbmeta_fld_itm.To_str_ary(Keys));
|
||||
Db_stmt stmt = conn.Stmt_select_order(Name, DbmetaFldItm.ToStrAry(Flds), DbmetaFldItm.StrAryEmpty, DbmetaFldItm.ToStrAry(Keys));
|
||||
return stmt.Exec_select__rls_auto();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class Gfdb_diff_tbl {
|
||||
Dbmeta_fld_mgr flds = tbl.Flds();
|
||||
int flds_len = flds.Len();
|
||||
for (int i = 0; i < flds_len; ++i) {
|
||||
Dbmeta_fld_itm fld = flds.Get_at(i);
|
||||
DbmetaFldItm fld = flds.Get_at(i);
|
||||
if (fld.Primary()) {
|
||||
rv.Add(fld);
|
||||
return rv;
|
||||
@@ -67,7 +67,7 @@ public class Gfdb_diff_tbl {
|
||||
}
|
||||
// just add all
|
||||
for (int i = 0; i < flds_len; ++i) {
|
||||
Dbmeta_fld_itm fld = flds.Get_at(i);
|
||||
DbmetaFldItm fld = flds.Get_at(i);
|
||||
rv.Add(fld);
|
||||
}
|
||||
return rv;
|
||||
@@ -76,7 +76,7 @@ public class Gfdb_diff_tbl {
|
||||
Dbmeta_fld_mgr rv = new Dbmeta_fld_mgr();
|
||||
int flds_len = flds.Len();
|
||||
for (int i = 0; i < flds_len; ++i) {
|
||||
Dbmeta_fld_itm fld = flds.Get_at(i);
|
||||
DbmetaFldItm fld = flds.Get_at(i);
|
||||
if (!keys.Has(fld.Name())) rv.Add(fld);
|
||||
}
|
||||
return rv;
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs; import gplx.*; import gplx.dbs.*;
|
||||
class Gfdb_diff_tbl_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Len() {return hash.Count();}
|
||||
public int Len() {return hash.Len();}
|
||||
public Gfdb_diff_tbl Get_at(int idx) {return (Gfdb_diff_tbl)hash.Get_at(idx);}
|
||||
public Gfdb_diff_tbl Get_by(String key) {return (Gfdb_diff_tbl)hash.Get_by(key);}
|
||||
public Gfdb_diff_tbl Get_by(String key) {return (Gfdb_diff_tbl)hash.GetByOrNull(key);}
|
||||
}
|
||||
class Gfdb_diff_tbl_mgr__sqlite {
|
||||
public void Fill(Gfdb_diff_tbl_mgr tbl_mgr, Db_conn conn) {
|
||||
|
||||
@@ -1,74 +1,73 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.dbs.metas.*;
|
||||
public class Gfdb_rdr_utl_ {
|
||||
public static int Compare(Dbmeta_fld_itm[] flds, int len, Db_rdr lhs_rdr, Db_rdr rhs_rdr) {
|
||||
public static int Compare(DbmetaFldItm[] flds, int len, Db_rdr lhs_rdr, Db_rdr rhs_rdr) {
|
||||
int comp = CompareAble_.Same;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbmeta_fld_itm fld = flds[i];
|
||||
DbmetaFldItm fld = flds[i];
|
||||
String fld_name = fld.Name();
|
||||
int tid = fld.Type().Tid_ansi();
|
||||
int tid = fld.Type().Tid();
|
||||
switch (tid) {
|
||||
case Dbmeta_fld_tid.Tid__bool: comp = Bool_.Compare (lhs_rdr.Read_bool_by_byte(fld_name), rhs_rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__byte: comp = Byte_.Compare (lhs_rdr.Read_byte(fld_name) , rhs_rdr.Read_byte(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__int: comp = Int_.Compare (lhs_rdr.Read_int(fld_name) , rhs_rdr.Read_int(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__long: comp = Long_.Compare (lhs_rdr.Read_long(fld_name) , rhs_rdr.Read_long(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__float: comp = Float_.Compare (lhs_rdr.Read_float(fld_name) , rhs_rdr.Read_float(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__double: comp = Double_.Compare (lhs_rdr.Read_double(fld_name) , rhs_rdr.Read_double(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__str: comp = String_.Compare (lhs_rdr.Read_str(fld_name) , rhs_rdr.Read_str(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__bry: comp = Bry_.Compare (lhs_rdr.Read_bry(fld_name) , rhs_rdr.Read_bry(fld_name)); break;
|
||||
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.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;
|
||||
case DbmetaFldType.TidFloat: comp = Float_.Compare (lhs_rdr.Read_float(fld_name) , rhs_rdr.Read_float(fld_name)); break;
|
||||
case DbmetaFldType.TidDouble: comp = Double_.Compare (lhs_rdr.Read_double(fld_name) , rhs_rdr.Read_double(fld_name)); break;
|
||||
case DbmetaFldType.TidStr: comp = String_.Compare (lhs_rdr.Read_str(fld_name) , rhs_rdr.Read_str(fld_name)); break;
|
||||
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;
|
||||
}
|
||||
return CompareAble_.Same;
|
||||
}
|
||||
public static void Stmt_args(Db_stmt stmt, Dbmeta_fld_itm[] flds, int bgn, int end, Db_rdr rdr) {
|
||||
public static void Stmt_args(Db_stmt stmt, DbmetaFldItm[] flds, int bgn, int end, Db_rdr rdr) {
|
||||
for (int i = bgn; i < end; ++i) {
|
||||
Dbmeta_fld_itm fld = flds[i];
|
||||
DbmetaFldItm fld = flds[i];
|
||||
String fld_name = fld.Name();
|
||||
int tid = fld.Type().Tid_ansi();
|
||||
int tid = fld.Type().Tid();
|
||||
switch (tid) {
|
||||
case Dbmeta_fld_tid.Tid__bool: stmt.Val_bool_as_byte (fld_name, rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__byte: stmt.Val_byte (fld_name, rdr.Read_byte(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__int: stmt.Val_int (fld_name, rdr.Read_int(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__long: stmt.Val_long (fld_name, rdr.Read_long(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__float: stmt.Val_float (fld_name, rdr.Read_float(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__double: stmt.Val_double (fld_name, rdr.Read_double(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__str: stmt.Val_str (fld_name, rdr.Read_str(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__bry: stmt.Val_bry (fld_name, rdr.Read_bry(fld_name)); break;
|
||||
case DbmetaFldType.TidBool: stmt.Val_bool_as_byte (fld_name, rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case DbmetaFldType.TidByte: stmt.Val_byte (fld_name, rdr.Read_byte(fld_name)); break;
|
||||
case DbmetaFldType.TidInt: stmt.Val_int (fld_name, rdr.Read_int(fld_name)); break;
|
||||
case DbmetaFldType.TidLong: stmt.Val_long (fld_name, rdr.Read_long(fld_name)); break;
|
||||
case DbmetaFldType.TidFloat: stmt.Val_float (fld_name, rdr.Read_float(fld_name)); break;
|
||||
case DbmetaFldType.TidDouble: stmt.Val_double (fld_name, rdr.Read_double(fld_name)); break;
|
||||
case DbmetaFldType.TidStr: stmt.Val_str (fld_name, rdr.Read_str(fld_name)); break;
|
||||
case DbmetaFldType.TidBry: stmt.Val_bry (fld_name, rdr.Read_bry(fld_name)); break;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void Stmt_args(Db_stmt stmt, Dbmeta_fld_list flds, int bgn, int end, Db_rdr rdr) {
|
||||
public static void Stmt_args(Db_stmt stmt, DbmetaFldList flds, int bgn, int end, Db_rdr rdr) {
|
||||
for (int i = bgn; i < end; ++i) {
|
||||
Dbmeta_fld_itm fld = flds.Get_at(i);
|
||||
DbmetaFldItm fld = flds.GetAt(i);
|
||||
String fld_name = fld.Name();
|
||||
int tid = fld.Type().Tid_ansi();
|
||||
int tid = fld.Type().Tid();
|
||||
switch (tid) {
|
||||
case Dbmeta_fld_tid.Tid__bool: stmt.Val_bool_as_byte (fld_name, rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__byte: stmt.Val_byte (fld_name, rdr.Read_byte(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__int: stmt.Val_int (fld_name, rdr.Read_int(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__long: stmt.Val_long (fld_name, rdr.Read_long(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__float: stmt.Val_float (fld_name, rdr.Read_float(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__double: stmt.Val_double (fld_name, rdr.Read_double(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__str: stmt.Val_str (fld_name, rdr.Read_str(fld_name)); break;
|
||||
case Dbmeta_fld_tid.Tid__bry: stmt.Val_bry (fld_name, rdr.Read_bry(fld_name)); break;
|
||||
case DbmetaFldType.TidBool: stmt.Val_bool_as_byte (fld_name, rdr.Read_bool_by_byte(fld_name)); break;
|
||||
case DbmetaFldType.TidByte: stmt.Val_byte (fld_name, rdr.Read_byte(fld_name)); break;
|
||||
case DbmetaFldType.TidInt: stmt.Val_int (fld_name, rdr.Read_int(fld_name)); break;
|
||||
case DbmetaFldType.TidLong: stmt.Val_long (fld_name, rdr.Read_long(fld_name)); break;
|
||||
case DbmetaFldType.TidFloat: stmt.Val_float (fld_name, rdr.Read_float(fld_name)); break;
|
||||
case DbmetaFldType.TidDouble: stmt.Val_double (fld_name, rdr.Read_double(fld_name)); break;
|
||||
case DbmetaFldType.TidStr: stmt.Val_str (fld_name, rdr.Read_str(fld_name)); break;
|
||||
case DbmetaFldType.TidBry: stmt.Val_bry (fld_name, rdr.Read_bry(fld_name)); break;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import org.junit.*;
|
||||
import gplx.dbs.*; import gplx.dbs.metas.*; import gplx.dbs.engines.mems.*;
|
||||
public class Gfdb_diff_bldr_tst {
|
||||
private final Gfdb_diff_bldr_fxt fxt = new Gfdb_diff_bldr_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@@ -58,13 +57,13 @@ class Gfdb_diff_bldr_fxt {
|
||||
private final Db_conn old_conn, new_conn;
|
||||
private final Gfdb_diff_tbl tbl;
|
||||
private final Gfdb_diff_wkr__test wkr = new Gfdb_diff_wkr__test();
|
||||
private final Dbmeta_fld_itm[] flds_ary;
|
||||
private final DbmetaFldItm[] flds_ary;
|
||||
private final String tbl_name = "tbl";
|
||||
private final Gdif_bldr_ctx ctx = new Gdif_bldr_ctx();
|
||||
public Gfdb_diff_bldr_fxt() {
|
||||
old_conn = Db_conn_utl.Conn__new("old_db");
|
||||
new_conn = Db_conn_utl.Conn__new("new_db");
|
||||
this.flds_ary = new Dbmeta_fld_itm[] {Dbmeta_fld_itm.new_int("id").Primary_y_(), Dbmeta_fld_itm.new_str("val", 255)};
|
||||
this.flds_ary = new DbmetaFldItm[] {DbmetaFldItm.NewInt("id").PrimarySetY(), DbmetaFldItm.NewStr("val", 255)};
|
||||
tbl = Gfdb_diff_tbl.New(Dbmeta_tbl_itm.New(tbl_name, flds_ary));
|
||||
bldr.Init(wkr);
|
||||
}
|
||||
@@ -101,5 +100,5 @@ class Gfdb_diff_wkr__test implements Gfdb_diff_wkr {
|
||||
public void Handle_new_missing() {
|
||||
list.Add(bfr.Add_str_a7("D").Add_byte_pipe().Add_obj(old_rdr.Read_obj("id")).To_str_and_clear());
|
||||
}
|
||||
public String[] To_str_ary() {return list.To_str_ary_and_clear();}
|
||||
public String[] To_str_ary() {return list.ToStrAryAndClear();}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
class Gfdb_diff_rdr_comparer {
|
||||
private Db_rdr old_rdr, new_rdr;
|
||||
private boolean old_rdr_move, new_rdr_move;
|
||||
private boolean old_rdr_done, new_rdr_done;
|
||||
private Dbmeta_fld_itm[] key_flds; private int key_flds_len;
|
||||
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;
|
||||
|
||||
@@ -1,22 +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.diffs.builds; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
import gplx.dbs.metas.*; import gplx.dbs.diffs.itms.*;
|
||||
import gplx.dbs.diffs.itms.*;
|
||||
public class Gfdb_diff_wkr__db implements Gfdb_diff_wkr {
|
||||
private Dbmeta_fld_itm[] val_flds; private int val_flds_len;
|
||||
private DbmetaFldItm[] val_flds; private int val_flds_len;
|
||||
private Gfdb_diff_tbl tbl; private Db_rdr old_rdr, new_rdr;
|
||||
private Gdif_bldr_ctx ctx;
|
||||
private Db_conn dif_conn; private Db_stmt stmt;
|
||||
@@ -28,7 +28,7 @@ public class Gfdb_diff_wkr__db implements Gfdb_diff_wkr {
|
||||
this.val_flds = tbl.Vals; val_flds_len = val_flds.length;
|
||||
this.uid = 0; this.prog_count = 0;
|
||||
|
||||
String dif_tbl = tbl.Name; Dbmeta_fld_itm[] dif_flds = Gfdb_diff_wkr__db_.New_dif_flds(tbl.Flds);
|
||||
String dif_tbl = tbl.Name; DbmetaFldItm[] dif_flds = Gfdb_diff_wkr__db_.New_dif_flds(tbl.Flds);
|
||||
if (!dif_conn.Meta_tbl_exists(dif_tbl)) dif_conn.Meta_tbl_create(Dbmeta_tbl_itm.New(dif_tbl, dif_flds));
|
||||
this.stmt = dif_conn.Stmt_insert(dif_tbl, Gfdb_diff_wkr__db_.To_str_ary(dif_flds));
|
||||
dif_conn.Txn_bgn("dif_db_tbl_" + dif_tbl);
|
||||
@@ -43,7 +43,7 @@ public class Gfdb_diff_wkr__db implements Gfdb_diff_wkr {
|
||||
if (Gfdb_rdr_utl_.Compare(val_flds, val_flds_len, old_rdr, new_rdr) != CompareAble_.Same)
|
||||
Insert(Gdif_db_.Tid__update, ++uid, new_rdr, tbl.Flds);
|
||||
}
|
||||
private void Insert(byte dif_type, int uid, Db_rdr rdr, Dbmeta_fld_itm[] flds) {
|
||||
private void Insert(byte dif_type, int uid, Db_rdr rdr, DbmetaFldItm[] flds) {
|
||||
if (cmd_create) {
|
||||
cmd_create = false;
|
||||
ctx.Cur_cmd = ctx.Core.New_cmd(ctx, Gdif_cmd_itm.Tid__data);
|
||||
@@ -61,23 +61,23 @@ public class Gfdb_diff_wkr__db implements Gfdb_diff_wkr {
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_wkr__db_ {
|
||||
public static Dbmeta_fld_itm[] New_dif_flds(Dbmeta_fld_itm[] cur_flds) {
|
||||
public static DbmetaFldItm[] New_dif_flds(DbmetaFldItm[] cur_flds) {
|
||||
int len = cur_flds.length;
|
||||
int sys_flds = 5;
|
||||
Dbmeta_fld_itm[] rv = new Dbmeta_fld_itm[len + sys_flds];
|
||||
rv[0] = Dbmeta_fld_itm.new_int (Gdif_db_.Fld__dif_txn);
|
||||
rv[1] = Dbmeta_fld_itm.new_int (Gdif_db_.Fld__dif_uid);
|
||||
rv[2] = Dbmeta_fld_itm.new_byte (Gdif_db_.Fld__dif_type);
|
||||
rv[3] = Dbmeta_fld_itm.new_int (Gdif_db_.Fld__dif_db_trg);
|
||||
rv[4] = Dbmeta_fld_itm.new_int (Gdif_db_.Fld__dif_db_src);
|
||||
DbmetaFldItm[] rv = new DbmetaFldItm[len + sys_flds];
|
||||
rv[0] = DbmetaFldItm.NewInt(Gdif_db_.Fld__dif_txn);
|
||||
rv[1] = DbmetaFldItm.NewInt(Gdif_db_.Fld__dif_uid);
|
||||
rv[2] = DbmetaFldItm.NewByte(Gdif_db_.Fld__dif_type);
|
||||
rv[3] = DbmetaFldItm.NewInt(Gdif_db_.Fld__dif_db_trg);
|
||||
rv[4] = DbmetaFldItm.NewInt(Gdif_db_.Fld__dif_db_src);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbmeta_fld_itm cur_fld = cur_flds[i];
|
||||
Dbmeta_fld_itm dif_fld = new Dbmeta_fld_itm(cur_fld.Name(), cur_fld.Type());
|
||||
DbmetaFldItm cur_fld = cur_flds[i];
|
||||
DbmetaFldItm dif_fld = new DbmetaFldItm(cur_fld.Name(), cur_fld.Type());
|
||||
rv[i + sys_flds] = dif_fld;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static String[] To_str_ary(Dbmeta_fld_itm[] ary) {
|
||||
public static String[] To_str_ary(DbmetaFldItm[] ary) {
|
||||
int len = ary.length;
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
|
||||
@@ -37,12 +37,12 @@ class Gfo_srl_mgr_rdr__db {
|
||||
|
||||
Gfo_srl_mgr_rdr__defn defn = new Gfo_srl_mgr_rdr__defn(); // Get(key)
|
||||
Db_conn conn = Db_conn_.Noop;
|
||||
Db_stmt select = conn.Stmt_select(defn.Tbl, Dbmeta_fld_itm.Str_ary_empty, defn.Select_crt_cols);
|
||||
Db_stmt select = conn.Stmt_select(defn.Tbl, DbmetaFldItm.StrAryEmpty, defn.Select_crt_cols);
|
||||
int crt_len = crt_mgr.Len();
|
||||
for (int i = 0; i < crt_len; ++i) {
|
||||
Dbmeta_dat_itm crt = crt_mgr.Get_at(i);
|
||||
switch (crt.Tid) {
|
||||
case Dbmeta_fld_tid.Tid__int: select.Crt_int(crt.Key, Int_.Cast(crt.Val)); break;
|
||||
case DbmetaFldType.TidInt: select.Crt_int(crt.Key, Int_.Cast(crt.Val)); break;
|
||||
}
|
||||
}
|
||||
Db_rdr rdr = select.Exec_select__rls_manual();
|
||||
@@ -53,7 +53,7 @@ class Gfo_srl_mgr_rdr__db {
|
||||
}
|
||||
rdr.Rls();
|
||||
|
||||
return list.To_ary_and_clear(proto.getClass());
|
||||
return list.ToAryAndClear(proto.getClass());
|
||||
}
|
||||
public void Set_subs (Gfo_srl_ctx ctx, Gfo_srl_itm owner, Gfo_srl_itm proto, Gfo_srl_itm[] subs_ary, String defn_key, Dbmeta_dat_mgr crt_mgr) {
|
||||
Gfo_srl_mgr_rdr__defn defn = new Gfo_srl_mgr_rdr__defn(); // Get(key)
|
||||
@@ -63,7 +63,7 @@ class Gfo_srl_mgr_rdr__db {
|
||||
for (int i = 0; i < crt_len; ++i) {
|
||||
Dbmeta_dat_itm crt = crt_mgr.Get_at(i);
|
||||
switch (crt.Tid) {
|
||||
case Dbmeta_fld_tid.Tid__int: delete.Crt_int(crt.Key, Int_.Cast(crt.Val)); break;
|
||||
case DbmetaFldType.TidInt: delete.Crt_int(crt.Key, Int_.Cast(crt.Val)); break;
|
||||
}
|
||||
}
|
||||
delete.Exec_delete();
|
||||
@@ -88,18 +88,18 @@ class Gfdb_diff_txn {
|
||||
public int Id = 0;
|
||||
}
|
||||
class Gfdb_diff_cmd__fld__create {
|
||||
public Gfdb_diff_cmd__fld__create(Dbmeta_fld_itm cur) {this.cur = cur;}
|
||||
private Dbmeta_fld_itm cur;
|
||||
public Gfdb_diff_cmd__fld__create(DbmetaFldItm cur) {this.cur = cur;}
|
||||
private DbmetaFldItm cur;
|
||||
public void Save(Gfo_srl_ctx ctx, Gfo_srl_itm owner) {
|
||||
Gfo_srl_mgr_wtr wtr = ctx.Wtr_bgn("cmd.fld");
|
||||
wtr.Set_int ("txn_id" , ((Gfdb_diff_txn)owner).Id);
|
||||
wtr.Set_str ("name" , cur.Name());
|
||||
wtr.Set_int ("type_tid" , cur.Type().Tid_ansi());
|
||||
wtr.Set_int ("type_len_1" , cur.Type().Len_1());
|
||||
wtr.Set_int ("type_len_2" , cur.Type().Len_2());
|
||||
wtr.Set_int ("type_tid" , cur.Type().Tid());
|
||||
wtr.Set_int ("type_len_1" , cur.Type().Len1());
|
||||
wtr.Set_int ("type_len_2" , cur.Type().Len2());
|
||||
wtr.Set_bool ("primary" , cur.Primary());
|
||||
wtr.Set_int ("nullable" , cur.Nullable_tid());
|
||||
wtr.Set_str ("dflt" , Object_.Xto_str_or(cur.Default(), null));
|
||||
wtr.Set_int ("nullable" , cur.Nullable());
|
||||
wtr.Set_str ("dflt" , Object_.Xto_str_or(cur.DefaultVal(), null));
|
||||
wtr.Itm_end();
|
||||
}
|
||||
public void Load(Gfo_srl_ctx ctx, Gfo_srl_itm owner) {
|
||||
@@ -111,10 +111,10 @@ class Gfdb_diff_cmd__fld__create {
|
||||
boolean primary = rdr.Get_bool("primary");
|
||||
int nullable_tid = rdr.Get_int("nullable");
|
||||
String dflt_str = rdr.Get_str("dflt");
|
||||
cur = new Dbmeta_fld_itm(name, Dbmeta_fld_tid.New(type_tid, type_len_1));
|
||||
cur.Nullable_tid_(nullable_tid);
|
||||
if (primary) cur.Primary_y_();
|
||||
if (dflt_str != null) cur.Default_(dflt_str);
|
||||
cur = new DbmetaFldItm(name, DbmetaFldType.New(type_tid, type_len_1));
|
||||
cur.NullableSet(nullable_tid);
|
||||
if (primary) cur.PrimarySetY();
|
||||
if (dflt_str != null) cur.DefaultValSet(dflt_str);
|
||||
rdr.Itm_end();
|
||||
// Gfdb_diff_cmd__idx__create idx = ((Gfdb_diff_cmd__idx__create)owner);
|
||||
// Dbmeta_tbl_itm tbl = ((Gfdb_diff_ctx)ctx).Tbls__get(idx.cur.Tbl());
|
||||
@@ -122,13 +122,13 @@ class Gfdb_diff_cmd__fld__create {
|
||||
}
|
||||
}
|
||||
class Gfdb_diff_cmd__fld__delete {
|
||||
public Gfdb_diff_cmd__fld__delete(Dbmeta_fld_itm old) {this.Old = old;}
|
||||
public final Dbmeta_fld_itm Old;
|
||||
public Gfdb_diff_cmd__fld__delete(DbmetaFldItm old) {this.Old = old;}
|
||||
public final DbmetaFldItm Old;
|
||||
}
|
||||
class Gfdb_diff_cmd__fld__modify {
|
||||
public Gfdb_diff_cmd__fld__modify(Dbmeta_fld_itm old, Dbmeta_fld_itm cur) {this.Old = old; this.Cur = cur;}
|
||||
public final Dbmeta_fld_itm Old;
|
||||
public final Dbmeta_fld_itm Cur;
|
||||
public Gfdb_diff_cmd__fld__modify(DbmetaFldItm old, DbmetaFldItm cur) {this.Old = old; this.Cur = cur;}
|
||||
public final DbmetaFldItm Old;
|
||||
public final DbmetaFldItm Cur;
|
||||
}
|
||||
class Gfdb_diff_cmd__tbl__create {
|
||||
public Gfdb_diff_cmd__tbl__create(Dbmeta_tbl_itm cur) {this.Cur = cur;}
|
||||
@@ -184,8 +184,8 @@ class Gfdb_diff_cmd_bldr {
|
||||
Dbmeta_fld_mgr old_flds = old_tbl.Flds(), cur_flds = cur_tbl.Flds();
|
||||
int cur_flds_len = cur_flds.Len();
|
||||
for (int i = 0; i < cur_flds_len; ++i) {
|
||||
Dbmeta_fld_itm cur_fld = cur_flds.Get_at(i);
|
||||
Dbmeta_fld_itm old_fld = old_flds.Get_by(cur_fld.Name());
|
||||
DbmetaFldItm cur_fld = cur_flds.Get_at(i);
|
||||
DbmetaFldItm old_fld = old_flds.Get_by(cur_fld.Name());
|
||||
if (old_fld == null)
|
||||
rv.Add(new Gfdb_diff_cmd__fld__create(cur_fld));
|
||||
else
|
||||
@@ -194,8 +194,8 @@ class Gfdb_diff_cmd_bldr {
|
||||
}
|
||||
int old_flds_len = old_flds.Len();
|
||||
for (int i = 0; i < old_flds_len; ++i) {
|
||||
Dbmeta_fld_itm old_fld = old_flds.Get_at(i);
|
||||
Dbmeta_fld_itm cur_fld = cur_flds.Get_by(old_fld.Name());
|
||||
DbmetaFldItm old_fld = old_flds.Get_at(i);
|
||||
DbmetaFldItm cur_fld = cur_flds.Get_by(old_fld.Name());
|
||||
if (cur_fld == null)
|
||||
rv.Add(new Gfdb_diff_cmd__fld__delete(old_fld));
|
||||
}
|
||||
|
||||
@@ -13,15 +13,15 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
package gplx.dbs.diffs.itms; import gplx.*; import gplx.dbs.*;
|
||||
public class Gdif_cmd_tbl implements Rls_able {
|
||||
private String tbl_name = "gdif_cmd";
|
||||
private String fld_grp_id, fld_cmd_id, fld_tid, fld_data;
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final DbmetaFldList flds = new DbmetaFldList();
|
||||
private final Db_conn conn; private Db_stmt stmt_insert;
|
||||
public Gdif_cmd_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
fld_grp_id = flds.Add_int("grp_id"); fld_cmd_id = flds.Add_int("cmd_id"); fld_tid = flds.Add_int("tid"); fld_data = flds.Add_text("data");
|
||||
fld_grp_id = flds.AddInt("grp_id"); fld_cmd_id = flds.AddInt("cmd_id"); fld_tid = flds.AddInt("tid"); fld_data = flds.AddText("data");
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "main", fld_grp_id, fld_cmd_id)));}
|
||||
|
||||
@@ -13,15 +13,15 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
package gplx.dbs.diffs.itms; import gplx.*; import gplx.dbs.*;
|
||||
public class Gdif_job_tbl implements Rls_able {
|
||||
private String tbl_name = "gdif_job";
|
||||
private String fld_job_id, fld_name, fld_made_by, fld_made_on, fld_data;
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final DbmetaFldList flds = new DbmetaFldList();
|
||||
private final Db_conn conn; private Db_stmt stmt_insert;
|
||||
public Gdif_job_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
fld_job_id = flds.Add_int_pkey("job_id"); fld_name = flds.Add_str("name", 255); fld_made_by = flds.Add_str("made_by", 255); fld_made_on = flds.Add_date("made_on"); fld_data = flds.Add_text("data");
|
||||
fld_job_id = flds.AddIntPkey("job_id"); fld_name = flds.AddStr("name", 255); fld_made_by = flds.AddStr("made_by", 255); fld_made_on = flds.AddDate("made_on"); fld_data = flds.AddText("data");
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;}
|
||||
|
||||
@@ -13,15 +13,15 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.diffs.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.diffs.*;
|
||||
package gplx.dbs.diffs.itms; import gplx.*; import gplx.dbs.*;
|
||||
public class Gdif_txn_tbl implements Rls_able {
|
||||
private String tbl_name = "gdif_txn";
|
||||
private String fld_job_id, fld_txn_id, fld_cmd_id, fld_owner_txn;
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final DbmetaFldList flds = new DbmetaFldList();
|
||||
private final Db_conn conn; private Db_stmt stmt_insert;
|
||||
public Gdif_txn_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
fld_job_id = flds.Add_int("job_id"); fld_txn_id = flds.Add_int("txn_id"); fld_cmd_id = flds.Add_int("cmd_id"); fld_owner_txn = flds.Add_int("owner_txn");
|
||||
fld_job_id = flds.AddInt("job_id"); fld_txn_id = flds.AddInt("txn_id"); fld_cmd_id = flds.AddInt("cmd_id"); fld_owner_txn = flds.AddInt("owner_txn");
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "main", fld_job_id, fld_txn_id)));}
|
||||
|
||||
@@ -23,7 +23,7 @@ import gplx.dbs.Db_conn_info;
|
||||
import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.Dbmeta_fld_itm;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.dbs.Dbmeta_idx_itm;
|
||||
import gplx.dbs.Dbmeta_tbl_itm;
|
||||
import gplx.dbs.conn_props.Db_conn_props_mgr;
|
||||
@@ -48,7 +48,7 @@ public interface Db_engine {
|
||||
void Txn_sav();
|
||||
void Meta_tbl_create(Dbmeta_tbl_itm meta);
|
||||
void Meta_tbl_delete(String tbl);
|
||||
void Meta_fld_append(String tbl, Dbmeta_fld_itm fld);
|
||||
void Meta_fld_append(String tbl, DbmetaFldItm fld);
|
||||
void Meta_idx_create(Gfo_usr_dlg usr_dlg, Dbmeta_idx_itm... ary);
|
||||
void Meta_idx_delete(String idx);
|
||||
Dbmeta_tbl_mgr Meta_mgr();
|
||||
|
||||
@@ -26,7 +26,7 @@ import gplx.dbs.Db_qry_;
|
||||
import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.Db_rdr__basic;
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.Dbmeta_fld_itm;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.dbs.Dbmeta_idx_itm;
|
||||
import gplx.dbs.Dbmeta_tbl_itm;
|
||||
import gplx.dbs.conn_props.Db_conn_props_mgr;
|
||||
@@ -65,7 +65,7 @@ public abstract class Db_engine_sql_base implements Db_engine {
|
||||
public Object Exec_as_obj(Db_qry qry) {
|
||||
if (qry.Tid() == Db_qry_.Tid_flush) return null; // ignore flush (delete-db) statements
|
||||
String sql = this.Sql_wtr().ToSqlStr(qry, false); // DBG: Tfds.Write(sql);
|
||||
return qry.Exec_is_rdr() ? (Object)this.Exec_as_rdr(sql) : this.Exec_as_int(sql);
|
||||
return qry.ReturnsRdr() ? (Object)this.Exec_as_rdr(sql) : this.Exec_as_int(sql);
|
||||
}
|
||||
protected int Exec_as_int(String sql) {
|
||||
try {
|
||||
@@ -97,7 +97,7 @@ public abstract class Db_engine_sql_base implements Db_engine {
|
||||
public void Meta_idx_delete(String idx) {
|
||||
if (Meta_idx_exists(idx)) Exec_as_int("DROP INDEX " + idx);
|
||||
}
|
||||
public void Meta_fld_append(String tbl, Dbmeta_fld_itm fld) {
|
||||
public void Meta_fld_append(String tbl, DbmetaFldItm fld) {
|
||||
Gfo_usr_dlg_.Instance.Plog_many("", "", "adding column to table: db=~{0} tbl=~{1} fld=~{2}", conn_info.Database(), tbl, fld.Name());
|
||||
try {
|
||||
Exec_as_int(this.Sql_wtr().Schema_wtr().Bld_alter_tbl_add(tbl, fld));
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*;
|
||||
class Mem_db_fxt {
|
||||
public Mem_db_fxt() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
@@ -21,10 +21,10 @@ class Mem_db_fxt {
|
||||
}
|
||||
public Db_conn Make_conn(String url) {return Db_conn_bldr.Instance.Get_or_autocreate(Bool_.Y, Io_url_.mem_fil_(url));}
|
||||
public Dbmeta_tbl_itm Exec__create_tbl(Db_conn conn, String tbl, String... fld_names) {
|
||||
Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
DbmetaFldList flds = new DbmetaFldList();
|
||||
int len = fld_names.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
flds.Add_str(fld_names[i], 255);
|
||||
flds.AddStr(fld_names[i], 255);
|
||||
Dbmeta_tbl_itm rv = Dbmeta_tbl_itm.New(tbl, flds);
|
||||
conn.Meta_tbl_create(rv);
|
||||
return rv;
|
||||
@@ -33,14 +33,14 @@ class Mem_db_fxt {
|
||||
Mem_engine engine = (Mem_engine)conn.Engine();
|
||||
int rows_len = rows.length;
|
||||
Mem_tbl tbl = engine.Tbls__get(tbl_name);
|
||||
Dbmeta_fld_list flds_list = tbl.Meta().Flds().To_fld_list();
|
||||
DbmetaFldList flds_list = tbl.Meta().Flds().To_fld_list();
|
||||
int flds_len = flds_list.Len();
|
||||
Db_stmt stmt = conn.Stmt_insert(tbl_name, flds_list);
|
||||
for (int i = 0; i < rows_len; ++i) {
|
||||
stmt.Clear();
|
||||
String[] row = rows[i];
|
||||
for (int j = 0; j < flds_len; ++j)
|
||||
stmt.Val_str(flds_list.Get_at(j).Name(), row[j]);
|
||||
stmt.Val_str(flds_list.GetAt(j).Name(), row[j]);
|
||||
stmt.Exec_insert();
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,6 @@ class Mem_db_fxt {
|
||||
}
|
||||
actl_list.Add(tmp_bfr.To_str_and_clear());
|
||||
}
|
||||
Tfds.Eq_ary(expd_rows, (String[])actl_list.To_ary_and_clear(String.class));
|
||||
Tfds.Eq_ary(expd_rows, (String[])actl_list.ToAryAndClear(String.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Mem_engine implements Db_engine {
|
||||
@Override public void CtorConn(SqlWkrMgr wkrMgr) {}
|
||||
public Db_engine New_clone(Db_conn_info conn_info) {return new Mem_engine(conn_info);}
|
||||
public Db_stmt Stmt_by_qry(Db_qry qry) {return new Mem_stmt(this, qry);}
|
||||
public Mem_tbl Tbls__get(String name) {return (Mem_tbl)tbl_hash.Get_by(name);}
|
||||
public Mem_tbl Tbls__get(String name) {return (Mem_tbl)tbl_hash.GetByOrNull(name);}
|
||||
public void Tbls__del(String name) {tbl_hash.Del(name);}
|
||||
public void Txn_bgn(String name) {}//++txn_count;} private int txn_count = 0;
|
||||
public String Txn_end() {return "";}// --txn_count; return "";}
|
||||
@@ -49,20 +49,20 @@ public class Mem_engine implements Db_engine {
|
||||
public Object Stmt_by_sql(String sql) {throw Err_.new_unimplemented();}
|
||||
public void Meta_tbl_create(Dbmeta_tbl_itm meta) {
|
||||
Mem_tbl mem_tbl = new Mem_tbl(meta);
|
||||
tbl_hash.Add_if_dupe_use_nth(meta.Name(), mem_tbl);
|
||||
tbl_hash.AddIfDupeUseNth(meta.Name(), mem_tbl);
|
||||
meta_mgr.Add(meta);
|
||||
}
|
||||
public void Meta_tbl_delete(String tbl_key) {
|
||||
Mem_tbl tbl = (Mem_tbl)tbl_hash.Get_by(tbl_key);
|
||||
Mem_tbl tbl = (Mem_tbl)tbl_hash.GetByOrNull(tbl_key);
|
||||
if (tbl != null) tbl.rows.Clear();
|
||||
}
|
||||
public void Meta_idx_create(Gfo_usr_dlg usr_dlg, Dbmeta_idx_itm... ary) {} // TODO_OLD: implement unique index
|
||||
public void Meta_idx_delete(String idx) {}
|
||||
public void Meta_fld_append(String tbl, Dbmeta_fld_itm fld) {}
|
||||
public void Meta_fld_append(String tbl, DbmetaFldItm fld) {}
|
||||
public Dbmeta_tbl_mgr Meta_mgr() {return meta_mgr;} private final Dbmeta_tbl_mgr meta_mgr = new Dbmeta_tbl_mgr(Dbmeta_reload_cmd_.Noop);
|
||||
public boolean Meta_tbl_exists(String tbl) {return tbl_hash.Has(tbl);}
|
||||
public boolean Meta_fld_exists(String tbl, String fld) {
|
||||
Mem_tbl mem_tbl = (Mem_tbl)tbl_hash.Get_by(tbl); if (mem_tbl == null) return false;
|
||||
Mem_tbl mem_tbl = (Mem_tbl)tbl_hash.GetByOrNull(tbl); if (mem_tbl == null) return false;
|
||||
return mem_tbl.Meta().Flds().Has(fld);
|
||||
}
|
||||
public boolean Meta_idx_exists(String idx) {return false;}
|
||||
|
||||
@@ -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.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.core.criterias.*;
|
||||
import gplx.dbs.qrys.*; import gplx.dbs.sqls.itms.*;
|
||||
public class Mem_exec_select {
|
||||
@@ -22,7 +22,7 @@ public class Mem_exec_select {
|
||||
public Mem_exec_select(Mem_engine engine) {this.engine = engine;}
|
||||
public Db_rdr Select(Mem_stmt stmt) {
|
||||
Db_qry stmt_qry = stmt.Qry();
|
||||
Mem_tbl tbl = engine.Tbls__get(stmt_qry.Base_table());
|
||||
Mem_tbl tbl = engine.Tbls__get(stmt_qry.BaseTable());
|
||||
String[] select = null; Criteria where = null;
|
||||
Db_qry__select_in_tbl qry = Db_qry__select_in_tbl.as_(stmt_qry);
|
||||
Db_qry__select_cmd qry2 = null;
|
||||
@@ -36,20 +36,20 @@ public class Mem_exec_select {
|
||||
where = qry.Where();
|
||||
}
|
||||
Mem_stmt_args_.Fill(stmt.Stmt_args(), where);
|
||||
Mem_row[] tbl_rows = (Mem_row[])tbl.rows.To_ary(Mem_row.class);
|
||||
Mem_row[] tbl_rows = (Mem_row[])tbl.rows.ToAry(Mem_row.class);
|
||||
if (qry2 != null) {
|
||||
tbl_rows = Mem_exec_.Rows__alias(tbl_rows, qry2.From().Base_tbl.Alias);
|
||||
List_adp join_tbls = qry2.From().Tbls;
|
||||
int join_tbls_len = join_tbls.Len();
|
||||
for (int i = 1; i < join_tbls_len; ++i) {
|
||||
Sql_tbl_itm join_tbl = (Sql_tbl_itm)join_tbls.Get_at(i);
|
||||
Mem_row[] join_rows = (Mem_row[])engine.Tbls__get(join_tbl.Name).rows.To_ary(Mem_row.class);
|
||||
Mem_row[] join_rows = (Mem_row[])engine.Tbls__get(join_tbl.Name).rows.ToAry(Mem_row.class);
|
||||
join_rows = Mem_exec_.Rows__alias(join_rows, join_tbl.Alias);
|
||||
tbl_rows = Mem_exec_.Rows__join(join_tbl.Join_tid, tbl_rows, join_rows, join_tbl.Alias, join_tbl.Join_flds);
|
||||
}
|
||||
}
|
||||
Mem_exec_.Where__filter(tmp_where_rows, tbl_rows, stmt, where);
|
||||
Mem_row[] rslt_rows = (Mem_row[])tmp_where_rows.To_ary_and_clear(Mem_row.class);
|
||||
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()));
|
||||
@@ -125,7 +125,7 @@ class Mem_exec_ {
|
||||
rv.Add(merged);
|
||||
}
|
||||
}
|
||||
return (Mem_row[])rv.To_ary_and_clear(Mem_row.class);
|
||||
return (Mem_row[])rv.ToAryAndClear(Mem_row.class);
|
||||
}
|
||||
public static Mem_row[] Rows__alias(Mem_row[] src_rows, String tbl_alias) {
|
||||
int src_rows_len = src_rows.length;
|
||||
|
||||
@@ -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.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.mems; import gplx.*;
|
||||
public class Mem_qry_set {
|
||||
private final List_adp rows = List_adp_.New();
|
||||
public int Len() {return rows.Count();}
|
||||
public int Len() {return rows.Len();}
|
||||
public Mem_row Get_at(int i) {return (Mem_row)rows.Get_at(i);}
|
||||
public void Add(Mem_row row) {rows.Add(row);}
|
||||
}
|
||||
|
||||
@@ -13,20 +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.engines.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*;
|
||||
public class Mem_row implements Gfo_invk {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
private final Ordered_hash flds = Ordered_hash_.New();
|
||||
public int Len() {return hash.Len();}
|
||||
public String Fld_at(int i) {return (String)flds.Get_at(i);}
|
||||
public Object Get_at(int i) {return hash.Get_at(i);}
|
||||
public Object Get_by(String key) {return hash.Get_by(key);}
|
||||
public Object Get_by(String key) {return hash.GetByOrNull(key);}
|
||||
public Object Get_by_or_dbnull(String key) {
|
||||
Object rv = hash.Get_by(key);
|
||||
Object rv = hash.GetByOrNull(key);
|
||||
return rv == null ? Db_null.Instance : rv;
|
||||
}
|
||||
public void Set_by(String key, Object val) {hash.Add_if_dupe_use_nth(key, val); flds.Add_if_dupe_use_1st(key, key);}
|
||||
public void Add(String key, Object val) {hash.Add(key, val); flds.Add_if_dupe_use_1st(key, key);}
|
||||
public void Set_by(String key, Object val) {hash.AddIfDupeUseNth(key, val); flds.AddIfDupeUse1st(key, key);}
|
||||
public void Add(String key, Object val) {hash.Add(key, val); flds.AddIfDupeUse1st(key, key);}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
Object rv = Get_by(k);
|
||||
if (rv == null) return Gfo_invk_.Rv_unhandled;
|
||||
|
||||
@@ -21,9 +21,9 @@ public class Mem_stmt implements Db_stmt {
|
||||
public Mem_stmt(Mem_engine engine, Db_qry qry) {Ctor_stmt(engine, qry);} private Mem_engine engine;
|
||||
public void Ctor_stmt(Db_engine engine, Db_qry qry) {this.engine = (Mem_engine)engine; this.qry = qry;}
|
||||
public Mem_stmt_args Stmt_args() {return stmt_args;} private final Mem_stmt_args stmt_args = new Mem_stmt_args();
|
||||
public int Args_len() {return val_list.Count();}
|
||||
public int Args_len() {return val_list.Len();}
|
||||
public Object Args_get_at(int i) {return val_list.Get_at(i);}
|
||||
public Object Args_get_by(String k) {return val_list.Get_by(k);}
|
||||
public Object Args_get_by(String k) {return val_list.GetByOrNull(k);}
|
||||
public Db_qry Qry() {return qry;} private Db_qry qry;
|
||||
public Db_stmt Reset_stmt() {return this;}
|
||||
public Db_stmt Clear() {
|
||||
@@ -118,16 +118,16 @@ public class Mem_stmt implements Db_stmt {
|
||||
return this;
|
||||
}
|
||||
public boolean Exec_insert() {
|
||||
Mem_tbl tbl = engine.Tbls__get(qry.Base_table());
|
||||
if (tbl == null) throw Err_.new_wo_type("must call Create_tbl", "tbl", qry.Base_table());
|
||||
Mem_tbl tbl = engine.Tbls__get(qry.BaseTable());
|
||||
if (tbl == null) throw Err_.new_wo_type("must call Create_tbl", "tbl", qry.BaseTable());
|
||||
return tbl.Insert(this) == 1;
|
||||
}
|
||||
public int Exec_update() {
|
||||
Mem_tbl tbl = engine.Tbls__get(qry.Base_table());
|
||||
Mem_tbl tbl = engine.Tbls__get(qry.BaseTable());
|
||||
return tbl.Update(this);
|
||||
}
|
||||
public int Exec_delete() {
|
||||
Mem_tbl tbl = engine.Tbls__get(qry.Base_table());
|
||||
Mem_tbl tbl = engine.Tbls__get(qry.BaseTable());
|
||||
return tbl.Delete(this);
|
||||
}
|
||||
public DataRdr Exec_select() {throw Err_.new_unimplemented();}
|
||||
@@ -139,8 +139,8 @@ public class Mem_stmt implements Db_stmt {
|
||||
}
|
||||
public Object Exec_select_val() {throw Err_.new_unimplemented();}
|
||||
private void Add(String k, boolean where, Object v) {
|
||||
if (k == Dbmeta_fld_itm.Key_null) return; // key is explicitly null; ignore; allows schema_2+ type definitions
|
||||
val_list.Add_if_dupe_use_1st(k, v); // NOTE: only add if new; WHERE with IN will call Add many times; fld_ttl IN ('A.png', 'B.png');
|
||||
if (k == DbmetaFldItm.KeyNull) return; // key is explicitly null; ignore; allows schema_2+ type definitions
|
||||
val_list.AddIfDupeUse1st(k, v); // NOTE: only add if new; WHERE with IN will call Add many times; fld_ttl IN ('A.png', 'B.png');
|
||||
if (where) stmt_args.Add(k, v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.mems; import gplx.*;
|
||||
import gplx.core.criterias.*;
|
||||
public class Mem_stmt_args {
|
||||
private final List_adp list = List_adp_.New();
|
||||
@@ -22,7 +22,7 @@ public class Mem_stmt_args {
|
||||
public void Add(String k, Object v) {list.Add(Keyval_.new_(k, v));}
|
||||
public Keyval Get_next() {
|
||||
int idx = ++cur_idx;
|
||||
return idx == list.Count() ? null: (Keyval)list.Get_at(idx);
|
||||
return idx == list.Len() ? null: (Keyval)list.Get_at(idx);
|
||||
}
|
||||
}
|
||||
class Mem_stmt_args_ {
|
||||
|
||||
@@ -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.mems; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.mems; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.core.primitives.*; import gplx.core.criterias.*; import gplx.dbs.qrys.*; import gplx.dbs.sqls.itms.*;
|
||||
import gplx.dbs.metas.*;
|
||||
public class Mem_tbl {
|
||||
@@ -27,7 +27,7 @@ public class Mem_tbl {
|
||||
Dbmeta_fld_mgr flds = meta.Flds();
|
||||
int len = flds.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbmeta_fld_itm fld = flds.Get_at(i);
|
||||
DbmetaFldItm fld = flds.Get_at(i);
|
||||
String fld_name = fld.Name();
|
||||
Object val = fld.Autonum() ? Autonum_calc(fld_name) : stmt.Args_get_by(fld_name);
|
||||
if (val == null) continue; // NOTE: allow Bulk_insert from test to skip filds
|
||||
@@ -37,7 +37,7 @@ public class Mem_tbl {
|
||||
return 1;
|
||||
}
|
||||
private int Autonum_calc(String name) {
|
||||
Int_obj_ref autonum_itm = (Int_obj_ref)autonum_hash.Get_by(name);
|
||||
Int_obj_ref autonum_itm = (Int_obj_ref)autonum_hash.GetByOrNull(name);
|
||||
if (autonum_itm == null) {
|
||||
autonum_itm = Int_obj_ref.New(0);
|
||||
autonum_hash.Add(name, autonum_itm);
|
||||
@@ -49,7 +49,7 @@ public class Mem_tbl {
|
||||
Criteria where_crt = qry.Where(); if (where_crt == null) where_crt = Criteria_.All;
|
||||
Mem_stmt_args_.Fill(stmt.Stmt_args(), where_crt);
|
||||
Select_rows_where(where_rows, stmt, where_crt);
|
||||
int where_rows_len = where_rows.Count();
|
||||
int where_rows_len = where_rows.Len();
|
||||
String[] update_cols = qry.Cols_for_update(); int update_cols_len = update_cols.length;
|
||||
for (int i = 0; i < where_rows_len; ++i) {
|
||||
Mem_row itm = (Mem_row)where_rows.Get_at(i);
|
||||
@@ -62,7 +62,7 @@ public class Mem_tbl {
|
||||
Db_qry_delete qry = (Db_qry_delete)stmt.Qry();
|
||||
Mem_stmt_args_.Fill(stmt.Stmt_args(), qry.Where());
|
||||
Select_rows_where(where_rows, stmt, qry.Where());
|
||||
int where_rows_len = where_rows.Count();
|
||||
int where_rows_len = where_rows.Len();
|
||||
for (int i = 0; i < where_rows_len; ++i) {
|
||||
Mem_row itm = (Mem_row)where_rows.Get_at(i);
|
||||
rows.Del(itm);
|
||||
@@ -83,7 +83,7 @@ public class Mem_tbl {
|
||||
}
|
||||
Mem_stmt_args_.Fill(stmt.Stmt_args(), where);
|
||||
Select_rows_where(where_rows, stmt, where);
|
||||
return new Mem_rdr(select, (Mem_row[])where_rows.To_ary_and_clear(Mem_row.class));
|
||||
return new Mem_rdr(select, (Mem_row[])where_rows.ToAryAndClear(Mem_row.class));
|
||||
}
|
||||
private String[] To_str_ary(Sql_select_fld_list flds) {
|
||||
int len = flds.Len();
|
||||
@@ -94,7 +94,7 @@ public class Mem_tbl {
|
||||
}
|
||||
private void Select_rows_where(List_adp rv, Mem_stmt stmt, Criteria crt) {
|
||||
rv.Clear();
|
||||
int rows_len = rows.Count();
|
||||
int rows_len = rows.Len();
|
||||
for (int i = 0; i < rows_len; ++i) {
|
||||
Mem_row itm = (Mem_row)rows.Get_at(i);
|
||||
if (crt.Matches(itm))
|
||||
|
||||
@@ -36,12 +36,12 @@ public class Noop_engine implements Db_engine {
|
||||
public String Txn_end() {return "";}
|
||||
public void Txn_cxl() {}
|
||||
public void Txn_sav() {}
|
||||
public Object Exec_as_obj(Db_qry cmd) {return cmd.Exec_is_rdr() ? (Object)DataRdr_.Null : -1;}
|
||||
public Object Exec_as_obj(Db_qry cmd) {return cmd.ReturnsRdr() ? (Object)DataRdr_.Null : -1;}
|
||||
public void Meta_tbl_create(Dbmeta_tbl_itm meta) {}
|
||||
public void Meta_tbl_delete(String tbl) {}
|
||||
public void Meta_idx_create(Gfo_usr_dlg usr_dlg, Dbmeta_idx_itm... ary) {}
|
||||
public void Meta_idx_delete(String idx) {}
|
||||
public void Meta_fld_append(String tbl, Dbmeta_fld_itm fld) {}
|
||||
public void Meta_fld_append(String tbl, DbmetaFldItm fld) {}
|
||||
public void Env_db_attach(String alias, Db_conn conn) {}
|
||||
public void Env_db_attach(String alias, Io_url db_url) {}
|
||||
public void Env_db_detach(String alias) {}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
Copyright (C) 2012-2021 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
@@ -13,7 +13,12 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.sqlite; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
public class Sqlite_tid {
|
||||
public static final int Tid_int = 1, Tid_text = 2, Tid_none = 3, Tid_real = 4, Tid_numeric = 5;
|
||||
}
|
||||
package gplx.dbs.engines.sqlite;
|
||||
public class SqliteType {
|
||||
public static final int
|
||||
Int = 1,
|
||||
Text = 2,
|
||||
None = 3,
|
||||
Real = 4,
|
||||
Numeric = 5;
|
||||
}
|
||||
@@ -39,7 +39,7 @@ import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.Db_rdr__basic;
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.Dbmeta_fld_itm;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.dbs.engines.Db_engine;
|
||||
import gplx.dbs.engines.Db_engine_sql_base;
|
||||
import gplx.dbs.metas.Dbmeta_tbl_mgr;
|
||||
@@ -214,7 +214,7 @@ class Sqlite_rdr extends Db_data_rdr { @Override public float ReadFloat(String
|
||||
}
|
||||
class Sqlite_stmt extends gplx.dbs.qrys.Db_stmt_cmd { public Sqlite_stmt(Db_engine engine, Db_qry qry) {super(engine, qry);}
|
||||
@Override protected Db_stmt Add_date(boolean where, String k, DateAdp v) {
|
||||
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
return super.Add_str(where, k, v.XtoStr_fmt_iso_8561());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ public class Sqlite_pragma implements Db_qry {
|
||||
this.sql = String_.Format(fmt, key, val);
|
||||
}
|
||||
public int Tid() {return Db_qry_.Tid_pragma;}
|
||||
public boolean Exec_is_rdr() {return false;}
|
||||
public String Base_table() {return "";}
|
||||
public String To_sql__exec(SqlQryWtr wtr) {return sql;}
|
||||
public boolean ReturnsRdr() {return false;}
|
||||
public String BaseTable() {return "";}
|
||||
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
|
||||
|
||||
@@ -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.engines.sqlite; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.sqlite; import gplx.*;
|
||||
import gplx.dbs.engines.*;
|
||||
import gplx.dbs.qrys.*;
|
||||
public class Sqlite_txn_mgr {
|
||||
private final List_adp txn_list = List_adp_.New();
|
||||
@@ -41,9 +42,9 @@ public class Sqlite_txn_mgr {
|
||||
txn_list.Add(name);
|
||||
}
|
||||
public String Txn_end() {
|
||||
if (txn_list.Count() == 0) {Gfo_usr_dlg_.Instance.Warn_many("", "", "no txns in stack;"); return "";}
|
||||
if (txn_list.Len() == 0) {Gfo_usr_dlg_.Instance.Warn_many("", "", "no txns in stack;"); return "";}
|
||||
String txn_last = (String)List_adp_.Pop_last(txn_list);
|
||||
if (txn_list.Count() == 0) {// no txns left; commit it
|
||||
if (txn_list.Len() == 0) {// no txns left; commit it
|
||||
engine.Exec_as_obj(Db_qry_sql.xtn_("COMMIT TRANSACTION;"));
|
||||
txn_started = false;
|
||||
}
|
||||
@@ -52,9 +53,9 @@ public class Sqlite_txn_mgr {
|
||||
return txn_last;
|
||||
}
|
||||
public void Txn_cxl() {
|
||||
if (txn_list.Count() == 0) {Gfo_usr_dlg_.Instance.Warn_many("", "", "no txns in stack;"); return;}
|
||||
if (txn_list.Len() == 0) {Gfo_usr_dlg_.Instance.Warn_many("", "", "no txns in stack;"); return;}
|
||||
String txn_last = (String)List_adp_.Pop_last(txn_list);
|
||||
if (txn_list.Count() == 0) {// no txns left; rollback
|
||||
if (txn_list.Len() == 0) {// no txns left; rollback
|
||||
engine.Exec_as_obj(Db_qry_sql.xtn_("ROLLBACK TRANSACTION;"));
|
||||
txn_started = false;
|
||||
}
|
||||
@@ -62,8 +63,8 @@ public class Sqlite_txn_mgr {
|
||||
engine.Exec_as_obj(Db_qry_sql.xtn_(String_.Format("ROLBACK TRANSACTION TO SAVEPOINT {0};", txn_last)));
|
||||
}
|
||||
public void Txn_sav() {
|
||||
if (txn_list.Count() == 0) {Gfo_usr_dlg_.Instance.Warn_many("", "", "no txns in stack;"); return;}
|
||||
String name = (String)txn_list.Get_at(txn_list.Count() - 1);
|
||||
if (txn_list.Len() == 0) {Gfo_usr_dlg_.Instance.Warn_many("", "", "no txns in stack;"); return;}
|
||||
String name = (String)txn_list.Get_at(txn_list.Len() - 1);
|
||||
this.Txn_end(); this.Txn_bgn(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
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.*;
|
||||
/*
|
||||
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.core.stores.*;
|
||||
class TdbDbLoadMgr {
|
||||
public TdbDatabase LoadTbls(Io_url dbInfo) {
|
||||
@@ -38,7 +38,7 @@ class TdbDbLoadMgr {
|
||||
else if (String_.Eq(name, TdbTableList.StoreTableName)) db.Tables().DataObj_Rdr(rdr, db.Files());
|
||||
else db.Tables().Get_by_or_fail(rdr.NameOfNode()).DataObj_Rdr(rdr);
|
||||
}
|
||||
if (db.Files().Count() == 0) throw Err_.new_wo_type("fatal error: db has no files", "connectInfo", db.DbUrl());
|
||||
if (db.Files().Len() == 0) throw Err_.new_wo_type("fatal error: db has no files", "connectInfo", db.DbUrl());
|
||||
}
|
||||
DataRdr MakeDataRdr(Io_url fil) {
|
||||
String text = Io_mgr.Instance.LoadFilStr(fil);
|
||||
|
||||
@@ -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.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.tdbs; import gplx.*;
|
||||
import org.junit.*; import gplx.core.gfo_ndes.*; import gplx.core.type_xtns.*;
|
||||
import gplx.core.stores.*; /*DsvDataRdr*/ import gplx.langs.dsvs.*; /*DsvDataWtr*/
|
||||
public class TdbDbLoadMgr_tst {
|
||||
@@ -38,7 +38,7 @@ public class TdbDbLoadMgr_tst {
|
||||
rdr = rdr_(raw);
|
||||
|
||||
db.Files().DataObj_Rdr(rdr);
|
||||
Tfds.Eq(db.Files().Count(), 2);
|
||||
Tfds.Eq(db.Files().Len(), 2);
|
||||
TdbFile file2 = db.Files().Get_by_or_fail(2);
|
||||
Tfds.Eq(file2.Path().Raw(), "C:\\file.dsv");
|
||||
|
||||
@@ -58,7 +58,7 @@ public class TdbDbLoadMgr_tst {
|
||||
rdr = rdr_(raw);
|
||||
|
||||
db.Tables().DataObj_Rdr(rdr, db.Files());
|
||||
Tfds.Eq(db.Tables().Count(), 1);
|
||||
Tfds.Eq(db.Tables().Len(), 1);
|
||||
TdbTable table = db.Tables().Get_by_or_fail("tbl1");
|
||||
Tfds.Eq(table.Name(), "tbl1");
|
||||
Tfds.Eq(table.File().Id(), 1);
|
||||
@@ -80,7 +80,7 @@ public class TdbDbLoadMgr_tst {
|
||||
|
||||
db.MakeTbl("tbl0", TdbFile.MainFileId);
|
||||
db.Tables().Get_by_or_fail(rdr.NameOfNode()).DataObj_Rdr(rdr);
|
||||
Tfds.Eq(db.Tables().Count(), 1);
|
||||
Tfds.Eq(db.Tables().Len(), 1);
|
||||
TdbTable tbl = db.Tables().Get_by_or_fail("tbl0");
|
||||
Tfds.Eq(tbl.Rows().Count(), 1);
|
||||
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
/*
|
||||
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.criterias.*; import gplx.core.lists.*; /*GfoNde*/ import gplx.dbs.qrys.*; import gplx.core.gfo_ndes.*;
|
||||
import gplx.core.criterias.*;
|
||||
import gplx.dbs.qrys.*; import gplx.core.gfo_ndes.*;
|
||||
class TdbDeleteWkr implements Db_qryWkr {
|
||||
public Object Exec(Db_engine engineObj, Db_qry cmdObj) {
|
||||
TdbEngine engine = TdbEngine.cast(engineObj); Db_qry_delete cmd = (Db_qry_delete)cmdObj;
|
||||
TdbTable tbl = engine.FetchTbl(cmd.Base_table());
|
||||
TdbTable tbl = engine.FetchTbl(cmd.BaseTable());
|
||||
List_adp deleted = List_adp_.New();
|
||||
int rv = 0;
|
||||
if (cmd.Where() == Db_qry_delete.Where__null) {
|
||||
@@ -32,7 +33,7 @@ class TdbDeleteWkr implements Db_qryWkr {
|
||||
if (crt.Matches(row))
|
||||
deleted.Add(row);
|
||||
}
|
||||
for (int i = 0; i < deleted.Count(); i++) {
|
||||
for (int i = 0; i < deleted.Len(); i++) {
|
||||
GfoNde row = (GfoNde)deleted.Get_at(i);
|
||||
tbl.Rows().Del(row);
|
||||
rv++;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class TdbEngine implements Db_engine {
|
||||
return rv;
|
||||
}
|
||||
public Object Exec_as_obj(Db_qry qry) {
|
||||
Db_qryWkr wkr = (Db_qryWkr)wkrs.Get_by_or_fail(qry.Tid());
|
||||
Db_qryWkr wkr = (Db_qryWkr)wkrs.GetByOrFail(qry.Tid());
|
||||
return wkr.Exec(this, qry);
|
||||
}
|
||||
public Db_stmt Stmt_by_qry(Db_qry qry) {return new Db_stmt_sql().Parse(qry, sql_wtr.ToSqlStr(qry, true));}
|
||||
@@ -64,7 +64,7 @@ public class TdbEngine implements Db_engine {
|
||||
public void Meta_tbl_create(Dbmeta_tbl_itm meta) {throw Err_.new_unimplemented();}
|
||||
public void Meta_idx_create(Gfo_usr_dlg usr_dlg, Dbmeta_idx_itm... ary) {throw Err_.new_unimplemented();}
|
||||
public void Meta_idx_delete(String idx) {throw Err_.new_unimplemented();}
|
||||
public void Meta_fld_append(String tbl, Dbmeta_fld_itm fld) {throw Err_.new_unimplemented();}
|
||||
public void Meta_fld_append(String tbl, DbmetaFldItm fld) {throw Err_.new_unimplemented();}
|
||||
public void Meta_tbl_delete(String tbl) {}
|
||||
public boolean Meta_tbl_exists(String name) {return false;}
|
||||
public boolean Meta_fld_exists(String tbl, String fld) {return false;}
|
||||
|
||||
@@ -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.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*;
|
||||
import org.junit.*;
|
||||
import gplx.core.ios.*; /*IoMgrFxt*/ import gplx.dbs.qrys.*; import gplx.core.type_xtns.*;
|
||||
public class TdbFlush_tst {
|
||||
@@ -96,7 +96,7 @@ class TdbEngineFxt {
|
||||
engine.Exec_as_obj(cmd);
|
||||
}
|
||||
|
||||
public void tst_FilesCount(TdbEngine engine, int count) {Tfds.Eq(engine.Db().Files().Count(), count);}
|
||||
public void tst_FilesCount(TdbEngine engine, int count) {Tfds.Eq(engine.Db().Files().Len(), count);}
|
||||
public void tst_File(TdbEngine engine, int index, int id, Io_url url, String format) {
|
||||
TdbFile src = engine.Db().Files().Get_by_or_fail(id);
|
||||
Tfds.Eq(src.Path().Raw(), url.Raw());
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import gplx.core.gfo_ndes.*; import gplx.core.stores.*;
|
||||
import gplx.core.lists.*; import gplx.dbs.qrys.*; import gplx.dbs.sqls.*; import gplx.dbs.sqls.itms.*;
|
||||
import gplx.dbs.qrys.*;
|
||||
import gplx.dbs.sqls.itms.*;
|
||||
class TdbInsertWkr implements Db_qryWkr {
|
||||
public Object Exec(Db_engine engineObj, Db_qry cmdObj) {
|
||||
TdbEngine engine = TdbEngine.cast(engineObj); Db_qry_insert cmd = (Db_qry_insert)cmdObj;
|
||||
|
||||
TdbTable tbl = engine.FetchTbl(cmd.Base_table());
|
||||
TdbTable tbl = engine.FetchTbl(cmd.BaseTable());
|
||||
tbl.IsDirty_set(true);
|
||||
return cmd.Select() == null
|
||||
? InsertRowsByVals(engine, tbl, cmd)
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.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.*; import gplx.dbs.sqls.itms.*;
|
||||
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*/
|
||||
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;
|
||||
if (cmd.From().Tbls.Count() > 1) throw Err_.new_("gplx.tdbs", "joins not supported for tdbs", "sql", cmd.To_sql__exec(engineObj.Sql_wtr()));
|
||||
if (cmd.From().Tbls.Len() > 1) throw Err_.new_("gplx.tdbs", "joins not supported for tdbs", "sql", cmd.ToSqlExec(engineObj.Sql_wtr()));
|
||||
|
||||
TdbTable tbl = engine.FetchTbl(cmd.From().Base_tbl.Name);
|
||||
GfoNdeList rv = (cmd.Where_itm() == Sql_where_clause.Where__null && cmd.Limit() == Db_qry__select_cmd.Limit__disabled) ? rv = tbl.Rows() : FilterRecords(tbl, cmd.Where_itm().Root, cmd.Limit());
|
||||
@@ -77,14 +78,14 @@ class TdbGroupByWkr {
|
||||
return rv;
|
||||
}
|
||||
static GfoNde FindOrNew(GfoFldList selectFldsForNewRow, List_adp groupByFlds, GfoNde selectRow, Ordered_hash groupByRows, GfoNdeList rslt) {
|
||||
int len = groupByFlds.Count();
|
||||
int len = groupByFlds.Len();
|
||||
Ordered_hash curHash = groupByRows;
|
||||
GfoNde rv = null;
|
||||
for (int i = 0; i < len; i++) {
|
||||
String fld = (String)groupByFlds.Get_at(i);
|
||||
boolean last = i == len - 1;
|
||||
Object val = selectRow.Read(fld);
|
||||
Object o = curHash.Get_by(val);
|
||||
Object o = curHash.GetByOrNull(val);
|
||||
if (last) {
|
||||
if (o == null) {
|
||||
Object[] valAry = new Object[selectFldsForNewRow.Count()];
|
||||
|
||||
@@ -13,18 +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.engines.tdbs; import gplx.*; import gplx.dbs.*; import gplx.dbs.engines.*;
|
||||
import gplx.core.stores.*;
|
||||
import gplx.core.stores.xmls.*; /*XmlDataRdr*/
|
||||
import gplx.langs.dsvs.*; /*DsvDataWtr*/
|
||||
import gplx.core.lists.*; /*GfoNdeRdr*/
|
||||
class TdbStores {
|
||||
public static final String Dsv = "dsv";
|
||||
public static final String Xml = "xml";
|
||||
public static DataRdr rdr_(String text) {return DsvDataRdr_.dsv_(text);}
|
||||
public static DataWtr wtr_() {return DsvDataWtr_.new_();}
|
||||
@gplx.Internal protected static DsvStoreLayout FetchLayout(DataRdr rdr) {
|
||||
GfoNdeRdr ndeRdr = GfoNdeRdr_.as_(rdr); if (ndeRdr == null) return null; // can happen for non-Dsv Rdrs (ex: Xml)
|
||||
return DsvStoreLayout.as_(ndeRdr.UnderNde().EnvVars().Get_by(DsvStoreLayout.Key_const));
|
||||
}
|
||||
package gplx.dbs.engines.tdbs;
|
||||
import gplx.core.stores.*;
|
||||
import gplx.langs.dsvs.*; /*DsvDataWtr*/
|
||||
class TdbStores {
|
||||
public static final String Dsv = "dsv";
|
||||
public static final String Xml = "xml";
|
||||
public static DataRdr rdr_(String text) {return DsvDataRdr_.dsv_(text);}
|
||||
public static DataWtr wtr_() {return DsvDataWtr_.new_();}
|
||||
@gplx.Internal protected static DsvStoreLayout FetchLayout(DataRdr rdr) {
|
||||
GfoNdeRdr ndeRdr = GfoNdeRdr_.as_(rdr); if (ndeRdr == null) return null; // can happen for non-Dsv Rdrs (ex: Xml)
|
||||
return DsvStoreLayout.as_(ndeRdr.UnderNde().EnvVars().GetByOrNull(DsvStoreLayout.Key_const));
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
*/
|
||||
/*
|
||||
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.criterias.*; import gplx.core.lists.*; /*GfoNde*/ import gplx.core.gfo_ndes.*;
|
||||
import gplx.core.criterias.*;
|
||||
import gplx.core.gfo_ndes.*;
|
||||
import gplx.dbs.qrys.*;
|
||||
class TdbUpdateWkr implements Db_qryWkr {
|
||||
public Object Exec(Db_engine engineObj, Db_qry cmdObj) {
|
||||
TdbEngine engine = TdbEngine.cast(engineObj); Db_qry_update cmd = (Db_qry_update)cmdObj;
|
||||
|
||||
int rv = 0;
|
||||
TdbTable tbl = engine.FetchTbl(cmd.Base_table());
|
||||
TdbTable tbl = engine.FetchTbl(cmd.BaseTable());
|
||||
Criteria crt = cmd.Where();
|
||||
for (int i = 0; i < tbl.Rows().Count(); i++) {
|
||||
GfoNde row = (GfoNde)tbl.Rows().FetchAt_asGfoNde(i);
|
||||
|
||||
@@ -16,16 +16,16 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
|
||||
public class Dbmeta_fld_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Len() {return hash.Count();}
|
||||
public int Len() {return hash.Len();}
|
||||
public void Clear() {hash.Clear();}
|
||||
public void Add(Dbmeta_fld_itm itm) {hash.Add(itm.Name(), itm);}
|
||||
public void Add(DbmetaFldItm itm) {hash.Add(itm.Name(), itm);}
|
||||
public boolean Has(String name) {return hash.Has(name);}
|
||||
public Dbmeta_fld_itm Get_at(int idx) {return (Dbmeta_fld_itm)hash.Get_at(idx);}
|
||||
public Dbmeta_fld_itm Get_by(String name) {return (Dbmeta_fld_itm)hash.Get_by(name);}
|
||||
public Dbmeta_fld_itm[] To_ary() {return hash.Count() == 0 ? Dbmeta_fld_itm.Ary_empty : (Dbmeta_fld_itm[])hash.To_ary(Dbmeta_fld_itm.class);}
|
||||
public Dbmeta_fld_list To_fld_list() {
|
||||
Dbmeta_fld_list rv = new Dbmeta_fld_list();
|
||||
int len = hash.Count();
|
||||
public DbmetaFldItm Get_at(int idx) {return (DbmetaFldItm)hash.Get_at(idx);}
|
||||
public DbmetaFldItm Get_by(String name) {return (DbmetaFldItm)hash.GetByOrNull(name);}
|
||||
public DbmetaFldItm[] To_ary() {return hash.Len() == 0 ? DbmetaFldItm.AryEmpty : (DbmetaFldItm[])hash.To_ary(DbmetaFldItm.class);}
|
||||
public DbmetaFldList To_fld_list() {
|
||||
DbmetaFldList rv = new DbmetaFldList();
|
||||
int len = hash.Len();
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv.Add(Get_at(i));
|
||||
return rv;
|
||||
|
||||
@@ -13,14 +13,14 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
|
||||
public class Dbmeta_idx_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Len() {return hash.Count();}
|
||||
public boolean Has(String name) {return hash.Has(name);}
|
||||
public Dbmeta_idx_itm Get_at(int idx) {return (Dbmeta_idx_itm)hash.Get_at(idx);}
|
||||
public Dbmeta_idx_itm Get_by(String name) {return (Dbmeta_idx_itm)hash.Get_by(name);}
|
||||
public void Add(Dbmeta_idx_itm itm) {hash.Add(itm.Name(), itm);}
|
||||
public void Clear() {hash.Clear();}
|
||||
public Dbmeta_idx_itm[] To_ary() {return (Dbmeta_idx_itm[])hash.To_ary(Dbmeta_idx_itm.class);}
|
||||
}
|
||||
package gplx.dbs.metas; import gplx.*; import gplx.dbs.*;
|
||||
public class Dbmeta_idx_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Len() {return hash.Len();}
|
||||
public boolean Has(String name) {return hash.Has(name);}
|
||||
public Dbmeta_idx_itm Get_at(int idx) {return (Dbmeta_idx_itm)hash.Get_at(idx);}
|
||||
public Dbmeta_idx_itm Get_by(String name) {return (Dbmeta_idx_itm)hash.GetByOrNull(name);}
|
||||
public void Add(Dbmeta_idx_itm itm) {hash.Add(itm.Name(), itm);}
|
||||
public void Clear() {hash.Clear();}
|
||||
public Dbmeta_idx_itm[] To_ary() {return (Dbmeta_idx_itm[])hash.To_ary(Dbmeta_idx_itm.class);}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ public class Dbmeta_tbl_mgr {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
private final Dbmeta_reload_cmd load_cmd;
|
||||
public Dbmeta_tbl_mgr(Dbmeta_reload_cmd load_cmd) {this.load_cmd = load_cmd;}
|
||||
public int Len() {return hash.Count();}
|
||||
public int Len() {return hash.Len();}
|
||||
public boolean Has(String name) {return hash.Has(name);}
|
||||
public Dbmeta_tbl_itm Get_at(int i) {return (Dbmeta_tbl_itm)hash.Get_at(i);}
|
||||
public Dbmeta_tbl_itm Get_by(String name) {return (Dbmeta_tbl_itm)hash.Get_by(name);}
|
||||
public void Add(Dbmeta_tbl_itm itm) {hash.Add_if_dupe_use_nth(itm.Name(), itm);}
|
||||
public Dbmeta_tbl_itm Get_by(String name) {return (Dbmeta_tbl_itm)hash.GetByOrNull(name);}
|
||||
public void Add(Dbmeta_tbl_itm itm) {hash.AddIfDupeUseNth(itm.Name(), itm);}
|
||||
public void Clear() {hash.Clear();}
|
||||
public Dbmeta_tbl_mgr Load_all() {load_cmd.Load_all(); 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.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
package gplx.dbs.metas.parsers; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.core.brys.*; import gplx.core.btries.*;
|
||||
abstract class Dbmeta_fld_wkr__base {
|
||||
private byte[] hook;
|
||||
@@ -29,7 +29,7 @@ abstract class Dbmeta_fld_wkr__base {
|
||||
public void Reg(Btrie_slim_mgr trie) {
|
||||
trie.Add_obj(hook, this);
|
||||
}
|
||||
public void Match(Bry_rdr rdr, Dbmeta_fld_itm fld) {
|
||||
public void Match(Bry_rdr rdr, DbmetaFldItm fld) {
|
||||
int words_len = words_trie.Count();
|
||||
for (int i = 0; i < words_len; ++i) {
|
||||
rdr.Skip_ws();
|
||||
@@ -37,82 +37,82 @@ abstract class Dbmeta_fld_wkr__base {
|
||||
}
|
||||
When_match(fld);
|
||||
}
|
||||
protected abstract void When_match(Dbmeta_fld_itm fld);
|
||||
protected abstract void When_match(DbmetaFldItm fld);
|
||||
public static final int Tid_end_comma = 1, Tid_end_paren = 2, Tid_other = 3;
|
||||
}
|
||||
class Dbmeta_fld_wkr__end_comma extends Dbmeta_fld_wkr__base {
|
||||
public Dbmeta_fld_wkr__end_comma() {this.Ctor(Hook);}
|
||||
@Override public int Tid() {return Tid_end_comma;}
|
||||
@Override protected void When_match(Dbmeta_fld_itm fld) {}
|
||||
@Override protected void When_match(DbmetaFldItm fld) {}
|
||||
private static final byte[] Hook = Bry_.new_a7(",");
|
||||
public static final Dbmeta_fld_wkr__end_comma Instance = new Dbmeta_fld_wkr__end_comma();
|
||||
}
|
||||
class Dbmeta_fld_wkr__end_paren extends Dbmeta_fld_wkr__base {
|
||||
public Dbmeta_fld_wkr__end_paren() {this.Ctor(Hook);}
|
||||
@Override public int Tid() {return Tid_end_paren;}
|
||||
@Override protected void When_match(Dbmeta_fld_itm fld) {}
|
||||
@Override protected void When_match(DbmetaFldItm fld) {}
|
||||
private static final byte[] Hook = Bry_.new_a7(")");
|
||||
public static final Dbmeta_fld_wkr__end_paren Instance = new Dbmeta_fld_wkr__end_paren();
|
||||
}
|
||||
class Dbmeta_fld_wkr__nullable_null extends Dbmeta_fld_wkr__base {
|
||||
public Dbmeta_fld_wkr__nullable_null() {this.Ctor(Hook);}
|
||||
@Override protected void When_match(Dbmeta_fld_itm fld) {
|
||||
fld.Nullable_tid_(Dbmeta_fld_itm.Nullable_null);
|
||||
@Override protected void When_match(DbmetaFldItm fld) {
|
||||
fld.NullableSet(DbmetaFldItm.NullableNull);
|
||||
}
|
||||
private static final byte[] Hook = Bry_.new_a7("null");
|
||||
public static final Dbmeta_fld_wkr__nullable_null Instance = new Dbmeta_fld_wkr__nullable_null();
|
||||
}
|
||||
class Dbmeta_fld_wkr__nullable_not extends Dbmeta_fld_wkr__base {
|
||||
public Dbmeta_fld_wkr__nullable_not() {this.Ctor(Hook, Bry_null);}
|
||||
@Override protected void When_match(Dbmeta_fld_itm fld) {
|
||||
fld.Nullable_tid_(Dbmeta_fld_itm.Nullable_not_null);
|
||||
@Override protected void When_match(DbmetaFldItm fld) {
|
||||
fld.NullableSet(DbmetaFldItm.NullableNotNull);
|
||||
}
|
||||
private static final byte[] Hook = Bry_.new_a7("not"), Bry_null = Bry_.new_a7("null");
|
||||
public static final Dbmeta_fld_wkr__nullable_not Instance = new Dbmeta_fld_wkr__nullable_not();
|
||||
}
|
||||
class Dbmeta_fld_wkr__primary_key extends Dbmeta_fld_wkr__base {
|
||||
public Dbmeta_fld_wkr__primary_key() {this.Ctor(Hook, Bry_key);}
|
||||
@Override protected void When_match(Dbmeta_fld_itm fld) {
|
||||
fld.Primary_y_();
|
||||
@Override protected void When_match(DbmetaFldItm fld) {
|
||||
fld.PrimarySetY();
|
||||
}
|
||||
private static final byte[] Hook = Bry_.new_a7("primary"), Bry_key = Bry_.new_a7("key");
|
||||
public static final Dbmeta_fld_wkr__primary_key Instance = new Dbmeta_fld_wkr__primary_key();
|
||||
}
|
||||
class Dbmeta_fld_wkr__autonumber extends Dbmeta_fld_wkr__base {
|
||||
public Dbmeta_fld_wkr__autonumber() {this.Ctor(Hook);}
|
||||
@Override protected void When_match(Dbmeta_fld_itm fld) {
|
||||
fld.Autonum_y_();
|
||||
@Override protected void When_match(DbmetaFldItm fld) {
|
||||
fld.AutonumSetY();
|
||||
}
|
||||
private static final byte[] Hook = Bry_.new_a7("autoincrement");
|
||||
public static final Dbmeta_fld_wkr__autonumber Instance = new Dbmeta_fld_wkr__autonumber();
|
||||
}
|
||||
class Dbmeta_fld_wkr__default extends Dbmeta_fld_wkr__base {
|
||||
public Dbmeta_fld_wkr__default() {this.Ctor(Hook);}
|
||||
@Override public void Match(Bry_rdr rdr, Dbmeta_fld_itm fld) {
|
||||
@Override public void Match(Bry_rdr rdr, DbmetaFldItm fld) {
|
||||
Object default_val = null;
|
||||
rdr.Skip_ws();
|
||||
byte[] src = rdr.Src();
|
||||
switch (fld.Type().Tid_ansi()) {
|
||||
case Dbmeta_fld_tid.Tid__bool:
|
||||
case Dbmeta_fld_tid.Tid__byte:
|
||||
case Dbmeta_fld_tid.Tid__short:
|
||||
case Dbmeta_fld_tid.Tid__int: default_val = Int_.Parse(Read_str_to_end_of_num(rdr)); break;
|
||||
case Dbmeta_fld_tid.Tid__long: default_val = Long_.parse(Read_str_to_end_of_num(rdr)); break;
|
||||
case Dbmeta_fld_tid.Tid__float: default_val = Float_.parse(Read_str_to_end_of_num(rdr)); break;
|
||||
case Dbmeta_fld_tid.Tid__double: default_val = Double_.parse(Read_str_to_end_of_num(rdr)); break;
|
||||
case Dbmeta_fld_tid.Tid__decimal: default_val = Decimal_adp_.parse(Read_str_to_end_of_num(rdr)); break;
|
||||
case Dbmeta_fld_tid.Tid__str:
|
||||
case Dbmeta_fld_tid.Tid__text:
|
||||
case Dbmeta_fld_tid.Tid__bry:
|
||||
switch (fld.Type().Tid()) {
|
||||
case DbmetaFldType.TidBool:
|
||||
case DbmetaFldType.TidByte:
|
||||
case DbmetaFldType.TidShort:
|
||||
case DbmetaFldType.TidInt: default_val = Int_.Parse(Read_str_to_end_of_num(rdr)); break;
|
||||
case DbmetaFldType.TidLong: default_val = Long_.parse(Read_str_to_end_of_num(rdr)); break;
|
||||
case DbmetaFldType.TidFloat: default_val = Float_.parse(Read_str_to_end_of_num(rdr)); break;
|
||||
case DbmetaFldType.TidDouble: default_val = Double_.parse(Read_str_to_end_of_num(rdr)); break;
|
||||
case DbmetaFldType.TidDecimal: default_val = Decimal_adp_.parse(Read_str_to_end_of_num(rdr)); break;
|
||||
case DbmetaFldType.TidStr:
|
||||
case DbmetaFldType.TidText:
|
||||
case DbmetaFldType.TidBry:
|
||||
byte b = src[rdr.Pos()];
|
||||
int bgn_pos = rdr.Pos() + 1;
|
||||
int end_pos = Bry_find_.Find_fwd(src, b, bgn_pos); if (end_pos == Bry_find_.Not_found) rdr.Err_wkr().Fail("unclosed quote");
|
||||
default_val = Bry_.Mid(src, bgn_pos, end_pos);
|
||||
rdr.Move_to(end_pos + 1);
|
||||
break;
|
||||
case Dbmeta_fld_tid.Tid__date: throw Err_.new_unhandled_default(fld.Type().Tid_ansi());
|
||||
case DbmetaFldType.TidDate: throw Err_.new_unhandled_default(fld.Type().Tid());
|
||||
}
|
||||
fld.Default_(default_val);
|
||||
fld.DefaultValSet(default_val);
|
||||
}
|
||||
public String Read_str_to_end_of_num(Bry_rdr rdr) {
|
||||
int bgn = rdr.Pos();
|
||||
@@ -140,7 +140,7 @@ class Dbmeta_fld_wkr__default extends Dbmeta_fld_wkr__base {
|
||||
rdr.Move_to(end);
|
||||
return String_.new_a7(src, bgn, end);
|
||||
}
|
||||
@Override protected void When_match(Dbmeta_fld_itm fld) {}
|
||||
@Override protected void When_match(DbmetaFldItm fld) {}
|
||||
private static final byte[] Hook = Bry_.new_a7("default");
|
||||
public static final Dbmeta_fld_wkr__default Instance = new Dbmeta_fld_wkr__default();
|
||||
}
|
||||
|
||||
@@ -13,15 +13,24 @@ 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 gplx.core.brys.*; import gplx.core.btries.*;
|
||||
import gplx.dbs.engines.sqlite.*;
|
||||
package gplx.dbs.metas.parsers; import gplx.Bry_;
|
||||
import gplx.Bry_find_;
|
||||
import gplx.Byte_ascii;
|
||||
import gplx.Err_;
|
||||
import gplx.Int_;
|
||||
import gplx.String_;
|
||||
import gplx.core.brys.Bry_rdr;
|
||||
import gplx.core.btries.Btrie_rv;
|
||||
import gplx.core.btries.Btrie_slim_mgr;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.dbs.DbmetaFldType;
|
||||
import gplx.dbs.engines.sqlite.SqliteType;
|
||||
public class Dbmeta_parser__fld {
|
||||
private final Btrie_rv trv = new Btrie_rv();
|
||||
public Dbmeta_fld_itm Parse_fld(Sql_bry_rdr rdr) { // starts after "(" or ","; EX: "(fld1 int", ", fld2 int"; ends at ")"
|
||||
public DbmetaFldItm Parse_fld(Sql_bry_rdr rdr) { // starts after "(" or ","; EX: "(fld1 int", ", fld2 int"; ends at ")"
|
||||
byte[] name = rdr.Read_sql_identifier();
|
||||
Dbmeta_fld_tid type = this.Parse_type(rdr);
|
||||
Dbmeta_fld_itm fld = new Dbmeta_fld_itm(String_.new_u8(name), type);
|
||||
DbmetaFldType type = this.Parse_type(rdr);
|
||||
DbmetaFldItm fld = new DbmetaFldItm(String_.new_u8(name), type);
|
||||
byte[] src = rdr.Src(); int src_len = rdr.Src_end();
|
||||
while (true) {
|
||||
rdr.Skip_ws();
|
||||
@@ -51,7 +60,7 @@ public class Dbmeta_parser__fld {
|
||||
}
|
||||
}
|
||||
}
|
||||
@gplx.Internal protected Dbmeta_fld_tid Parse_type(Bry_rdr rdr) {
|
||||
@gplx.Internal protected DbmetaFldType Parse_type(Bry_rdr rdr) {
|
||||
rdr.Skip_ws();
|
||||
Dbmeta_parser__fld_itm type_itm = (Dbmeta_parser__fld_itm)rdr.Chk_trie_as_obj(trv, type_trie);
|
||||
rdr.Move_by(type_itm.Word().length);
|
||||
@@ -66,7 +75,7 @@ public class Dbmeta_parser__fld {
|
||||
}
|
||||
rdr.Skip_ws().Chk(Byte_ascii.Paren_end);
|
||||
}
|
||||
return new Dbmeta_fld_tid(type_itm.Tid_ansi(), type_itm.Tid_sqlite(), type_itm.Word(), len_1, len_2);
|
||||
return new DbmetaFldType(type_itm.Tid_ansi(), String_.new_u8(type_itm.Word()), len_1, len_2);
|
||||
}
|
||||
private static final Btrie_slim_mgr fld_trie = fld_trie_init
|
||||
( Dbmeta_fld_wkr__nullable_null.Instance
|
||||
@@ -84,20 +93,20 @@ public class Dbmeta_parser__fld {
|
||||
private static final Btrie_slim_mgr type_trie = type_trie_init();
|
||||
private static Btrie_slim_mgr type_trie_init() {
|
||||
Btrie_slim_mgr rv = Btrie_slim_mgr.ci_a7();
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__byte , Sqlite_tid.Tid_int , 0, "tinyint", "int2");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__short , Sqlite_tid.Tid_int , 0, "smallint");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__int , Sqlite_tid.Tid_int , 0, "int", "integer", "mediumint");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__long , Sqlite_tid.Tid_int , 0, "bigint", "int8"); // "UNSIGNED BIG INT"
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__str , Sqlite_tid.Tid_text , 1, "character", "varchar", "nchar"); // "varying character", "native character"
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__text , Sqlite_tid.Tid_text , 0, "text", "clob");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__bry , Sqlite_tid.Tid_none , 0, "blob", "mediumblob");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__float , Sqlite_tid.Tid_real , 0, "float");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__double , Sqlite_tid.Tid_real , 0, "real", "double"); // "double precision"
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__decimal , Sqlite_tid.Tid_numeric , 0, "numeric");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__decimal , Sqlite_tid.Tid_numeric , 2, "decimal");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__decimal , Sqlite_tid.Tid_numeric , 2, "decimal");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__bool , Sqlite_tid.Tid_numeric , 0, "boolean", "bit"); // "bit" is not SQLITE
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, Dbmeta_fld_tid.Tid__date , Sqlite_tid.Tid_numeric , 0, "date", "datetime");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, DbmetaFldType.TidByte, SqliteType.Int, 0, "tinyint", "int2");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, DbmetaFldType.TidShort, SqliteType.Int, 0, "smallint");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, DbmetaFldType.TidInt, SqliteType.Int, 0, "int", "integer", "mediumint");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, DbmetaFldType.TidLong, SqliteType.Int, 0, "bigint", "int8"); // "UNSIGNED BIG INT"
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, DbmetaFldType.TidStr, SqliteType.Text, 1, "character", "varchar", "nchar"); // "varying character", "native character"
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, DbmetaFldType.TidText, SqliteType.Text, 0, "text", "clob");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, DbmetaFldType.TidBry, SqliteType.None, 0, "blob", "mediumblob");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, DbmetaFldType.TidFloat, SqliteType.Real, 0, "float");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, DbmetaFldType.TidDouble, SqliteType.Real, 0, "real", "double"); // "double precision"
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, DbmetaFldType.TidDecimal, SqliteType.Numeric, 0, "numeric");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, DbmetaFldType.TidDecimal, SqliteType.Numeric, 2, "decimal");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, DbmetaFldType.TidDecimal, SqliteType.Numeric, 2, "decimal");
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, DbmetaFldType.TidBool, SqliteType.Numeric, 0, "boolean", "bit"); // "bit" is not SQLITE
|
||||
Dbmeta_parser__fld_itm.reg_many(rv, DbmetaFldType.TidDate, SqliteType.Numeric, 0, "date", "datetime");
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,60 +13,67 @@ 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.Bool_;
|
||||
import gplx.Bry_;
|
||||
import gplx.Int_;
|
||||
import gplx.Object_;
|
||||
import gplx.Tfds;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.dbs.DbmetaFldType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
public class Dbmeta_parser__fld_tst {
|
||||
@Before public void init() {fxt.Clear();} private Dbmeta_parser__fld_fxt fxt = new Dbmeta_parser__fld_fxt();
|
||||
@Test public void Parse_type() {
|
||||
fxt.Test_parse_type("int" , fxt.Make_type(Dbmeta_fld_tid.Tid__int));
|
||||
fxt.Test_parse_type("varchar(255)" , fxt.Make_type(Dbmeta_fld_tid.Tid__str, 255));
|
||||
fxt.Test_parse_type("decimal(12,10)" , fxt.Make_type(Dbmeta_fld_tid.Tid__decimal, 12, 10));
|
||||
fxt.Test_parse_type(" int" , fxt.Make_type(Dbmeta_fld_tid.Tid__int));
|
||||
fxt.Test_parse_type(" decimal ( 12 , 10 )" , fxt.Make_type(Dbmeta_fld_tid.Tid__decimal, 12, 10));
|
||||
fxt.Test_parse_type("int" , fxt.Make_type(DbmetaFldType.TidInt));
|
||||
fxt.Test_parse_type("varchar(255)" , fxt.Make_type(DbmetaFldType.TidStr, 255));
|
||||
fxt.Test_parse_type("decimal(12,10)" , fxt.Make_type(DbmetaFldType.TidDecimal, 12, 10));
|
||||
fxt.Test_parse_type(" int" , fxt.Make_type(DbmetaFldType.TidInt));
|
||||
fxt.Test_parse_type(" decimal ( 12 , 10 )" , fxt.Make_type(DbmetaFldType.TidDecimal, 12, 10));
|
||||
}
|
||||
@Test public void Parse_fld() {
|
||||
fxt.Test_parse_fld("name_1 int" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_unknown));
|
||||
fxt.Test_parse_fld("name_1 int null" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_null));
|
||||
fxt.Test_parse_fld("name_1 int not null" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_not_null));
|
||||
fxt.Test_parse_fld("name_1 int not null autoincrement" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_not_null, Bool_.N, Bool_.Y));
|
||||
fxt.Test_parse_fld("name_1 int not null primary key" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_not_null, Bool_.Y, Bool_.N));
|
||||
fxt.Test_parse_fld("name_1 int not null default -1" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_not_null, Bool_.Y, Bool_.N, -1));
|
||||
fxt.Test_parse_fld("name_1 varchar(3) not null default 'abc'" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__str, Dbmeta_fld_itm.Nullable_not_null, Bool_.Y, Bool_.N, "abc"));
|
||||
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"));
|
||||
}
|
||||
@Test public void Comment() {
|
||||
fxt.Test_parse_fld("name_1 int --a\n" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_unknown));
|
||||
fxt.Test_parse_fld("name_1 int --a\n" , fxt.Make_fld("name_1", DbmetaFldType.TidInt, DbmetaFldItm.NullableUnspecified));
|
||||
}
|
||||
}
|
||||
class Dbmeta_parser__fld_fxt {
|
||||
private final Dbmeta_parser__fld fld_parser = new Dbmeta_parser__fld();
|
||||
private final Sql_bry_rdr rdr = new Sql_bry_rdr();
|
||||
public void Clear() {}
|
||||
public Dbmeta_fld_tid Make_type(int tid_ansi) {return new Dbmeta_fld_tid(tid_ansi, -1, null, Int_.Min_value, Int_.Min_value);}
|
||||
public Dbmeta_fld_tid Make_type(int tid_ansi, int len_1) {return new Dbmeta_fld_tid(tid_ansi, -1, null, len_1, Int_.Min_value);}
|
||||
public Dbmeta_fld_tid Make_type(int tid_ansi, int len_1, int len_2) {return new Dbmeta_fld_tid(tid_ansi, -1, null, len_1, len_2);}
|
||||
public Dbmeta_fld_itm Make_fld(String name, int tid_ansi, int nullable) {return Make_fld(name, tid_ansi, nullable, false, false, null);}
|
||||
public Dbmeta_fld_itm Make_fld(String name, int tid_ansi, int nullable, boolean autonumber, boolean primary_key) {return Make_fld(name, tid_ansi, nullable, false, false, null);}
|
||||
public Dbmeta_fld_itm Make_fld(String name, int tid_ansi, int nullable, boolean autonumber, boolean primary_key, Object default_val) {
|
||||
Dbmeta_fld_itm rv = new Dbmeta_fld_itm(name, Make_type(tid_ansi));
|
||||
rv.Nullable_tid_(nullable);
|
||||
if (autonumber) rv.Autonum_y_();
|
||||
if (primary_key) rv.Primary_y_();
|
||||
rv.Default_(default_val);
|
||||
public DbmetaFldType Make_type(int tid_ansi) {return new DbmetaFldType(tid_ansi, null, Int_.Min_value, Int_.Min_value);}
|
||||
public DbmetaFldType Make_type(int tid_ansi, int len_1) {return new DbmetaFldType(tid_ansi, null, len_1, Int_.Min_value);}
|
||||
public DbmetaFldType Make_type(int tid_ansi, int len_1, int len_2) {return new DbmetaFldType(tid_ansi, null, len_1, len_2);}
|
||||
public DbmetaFldItm Make_fld(String name, int tid_ansi, int nullable) {return Make_fld(name, tid_ansi, nullable, false, false, null);}
|
||||
public DbmetaFldItm Make_fld(String name, int tid_ansi, int nullable, boolean autonumber, boolean primary_key) {return Make_fld(name, tid_ansi, nullable, false, false, null);}
|
||||
public DbmetaFldItm Make_fld(String name, int tid_ansi, int nullable, boolean autonumber, boolean primary_key, Object default_val) {
|
||||
DbmetaFldItm rv = new DbmetaFldItm(name, Make_type(tid_ansi));
|
||||
rv.NullableSet(nullable);
|
||||
if (autonumber) rv.AutonumSetY();
|
||||
if (primary_key) rv.PrimarySetY();
|
||||
rv.DefaultValSet(default_val);
|
||||
return rv;
|
||||
}
|
||||
public void Test_parse_type(String src, Dbmeta_fld_tid expd_type) {
|
||||
public void Test_parse_type(String src, DbmetaFldType expd_type) {
|
||||
rdr.Init_by_src(Bry_.new_u8(src));
|
||||
Dbmeta_fld_tid actl_type = fld_parser.Parse_type(rdr);
|
||||
Tfds.Eq(expd_type.Tid_ansi() , actl_type.Tid_ansi());
|
||||
Tfds.Eq(expd_type.Len_1() , actl_type.Len_1());
|
||||
Tfds.Eq(expd_type.Len_2() , actl_type.Len_2());
|
||||
DbmetaFldType actl_type = fld_parser.Parse_type(rdr);
|
||||
Tfds.Eq(expd_type.Tid() , actl_type.Tid());
|
||||
Tfds.Eq(expd_type.Len1() , actl_type.Len1());
|
||||
Tfds.Eq(expd_type.Len2() , actl_type.Len2());
|
||||
}
|
||||
public void Test_parse_fld(String src, Dbmeta_fld_itm expd_fld) {
|
||||
public void Test_parse_fld(String src, DbmetaFldItm expd_fld) {
|
||||
rdr.Init_by_src(Bry_.new_u8(src));
|
||||
Dbmeta_fld_itm actl_fld = fld_parser.Parse_fld(rdr);
|
||||
DbmetaFldItm actl_fld = fld_parser.Parse_fld(rdr);
|
||||
Tfds.Eq(expd_fld.Name() , actl_fld.Name());
|
||||
Tfds.Eq(expd_fld.Type().Tid_ansi() , actl_fld.Type().Tid_ansi());
|
||||
Tfds.Eq(expd_fld.Nullable_tid() , actl_fld.Nullable_tid());
|
||||
Tfds.Eq(Object_.Xto_str_strict_or_empty(expd_fld.Default()), Object_.Xto_str_strict_or_empty(actl_fld.Default()));
|
||||
Tfds.Eq(expd_fld.Type().Tid() , actl_fld.Type().Tid());
|
||||
Tfds.Eq(expd_fld.Nullable() , actl_fld.Nullable());
|
||||
Tfds.Eq(Object_.Xto_str_strict_or_empty(expd_fld.DefaultVal()), Object_.Xto_str_strict_or_empty(actl_fld.DefaultVal()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import gplx.core.brys.*; import gplx.core.btries.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Dbmeta_parser__idx {
|
||||
private final Sql_bry_rdr rdr = new Sql_bry_rdr();
|
||||
private final List_adp tmp_list = List_adp_.New();
|
||||
@@ -40,7 +40,7 @@ public class Dbmeta_parser__idx {
|
||||
byte sym = rdr.Skip_ws().Read_byte();
|
||||
if (sym == Byte_ascii.Paren_end) break;
|
||||
}
|
||||
return new Dbmeta_idx_itm(unique, String_.new_u8(tbl_name), String_.new_u8(idx_name), (Dbmeta_idx_fld[])tmp_list.To_ary_and_clear(Dbmeta_idx_fld.class));
|
||||
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));
|
||||
}
|
||||
private static final byte Tid__create = 0, Tid__unique = 1, Tid__index = 2, Tid__on = 3;
|
||||
private static final byte[]
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import gplx.core.brys.*; import gplx.core.btries.*;
|
||||
/*
|
||||
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.core.btries.*;
|
||||
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();
|
||||
@@ -27,7 +27,7 @@ public class Dbmeta_parser__tbl {
|
||||
Dbmeta_tbl_itm rv = Dbmeta_tbl_itm.New(String_.new_u8(tbl_name));
|
||||
boolean loop = true;
|
||||
while (loop) {
|
||||
Dbmeta_fld_itm fld = fld_parser.Parse_fld(rdr); if (fld == null) rdr.Err_wkr().Fail("unknown field", "src", src);
|
||||
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];
|
||||
|
||||
@@ -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.metas.parsers; import gplx.*; import gplx.dbs.*; import gplx.dbs.metas.*;
|
||||
import org.junit.*; import gplx.dbs.engines.sqlite.*;
|
||||
package gplx.dbs.metas.parsers; import gplx.Bry_;
|
||||
import gplx.String_;
|
||||
import gplx.Tfds;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.dbs.DbmetaFldType;
|
||||
import gplx.dbs.Dbmeta_tbl_itm;
|
||||
import gplx.dbs.metas.Dbmeta_fld_mgr;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
public class Dbmeta_parser__tbl_tst {
|
||||
@Before public void init() {fxt.Clear();} private Dbmeta_parser__tbl_fxt fxt = new Dbmeta_parser__tbl_fxt();
|
||||
@Test public void Test_parse() {
|
||||
@@ -42,9 +49,9 @@ class Dbmeta_parser__tbl_fxt {
|
||||
public void Clear() {}
|
||||
public Dbmeta_tbl_itm Make_tbl(String tbl_name, String... fld_names) {
|
||||
int len = fld_names.length;
|
||||
Dbmeta_fld_itm[] flds = new Dbmeta_fld_itm[len];
|
||||
DbmetaFldItm[] flds = new DbmetaFldItm[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
flds[i] = new Dbmeta_fld_itm(fld_names[i], new Dbmeta_fld_tid(Dbmeta_fld_tid.Tid__int, Sqlite_tid.Tid_int, Bry_.new_a7("int"), Int_.Min_value, Int_.Min_value));
|
||||
flds[i] = new DbmetaFldItm(fld_names[i], DbmetaFldType.ItmInt);
|
||||
return Dbmeta_tbl_itm.New(tbl_name, flds);
|
||||
}
|
||||
public void Test_parse(String src, Dbmeta_tbl_itm expd_tbl) {
|
||||
|
||||
@@ -19,8 +19,8 @@ import gplx.dbs.sqls.SqlQryWtr;
|
||||
import gplx.dbs.sqls.itms.*;
|
||||
public class Db_qry__select_cmd implements Db_qry {
|
||||
public int Tid() {return Db_qry_.Tid_select;}
|
||||
public boolean Exec_is_rdr() {return Bool_.Y;}
|
||||
public String Base_table() {return from.Base_tbl.Name;}
|
||||
public boolean ReturnsRdr() {return Bool_.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);}
|
||||
public Db_qry__select_cmd From_(String name, String alias) {return From_(Sql_tbl_itm.Db__null, name, alias);}
|
||||
@@ -108,6 +108,6 @@ public class Db_qry__select_cmd implements Db_qry {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String To_sql__exec(SqlQryWtr wtr) {return wtr.ToSqlStr(this, Bool_.N);}
|
||||
public String ToSqlExec(SqlQryWtr wtr) {return wtr.ToSqlStr(this, Bool_.N);}
|
||||
public String To_sql__prep(SqlQryWtr wtr) {return wtr.ToSqlStr(this, Bool_.Y);}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ public class Db_qry__select_in_tbl implements Db_qry {
|
||||
this.base_table = base_table; this.select_flds = select_flds; this.where_flds = where_flds; this.group_by_sql = group_by_sql; this.having_sql = having_sql; this.order_by_sql = order_by_sql; this.limit_sql = limit_sql;
|
||||
}
|
||||
public int Tid() {return Db_qry_.Tid_select_in_tbl;}
|
||||
public boolean Exec_is_rdr() {return true;}
|
||||
public String Base_table() {return base_table;} private final String base_table;
|
||||
public boolean ReturnsRdr() {return true;}
|
||||
public String BaseTable() {return base_table;} private final String base_table;
|
||||
public Criteria Where() {return where;} private Criteria where;
|
||||
public void Where_(Criteria v) {this.where = v;}
|
||||
public String[] Select_flds() {return select_flds;} private final String[] select_flds;
|
||||
@@ -40,7 +40,7 @@ public class Db_qry__select_in_tbl implements Db_qry {
|
||||
public String Having_sql() {return having_sql;} private final String having_sql;
|
||||
public String Order_by_sql() {return order_by_sql;} public Db_qry__select_in_tbl Order_by_sql_(String v) {order_by_sql = v; return this;} private String order_by_sql;
|
||||
public String Limit_sql() {return limit_sql;} private final String limit_sql;
|
||||
public String To_sql__exec(SqlQryWtr wtr) {
|
||||
public String ToSqlExec(SqlQryWtr wtr) {
|
||||
synchronized (this) {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
sb.Add("SELECT ");
|
||||
|
||||
@@ -18,9 +18,9 @@ import gplx.core.criterias.*; import gplx.dbs.sqls.*;
|
||||
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 Exec_is_rdr() {return Bool_.N;}
|
||||
public String Base_table() {return base_table;} private final String base_table;
|
||||
public String To_sql__exec(SqlQryWtr wtr) {return wtr.ToSqlStr(this, false);}
|
||||
public boolean ReturnsRdr() {return Bool_.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;
|
||||
public int Exec_qry(Db_conn conn) {return conn.Exec_qry(this);}
|
||||
public static Db_qry_delete new_all_(String tbl) {return new Db_qry_delete(tbl, Criteria_.All);}
|
||||
|
||||
@@ -39,5 +39,5 @@ public class Db_qry_dml_tst {
|
||||
qry.Where_(Criteria_.And(Db_crt_.New_eq("id", 0), Db_crt_.New_mt("startTime", DateAdp_.parse_gplx("2005-01-01"))));
|
||||
tst_XtoSql(qry, "UPDATE tbl0 SET id=1, name='me', startTime='2007-12-23 00:00:00.000' WHERE (id = 0 AND startTime > '2005-01-01 00:00:00.000')");
|
||||
}
|
||||
void tst_XtoSql(Db_qry qry, String expd) {Tfds.Eq(expd, qry.To_sql__exec(SqlQryWtrUtl.NewBasic()));}
|
||||
void tst_XtoSql(Db_qry qry, String expd) {Tfds.Eq(expd, qry.ToSqlExec(SqlQryWtrUtl.NewBasic()));}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ package gplx.dbs.qrys; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.dbs.sqls.*;
|
||||
public class Db_qry_flush implements Db_qry {
|
||||
public int Tid() {return Db_qry_.Tid_flush;}
|
||||
public boolean Exec_is_rdr() {return false;}
|
||||
public String Base_table() {return tableNames[0];}
|
||||
public String To_sql__exec(SqlQryWtr wtr) {return wtr.ToSqlStr(this, false);}
|
||||
public boolean ReturnsRdr() {return false;}
|
||||
public String BaseTable() {return tableNames[0];}
|
||||
public String ToSqlExec(SqlQryWtr wtr) {return wtr.ToSqlStr(this, false);}
|
||||
public int Exec_qry(Db_conn conn) {return conn.Exec_qry(this);}
|
||||
|
||||
public String[] TableNames() {return tableNames;} private String[] tableNames;
|
||||
|
||||
@@ -18,10 +18,10 @@ import gplx.dbs.sqls.*; import gplx.dbs.sqls.itms.*;
|
||||
public class Db_qry_insert implements Db_arg_owner {
|
||||
public Db_qry_insert(String base_table) {this.base_table = base_table;}
|
||||
public int Tid() {return Db_qry_.Tid_insert;}
|
||||
public boolean Exec_is_rdr() {return false;}
|
||||
public String To_sql__exec(SqlQryWtr wtr) {return wtr.ToSqlStr(this, false);}
|
||||
public boolean ReturnsRdr() {return false;}
|
||||
public String ToSqlExec(SqlQryWtr wtr) {return wtr.ToSqlStr(this, false);}
|
||||
public int Exec_qry(Db_conn conn) {return conn.Exec_qry(this);}
|
||||
public String Base_table() {return base_table;} private String base_table;
|
||||
public String BaseTable() {return base_table;} private String base_table;
|
||||
public String[] Cols_for_insert() {return cols_for_insert;} private String[] cols_for_insert;
|
||||
public Db_arg_owner From_(String tbl) {base_table = tbl; return this;}
|
||||
public Keyval_hash Args() {return args;} private final Keyval_hash args = new Keyval_hash();
|
||||
@@ -35,7 +35,7 @@ public class Db_qry_insert implements Db_arg_owner {
|
||||
public Db_arg_owner Val_blob(String k, byte[] v) {return Val_obj_type(k, v, Db_val_type.Tid_bry);}
|
||||
public Db_arg_owner Val_obj(String k, Object v) {return Val_obj_type(k, v, Db_val_type.Tid_null);}
|
||||
public Db_arg_owner Val_obj_type(String key, Object val, byte val_tid) {
|
||||
if (key == Dbmeta_fld_itm.Key_null) return this;
|
||||
if (key == DbmetaFldItm.KeyNull) return this;
|
||||
args.Add(key, new Db_arg(key, val, val_tid));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -83,5 +83,5 @@ public class Db_qry_select_tst {
|
||||
// expd = "SELECT fld0, fld1 FROM tbl0 GROUP BY fld0, fld1 HAVING Count(fld0) > 1";
|
||||
// Tfds.Eq(cmd.To_str(), expd);
|
||||
// }
|
||||
void tst_XtoStr(Db_qry qry, String expd) {Tfds.Eq(expd, cmd.To_sql__exec(SqlQryWtrUtl.NewBasic()));}
|
||||
void tst_XtoStr(Db_qry qry, String expd) {Tfds.Eq(expd, cmd.ToSqlExec(SqlQryWtrUtl.NewBasic()));}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ package gplx.dbs.qrys; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.dbs.sqls.*;
|
||||
public class Db_qry_sql implements Db_qry {
|
||||
public int Tid() {return Db_qry_.Tid_sql;}
|
||||
public boolean Exec_is_rdr() {return isReader;} private boolean isReader;
|
||||
public String Base_table() {throw Err_.new_unimplemented();}
|
||||
public String To_sql__exec(SqlQryWtr wtr) {return sql;} private String sql;
|
||||
public boolean ReturnsRdr() {return isReader;} private boolean isReader;
|
||||
public String BaseTable() {throw Err_.new_unimplemented();}
|
||||
public String ToSqlExec(SqlQryWtr wtr) {return sql;} private String sql;
|
||||
public int Exec_qry(Db_conn conn) {return conn.Exec_qry(this);}
|
||||
public static Db_qry_sql dml_(String sql) {return sql_(sql);}
|
||||
public static Db_qry_sql ddl_(String sql) {return sql_(sql);}
|
||||
|
||||
@@ -17,10 +17,10 @@ package gplx.dbs.qrys; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.core.criterias.*; import gplx.dbs.sqls.*;
|
||||
public class Db_qry_update implements Db_arg_owner {
|
||||
public int Tid() {return Db_qry_.Tid_update;}
|
||||
public boolean Exec_is_rdr() {return false;}
|
||||
public String To_sql__exec(SqlQryWtr wtr) {return wtr.ToSqlStr(this, false);}
|
||||
public boolean ReturnsRdr() {return false;}
|
||||
public String ToSqlExec(SqlQryWtr wtr) {return wtr.ToSqlStr(this, false);}
|
||||
public int Exec_qry(Db_conn conn) {return conn.Exec_qry(this);}
|
||||
public String Base_table() {return base_table;} private String base_table;
|
||||
public String BaseTable() {return base_table;} private String base_table;
|
||||
public String[] Cols_for_update() {return cols_for_update;} private String[] cols_for_update;
|
||||
public Criteria Where() {return where;} public Db_qry_update Where_(Criteria crt) {where = crt; return this;} private Criteria where;
|
||||
public Db_arg_owner From_(String tbl) {base_table = tbl; return this;}
|
||||
@@ -35,7 +35,7 @@ public class Db_qry_update implements Db_arg_owner {
|
||||
public Db_arg_owner Val_blob(String k, byte[] v) {return Val_obj_type(k, v, Db_val_type.Tid_bry);}
|
||||
public Db_arg_owner Val_obj(String k, Object v) {return Val_obj_type(k, v, Db_val_type.Tid_null);}
|
||||
public Db_arg_owner Val_obj_type(String key, Object val, byte val_tid) {
|
||||
if (key == Dbmeta_fld_itm.Key_null) return this;
|
||||
if (key == DbmetaFldItm.KeyNull) return this;
|
||||
args.Add(key, new Db_arg(key, val, val_tid));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import gplx.dbs.Db_qry;
|
||||
import gplx.dbs.Db_qry_;
|
||||
import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.Dbmeta_fld_itm;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.dbs.engines.Db_engine;
|
||||
import gplx.objects.lists.GfoListBase;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt_cmd(Db_engine engine, Db_qry qry) {Ctor_stmt(engine, qry);}
|
||||
public void Ctor_stmt(Db_engine engine, Db_qry qry) {
|
||||
this.engine = engine;
|
||||
sql = qry.Tid() == Db_qry_.Tid_select_in_tbl ? ((Db_qry__select_in_tbl)qry).To_sql__exec(engine.Sql_wtr()) : engine.Sql_wtr().ToSqlStr(qry, true);
|
||||
sql = qry.Tid() == Db_qry_.Tid_select_in_tbl ? ((Db_qry__select_in_tbl)qry).ToSqlExec(engine.Sql_wtr()) : engine.Sql_wtr().ToSqlStr(qry, true);
|
||||
Reset_stmt();
|
||||
}
|
||||
public Db_stmt Reset_stmt() {
|
||||
@@ -57,7 +57,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Val_byte(String k, byte v) {return Add_byte(Bool_.N, k, v);}
|
||||
public Db_stmt Val_byte(byte v) {return Add_byte(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_byte(boolean where, String k, byte v) {
|
||||
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
stmt.setByte(++val_idx, v);
|
||||
paramList.Add(v);
|
||||
@@ -72,7 +72,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Val_int(String k, int v) {return Add_int(Bool_.N, k, v);}
|
||||
public Db_stmt Val_int(int v) {return Add_int(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_int(boolean where, String k, int v) {
|
||||
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
stmt.setInt(++val_idx, v);
|
||||
paramList.Add(v);
|
||||
@@ -86,7 +86,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Val_long(String k, long v) {return Add_long(Bool_.N, k, v);}
|
||||
public Db_stmt Val_long(long v) {return Add_long(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_long(boolean where, String k, long v) {
|
||||
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
stmt.setLong(++val_idx, v);
|
||||
paramList.Add(v);
|
||||
@@ -100,7 +100,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Val_float(String k, float v) {return Add_float(Bool_.N, k, v);}
|
||||
public Db_stmt Val_float(float v) {return Add_float(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_float(boolean where, String k, float v) {
|
||||
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
stmt.setFloat(++val_idx, v);
|
||||
paramList.Add(v);
|
||||
@@ -114,7 +114,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Val_double(String k, double v) {return Add_double(Bool_.N, k, v);}
|
||||
public Db_stmt Val_double(double v) {return Add_double(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_double(boolean where, String k, double v) {
|
||||
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
stmt.setDouble(++val_idx, v);
|
||||
paramList.Add(v);
|
||||
@@ -128,7 +128,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Val_decimal(String k, Decimal_adp v) {return Add_decimal(Bool_.N, k, v);}
|
||||
public Db_stmt Val_decimal(Decimal_adp v) {return Add_decimal(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_decimal(boolean where, String k, Decimal_adp v) {
|
||||
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
stmt.setBigDecimal(++val_idx, v.Under_as_native());
|
||||
paramList.Add(v);
|
||||
@@ -142,7 +142,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Val_bry(String k, byte[] v) {return Add_bry(Bool_.N, k, v);}
|
||||
public Db_stmt Val_bry(byte[] v) {return Add_bry(Bool_.N, Key_na, v);}
|
||||
private Db_stmt Add_bry(boolean where, String k, byte[] v) {
|
||||
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
stmt.setBytes(++val_idx, v);
|
||||
paramList.Add(v);
|
||||
@@ -160,7 +160,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Val_str(String k, String v) {return Add_str(Bool_.N, k, v);}
|
||||
public Db_stmt Val_str(String v) {return Add_str(Bool_.N, Key_na, v);}
|
||||
protected Db_stmt Add_str(boolean where, String k, String v) {
|
||||
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
stmt.setString(++val_idx, v);
|
||||
paramList.Add(v);
|
||||
@@ -173,7 +173,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Crt_date(String k, DateAdp v) {return Add_date(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_date(String k, DateAdp v) {return Add_date(Bool_.N, k, v);}
|
||||
protected Db_stmt Add_date(boolean where, String k, DateAdp v) {
|
||||
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
stmt.setTimestamp(++val_idx, new java.sql.Timestamp(v.UnderDateTime().getTime().getTime()));
|
||||
paramList.Add(v);
|
||||
@@ -186,7 +186,7 @@ public class Db_stmt_cmd implements Db_stmt {
|
||||
public Db_stmt Crt_text(String k, String v) {return Add_text(Bool_.Y, k, v);}
|
||||
public Db_stmt Val_text(String k, String v) {return Add_text(Bool_.N, k, v);}
|
||||
private Db_stmt Add_text(boolean where, String k, String v) {
|
||||
if (k == Dbmeta_fld_itm.Key_null) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
if (k == DbmetaFldItm.KeyNull) return this; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
try {
|
||||
stmt.setString(++val_idx, v);
|
||||
paramList.Add(v);
|
||||
|
||||
@@ -135,14 +135,14 @@ public class Db_stmt_sql implements Db_stmt {// used for formatting SQL statemen
|
||||
}
|
||||
public void Rls() {this.Clear();}
|
||||
public void Add(String k, String v) {
|
||||
if (k == Dbmeta_fld_itm.Key_null) return; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
if (k == DbmetaFldItm.KeyNull) return; // key is explicitly null; ignore; allows version_2+ type definitions
|
||||
args.Add(v);
|
||||
}
|
||||
public String Xto_sql() {
|
||||
tmp_fmtr.Bld_bfr_many(tmp_bfr, (Object[])args.To_ary_and_clear(Object.class));
|
||||
tmp_fmtr.Bld_bfr_many(tmp_bfr, (Object[])args.ToAryAndClear(Object.class));
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
public int Args_len() {return args.Count();}
|
||||
public int Args_len() {return args.Len();}
|
||||
public String Args_get_at(int i) {return (String)args.Get_at(i);}
|
||||
private String sql_orig;
|
||||
public Db_qry Qry() {return qry;} private Db_qry qry;
|
||||
@@ -169,7 +169,7 @@ public class Db_stmt_sql implements Db_stmt {// used for formatting SQL statemen
|
||||
}
|
||||
public static String Xto_str(Bry_bfr tmp_bfr, Bry_fmtr tmp_fmtr, String sql_str, List_adp args) {
|
||||
Init_fmtr(tmp_bfr, tmp_fmtr, sql_str);
|
||||
Object[] ary = args.To_obj_ary();
|
||||
Object[] ary = args.ToObjAry();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Object obj = ary[i];
|
||||
|
||||
@@ -33,8 +33,8 @@ class Db_obj_ary_fxt {
|
||||
public Db_obj_ary_fxt Init_vals(Object... ary) {vals_list.Add(ary); return this;} private List_adp vals_list = List_adp_.New();
|
||||
public Db_obj_ary_fxt Test_sql(String expd) {
|
||||
Sql_core_wtr cmd_wtr = (Sql_core_wtr)SqlQryWtrUtl.NewBasic();
|
||||
crt.Flds_((Db_obj_ary_fld[])flds_list.To_ary_and_clear(Db_obj_ary_fld.class));
|
||||
crt.Vals_((Object[][])vals_list.To_ary_and_clear(Object[].class));
|
||||
crt.Flds_((Db_obj_ary_fld[])flds_list.ToAryAndClear(Db_obj_ary_fld.class));
|
||||
crt.Vals_((Object[][])vals_list.ToAryAndClear(Object[].class));
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
cmd_wtr.Where_wtr().Bld_where__db_obj(bfr, ctx, crt);
|
||||
Tfds.Eq(expd, bfr.To_str_and_clear());
|
||||
|
||||
@@ -13,13 +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.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
package gplx.dbs.sqls.itms; import gplx.*;
|
||||
public class Sql_order_clause {
|
||||
private final List_adp list = List_adp_.New();
|
||||
private Sql_order_fld[] ary;
|
||||
public void Flds__add(Sql_order_fld fld) {list.Add(fld);}
|
||||
public Sql_order_fld[] Flds() {
|
||||
if (ary == null) ary = (Sql_order_fld[])list.To_ary_and_clear(Sql_order_fld.class);
|
||||
if (ary == null) ary = (Sql_order_fld[])list.ToAryAndClear(Sql_order_fld.class);
|
||||
return ary;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +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.sqls.itms; import gplx.*; import gplx.dbs.*; import gplx.dbs.sqls.*;
|
||||
public class Sql_select_fld_list {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Len() {return hash.Count();}
|
||||
public Sql_select_fld_list Clear() {hash.Clear();return this;}
|
||||
public Sql_select_fld Get_at(int i) {return (Sql_select_fld)hash.Get_at(i);}
|
||||
public void Add(Sql_select_fld fld) {hash.Add(fld.Alias, fld);}
|
||||
}
|
||||
package gplx.dbs.sqls.itms; import gplx.*;
|
||||
public class Sql_select_fld_list {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Len() {return hash.Len();}
|
||||
public Sql_select_fld_list Clear() {hash.Clear();return this;}
|
||||
public Sql_select_fld Get_at(int i) {return (Sql_select_fld)hash.Get_at(i);}
|
||||
public void Add(Sql_select_fld fld) {hash.Add(fld.Alias, fld);}
|
||||
}
|
||||
|
||||
@@ -54,20 +54,20 @@ public class Sql_core_wtr implements SqlQryWtr {
|
||||
case Db_qry_.Tid_update: return Bld_qry_update(ctx, (Db_qry_update)qry);
|
||||
case Db_qry_.Tid_select_in_tbl:
|
||||
case Db_qry_.Tid_select: select_wtr.Bld_qry_select(bfr, ctx, (Db_qry__select_cmd)qry); return bfr.To_str_and_clear();
|
||||
case Db_qry_.Tid_pragma: return ((gplx.dbs.engines.sqlite.Sqlite_pragma)qry).To_sql__exec(this);
|
||||
case Db_qry_.Tid_sql: return ((Db_qry_sql)qry).To_sql__exec(this);
|
||||
case Db_qry_.Tid_pragma: return ((gplx.dbs.engines.sqlite.Sqlite_pragma)qry).ToSqlExec(this);
|
||||
case Db_qry_.Tid_sql: return ((Db_qry_sql)qry).ToSqlExec(this);
|
||||
default: throw Err_.new_unhandled(qry.Tid());
|
||||
}
|
||||
}
|
||||
}
|
||||
private String Bld_qry_delete(Sql_wtr_ctx ctx, Db_qry_delete qry) {
|
||||
bfr.Add_str_u8_many("DELETE FROM ", qry.Base_table());
|
||||
bfr.Add_str_u8_many("DELETE FROM ", qry.BaseTable());
|
||||
where_wtr.Bld_where(bfr, ctx, qry.Where());
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
private String Bld_qry_insert(Sql_wtr_ctx ctx, Db_qry_insert qry) {
|
||||
if (qry.Select() != null) {
|
||||
bfr.Add_str_u8_many("INSERT INTO ", qry.Base_table(), " (");
|
||||
bfr.Add_str_u8_many("INSERT INTO ", qry.BaseTable(), " (");
|
||||
int cols_len = qry.Cols().Len();
|
||||
for (int i = 0; i < cols_len; i++) {
|
||||
Sql_select_fld fld = qry.Cols().Get_at(i);
|
||||
@@ -77,9 +77,9 @@ public class Sql_core_wtr implements SqlQryWtr {
|
||||
select_wtr.Bld_qry_select(bfr, ctx, qry.Select());
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
int arg_count = qry.Args().Count(); if (arg_count == 0) throw Err_.new_wo_type("Db_qry_insert has no columns", "base_table", qry.Base_table());
|
||||
int arg_count = qry.Args().Count(); if (arg_count == 0) throw Err_.new_wo_type("Db_qry_insert has no columns", "base_table", qry.BaseTable());
|
||||
int last = arg_count - 1;
|
||||
bfr.Add_str_u8_many("INSERT INTO ", qry.Base_table(), " (");
|
||||
bfr.Add_str_u8_many("INSERT INTO ", qry.BaseTable(), " (");
|
||||
for (int i = 0; i < arg_count; i++) {
|
||||
Keyval pair = qry.Args().Get_at(i);
|
||||
this.Bld_col_name(bfr, pair.Key());
|
||||
@@ -95,8 +95,8 @@ public class Sql_core_wtr implements SqlQryWtr {
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
private String Bld_qry_update(Sql_wtr_ctx ctx, Db_qry_update qry) {
|
||||
int arg_count = qry.Args().Count(); if (arg_count == 0) throw Err_.new_wo_type("Db_qry_update has no columns", "base_table", qry.Base_table());
|
||||
bfr.Add_str_u8_many("UPDATE ", qry.Base_table(), " SET ");
|
||||
int arg_count = qry.Args().Count(); if (arg_count == 0) throw Err_.new_wo_type("Db_qry_update has no columns", "base_table", qry.BaseTable());
|
||||
bfr.Add_str_u8_many("UPDATE ", qry.BaseTable(), " SET ");
|
||||
for (int i = 0; i < arg_count; i++) {
|
||||
Keyval pair = qry.Args().Get_at(i);
|
||||
if (i > 0) bfr.Add_str_a7(", ");
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.dbs.sqls.wtrs; 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.wtrs; import gplx.*;
|
||||
import gplx.dbs.sqls.itms.*;
|
||||
public class Sql_from_wtr {
|
||||
public void Bld_clause_from(Bry_bfr bfr, Sql_from_clause from) {
|
||||
List_adp tbls = from.Tbls; int tbls_len = tbls.Count();
|
||||
List_adp tbls = from.Tbls; int tbls_len = tbls.Len();
|
||||
for (int i = 0; i < tbls_len; ++i) {
|
||||
Sql_tbl_itm tbl = (Sql_tbl_itm)tbls.Get_at(i);
|
||||
bfr.Add_byte_space().Add_str_a7(Bld_join(tbl.Join_tid)).Add_byte_space();
|
||||
|
||||
@@ -20,8 +20,8 @@ import gplx.Byte_ascii;
|
||||
import gplx.Err_;
|
||||
import gplx.Object_;
|
||||
import gplx.String_;
|
||||
import gplx.dbs.Dbmeta_fld_itm;
|
||||
import gplx.dbs.Dbmeta_fld_tid;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.dbs.DbmetaFldType;
|
||||
import gplx.dbs.Dbmeta_idx_itm;
|
||||
import gplx.dbs.Dbmeta_tbl_itm;
|
||||
import gplx.dbs.metas.Dbmeta_fld_mgr;
|
||||
@@ -55,7 +55,7 @@ public class Sql_schema_wtr {
|
||||
Dbmeta_fld_mgr flds = tbl.Flds();
|
||||
int len = flds.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Dbmeta_fld_itm fld = flds.Get_at(i);
|
||||
DbmetaFldItm fld = flds.Get_at(i);
|
||||
tmp_bfr.Add_byte(i == 0 ? Byte_ascii.Paren_bgn : Byte_ascii.Comma).Add_byte_space();
|
||||
Bld_fld(tmp_bfr, fld);
|
||||
tmp_bfr.Add_byte_nl();
|
||||
@@ -63,7 +63,7 @@ public class Sql_schema_wtr {
|
||||
tmp_bfr.Add_str_a7(");");
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
public String Bld_alter_tbl_add(String tbl, Dbmeta_fld_itm fld) {
|
||||
public String Bld_alter_tbl_add(String tbl, DbmetaFldItm fld) {
|
||||
tmp_bfr.Add_str_a7("ALTER TABLE ").Add_str_a7(tbl).Add_str_a7(" ADD ");
|
||||
Bld_fld(tmp_bfr, fld);
|
||||
tmp_bfr.Add_byte_semic();
|
||||
@@ -72,22 +72,22 @@ public class Sql_schema_wtr {
|
||||
public String Bld_drop_tbl(String tbl) {
|
||||
return String_.Format("DROP TABLE IF EXISTS {0};", tbl);
|
||||
}
|
||||
private void Bld_fld(Bry_bfr tmp_bfr, Dbmeta_fld_itm fld) {
|
||||
private void Bld_fld(Bry_bfr tmp_bfr, DbmetaFldItm fld) {
|
||||
tmp_bfr.Add_str_a7(fld.Name()).Add_byte_space();
|
||||
Tid_to_sql(tmp_bfr, fld.Type().Tid_ansi(), fld.Type().Len_1()); tmp_bfr.Add_byte_space();
|
||||
switch (fld.Nullable_tid()) {
|
||||
case Dbmeta_fld_itm.Nullable_unknown:
|
||||
case Dbmeta_fld_itm.Nullable_not_null: tmp_bfr.Add_str_a7("NOT NULL "); break;
|
||||
case Dbmeta_fld_itm.Nullable_null: tmp_bfr.Add_str_a7("NULL "); break;
|
||||
Tid_to_sql(tmp_bfr, fld.Type().Tid(), fld.Type().Len1()); tmp_bfr.Add_byte_space();
|
||||
switch (fld.Nullable()) {
|
||||
case DbmetaFldItm.NullableUnspecified:
|
||||
case DbmetaFldItm.NullableNotNull: tmp_bfr.Add_str_a7("NOT NULL "); break;
|
||||
case DbmetaFldItm.NullableNull: tmp_bfr.Add_str_a7("NULL "); break;
|
||||
}
|
||||
if (fld.Default() != Dbmeta_fld_itm.Default_value_null) {
|
||||
if (fld.DefaultVal() != DbmetaFldItm.DefaultValNull) {
|
||||
tmp_bfr.Add_str_a7("DEFAULT ");
|
||||
boolean quote = Bool_.N;
|
||||
switch (fld.Type().Tid_ansi()) {
|
||||
case Dbmeta_fld_tid.Tid__str: case Dbmeta_fld_tid.Tid__text: quote = Bool_.Y; break;
|
||||
switch (fld.Type().Tid()) {
|
||||
case DbmetaFldType.TidStr: case DbmetaFldType.TidText: quote = Bool_.Y; break;
|
||||
}
|
||||
if (quote) tmp_bfr.Add_byte_apos();
|
||||
tmp_bfr.Add_str_u8(Object_.Xto_str_strict_or_null(fld.Default()));
|
||||
tmp_bfr.Add_str_u8(Object_.Xto_str_strict_or_null(fld.DefaultVal()));
|
||||
if (quote) tmp_bfr.Add_byte_apos();
|
||||
tmp_bfr.Add_byte_space();
|
||||
}
|
||||
@@ -97,16 +97,16 @@ public class Sql_schema_wtr {
|
||||
}
|
||||
public static void Tid_to_sql(Bry_bfr tmp_bfr, int tid, int len) {// REF: https://www.sqlite.org/datatype3.html
|
||||
switch (tid) {
|
||||
case Dbmeta_fld_tid.Tid__bool: tmp_bfr.Add_str_a7("boolean"); break;
|
||||
case Dbmeta_fld_tid.Tid__byte: tmp_bfr.Add_str_a7("tinyint"); break;
|
||||
case Dbmeta_fld_tid.Tid__short: tmp_bfr.Add_str_a7("smallint"); break;
|
||||
case Dbmeta_fld_tid.Tid__int: tmp_bfr.Add_str_a7("integer"); break; // NOTE: must be integer, not int, else "int PRIMARY KEY AUTONUMBER" will fail; DATE:2015-02-12
|
||||
case Dbmeta_fld_tid.Tid__long: tmp_bfr.Add_str_a7("bigint"); break;
|
||||
case Dbmeta_fld_tid.Tid__float: tmp_bfr.Add_str_a7("float"); break;
|
||||
case Dbmeta_fld_tid.Tid__double: tmp_bfr.Add_str_a7("double"); break;
|
||||
case Dbmeta_fld_tid.Tid__str: tmp_bfr.Add_str_a7("varchar(").Add_int_variable(len).Add_byte(Byte_ascii.Paren_end); break;
|
||||
case Dbmeta_fld_tid.Tid__text: tmp_bfr.Add_str_a7("text"); break;
|
||||
case Dbmeta_fld_tid.Tid__bry: tmp_bfr.Add_str_a7("blob"); break;
|
||||
case DbmetaFldType.TidBool: tmp_bfr.Add_str_a7("boolean"); break;
|
||||
case DbmetaFldType.TidByte: tmp_bfr.Add_str_a7("tinyint"); break;
|
||||
case DbmetaFldType.TidShort: tmp_bfr.Add_str_a7("smallint"); break;
|
||||
case DbmetaFldType.TidInt: tmp_bfr.Add_str_a7("integer"); break; // NOTE: must be integer, not int, else "int PRIMARY KEY AUTONUMBER" will fail; DATE:2015-02-12
|
||||
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.TidText: tmp_bfr.Add_str_a7("text"); break;
|
||||
case DbmetaFldType.TidBry: tmp_bfr.Add_str_a7("blob"); break;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class Sql_select_wtr {
|
||||
private void Bld_select_group_by(Bry_bfr bfr, Sql_wtr_ctx ctx, Db_qry__select_cmd qry, Sql_group_clause groupBy) {
|
||||
if (groupBy == null) return;
|
||||
bfr.Add_str_a7(" GROUP BY ");
|
||||
for (int i = 0; i < groupBy.Flds().Count(); i++) {
|
||||
for (int i = 0; i < groupBy.Flds().Len(); i++) {
|
||||
String item = (String)groupBy.Flds().Get_at(i);
|
||||
if (i > 0) bfr.Add_str_a7(", ");
|
||||
bfr.Add_str_a7(item);
|
||||
|
||||
@@ -19,9 +19,9 @@ public class Db_stmt_arg_list {
|
||||
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, Dbmeta_fld_tid.Tid__int, key, val);}
|
||||
public Db_stmt_arg_list Crt_str_by_bry (String key, byte[] val) {return Add(Bool_.Y, Dbmeta_fld_tid.Tid__str, key, String_.new_u8(val));}
|
||||
public Db_stmt_arg_list Crt_str (String key, String val) {return Add(Bool_.Y, Dbmeta_fld_tid.Tid__str, key, val);}
|
||||
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 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,29 +36,29 @@ public class Db_stmt_arg_list {
|
||||
}
|
||||
public static void Fill_crt(Db_stmt stmt, int tid, String key, Object val) {
|
||||
switch (tid) {
|
||||
case Dbmeta_fld_tid.Tid__bool: stmt.Crt_bool_as_byte (key, Bool_.Cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__byte: stmt.Crt_byte (key, Byte_.Cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__int: stmt.Crt_int (key, Int_.Cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__long: stmt.Crt_long (key, Long_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__float: stmt.Crt_float (key, Float_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__double: stmt.Crt_double (key, Double_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__str: stmt.Crt_str (key, String_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__text: stmt.Crt_text (key, String_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__bry: stmt.Crt_bry (key, Bry_.cast(val)); break;
|
||||
case DbmetaFldType.TidBool: stmt.Crt_bool_as_byte (key, Bool_.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;
|
||||
case DbmetaFldType.TidFloat: stmt.Crt_float (key, Float_.cast(val)); break;
|
||||
case DbmetaFldType.TidDouble: stmt.Crt_double (key, Double_.cast(val)); break;
|
||||
case DbmetaFldType.TidStr: stmt.Crt_str (key, String_.cast(val)); break;
|
||||
case DbmetaFldType.TidText: stmt.Crt_text (key, String_.cast(val)); break;
|
||||
case DbmetaFldType.TidBry: stmt.Crt_bry (key, Bry_.cast(val)); break;
|
||||
default: throw Err_.new_unhandled_default(tid);
|
||||
}
|
||||
}
|
||||
public static void Fill_val(Db_stmt stmt, int tid, String key, Object val) {
|
||||
switch (tid) {
|
||||
case Dbmeta_fld_tid.Tid__bool: stmt.Val_bool_as_byte (key, Bool_.Cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__byte: stmt.Val_byte (key, Byte_.Cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__int: stmt.Val_int (key, Int_.Cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__long: stmt.Val_long (key, Long_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__float: stmt.Val_float (key, Float_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__double: stmt.Val_double (key, Double_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__str: stmt.Val_str (key, String_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__text: stmt.Val_text (key, String_.cast(val)); break;
|
||||
case Dbmeta_fld_tid.Tid__bry: stmt.Val_bry (key, Bry_.cast(val)); break;
|
||||
case DbmetaFldType.TidBool: stmt.Val_bool_as_byte (key, Bool_.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;
|
||||
case DbmetaFldType.TidFloat: stmt.Val_float (key, Float_.cast(val)); break;
|
||||
case DbmetaFldType.TidDouble: stmt.Val_double (key, Double_.cast(val)); break;
|
||||
case DbmetaFldType.TidStr: stmt.Val_str (key, String_.cast(val)); break;
|
||||
case DbmetaFldType.TidText: stmt.Val_text (key, String_.cast(val)); break;
|
||||
case DbmetaFldType.TidBry: stmt.Val_bry (key, Bry_.cast(val)); break;
|
||||
default: throw Err_.new_unhandled_default(tid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,14 +27,14 @@ 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, Dbmeta_fld_tid.Tid__str, key, val);
|
||||
arg_list.Add(Bool_.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, Dbmeta_fld_tid.Tid__int, key, val);
|
||||
arg_list.Add(Bool_.Y, DbmetaFldType.TidInt, key, val);
|
||||
}
|
||||
public void Write_fmt(Bry_fmt fmt) {
|
||||
fmt.Bld_many(bfr, (Object[])fmt_list.To_ary_and_clear(Object.class));
|
||||
fmt.Bld_many(bfr, (Object[])fmt_list.ToAryAndClear(Object.class));
|
||||
}
|
||||
public String Make_sql(Bry_fmt fmt) { // should only be called publicly for debugging purposes
|
||||
Write_fmt(fmt);
|
||||
|
||||
@@ -17,11 +17,11 @@ package gplx.dbs.sys; import gplx.*; import gplx.dbs.*;
|
||||
class Db_sys_tbl implements Rls_able {
|
||||
private final String tbl_name = "gfdb_sys";
|
||||
private String fld_key, fld_val;
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final DbmetaFldList flds = new DbmetaFldList();
|
||||
private final Db_conn conn; private Db_stmt stmt_insert, stmt_update, stmt_select;
|
||||
public Db_sys_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
fld_key = flds.Add_str_pkey("sys_key", 255); fld_val = flds.Add_text("sys_val");
|
||||
fld_key = flds.AddStrPkey("sys_key", 255); fld_val = flds.AddText("sys_val");
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;}
|
||||
|
||||
@@ -1,22 +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.utls; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.dbs.stmts.*;
|
||||
public class Db_tbl__crud_ {
|
||||
public static boolean Upsert(Db_conn conn, String tbl_name, Dbmeta_fld_list flds, String[] crt_cols, Object... objs) {
|
||||
public static boolean Upsert(Db_conn conn, String tbl_name, DbmetaFldList flds, String[] crt_cols, Object... objs) {
|
||||
// init
|
||||
int crt_cols_len = crt_cols.length;
|
||||
String[] val_cols = Find_excepts(flds, crt_cols);
|
||||
@@ -48,33 +48,33 @@ public class Db_tbl__crud_ {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
private static String[] Find_excepts(Dbmeta_fld_list flds, String[] cols) {
|
||||
private static String[] Find_excepts(DbmetaFldList flds, String[] cols) {
|
||||
// hash cols
|
||||
Hash_adp hash = Hash_adp_.New();
|
||||
int cols_len = cols.length;
|
||||
for (int i = 0; i < cols_len; ++i)
|
||||
hash.Add_as_key_and_val(cols[i]);
|
||||
hash.AddAsKeyAndVal(cols[i]);
|
||||
|
||||
// loop flds and get excepts
|
||||
List_adp list = List_adp_.New();
|
||||
int flds_len = flds.Len();
|
||||
for (int i = 0; i < flds_len; ++i) {
|
||||
Dbmeta_fld_itm fld = flds.Get_at(i);
|
||||
DbmetaFldItm fld = flds.GetAt(i);
|
||||
if (!hash.Has(fld.Name()))
|
||||
list.Add(fld.Name());
|
||||
}
|
||||
return list.To_str_ary_and_clear();
|
||||
return list.ToStrAryAndClear();
|
||||
}
|
||||
private static void Add_arg(Db_stmt stmt, Dbmeta_fld_list flds, String[] cols, Object[] objs, boolean mode_is_crt, int objs_bgn) {
|
||||
private static void Add_arg(Db_stmt stmt, DbmetaFldList flds, String[] cols, Object[] objs, boolean mode_is_crt, int objs_bgn) {
|
||||
int cols_len = cols.length;
|
||||
for (int i = 0; i < cols_len; ++i) {
|
||||
String col = cols[i];
|
||||
Dbmeta_fld_itm fld = flds.Get_by(col);
|
||||
DbmetaFldItm fld = flds.GetByOrNull(col);
|
||||
Object obj = objs[i + objs_bgn];
|
||||
if (mode_is_crt)
|
||||
Db_stmt_arg_list.Fill_crt(stmt, fld.Type().Tid_ansi(), col, obj);
|
||||
Db_stmt_arg_list.Fill_crt(stmt, fld.Type().Tid(), col, obj);
|
||||
else
|
||||
Db_stmt_arg_list.Fill_val(stmt, fld.Type().Tid_ansi(), col, obj);
|
||||
Db_stmt_arg_list.Fill_val(stmt, fld.Type().Tid(), col, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ package gplx.gfdbs.cores;
|
||||
|
||||
import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.Dbmeta_fld_list;
|
||||
import gplx.dbs.DbmetaFldList;
|
||||
|
||||
public interface GfdbMeta<I> extends GfdbItmFactory<I> {
|
||||
String TblName();
|
||||
Dbmeta_fld_list Flds();
|
||||
DbmetaFldList Flds();
|
||||
String[] Pkeys();
|
||||
void SaveStmtPkeys(Db_stmt stmt, I itm);
|
||||
void SaveStmtVals(GfdbState state, Db_stmt stmt, I itm);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package gplx.gfdbs.cores;
|
||||
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.Dbmeta_fld_list;
|
||||
import gplx.dbs.DbmetaFldList;
|
||||
|
||||
public abstract class GfdbMetaBase<I> implements GfdbMeta<I> {
|
||||
public GfdbMetaBase(String tblName) {
|
||||
@@ -10,7 +10,7 @@ public abstract class GfdbMetaBase<I> implements GfdbMeta<I> {
|
||||
this.pkeys = CtorPkeys();
|
||||
}
|
||||
@Override public String TblName() {return tblName;} private final String tblName;
|
||||
@Override public Dbmeta_fld_list Flds() {return flds;} protected final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
@Override public DbmetaFldList Flds() {return flds;} protected final DbmetaFldList flds = new DbmetaFldList();
|
||||
@Override public String[] Pkeys() {return pkeys;} protected String[] pkeys;
|
||||
@Override public abstract void SaveStmtPkeys(Db_stmt stmt, I itm);
|
||||
@Override public abstract void SaveStmtVals(GfdbState state, Db_stmt stmt, I itm);
|
||||
|
||||
@@ -10,8 +10,8 @@ public class GfdbCfgMeta extends GfdbMetaBase<GfdbCfgItm> {
|
||||
public String Key() {return key;} private String key;
|
||||
public String Val() {return val;} private String val;
|
||||
@Override protected void CtorFlds() {
|
||||
this.key = flds.Add_str_pkey("cfg_key", 1024);
|
||||
this.val = flds.Add_str("cfg_val", 1024);
|
||||
this.key = flds.AddStrPkey("cfg_key", 1024);
|
||||
this.val = flds.AddStr("cfg_val", 1024);
|
||||
}
|
||||
@Override protected String[] CtorPkeys() {return new String[] {key};}
|
||||
@Override public void SaveStmtPkeys(Db_stmt stmt, GfdbCfgItm itm) {stmt.Crt_str(this.Key(), itm.Key());}
|
||||
|
||||
@@ -4,7 +4,7 @@ import gplx.Err_;
|
||||
import gplx.dbs.Db_conn;
|
||||
import gplx.dbs.Db_rdr;
|
||||
import gplx.dbs.Db_stmt;
|
||||
import gplx.dbs.Dbmeta_fld_itm;
|
||||
import gplx.dbs.DbmetaFldItm;
|
||||
import gplx.gfdbs.cores.GfdbMeta;
|
||||
import gplx.dbs.stmts.Db_stmt_arg_list;
|
||||
|
||||
@@ -20,8 +20,8 @@ public class GfoDbSelectWkrOne<I, M extends GfdbMeta<I>> implements GfoDbSelectW
|
||||
if (pkeyCols.length != pkeyVals.length) throw Err_.new_wo_type("pkey lengths don't match");
|
||||
for (int i = 0; i < pkeyCols.length; i++) {
|
||||
String pkeyCol = pkeyCols[i];
|
||||
Dbmeta_fld_itm pkeyFld = meta.Flds().Get_by(pkeyCol);
|
||||
Db_stmt_arg_list.Fill_crt(stmt, pkeyFld.Type().Tid_ansi(), pkeyCol, pkeyVals[i]);
|
||||
DbmetaFldItm pkeyFld = meta.Flds().GetByOrNull(pkeyCol);
|
||||
Db_stmt_arg_list.Fill_crt(stmt, pkeyFld.Type().Tid(), pkeyCol, pkeyVals[i]);
|
||||
}
|
||||
|
||||
return stmt.Exec_select__rls_auto();
|
||||
|
||||
@@ -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.core.stores; import gplx.*; import gplx.core.*;
|
||||
package gplx.core.stores; import gplx.*;
|
||||
import org.junit.*;
|
||||
import gplx.dbs.*; /*Db_conn_info*/
|
||||
public class DbMaprMgr_tst {
|
||||
@@ -95,7 +95,7 @@ public class DbMaprMgr_tst {
|
||||
|
||||
Tfds.Eq(1, disc.Id());
|
||||
Tfds.Eq("name", disc.Name());
|
||||
Tfds.Eq(0, disc.Titles().Count());
|
||||
Tfds.Eq(0, disc.Titles().Len());
|
||||
}
|
||||
@Test public void Load_subs() {
|
||||
rdr = rdr_();
|
||||
@@ -106,7 +106,7 @@ public class DbMaprMgr_tst {
|
||||
|
||||
Tfds.Eq(1, disc.Id());
|
||||
Tfds.Eq("name", disc.Name());
|
||||
Tfds.Eq(2, disc.Titles().Count());
|
||||
Tfds.Eq(2, disc.Titles().Len());
|
||||
Tfds.Eq("title1", ((MockTitle)disc.Titles().Get_at(0)).Name());
|
||||
Tfds.Eq("title2", ((MockTitle)disc.Titles().Get_at(1)).Name());
|
||||
}
|
||||
@@ -121,12 +121,12 @@ public class DbMaprMgr_tst {
|
||||
|
||||
Tfds.Eq(1, disc.Id());
|
||||
Tfds.Eq("name", disc.Name());
|
||||
Tfds.Eq(1, disc.Titles().Count());
|
||||
Tfds.Eq(1, disc.Titles().Len());
|
||||
MockTitle t = ((MockTitle)disc.Titles().Get_at(0));
|
||||
Tfds.Eq("title1", t.Name());
|
||||
Tfds.Eq("chapter1", ((MockChapter)t.Chapters().Get_at(0)).Name());
|
||||
Tfds.Eq(1, t.Audios().Count());
|
||||
Tfds.Eq(1, t.Subtitles().Count());
|
||||
Tfds.Eq(1, t.Audios().Len());
|
||||
Tfds.Eq(1, t.Subtitles().Len());
|
||||
Tfds.Eq("audio1", ((MockStream)t.Audios().Get_at(0)).Name());
|
||||
Tfds.Eq("subtitle1", ((MockStream)t.Subtitles().Get_at(0)).Name());
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class Db_conn_fxt implements Rls_able {
|
||||
public void tst_ExecDml(int expd, Db_qry qry) {
|
||||
int actl = conn.Exec_qry(qry);
|
||||
if (dmlAffectedAvailable)
|
||||
Tfds.Eq(expd, actl, "Exec_qry failed: sql={0}", qry.To_sql__exec(conn.Engine().Sql_wtr()));
|
||||
Tfds.Eq(expd, actl, "Exec_qry failed: sql={0}", qry.ToSqlExec(conn.Engine().Sql_wtr()));
|
||||
}
|
||||
public void tst_ExecRdrTbl(int expd, String tblName) {tst_ExecRdr(expd, Db_qry_.select_tbl_(tblName));}
|
||||
public void tst_ExecRdr(int expd, Db_qry qry) {
|
||||
@@ -33,7 +33,7 @@ public class Db_conn_fxt implements Rls_able {
|
||||
tbl = GfoNde_.rdr_(rdr);
|
||||
}
|
||||
catch (Exception e) {Err_.Noop(e); rdr.Rls();}
|
||||
Tfds.Eq(expd, tbl.Subs().Count(), "Exec_qry_as_rdr failed: sql={0}", qry.To_sql__exec(conn.Engine().Sql_wtr()));
|
||||
Tfds.Eq(expd, tbl.Subs().Count(), "Exec_qry_as_rdr failed: sql={0}", qry.ToSqlExec(conn.Engine().Sql_wtr()));
|
||||
} GfoNde tbl;
|
||||
public GfoNde tst_RowAry(int index, Object... expdValAry) {
|
||||
GfoNde record = tbl.Subs().FetchAt_asGfoNde(index);
|
||||
|
||||
@@ -13,19 +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; import gplx.*;
|
||||
import gplx.core.gfo_ndes.*;
|
||||
public class GfoNdeTstr {
|
||||
public static void tst_ValsByCol(GfoNde nde, String fld, Object... expdAry) {
|
||||
List_adp expd = List_adp_.New();
|
||||
for (int i = 0; i < expdAry.length; i++) {
|
||||
expd.Add(Object_.Xto_str_strict_or_empty(expdAry[i]));
|
||||
}
|
||||
List_adp actl = List_adp_.New();
|
||||
for (int i = 0; i < nde.Subs().Count(); i++) {
|
||||
GfoNde sub = nde.Subs().FetchAt_asGfoNde(i);
|
||||
actl.Add(Object_.Xto_str_strict_or_empty(sub.Read(fld)));
|
||||
}
|
||||
Tfds.Eq_ary(expd.To_str_ary(), actl.To_str_ary());
|
||||
}
|
||||
package gplx.dbs; import gplx.*;
|
||||
import gplx.core.gfo_ndes.*;
|
||||
public class GfoNdeTstr {
|
||||
public static void tst_ValsByCol(GfoNde nde, String fld, Object... expdAry) {
|
||||
List_adp expd = List_adp_.New();
|
||||
for (int i = 0; i < expdAry.length; i++) {
|
||||
expd.Add(Object_.Xto_str_strict_or_empty(expdAry[i]));
|
||||
}
|
||||
List_adp actl = List_adp_.New();
|
||||
for (int i = 0; i < nde.Subs().Count(); i++) {
|
||||
GfoNde sub = nde.Subs().FetchAt_asGfoNde(i);
|
||||
actl.Add(Object_.Xto_str_strict_or_empty(sub.Read(fld)));
|
||||
}
|
||||
Tfds.Eq_ary(expd.ToStrAry(), actl.ToStrAry());
|
||||
}
|
||||
}
|
||||
@@ -23,18 +23,18 @@ public class Sql_schema_wtr_tst {
|
||||
);
|
||||
}
|
||||
@Test public void Tbl_basic() {
|
||||
Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
flds.Add_int_pkey("fld_int_pkey");
|
||||
flds.Add_bool("fld_bool");
|
||||
flds.Add_short("fld_short");
|
||||
flds.Add_int("fld_int");
|
||||
flds.Add_long("fld_long");
|
||||
flds.Add_float("fld_float");
|
||||
flds.Add_double("fld_double");
|
||||
flds.Add_str("fld_str", 123);
|
||||
flds.Add_text("fld_text");
|
||||
flds.Add_bry("fld_bry");
|
||||
fxt.Test_create_tbl(Dbmeta_tbl_itm.New("tbl_name", flds.To_fld_ary())
|
||||
DbmetaFldList flds = new DbmetaFldList();
|
||||
flds.AddIntPkey("fld_int_pkey");
|
||||
flds.AddBool("fld_bool");
|
||||
flds.AddShort("fld_short");
|
||||
flds.AddInt("fld_int");
|
||||
flds.AddLong("fld_long");
|
||||
flds.AddFloat("fld_float");
|
||||
flds.AddDouble("fld_double");
|
||||
flds.AddStr("fld_str", 123);
|
||||
flds.AddText("fld_text");
|
||||
flds.AddBry("fld_bry");
|
||||
fxt.Test_create_tbl(Dbmeta_tbl_itm.New("tbl_name", flds.ToFldAry())
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( "CREATE TABLE IF NOT EXISTS tbl_name"
|
||||
, "( fld_int_pkey integer NOT NULL PRIMARY KEY"
|
||||
@@ -51,16 +51,16 @@ public class Sql_schema_wtr_tst {
|
||||
));
|
||||
}
|
||||
@Test public void Tbl_alter_tbl_add() {
|
||||
Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
flds.Add_int_dflt("fld_int", -1);
|
||||
flds.Add_str_dflt("fld_str", 255, "a");
|
||||
fxt.Test_alter_tbl_add("tbl_name", flds.Get_by("fld_int"), "ALTER TABLE tbl_name ADD fld_int integer NOT NULL DEFAULT -1;");
|
||||
fxt.Test_alter_tbl_add("tbl_name", flds.Get_by("fld_str"), "ALTER TABLE tbl_name ADD fld_str varchar(255) NOT NULL DEFAULT 'a';");
|
||||
DbmetaFldList flds = new DbmetaFldList();
|
||||
flds.AddIntDflt("fld_int", -1);
|
||||
flds.AddStrDflt("fld_str", 255, "a");
|
||||
fxt.Test_alter_tbl_add("tbl_name", flds.GetByOrNull("fld_int"), "ALTER TABLE tbl_name ADD fld_int integer NOT NULL DEFAULT -1;");
|
||||
fxt.Test_alter_tbl_add("tbl_name", flds.GetByOrNull("fld_str"), "ALTER TABLE tbl_name ADD fld_str varchar(255) NOT NULL DEFAULT 'a';");
|
||||
}
|
||||
}
|
||||
class Sql_schema_wtr_fxt {
|
||||
private Sql_schema_wtr sqlbldr = SqlQryWtrUtl.NewSqlite().Schema_wtr();
|
||||
public void Test_create_idx(Dbmeta_idx_itm idx, String expd) {Tfds.Eq(expd, sqlbldr.Bld_create_idx(idx));}
|
||||
public void Test_create_tbl(Dbmeta_tbl_itm tbl, String expd) {Tfds.Eq_str_lines(expd, sqlbldr.Bld_create_tbl(tbl));}
|
||||
public void Test_alter_tbl_add(String tbl, Dbmeta_fld_itm fld, String expd) {Tfds.Eq_str_lines(expd, sqlbldr.Bld_alter_tbl_add(tbl, fld));}
|
||||
public void Test_alter_tbl_add(String tbl, DbmetaFldItm fld, String expd) {Tfds.Eq_str_lines(expd, sqlbldr.Bld_alter_tbl_add(tbl, fld));}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user