Exemplo n.º 1
0
  /**
   * Generates the SQL required to populate the strings table with jabref data.
   *
   * @param database BibtexDatabase object used from where the strings will be exported
   * @param out The output (PrintStream or Connection) object to which the DML should be written.
   * @param database_id ID of Jabref database related to the entries to be exported This information
   *     can be gathered using getDatabaseIDByPath(metaData, out)
   * @throws SQLException
   */
  private void populateStringTable(BibtexDatabase database, Object out, int database_id)
      throws SQLException {
    String insert = "INSERT INTO strings (label, content, database_id) VALUES (";

    if (database.getPreamble() != null) {
      String dml =
          insert
              + "'@PREAMBLE', "
              + '\''
              + StringUtil.quote(database.getPreamble(), "'", '\\')
              + "', "
              + '\''
              + database_id
              + "');";
      SQLUtil.processQuery(out, dml);
    }
    for (String key : database.getStringKeySet()) {
      BibtexString string = database.getString(key);
      String dml =
          insert
              + '\''
              + StringUtil.quote(string.getName(), "'", '\\')
              + "', "
              + '\''
              + StringUtil.quote(string.getContent(), "'", '\\')
              + "', "
              + '\''
              + database_id
              + '\''
              + ");";
      SQLUtil.processQuery(out, dml);
    }
  }