Skip to content

Commit

Permalink
net-sf-ucanaccess-fork: Use sql constants
Browse files Browse the repository at this point in the history
  • Loading branch information
spannm committed Nov 28, 2023
1 parent cb1415c commit f4896f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
24 changes: 14 additions & 10 deletions src/main/java/net/ucanaccess/console/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package net.ucanaccess.console;

import static net.ucanaccess.type.SqlConstants.*;

import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.DatabaseBuilder;
import net.ucanaccess.converters.Metadata.Property;
import net.ucanaccess.log.Logger;
import net.ucanaccess.util.Sql;
import net.ucanaccess.util.Try;
import net.ucanaccess.util.UcanaccessRuntimeException;

Expand Down Expand Up @@ -265,7 +268,7 @@ private void start(String[] commands) {
* </pre>
*
* The {@code -d ,} option changes the delimiter character to a comma instead of the default semicolon. The
* {@code -t License} option dumps the {@code License} table using the SQL statement "select * from [License]".
* {@code -t License} option dumps the {@code License} table using the SQL statement "SELECT * FROM [License]".
*/
private void executeExport(String cmd) throws SQLException, IOException {
List<String> tokens = tokenize(cmd);
Expand Down Expand Up @@ -347,7 +350,7 @@ private void executeExport(String cmd) throws SQLException, IOException {
// executing the 'lastSqlQuery'.
String sqlQuery;
if (table != null && !table.isEmpty()) {
sqlQuery = "SELECT * FROM [" + table + "]";
sqlQuery = Sql.of(SELECT, "*", FROM, "[" + table + "]").toString();
} else if (lastSqlQuery != null) {
sqlQuery = lastSqlQuery;
} else {
Expand All @@ -363,24 +366,25 @@ private void executeExport(String cmd) throws SQLException, IOException {
* {@code schemaFileName} (if given). Uses the given {@code exporter} to perform the actual CSV and schema export
* operations.
*/
private void exportCsvAndSchema(String sqlQuery, String csvFileName, String schemaFileName, Exporter exporter)
throws SQLException, IOException {
private void exportCsvAndSchema(CharSequence _sqlQuery, String _csvFileName, String _schemaFileName, Exporter _exporter)
throws SQLException, IOException {
Objects.requireNonNull(_sqlQuery, "Sql required");
try (Statement statement = conn.createStatement()) {
ResultSet rs = statement.executeQuery(sqlQuery);
ResultSet rs = statement.executeQuery(_sqlQuery.toString());

// output the csvFile
File csvFile = new File(csvFileName);
File csvFile = new File(_csvFileName);
try (PrintStream out = new PrintStream(csvFile)) {
exporter.dumpCsv(rs, out);
_exporter.dumpCsv(rs, out);
out.flush();
}
prompt("Created CSV file: " + csvFile.getAbsolutePath());

// output the schema file if requested
if (schemaFileName != null) {
File schemaFile = new File(schemaFileName);
if (_schemaFileName != null) {
File schemaFile = new File(_schemaFileName);
try (PrintStream out = new PrintStream(csvFile)) {
exporter.dumpSchema(rs, out);
_exporter.dumpSchema(rs, out);
out.flush();
}
prompt("Created schema file: " + schemaFile.getAbsolutePath());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/ucanaccess/converters/LoadJet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1545,9 +1545,9 @@ public void synchronisationTriggers(String tableName, boolean hasAutoNumberColum
triggersGenerator.synchronisationTriggers(tableName, hasAutoNumberColumn, hasAppendOnly);
}

public Object tryDefault(Object defaulT) {
public Object tryDefault(Object _default) {
try (Statement st = conn.createStatement()) {
ResultSet rs = st.executeQuery("SELECT " + defaulT + " FROM DUAL ");
ResultSet rs = st.executeQuery("SELECT " + _default + " FROM DUAL");
if (rs.next()) {
return rs.getObject(1);
}
Expand Down

0 comments on commit f4896f2

Please sign in to comment.