Ignore:
Timestamp:
2019-02-05T23:03:16+13:00 (5 years ago)
Author:
ak19
Message:

More Western Wilson stuff. 1. Major changes to fix handling of utf8 stuff in db so uniqueness actually works: so finding (selecting) exact matches works and insert unique violations don't happen from code. Inserting is now made lowercase since only macrons matter and case doesn't. 2. The SQL db's MarkedWords table needs to specify the uniqueness of its utf8 marked_word column differently for the utf8-ness to work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/the-macronizer/trunk/src/java/util/MySQLAccess.java

    r32743 r32745  
    5656
    5757    private final String DB_NAME = "Macroniser";
    58     // TODO: from Properties file
     58    // obtained from Properties file:
    5959    private String USERNAME; //= "root"; by default
    6060    private String PASSWORD; //= "pinky";
     
    9191
    9292            }
    93             System.err.println("*** Found user: |" + USERNAME + "|");
    94             System.err.println("*** Found pwd: " + PASSWORD);
     93            //System.out.println("*** Found user: |" + USERNAME + "|");
     94            //System.out.println("*** Found pwd: " + PASSWORD);
    9595
    9696            // This will load the MySQL driver, each DB has its own driver Class.forName("com.mysql.jdbc.Driver");
     
    9999            statement = connect.createStatement();
    100100
    101             // TODO: can we use preparedStatement here instead of statement?
    102             int result = statement.executeUpdate("set names utf8mb4");
    103             System.err.println("Was set utf8 a success? " + result); // should return 0 for SQL stmts that return nothing
     101            int result = statement.executeUpdate("set names utf8mb4"); // should return 0 for SQL stmts that return nothing
     102
    104103            success = true;
    105104        } catch (SQLException e) {
     
    192191            insertOccurrence(word_id, time_id, date_id);
    193192
    194             System.err.println("The ID's are:(word, date, time) (" + word_id + "," + date_id + "," + time_id + ")");
     193            if(MacroniserLogFileProcessor.debug) {
     194                System.out.println("The IDs are:(word, date, time) (" + word_id + "," + date_id + "," + time_id + ")");
     195            }
    195196
    196197            connect.commit();
     
    234235    //gets the specified marked word's id
    235236    private int getMarkedWordID(String marked_word) throws SQLException {
     237        // in cases where the user didn't enter any input str, marked_word will be null. Still of interest, store to db as string "NULL"
     238        if(marked_word == null) {
     239            marked_word = "NULL";
     240        }
     241
    236242        // Warning: "select * from table WHERE str_field LIKE ?" does not work when we want exact matches (or matches featuring macrons)
    237243        // Use "WHERE BINARY str_filed = ?" instead
     
    253259    private int insertMarkedWord(String word) throws SQLException {
    254260
     261        if(word == null) {
     262            word = "NULL";
     263        }
     264
    255265        String query = "INSERT INTO MarkedWords (marked_word) VALUES (?)";
    256266        preparedStatement = connect.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
    257267        preparedStatement.setString(1, word);
     268
    258269
    259270        int word_id = -1;
     
    293304        while (resultSet.next()) {
    294305            date_id = resultSet.getInt("date_id");
    295             System.err.println(date_id + " - " + date.toString());
     306            if(MacroniserLogFileProcessor.debug) System.out.println(date_id + " - " + date.toString());
    296307        }
    297308        return date_id;
     
    382393
    383394    public static void main(String[] args) {
    384         System.err.println("Hello pinky!");
    385395        MySQLAccess mysql = new MySQLAccess();
    386396
Note: See TracChangeset for help on using the changeset viewer.