mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.7.2.1'
This commit is contained in:
@@ -16,7 +16,8 @@ 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.xowa.bldrs.cmds.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.cmds.*;
|
||||
import org.junit.*; import gplx.core.primitives.*; import gplx.core.stores.*; import gplx.dbs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.ctgs.*; import gplx.xowa.bldrs.*; import gplx.xowa.wikis.nss.*;
|
||||
import org.junit.*; import gplx.core.primitives.*; import gplx.core.stores.*;
|
||||
import gplx.dbs.*; import gplx.dbs.sqls.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.ctgs.*; import gplx.xowa.bldrs.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xob_categorylinks_sql_tst {
|
||||
@Before public void init() {if (Xoa_test_.Db_skip()) return; fxt.Ctor_fsys();} Db_mgr_fxt fxt = new Db_mgr_fxt();
|
||||
@After public void term() {if (Xoa_test_.Db_skip()) return; fxt.Rls();}
|
||||
@@ -84,6 +85,7 @@ class Db_tst_row {
|
||||
}
|
||||
}
|
||||
class Db_tst_qry {
|
||||
private final Sql_qry_wtr qry_wtr = Sql_qry_wtr_.New__sqlite();
|
||||
public Db_qry Qry() {return qry;} Db_qry qry;
|
||||
public String[] Cols() {return cols;} public Db_tst_qry Cols_(String... v) {this.cols = v; return this;} private String[] cols;
|
||||
public List_adp Rows() {return rows;} List_adp rows = List_adp_.New();
|
||||
@@ -127,7 +129,7 @@ class Db_tst_qry {
|
||||
}
|
||||
if (!pass) {
|
||||
bfr.Add(Lbl_row_hdr).Add_int_variable(expd_row_idx).Add_byte_nl();
|
||||
bfr.Add_str_u8(qry.To_sql__exec(gplx.dbs.sqls.Sql_qry_wtr_.Sqlite)).Add_byte(Byte_ascii.Semic);
|
||||
bfr.Add_str_u8(qry.To_sql__exec(qry_wtr)).Add_byte(Byte_ascii.Semic);
|
||||
throw Err_.new_wo_type(bfr.To_str_and_clear());
|
||||
}
|
||||
} static final byte[] Lbl_row_hdr = Bry_.new_a7("row: "), Lbl_eq_y = Bry_.new_a7(" == "), Lbl_eq_n = Bry_.new_a7(" != ");
|
||||
|
||||
@@ -28,7 +28,12 @@ class Sql_fld_mgr {
|
||||
int bgn = Bry_find_.Find_fwd(raw, Tkn_create_table); if (bgn == Bry_find_.Not_found) throw Err_.new_wo_type("could not find 'CREATE TABLE'");
|
||||
bgn = Bry_find_.Find_fwd(raw, Byte_ascii.Nl, bgn); if (bgn == Bry_find_.Not_found) throw Err_.new_wo_type("could not find new line after 'CREATE TABLE'");
|
||||
bgn += Int_.Const_position_after_char;
|
||||
int end = Bry_find_.Find_fwd(raw, Tkn_unique_index); if (end == Bry_find_.Not_found) throw Err_.new_wo_type("could not find 'UNIQUE KEY'");
|
||||
int end = Bry_find_.Find_fwd(raw, Tkn_unique_index);
|
||||
if (end == Bry_find_.Not_found) { // as of 2016-07, en.w:categorylinks no longer has UNIQUE KEY; try PRIMARY KEY; DATE:2016-07-08
|
||||
end = Bry_find_.Find_fwd(raw, Tkn_primary_key);
|
||||
if (end == Bry_find_.Not_found)
|
||||
throw Err_.new_wo_type("could not find 'UNIQUE KEY' or 'PRIMARY KEY'");
|
||||
}
|
||||
end = Bry_find_.Find_bwd(raw, Byte_ascii.Nl, end); if (bgn == Bry_find_.Not_found) throw Err_.new_wo_type("could not find new line before 'UNIQUE KEY'");
|
||||
Parse_lines(Bry_.Mid(raw, bgn, end));
|
||||
return this;
|
||||
@@ -47,9 +52,10 @@ class Sql_fld_mgr {
|
||||
hash.Add(fld.Key(), fld);
|
||||
}
|
||||
}
|
||||
private static final byte[]
|
||||
Tkn_create_table = Bry_.new_a7("CREATE TABLE")
|
||||
, Tkn_unique_index = Bry_.new_a7("UNIQUE KEY")
|
||||
private static final byte[]
|
||||
Tkn_create_table = Bry_.new_a7("CREATE TABLE")
|
||||
, Tkn_unique_index = Bry_.new_a7("UNIQUE KEY")
|
||||
, Tkn_primary_key = Bry_.new_a7("PRIMARY KEY")
|
||||
;
|
||||
public static final int Not_found = -1;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,22 @@ Sql_fld_mgr_fxt fxt = new Sql_fld_mgr_fxt();
|
||||
fxt.Exec_get("fld_2", 0);
|
||||
fxt.Exec_get("fld_3", -1);
|
||||
}
|
||||
@Test public void Primary_key() {
|
||||
fxt.Exec_parse(String_.Concat_lines_nl
|
||||
( "ignore"
|
||||
, "CREATE TABLE tbl_0 ("
|
||||
, " `fld_2` int,"
|
||||
, " `fld_1` int,"
|
||||
, " `fld_0` int,"
|
||||
, " PRIMARY KEY idx_0 (fld_2)"
|
||||
, ");"
|
||||
));
|
||||
fxt.Test_count(3);
|
||||
fxt.Exec_get("fld_0", 2);
|
||||
fxt.Exec_get("fld_1", 1);
|
||||
fxt.Exec_get("fld_2", 0);
|
||||
fxt.Exec_get("fld_3", -1);
|
||||
}
|
||||
}
|
||||
class Sql_fld_mgr_fxt {
|
||||
Sql_fld_mgr fld_mgr = new Sql_fld_mgr();
|
||||
|
||||
Reference in New Issue
Block a user