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

@@ -25,4 +25,11 @@ public class Dbmeta_fld_mgr {
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 = Dbmeta_fld_list.new_();
int len = hash.Count();
for (int i = 0; i < len; ++i)
rv.Add(Get_at(i));
return rv;
}
}

View File

@@ -1,70 +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.metas; import gplx.*; import gplx.dbs.*;
import gplx.dbs.engines.sqlite.*;
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);
}
}
}

View File

@@ -94,25 +94,54 @@ class Dbmeta_fld_wkr__default extends Dbmeta_fld_wkr__base {
Object default_val = null;
rdr.Skip_ws();
byte[] src = rdr.Src();
byte b = src[rdr.Pos()];
switch (b) {
case Byte_ascii.Quote:
case Byte_ascii.Apos:
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:
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 Byte_ascii.Dash:
case Byte_ascii.Num_0: case Byte_ascii.Num_1: case Byte_ascii.Num_2: case Byte_ascii.Num_3: case Byte_ascii.Num_4:
case Byte_ascii.Num_5: case Byte_ascii.Num_6: case Byte_ascii.Num_7: case Byte_ascii.Num_8: case Byte_ascii.Num_9:
default_val = rdr.Read_int_to_non_num();
break;
default:
rdr.Err_wkr().Fail("invalid field_default"); break;
case Dbmeta_fld_tid.Tid__date: throw Err_.new_unhandled_default(fld.Type().Tid_ansi());
}
fld.Default_(default_val);
}
public String Read_str_to_end_of_num(Bry_rdr rdr) {
int bgn = rdr.Pos();
int pos = bgn, end = bgn;
int src_end = rdr.Src_end();
byte[] src = rdr.Src();
boolean loop = true;
while (loop) {
if (pos >= src_end) {
end = src_end;
break;
}
byte b = src[pos]; ++pos;
switch (b) {
case Byte_ascii.Space: case Byte_ascii.Tab: case Byte_ascii.Nl: case Byte_ascii.Cr:
case Byte_ascii.Paren_end:
case Byte_ascii.Comma:
end = pos - 1;
loop = false;
break;
default:
break;
}
}
rdr.Move_to(end);
return String_.new_a7(src, bgn, end);
}
@Override protected void When_match(Dbmeta_fld_itm fld) {}
private static final byte[] Hook = Bry_.new_a7("default");
public static final Dbmeta_fld_wkr__default Instance = new Dbmeta_fld_wkr__default();

View File

@@ -27,13 +27,13 @@ public class Dbmeta_parser__fld_tst {
fxt.Test_parse_type(" decimal ( 12 , 10 )" , fxt.Make_type(Dbmeta_fld_tid.Tid__decimal, 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 int not null default 'abc'" , fxt.Make_fld("name_1", Dbmeta_fld_tid.Tid__int, Dbmeta_fld_itm.Nullable_not_null, Bool_.Y, Bool_.N, "abc"));
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"));
}
}
class Dbmeta_parser__fld_fxt {