Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

68
LINES

< > BotCompany Repo | #1000694 // spike of SnippetDB

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (2081L/16K/49K).

!636
!modern
!* ctr

main {
  psvm {
    new SnippetDB db;
    db.importMySQLDump(gunzipToText("#1000673"));
    //db.printStats();
    
    print();
    db.printFullSnippet("#636");
  }
  
  static class Table {
    List<List<String>> data;
    List<String> fields;
    
    *(List<List<String>> *data, List<String> *fields) {}
    
    Map<S, S> rowAsMap(L<S> row) {
      new Map<S, S> map;
      for (int i = 0; i < row.size(); i++)
        map.put(fields.get(i), row.get(i));
      return map;
    }
  }
  
  static class SnippetDB {
    Map<String, List> tables;
    Map<String, List> tableFields;
    
    void importMySQLDump(String dump) {
      print("Importing " + dump.length() + " chars.");
      Class importer = hotwire("#1000660");
      set(importer, "in", dump);
      callMain(importer);
      tables = (Map) get(importer, "tables");
      tableFields = (Map) get(importer, "tableFields");
      print("Total rows imported: " + get(importer, "totalRows"));
    }
    
    void printStats() {
      print(structure(tables.keySet()));
      print(structure(tableFields));
    }
    
    Table table(String name) {
      return new Table(tables.get(name), tableFields.get(name));
    }
    
    Map<S, S> getFullSnippet(String id) {
      id = "" + parseSnippetID(id);
      Table t = table("snippets_public");
      for (List row : t.data) {
        Map<S, S> map = t.rowAsMap(row);
        String _id = map.get("sn_id");
        if (id.equals(_id))
          return map;
      }
      return null;
    }
    
    void printFullSnippet(S id) {
      print(structure(getFullSnippet(id)));
    }
  }
}

Author comment

Began life as a copy of #1000678

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1000694
Snippet name: spike of SnippetDB
Eternal ID of this version: #1000694/1
Text MD5: 8bbafe6973aa980ffc98692f8dfe96aa
Transpilation MD5: 14423f260d9868d003c6a21d4c30f053
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-09-15 18:14:11
Source code size: 1683 bytes / 68 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 658 / 692
Referenced in: [show references]