2014-06-30 04:04:32 +00:00
|
|
|
/*
|
|
|
|
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.*;
|
2015-02-23 02:03:49 +00:00
|
|
|
import gplx.dbs.qrys.*;
|
2014-06-30 04:04:32 +00:00
|
|
|
public class Db_qry_fxt {
|
2015-01-26 01:56:50 +00:00
|
|
|
public static void Insert_kvo(Db_conn conn, String tblName, KeyValList kvList) {
|
2014-06-30 04:04:32 +00:00
|
|
|
Db_qry_insert qry = Db_qry_.insert_(tblName);
|
|
|
|
for (int i = 0; i < kvList.Count(); i++) {
|
|
|
|
KeyVal kv = kvList.GetAt(i);
|
|
|
|
qry.Arg_obj_(kv.Key(), kv.Val());
|
|
|
|
}
|
2015-01-26 01:56:50 +00:00
|
|
|
qry.Exec_qry(conn);
|
2014-06-30 04:04:32 +00:00
|
|
|
}
|
2015-01-26 01:56:50 +00:00
|
|
|
public static GfoNde SelectAll(Db_conn conn, String tblName) {
|
|
|
|
return Db_qry_.select_tbl_(tblName).ExecRdr_nde(conn);
|
2014-06-30 04:04:32 +00:00
|
|
|
}
|
2015-01-26 01:56:50 +00:00
|
|
|
public static int SelectAll_count(Db_conn conn, String tblName) {
|
|
|
|
GfoNde nde = Db_qry_fxt.SelectAll(conn, tblName);
|
2014-06-30 04:04:32 +00:00
|
|
|
return nde.Subs().Count();
|
|
|
|
}
|
2015-01-26 01:56:50 +00:00
|
|
|
public static void DeleteAll(Db_conn conn, String... ary) {
|
2014-06-30 04:04:32 +00:00
|
|
|
for (String s : ary)
|
2015-01-26 01:56:50 +00:00
|
|
|
Db_qry_.delete_tbl_(s).Exec_qry(conn);
|
2014-06-30 04:04:32 +00:00
|
|
|
}
|
2015-01-26 01:56:50 +00:00
|
|
|
public static void tst_Select(Db_conn conn, String tblName, DbTstRow... expdAry) {
|
|
|
|
GfoNde nde = Db_qry_fxt.SelectAll(conn, tblName);
|
2014-06-30 04:04:32 +00:00
|
|
|
int len = Array_.Len(expdAry);
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
DbTstRow expdRow = expdAry[i];
|
|
|
|
int actlIdx = (expdRow.Idx() == -1) ? i : expdRow.Idx();
|
|
|
|
GfoNde actlNde = nde.Subs().FetchAt_asGfoNde(actlIdx);
|
|
|
|
int fldLen = Array_.Len(expdRow.Dat());
|
|
|
|
for (int j = 0; j < fldLen; j++) {
|
|
|
|
DbTstDat expdDat = expdRow.Dat()[j];
|
|
|
|
Object actlVal = expdDat.Fld() == null ? actlNde.ReadAt(j) : actlNde.Read(expdDat.Fld());
|
|
|
|
Tfds.Eq(expdDat.Val(), actlVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|