aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2019-01-31 03:01:15 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2019-01-31 03:01:15 +0000
commitc8a05d8f59f131312b078aca5726a194a45bafa5 (patch)
treecfaf9ad3564eeddd91bfcf274f4b4cec1c684728 /src
parentb2bb4fcdba54b5ecf5d9cbc56f2d3e0fca3326ef (diff)
parenta06385c7c985f31561ad52a4643419ab57222e37 (diff)
downloadjackcess-c8a05d8f59f131312b078aca5726a194a45bafa5.tar.gz
jackcess-c8a05d8f59f131312b078aca5726a194a45bafa5.zip
merge trunk changes through r1271
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/jdk8@1272 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src')
-rw-r--r--src/changes/changes.xml8
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/util/ImportUtil.java88
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/util/ImportTest.java15
3 files changed, 60 insertions, 51 deletions
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 633314f..0922c60 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -29,6 +29,14 @@
commons-lang3.
</action>
</release>
+ <release version="2.2.3" date="TBD">
+ <action dev="jahlborn" type="fix">
+ Fix parsing of escaped double quotes in expressions.
+ </action>
+ <action dev="jahlborn" type="fix" system="SourceForge2" issue="152">
+ Use column label from ResultSetMetaData when importing.
+ </action>
+ </release>
<release version="2.2.2" date="2019-01-05">
<action dev="jahlborn" type="fix" system="SourceForge2" issue="151">
Fix length in units calculation for Access 97 text fields.
diff --git a/src/main/java/com/healthmarketscience/jackcess/util/ImportUtil.java b/src/main/java/com/healthmarketscience/jackcess/util/ImportUtil.java
index 61e91b9..8cfa9f9 100644
--- a/src/main/java/com/healthmarketscience/jackcess/util/ImportUtil.java
+++ b/src/main/java/com/healthmarketscience/jackcess/util/ImportUtil.java
@@ -47,14 +47,14 @@ import com.healthmarketscience.jackcess.impl.DatabaseImpl;
* @author James Ahlborn
* @usage _general_class_
*/
-public class ImportUtil
+public class ImportUtil
{
/** Batch commit size for copying other result sets into this database */
private static final int COPY_TABLE_BATCH_SIZE = 200;
/** the platform line separator */
static final String LINE_SEPARATOR = System.getProperty("line.separator");
-
+
private ImportUtil() {}
/**
@@ -69,7 +69,7 @@ public class ImportUtil
{
List<ColumnBuilder> columns = new LinkedList<ColumnBuilder>();
for (int i = 1; i <= md.getColumnCount(); i++) {
- ColumnBuilder column = new ColumnBuilder(md.getColumnName(i))
+ ColumnBuilder column = new ColumnBuilder(md.getColumnLabel(i))
.escapeName();
int lengthInUnits = md.getColumnDisplaySize(i);
column.setSQLType(md.getColumnType(i), lengthInUnits);
@@ -100,7 +100,7 @@ public class ImportUtil
* <p>
* Equivalent to:
* {@code importResultSet(source, db, name, SimpleImportFilter.INSTANCE);}
- *
+ *
* @param name Name of the new table to create
* @param source ResultSet to copy from
*
@@ -115,13 +115,13 @@ public class ImportUtil
{
return importResultSet(source, db, name, SimpleImportFilter.INSTANCE);
}
-
+
/**
* Copy an existing JDBC ResultSet into a new table in this database.
* <p>
* Equivalent to:
* {@code importResultSet(source, db, name, filter, false);}
- *
+ *
* @param name Name of the new table to create
* @param source ResultSet to copy from
* @param filter valid import filter
@@ -137,11 +137,11 @@ public class ImportUtil
{
return importResultSet(source, db, name, filter, false);
}
-
+
/**
* Copy an existing JDBC ResultSet into a new (or optionally existing) table
* in this database.
- *
+ *
* @param name Name of the new table to create
* @param source ResultSet to copy from
* @param filter valid import filter
@@ -150,7 +150,7 @@ public class ImportUtil
* name
*
* @return the name of the imported table
- *
+ *
* @see Builder
*/
public static String importResultSet(ResultSet source, Database db,
@@ -191,13 +191,13 @@ public class ImportUtil
return table.getName();
}
-
+
/**
* Copy a delimited text file into a new table in this database.
* <p>
* Equivalent to:
* {@code importFile(f, name, db, delim, SimpleImportFilter.INSTANCE);}
- *
+ *
* @param name Name of the new table to create
* @param f Source file to import
* @param delim Regular expression representing the delimiter string.
@@ -219,7 +219,7 @@ public class ImportUtil
* <p>
* Equivalent to:
* {@code importFile(f, name, db, delim, "'", filter, false);}
- *
+ *
* @param name Name of the new table to create
* @param f Source file to import
* @param delim Regular expression representing the delimiter string.
@@ -243,7 +243,7 @@ public class ImportUtil
* <p>
* Equivalent to:
* {@code importReader(new BufferedReader(new FileReader(f)), db, name, delim, "'", filter, useExistingTable, true);}
- *
+ *
* @param name Name of the new table to create
* @param f Source file to import
* @param delim Regular expression representing the delimiter string.
@@ -258,8 +258,8 @@ public class ImportUtil
* @see #importReader(BufferedReader,Database,String,String,ImportFilter,boolean)
* @see Builder
*/
- public static String importFile(File f, Database db, String name,
- String delim, char quote,
+ public static String importFile(File f, Database db, String name,
+ String delim, char quote,
ImportFilter filter,
boolean useExistingTable)
throws IOException
@@ -272,7 +272,7 @@ public class ImportUtil
* <p>
* Equivalent to:
* {@code importReader(new BufferedReader(new FileReader(f)), db, name, delim, "'", filter, useExistingTable, header);}
- *
+ *
* @param name Name of the new table to create
* @param f Source file to import
* @param delim Regular expression representing the delimiter string.
@@ -288,8 +288,8 @@ public class ImportUtil
* @see #importReader(BufferedReader,Database,String,String,char,ImportFilter,boolean,boolean)
* @see Builder
*/
- public static String importFile(File f, Database db, String name,
- String delim, char quote,
+ public static String importFile(File f, Database db, String name,
+ String delim, char quote,
ImportFilter filter,
boolean useExistingTable,
boolean header)
@@ -298,7 +298,7 @@ public class ImportUtil
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(f));
- return importReader(in, db, name, delim, quote, filter,
+ return importReader(in, db, name, delim, quote, filter,
useExistingTable, header);
} finally {
ByteUtil.closeQuietly(in);
@@ -310,7 +310,7 @@ public class ImportUtil
* <p>
* Equivalent to:
* {@code importReader(in, db, name, delim, SimpleImportFilter.INSTANCE);}
- *
+ *
* @param name Name of the new table to create
* @param in Source reader to import
* @param delim Regular expression representing the delimiter string.
@@ -320,19 +320,19 @@ public class ImportUtil
* @see #importReader(BufferedReader,Database,String,String,ImportFilter)
* @see Builder
*/
- public static String importReader(BufferedReader in, Database db,
+ public static String importReader(BufferedReader in, Database db,
String name, String delim)
throws IOException
{
return importReader(in, db, name, delim, SimpleImportFilter.INSTANCE);
}
-
+
/**
* Copy a delimited text file into a new table in this database.
* <p>
* Equivalent to:
* {@code importReader(in, db, name, delim, filter, false);}
- *
+ *
* @param name Name of the new table to create
* @param in Source reader to import
* @param delim Regular expression representing the delimiter string.
@@ -343,7 +343,7 @@ public class ImportUtil
* @see #importReader(BufferedReader,Database,String,String,ImportFilter,boolean)
* @see Builder
*/
- public static String importReader(BufferedReader in, Database db,
+ public static String importReader(BufferedReader in, Database db,
String name, String delim,
ImportFilter filter)
throws IOException
@@ -357,7 +357,7 @@ public class ImportUtil
* <p>
* Equivalent to:
* {@code importReader(in, db, name, delim, '"', filter, false);}
- *
+ *
* @param name Name of the new table to create
* @param in Source reader to import
* @param delim Regular expression representing the delimiter string.
@@ -367,12 +367,12 @@ public class ImportUtil
* name
*
* @return the name of the imported table
- *
+ *
* @see Builder
*/
- public static String importReader(BufferedReader in, Database db,
+ public static String importReader(BufferedReader in, Database db,
String name, String delim,
- ImportFilter filter,
+ ImportFilter filter,
boolean useExistingTable)
throws IOException
{
@@ -386,7 +386,7 @@ public class ImportUtil
* <p>
* Equivalent to:
* {@code importReader(in, db, name, delim, '"', filter, useExistingTable, true);}
- *
+ *
* @param name Name of the new table to create
* @param in Source reader to import
* @param delim Regular expression representing the delimiter string.
@@ -397,23 +397,23 @@ public class ImportUtil
* name
*
* @return the name of the imported table
- *
+ *
* @see Builder
*/
- public static String importReader(BufferedReader in, Database db,
+ public static String importReader(BufferedReader in, Database db,
String name, String delim, char quote,
ImportFilter filter,
boolean useExistingTable)
throws IOException
{
- return importReader(in, db, name, delim, quote, filter, useExistingTable,
+ return importReader(in, db, name, delim, quote, filter, useExistingTable,
true);
}
/**
* Copy a delimited text file into a new (or optionally exixsting) table in
* this database.
- *
+ *
* @param name Name of the new table to create
* @param in Source reader to import
* @param delim Regular expression representing the delimiter string.
@@ -426,10 +426,10 @@ public class ImportUtil
* valid if useExistingTable is {@code true}
*
* @return the name of the imported table
- *
+ *
* @see Builder
*/
- public static String importReader(BufferedReader in, Database db,
+ public static String importReader(BufferedReader in, Database db,
String name, String delim, char quote,
ImportFilter filter,
boolean useExistingTable, boolean header)
@@ -449,7 +449,7 @@ public class ImportUtil
List<ColumnBuilder> columns = new LinkedList<ColumnBuilder>();
Object[] columnNames = splitLine(line, delimPat, quote, in, 0);
-
+
for (int i = 0; i < columnNames.length; i++) {
columns.add(new ColumnBuilder((String)columnNames[i], DataType.TEXT)
.escapeName()
@@ -458,21 +458,21 @@ public class ImportUtil
}
table = createUniqueTable(db, name, columns, null, filter);
-
+
// the first row was a header row
header = true;
}
List<Object[]> rows = new ArrayList<Object[]>(COPY_TABLE_BATCH_SIZE);
int numColumns = table.getColumnCount();
-
+
if(!header) {
// first line is _not_ a header line
Object[] data = splitLine(line, delimPat, quote, in, numColumns);
data = filter.filterRow(data);
if(data != null) {
rows.add(data);
- }
+ }
}
while ((line = in.readLine()) != null)
@@ -535,7 +535,7 @@ public class ImportUtil
idx = endIdx + 1;
} else {
-
+
// done
idx = endIdx;
break;
@@ -582,7 +582,7 @@ public class ImportUtil
*/
private static Table createUniqueTable(Database db, String name,
List<ColumnBuilder> columns,
- ResultSetMetaData md,
+ ResultSetMetaData md,
ImportFilter filter)
throws IOException, SQLException
{
@@ -592,7 +592,7 @@ public class ImportUtil
while(db.getTable(name) != null) {
name = baseName + (counter++);
}
-
+
return new TableBuilder(name)
.addColumns(filter.filterColumns(columns, md))
.toTable(db);
@@ -661,7 +661,7 @@ public class ImportUtil
public String importResultSet(ResultSet source)
throws SQLException, IOException
{
- return ImportUtil.importResultSet(source, _db, _tableName, _filter,
+ return ImportUtil.importResultSet(source, _db, _tableName, _filter,
_useExistingTable);
}
@@ -677,7 +677,7 @@ public class ImportUtil
* @see ImportUtil#importReader(BufferedReader,Database,String,String,char,ImportFilter,boolean,boolean)
*/
public String importReader(BufferedReader reader) throws IOException {
- return ImportUtil.importReader(reader, _db, _tableName, _delim, _quote,
+ return ImportUtil.importReader(reader, _db, _tableName, _delim, _quote,
_filter, _useExistingTable, _header);
}
}
diff --git a/src/test/java/com/healthmarketscience/jackcess/util/ImportTest.java b/src/test/java/com/healthmarketscience/jackcess/util/ImportTest.java
index 97c0faf..5e0b036 100644
--- a/src/test/java/com/healthmarketscience/jackcess/util/ImportTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/util/ImportTest.java
@@ -39,9 +39,9 @@ import com.healthmarketscience.jackcess.impl.JetFormatTest;
import junit.framework.TestCase;
import static com.healthmarketscience.jackcess.TestUtil.*;
-/**
+/**
* @author Rob Di Marco
- */
+ */
public class ImportTest extends TestCase
{
@@ -194,7 +194,7 @@ public class ImportTest extends TestCase
assertEquals(Arrays.asList(
"RESULT_PHYS_ID", "FIRST", "MIDDLE", "LAST", "OUTLIER",
"RANK", "CLAIM_COUNT", "PROCEDURE_COUNT",
- "WEIGHTED_CLAIM_COUNT", "WEIGHTED_PROCEDURE_COUNT"),
+ "WEIGHTED_CLAIM_COUNT", "WEIGHTED_PROCEDURE_COUNT"),
colNames);
db.close();
@@ -271,7 +271,7 @@ public class ImportTest extends TestCase
private List<Integer> _displaySizes = new ArrayList<Integer>();
private List<Integer> _scales = new ArrayList<Integer>();
private List<Integer> _precisions = new ArrayList<Integer>();
-
+
public Object invoke(Object proxy, Method method, Object[] args)
{
String methodName = method.getName();
@@ -284,7 +284,8 @@ public class ImportTest extends TestCase
return Boolean.FALSE;
} else if(methodName.equals("getColumnCount")) {
return _types.size();
- } else if(methodName.equals("getColumnName")) {
+ } else if(methodName.equals("getColumnName") ||
+ methodName.equals("getColumnLabel")) {
return getValue(_names, args[0]);
} else if(methodName.equals("getColumnDisplaySize")) {
return getValue(_displaySizes, args[0]);
@@ -318,5 +319,5 @@ public class ImportTest extends TestCase
return values.get((Integer)index - 1);
}
}
-
-}
+
+}