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

'v3.3.4.1'

This commit is contained in:
gnosygnu
2016-03-27 23:44:59 -04:00
parent de67253a9c
commit baaef32df2
903 changed files with 13339 additions and 8695 deletions

View File

@@ -1,54 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs; import gplx.*;
import gplx.dbs.engines.sqlite.*;
public class Db_attach_cmd {
private final boolean diff_db;
private final Db_conn conn; private final String attach_name; private final Io_url attach_url;
private final List_adp sql_list = List_adp_.new_();
Db_attach_cmd(Db_conn conn, String attach_name, Io_url attach_url) {
this.conn = conn; this.attach_name = attach_name; this.attach_url = attach_url;
Sqlite_conn_info conn_info = (Sqlite_conn_info)conn.Conn_info();
this.diff_db = !String_.Eq(conn_info.Url().Raw(), attach_url.Raw());
}
public Db_attach_cmd Add_fmt(String msg, String sql_fmt, Object... sql_args) {
String sql = String_.Format(sql_fmt, sql_args);
sql = String_.Replace(sql, "<attach_db>", diff_db ? attach_name + "." : ""); // replace <attach> with either "attach_db." or "";
sql_list.Add(new Db_exec_sql_by_attach_itm(msg, sql));
return this;
}
public void Exec() {
Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Instance;
if (diff_db) conn.Env_db_attach(attach_name, attach_url);
conn.Txn_bgn(attach_name); // NOTE: BEGIN TRAN must occur after ATTACH else sqlite will throw error
int len = sql_list.Count();
for (int i = 0; i < len; ++i) {
Db_exec_sql_by_attach_itm itm = (Db_exec_sql_by_attach_itm)sql_list.Get_at(i);
usr_dlg.Plog_many("", "", itm.Msg());
conn.Exec_sql(itm.Sql());
}
conn.Txn_end();
if (diff_db) conn.Env_db_detach(attach_name);
}
public static Db_attach_cmd new_(Db_conn conn, String attach_name, Io_url attach_url) {return new Db_attach_cmd(conn, attach_name, attach_url);}
}
class Db_exec_sql_by_attach_itm {
public Db_exec_sql_by_attach_itm(String msg, String sql) {this.msg = msg; this.sql = sql;}
public String Msg() {return msg;} private final String msg;
public String Sql() {return sql;} private final String sql;
}

View File

@@ -1,40 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs; import gplx.*;
import gplx.dbs.engines.sqlite.*;
public class Db_attach_rdr {
private final boolean diff_db;
private final Db_conn conn; private final String attach_name; private final Io_url attach_url;
public Db_attach_rdr(Db_conn conn, String attach_name, Io_url attach_url) {
this.conn = conn; this.attach_name = attach_name; this.attach_url = attach_url;
Sqlite_conn_info conn_info = (Sqlite_conn_info)conn.Conn_info();
this.diff_db = !String_.Eq(conn_info.Url().Raw(), attach_url.Raw());
}
public void Attach() {
try {
if (diff_db) conn.Env_db_attach(attach_name, attach_url);
} catch (Exception e) {Err_.Noop(e); Gfo_usr_dlg_.Instance.Warn_many("", "", "db:failed to attach db; name=~{0} url=~{1}", attach_name, attach_url.Raw());}
}
public Db_rdr Exec_as_rdr(String sql) {
sql = String_.Replace(sql, "<attach_db>", diff_db ? attach_name + "." : ""); // replace <attach> with either "attach_db." or "";
return conn.Exec_sql_as_rdr_v2(sql);
}
public void Detach() {
if (diff_db) conn.Env_db_detach(attach_name);
}
}

View File

@@ -36,7 +36,6 @@ public class Db_cfg_itm {
public String To_str() {Fail_if_null(); return val;}
private void Fail_if_null() {if (val == null) throw Err_.new_wo_type("cfg.val is empty", "grp", grp, "key", key); }
private Err err_parse(Exception e, String type) {return Err_.new_wo_type("cfg.val is not parseable", "grp", grp, "key", key, "val", val, "type", type).Trace_ignore_add_1_();}
private static final String Grp_none = "";
public static Db_cfg_itm new_str (String key, String val) {return new Db_cfg_itm(Grp_none , key, val);}
public static Db_cfg_itm new_str (String grp, String key, String val) {return new Db_cfg_itm(grp , key, val);}
@@ -54,6 +53,5 @@ public class Db_cfg_itm {
public static Db_cfg_itm new_DateAdp (String grp, String key, DateAdp val) {return new Db_cfg_itm(grp , key, val.XtoStr_fmt_yyyyMMdd_HHmmss());}
public static Db_cfg_itm new_guid (String key, Guid_adp val) {return new Db_cfg_itm(Grp_none , key, val.To_str());}
public static Db_cfg_itm new_guid (String grp, String key, Guid_adp val) {return new Db_cfg_itm(grp , key, val.To_str());}
public static final Db_cfg_itm Empty = new Db_cfg_itm("empty", "empty", null);
}

View File

@@ -34,7 +34,7 @@ public class Db_cfg_tbl implements Rls_able {
stmt_update = Db_stmt_.Rls(stmt_update);
stmt_select = Db_stmt_.Rls(stmt_select);
}
public void Create_tbl() {conn.Ddl_create_tbl(Dbmeta_tbl_itm.New(tbl_name, flds, Dbmeta_idx_itm.new_unique_by_tbl(tbl_name, "main", fld_grp, fld_key, fld_val)));}
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, fld_key, fld_val)));}
public void Delete_val(String grp, String key) {conn.Stmt_delete(tbl_name, fld_grp, fld_key).Crt_str(fld_grp, grp).Crt_str(fld_key, key).Exec_delete();}
public void Delete_grp(String grp) {conn.Stmt_delete(tbl_name, fld_grp).Crt_str(fld_grp, grp).Exec_delete();}
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
@@ -49,7 +49,7 @@ public class Db_cfg_tbl implements Rls_able {
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
try {
stmt_insert.Clear().Val_str(fld_grp, grp).Val_str(fld_key, key).Val_str(fld_val, val).Exec_insert();
} catch (Exception e) {throw Err_.new_exc(e, "db", "db_cfg.insert failed", "grp", grp, "key", key, "val", val, "db", conn.Conn_info().Xto_api());}
} catch (Exception e) {throw Err_.new_exc(e, "db", "db_cfg.insert failed", "grp", grp, "key", key, "val", val, "db", conn.Conn_info().Db_api());}
}
public void Update_yn (String grp, String key, boolean val) {Update_str(grp, key, val ? "y" : "n");}
public void Update_byte (String grp, String key, byte val) {Update_str(grp, key, Byte_.To_str(val));}

View File

@@ -26,7 +26,7 @@ class Schema_loader_mgr__null implements Schema_loader_mgr {
}
class Schema_loader_mgr__sqlite implements Schema_loader_mgr {
public void Load(Schema_db_mgr db_mgr, Db_conn conn) {
Gfo_usr_dlg_.Instance.Log_many("", "", "db.schema.load.bgn: conn=~{0}", conn.Conn_info().Xto_api());
Gfo_usr_dlg_.Instance.Log_many("", "", "db.schema.load.bgn: conn=~{0}", conn.Conn_info().Db_api());
Dbmeta_tbl_mgr tbl_mgr = db_mgr.Tbl_mgr();
Db_qry__select_in_tbl qry = Db_qry__select_in_tbl.new_("sqlite_master", String_.Ary_empty, String_.Ary("type", "name", "sql"), Db_qry__select_in_tbl.Order_by_null);
Db_rdr rdr = conn.Stmt_new(qry).Exec_select__rls_auto();

View File

@@ -0,0 +1,74 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.percentiles; import gplx.*; import gplx.dbs.*;
class Log_tbl_fmtr {
private final Bry_bfr bfr = Bry_bfr.new_();
private final List_adp itms = List_adp_.new_();
private Log_fld_itm[] ary;
public Log_tbl_fmtr Add_str(String key, int len) {ary = null; itms.Add(new Log_fld_itm__bry(Type_adp_.Tid__bry, key, len)); return this;}
public Log_tbl_fmtr Add_int(String key, int bgn, int end) {ary = null; itms.Add(new Log_fld_itm__int(Type_adp_.Tid__int, key, bgn, end)); return this;}
public void Log(Object... vals) {
if (ary == null)
ary = (Log_fld_itm[])itms.To_ary_and_clear(Log_fld_itm.class);
int len = ary.length;
for (int i = 0; i < len; ++i) {
Log_fld_itm itm = ary[i];
Object val = vals[i];
if (i != 0) bfr.Add_byte_pipe();
itm.Fmt(bfr, val);
}
bfr.Add_byte_nl();
}
public String To_str_and_clear() {return bfr.To_str_and_clear();}
}
interface Log_fld_itm {
void Fmt(Bry_bfr bfr, Object val);
}
abstract class Log_fld_itm__base implements Log_fld_itm {
public Log_fld_itm__base(int tid, String key, int len) {
this.tid = tid; this.key = key; this.len = len;
}
public int Tid() {return tid;} private final int tid;
public String Key() {return key;} private final String key;
public int Len() {return len;} protected int len;
public abstract void Fmt(Bry_bfr bfr, Object val);
}
class Log_fld_itm__bry extends Log_fld_itm__base {
public Log_fld_itm__bry(int tid, String key, int len) {super(tid, key, len);}
@Override public void Fmt(Bry_bfr bfr, Object val) {
byte[] val_bry = Bry_.cast(val);
int val_bry_len = val_bry.length;
int pad_len = this.len - val_bry_len;
bfr.Add(val_bry);
if (pad_len > 0)
bfr.Add_byte_repeat(Byte_ascii.Space, pad_len);
}
}
class Log_fld_itm__int extends Log_fld_itm__base {
public Log_fld_itm__int(int tid, String key, int bgn, int end) {super(tid, key, 0);
this.bgn = bgn; this.end = end;
this.len = Int_.DigitCount(end);
}
public int Bgn() {return bgn;} private final int bgn;
public int End() {return end;} private final int end;
@Override public void Fmt(Bry_bfr bfr, Object val) {
int val_int = Int_.cast(val);
String val_str = String_.PadBgn(Int_.To_str(val_int), this.Len(), " ");
bfr.Add_str_u8(val_str);
}
}

View File

@@ -0,0 +1,87 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.percentiles; import gplx.*; import gplx.dbs.*;
public class Percentile_rng {
private long total_max; private int total_needed;
private int score_max, score_len_max;
private long prv_time;
public int Score_bgn() {return score_bgn;} private int score_bgn;
public int Score_end() {return score_end;} private int score_end;
public int Score_len() {return score_len;} private int score_len;
public int Found_rdr() {return found_rdr;} private int found_rdr;
public int Found_all() {return found_all;} private int found_all;
public int Elapsed() {return elapsed;} private int elapsed;
public Percentile_rng Init(long total_max, int score_max) {
this.total_max = total_max;
this.score_max = score_max;
this.score_len_max = score_max / 20; // limit to 5%
return this;
}
public void Select_init(int total_needed, int prv_score_bgn, int prv_score_len, int score_len_adj) {
this.total_needed = total_needed;
this.found_all = 0;
this.prv_time = gplx.core.envs.Env_.TickCount();
int score_unit = Calc_score_unit(total_needed, total_max, score_max);
if (prv_score_bgn == Score_null) {
score_len = score_unit + (score_unit * score_len_adj);
score_bgn = score_max;
Rng_len_(Bool_.Y);
}
else {
score_len = prv_score_len;
score_bgn = prv_score_bgn;
score_end = score_bgn + score_len;
}
}
public void Update(int found_rdr) {
this.found_rdr = found_rdr;
this.found_all += found_rdr;
// calc rng_multiplier based on found_rdr and total_needed; EX: 100=total_needed; 10=found_rdr; 40=found_all -> 6=rng_multiplier; (100 - 40 / 10)
int rng_multiplier = 1;
if (found_rdr == 0) {
rng_multiplier = 4;
} else {
int total_remaining = total_needed - found_all;
rng_multiplier = total_remaining == 0 ? 1 : Math_.Ceil_as_int(total_remaining / found_rdr);
}
// calc new score_len
int new_score_len = score_len * rng_multiplier;
if (new_score_len < 1) new_score_len = score_len;
else if (new_score_len > score_len_max) new_score_len = score_len_max;
score_len = new_score_len;
Rng_len_(Bool_.N);
// update times
long new_time = gplx.core.envs.Env_.TickCount();
this.elapsed = Int_.Subtract_long(new_time, prv_time);
prv_time = new_time;
}
private void Rng_len_(boolean first) {
score_end = score_bgn + (first ? 1 : 0); // + 1 to include rows with scores at max; EX: > 999,998 AND < 1,000,001
score_bgn = score_end - score_len;
if (score_bgn < 0) score_bgn = 0; // make sure score is not negative
}
@gplx.Internal protected static int Calc_score_unit(int total_needed, long total_max, int score_max) {// TEST:
int rv = (int)Math_.Ceil(Math_.Div_safe_as_double(total_needed, Math_.Div_safe_as_double(total_max, score_max))); // EX: 100 needed / (16 M / 1 M) -> 7 units to fill 100
if (rv > score_max) rv = score_max; // never allow score_unit to be > score_max; occurs when total_needed > total_max; EX: 50 needed; 10 available
return rv;
}
public static final int Score_null = -1;
}

View File

@@ -0,0 +1,43 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.percentiles; import gplx.*; import gplx.dbs.*;
public class Percentile_rng_log {
private final Log_tbl_fmtr fmtr = new Log_tbl_fmtr();
private byte[] search; private int rslts_needed;
private int rdr_idx;
public Percentile_rng_log(int score_max) {
fmtr.Add_str("search" , 50)
.Add_int("rslts_needed" , 1, 999)
.Add_int("rdr_idx" , 0, 100) // warn if more than 100 sql queries
.Add_int("score_bgn" , 0, score_max)
.Add_int("score_end" , 0, score_max)
.Add_int("score_len" , 1, 100000)
.Add_int("rdr_found" , 0, 9999) // warn if more than 9.999 seconds
.Add_int("total_found" , 0, 999)
.Add_int("total_needed" , 1, 999)
;
}
public void Init(byte[] search, int rslts_needed) {
this.search = search; this.rslts_needed = rslts_needed;
rdr_idx = -1;
}
public void Log(int score_bgn, int score_end, int rdr_found, int total_found, int pass_time) {
fmtr.Log(search, rslts_needed, ++rdr_idx, score_bgn, score_end, score_end - score_bgn, rdr_found, total_found, pass_time);
}
public String To_str_and_clear() {return fmtr.To_str_and_clear();}
}

View File

@@ -0,0 +1,63 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.percentiles; import gplx.*; import gplx.dbs.*;
import org.junit.*;
public class Percentile_rng_tst {
private final Percentile_rng_fxt fxt = new Percentile_rng_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Found__000() {
fxt.Test__rng(999994, 1000001);
fxt.Exec__update( 0).Test__rng(999966, 999994);
fxt.Exec__update( 0).Test__rng(999854, 999966);
}
@Test public void Found__025() {
fxt.Test__rng(999994, 1000001);
fxt.Exec__update( 25).Test__rng(999973, 999994);
fxt.Exec__update( 25).Test__rng(999931, 999973);
fxt.Exec__update( 25).Test__rng(999889, 999931);
fxt.Exec__update( 25).Test__rng(999847, 999889);
}
@Test public void Calc_score_unit() {
fxt.Test__calc_score_unit(50, 16000000, 1000000, 4); // to fill 50 -> 16 pages per point -> read every 4 points to get 64 pages
fxt.Test__calc_score_unit(50, 1000, 1000000, 50000); // to fill 50 -> 1000 points per page -> read every 50k points to get 50 pages
fxt.Test__calc_score_unit(50, 25, 1000000, 1000000); // range bounds check; to fill 50, always read full amount
}
}
class Percentile_rng_fxt {
private final Percentile_rng rng = new Percentile_rng();
public void Clear() {
this.Exec__init_for_wiki(16000000, 1000000);
this.Exec__init_for_search(100, 0);
}
public Percentile_rng_fxt Exec__init_for_wiki (int pages_max, int score_max) {
rng.Init(pages_max, score_max); return this;
}
public Percentile_rng_fxt Exec__init_for_search(int request_count, int score_len_adj) {
rng.Select_init(request_count, Percentile_rng.Score_null, Percentile_rng.Score_null, score_len_adj); return this;
}
public Percentile_rng_fxt Exec__update(int rdr_found) {
rng.Update(rdr_found); return this;
}
public void Test__rng(int expd_bgn, int expd_end) {
Tfds.Eq(expd_end, rng.Score_end(), "rng_end");
Tfds.Eq(expd_bgn, rng.Score_bgn(), "rng_bgn");
}
public void Test__calc_score_unit(int request_count, long pages_max, int score_max, int expd) {
Tfds.Eq(expd, Percentile_rng.Calc_score_unit(request_count, pages_max, score_max));
}
}

View File

@@ -0,0 +1,67 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.percentiles; import gplx.*; import gplx.dbs.*;
public abstract class Percentile_select_base { // SELECT * FROM x ORDER BY y LIMIT 10;
protected Cancelable cxl;
protected Percentile_rng rng;
protected Percentile_rng_log rng_log;
protected void Select() {
Db_rdr rdr = null;
try {
int rdr_found = 0;
while (true) {
if (cxl.Canceled()) return;
if (rdr == null) {
rdr = Rdr__init(); // EXPENSIVE
rdr_found = 0;
if (cxl.Canceled()) return;
}
if (!Row__read(rdr)) { // EXPENSIVE
if (cxl.Canceled()) return;
rng_log.Log(rng.Score_bgn(), rng.Score_end(), rng.Found_rdr(), rng.Found_all(), rng.Elapsed());
rdr = Rdr__term(rdr);
Rng__update(rdr_found);
boolean found_enough = Found_enough();
boolean none_left = rng.Score_bgn() == 0;
Rdr__done(found_enough, none_left);
if (found_enough || none_left)
break;
else
continue; // resume from top; will create new rdrd
}
if (Row__eval()) ++rdr_found;
}
}
catch (Exception exc) {
Gfo_usr_dlg_.Instance.Warn_many("", "", "error during percentile; err=~{0}", Err_.Message_gplx_log(exc));
}
finally {
rdr = Rdr__term(rdr);
}
}
protected abstract Db_rdr Rdr__init();
@gplx.Virtual protected void Rdr__done(boolean found_enough, boolean none_left) {}
@gplx.Virtual protected Db_rdr Rdr__term(Db_rdr rdr) {
if (rdr != null) rdr.Rls();
return null;
}
@gplx.Virtual protected void Rng__update(int rdr_found) {rng.Update(rdr_found);}
@gplx.Virtual protected boolean Row__read(Db_rdr rdr) {return true;}
@gplx.Virtual protected boolean Row__eval() {return true;} // NOTE: return true by default; DEPENDENCY: Srch_word_count_wkr
@gplx.Virtual protected boolean Found_enough() {return false;}
}

View File

@@ -0,0 +1,55 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.dbs.updates; import gplx.*; import gplx.dbs.*;
import gplx.dbs.stmts.*;
/*
sql =
UPDATE page
SET page_score = page_len
WHERE page_id >= ?
AND page_id < ?
state = -1|100000
*/
public class Sql_runner {
private final Db_stmt_arg_list list = new Db_stmt_arg_list();
public Db_conn Conn() {return conn;} public void Conn_(Db_conn v) {conn = v;} private Db_conn conn;
public boolean Quiet() {return quiet;} public void Quiet_(boolean v) {quiet = v;} private boolean quiet;
public String Sql_fmt() {return sql_fmt;} public void Sql_fmt_(String v) {sql_fmt = v;} private String sql_fmt;
// public Db_stmt_arg[] Sql_args() {return sql_args;} public void Sql_args_(Db_stmt_arg[] v) {sql_args = v;} private Db_stmt_arg[] sql_args;
public String Msg() {return msg;} public void Msg_(String v) {msg = v;} private String msg;
public String Fill_next(String state) {
String[] vals = String_.Split(state, "|");
int val_lo = Int_.parse(vals[0]);
int interval = Int_.parse(vals[1]);
int val_hi = val_lo + interval;
Db_stmt_arg arg = list.Get_at(0);
arg.Val = val_lo;
arg = list.Get_at(1);
arg.Val = val_hi;
return String_.Concat_with_str("|", Int_.To_str(val_hi), vals[1]);
}
public void Run() {
Db_stmt stmt = conn.Stmt_sql(sql_fmt);
// foreach (itme) Db_stmt_arg_list list = Db_stmt_arg_list
Gfo_usr_dlg_.Instance.Note_many("", "", msg);
stmt.Exec_update();
// increment ranges
}
}