public void Split__trg__nth__new(Split_ctx ctx, Db_conn trg_conn) {
   if (cur_ns_id != ctx.Trg_ns()) {
     if (cur_ns_id != -1) bldr.Exec_qry_end();
     cur_ns_id = ctx.Trg_ns();
     bldr.Exec_qry_bgn(Rndm_qry_itm.New_by_ns(ctx.Wiki(), cur_ns_id));
   }
   bldr.Exec_rng_bgn();
   bldr.Conn().Txn_bgn("rndm");
 }
  public void Exec_qry_bgn(Rndm_qry_itm qry_itm) {
    this.qry_itm = qry_itm;

    qry_idx = qry_tbl.Select_by_key(qry_itm.Qry_key());
    if (qry_idx == -1) qry_idx = ++qry_idx_max;
    else {
      // delete all
      qry_tbl.Delete_by_qry_idx(qry_idx);
      rng_tbl.Delete_by_qry_idx(qry_idx);
      seq_tbl.Delete_by_qry_idx(qry_idx);
    }

    rng_idx = seq_in_rng = seq_in_qry = 0;
    rng_stmt = rng_tbl.Insert_stmt();
    seq_stmt = seq_tbl.Insert_stmt();
  }
 public void Exec_qry_end() {
   if (seq_in_qry == 0) return; // no sequences added
   qry_tbl.Insert(qry_idx, rng_idx, qry_itm.Qry_key(), qry_itm.Qry_data(), qry_itm.Qry_name());
 }