Libraryless. Click here for Pure Java version (2397L/18K/52K).
1 | !636 |
2 | !sf |
3 | !string == |
4 | !L<S> |
5 | !cast |
6 | !class _javax 19 // this is only required because of #629 bugs... |
7 | |
8 | main { |
9 | static O in; |
10 | static boolean silent; |
11 | |
12 | psvm { |
13 | if (in == null) |
14 | in = "values (1,,'yo\"yo\"',3),(4,null,5);"; |
15 | |
16 | new main m; |
17 | List data = m.process((S) in); |
18 | if (!silent) |
19 | print(structure(data)); |
20 | in = data; |
21 | } |
22 | |
23 | List data; |
24 | List row; |
25 | |
26 | List process(String in) { |
27 | data = null; |
28 | |
29 | debug(in); |
30 | L<S> tok = mysqlTok(in); |
31 | data = new List; |
32 | |
33 | int i = indexOfIgnoreCase(tok, "values"), j = indexOfIgnoreCase(tok, ";"); |
34 | if (i < 0 || j < 0) fail("ouch"); |
35 | debug(i, j); |
36 | for (i += 2; i < j; i += 2) { |
37 | S token = tok.get(i); |
38 | if (token == "(") { |
39 | start_a_row(); |
40 | } else if (token == ")") { |
41 | end_row(); |
42 | } else if (token == ",") { |
43 | } else if (token.startsWith("\"") || token.startsWith("'")) |
44 | save(mysqlUnquote(token)); |
45 | else if (isInteger(token)) |
46 | save(token); |
47 | else if (token.equalsIgnoreCase("null")) |
48 | save(null); |
49 | else |
50 | badToken(token); |
51 | } |
52 | |
53 | return data; |
54 | } |
55 | |
56 | void start_a_row() { |
57 | debug("start_a_row"); |
58 | row = new List; |
59 | } |
60 | |
61 | boolean end_row() { |
62 | debug("end_row"); |
63 | if (row != null) { |
64 | data.add(row); |
65 | row = null; |
66 | return true; |
67 | } |
68 | return false; |
69 | } |
70 | |
71 | void save(Object value) { |
72 | debug("save"); |
73 | row.add(value); |
74 | } |
75 | |
76 | static boolean debug; |
77 | void debug(O... o) { |
78 | if (debug) |
79 | print(structure(o)); |
80 | } |
81 | |
82 | void badToken(S token) { |
83 | fail("Bad token: " + token); |
84 | } |
85 | } |
Began life as a copy of #1000654
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1000656 |
Snippet name: | Parse MySQL values (part of insert statement) |
Eternal ID of this version: | #1000656/1 |
Text MD5: | 10f2d1288dc745e13d1e14b1046027ae |
Transpilation MD5: | 20a1374b702ab773ece28ae67888a88d |
Author: | stefan |
Category: | |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-08-22 16:39:18 |
Source code size: | 1674 bytes / 85 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 758 / 1297 |
Referenced in: | [show references] |