Skip to content

Commit

Permalink
Fixes the export of more than one entry through the connection option
Browse files Browse the repository at this point in the history
Added ability to add server specific connection parameters
Using setCatalog instead of use database (recommended in mysql doc)
  • Loading branch information
Siedlerchr committed Feb 13, 2016
1 parent c917a4a commit 2654b0b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ to [sourceforge feature requests](https://sourceforge.net/p/jabref/features/) by
- Fixed [#710](https://github.com/JabRef/jabref/issues/710): Fixed quit behaviour under OSX
- Merge from DOI now honors removed fields
- Fixed [#778](https://github.com/JabRef/jabref/issues/778): Fixed NPE when exporting to .sql File

- Fixed [#685](https://github.com/JabRef/jabref/issues/685): Fixed MySQL exporting for more than one entry

### Removed
- Fixed [#627](https://github.com/JabRef/jabref/issues/627): The pdf field is removed from the export formats, use the file field
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/net/sf/jabref/sql/DBStrings.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class DBStrings {
private String database;
private String username;
private String password;
private String dbParameters = "";

private List<String> serverTypes;
private boolean isInitialized;
Expand Down Expand Up @@ -123,6 +124,25 @@ public void isConfigValid(boolean confValid) {
this.configValid = confValid;
}

/**
* Returns the database parameters set
* @return dbParameters: The concatenated parameters
*/
public String getDbParameters() {
return dbParameters;
}

/**
* Add server specific database parameter(s) <br>
* Multiple parameters must be concatenated in the format <br>
* {@code ?Parameter1=value&parameter2=value2}
* @param dbParameter The concatendated parameter
*/
public void setDbParameters(String dbParameters) {
this.dbParameters = dbParameters;
}


/**
* Store these db strings into JabRef preferences.
*/
Expand All @@ -132,4 +152,6 @@ public void storeToPreferences() {
Globals.prefs.put(JabRefPreferences.DB_CONNECT_DATABASE, getDatabase());
Globals.prefs.put(JabRefPreferences.DB_CONNECT_USERNAME, getUsername());
}


}
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/sql/SQLUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public static AutoCloseable processQueryWithResults(Object out, String query) th
public static String createJDBCurl(DBStrings dbStrings, boolean withDBName) {
String url;
url = "jdbc:" + dbStrings.getServerType().toLowerCase() + "://" + dbStrings.getServerHostname()
+ (withDBName ? '/' + dbStrings.getDatabase() : "");
+ (withDBName ? '/' + dbStrings.getDatabase() : "") + dbStrings.getDbParameters();
return url;
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/net/sf/jabref/sql/exporter/MySQLExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
final public class MySQLExporter extends DBExporter {

private static MySQLExporter instance;
private static String optAllowMultiQueries = "?allowMultiQueries=true";


private MySQLExporter() {
Expand All @@ -55,15 +56,19 @@ public static MySQLExporter getInstance() {
@Override
public Connection connectToDB(DBStrings dbstrings) throws Exception {
this.dbStrings = dbstrings;

dbStrings.setDbParameters(optAllowMultiQueries);
String url = SQLUtil.createJDBCurl(dbstrings, false);
String drv = "com.mysql.jdbc.Driver";


Class.forName(drv).newInstance();
Connection conn = DriverManager.getConnection(url,
dbstrings.getUsername(), dbstrings.getPassword());
SQLUtil.processQuery(conn, "CREATE DATABASE IF NOT EXISTS `"
+ dbStrings.getDatabase() + '`');
SQLUtil.processQuery(conn, "USE `" + dbStrings.getDatabase() + '`');

conn.setCatalog(dbStrings.getDatabase());
return conn;
}

Expand Down

0 comments on commit 2654b0b

Please sign in to comment.