Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes MySQL export for more than one entry #807

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ 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
- Fixed [#803](https://github.com/JabRef/jabref/issues/803): Fixed dynamically group, free-form search
- Fixed [#743](https://github.com/JabRef/jabref/issues/743): Logger not configured when JAR is started
- Fixed [#822](https://github.com/JabRef/jabref/issues/822):OSX - Exception when adding the icon to the dock


### Removed
- Fixed [#627](https://github.com/JabRef/jabref/issues/627): The pdf field is removed from the export formats, use the file field
- Removed configuration option to use database file directory as base directory for attached files and make it default instead.
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 final String OPT_ALLOW_MULTI_QUERIES = "?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(OPT_ALLOW_MULTI_QUERIES);
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