aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/com/healthmarketscience/jackcess
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/healthmarketscience/jackcess')
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/query/AppendQueryImpl.java32
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/query/AppendQuery.java2
2 files changed, 28 insertions, 6 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/query/AppendQueryImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/query/AppendQueryImpl.java
index 8fb3296..140fde3 100644
--- a/src/main/java/com/healthmarketscience/jackcess/impl/query/AppendQueryImpl.java
+++ b/src/main/java/com/healthmarketscience/jackcess/impl/query/AppendQueryImpl.java
@@ -40,6 +40,14 @@ public class AppendQueryImpl extends BaseSelectQueryImpl implements AppendQuery
return getTypeRow().name1;
}
+ public List<String> getTargetColumns() {
+ return new RowFormatter(getTargetRows()) {
+ @Override protected void format(StringBuilder builder, Row row) {
+ toOptionalQuotedExpr(builder, row.name2, true);
+ }
+ }.format();
+ }
+
public String getRemoteDbPath() {
return getTypeRow().name2;
}
@@ -48,6 +56,14 @@ public class AppendQueryImpl extends BaseSelectQueryImpl implements AppendQuery
return getTypeRow().expression;
}
+ public List<String> getValues() {
+ return new RowFormatter(getValueRows()) {
+ @Override protected void format(StringBuilder builder, Row row) {
+ builder.append(row.expression);
+ }
+ }.format();
+ }
+
protected List<Row> getValueRows() {
return filterRowsByFlag(super.getColumnRows(), APPEND_VALUE_FLAG);
}
@@ -57,12 +73,12 @@ public class AppendQueryImpl extends BaseSelectQueryImpl implements AppendQuery
return filterRowsByNotFlag(super.getColumnRows(), APPEND_VALUE_FLAG);
}
- public List<String> getValues() {
- return new RowFormatter(getValueRows()) {
- @Override protected void format(StringBuilder builder, Row row) {
- builder.append(row.expression);
- }
- }.format();
+ protected List<Row> getTargetRows() {
+ return new RowFilter() {
+ @Override protected boolean keep(Row row) {
+ return (row.name2 != null);
+ }
+ }.filter(super.getColumnRows());
}
@Override
@@ -70,6 +86,10 @@ public class AppendQueryImpl extends BaseSelectQueryImpl implements AppendQuery
{
builder.append("INSERT INTO ");
toOptionalQuotedExpr(builder, getTargetTable(), true);
+ List<String> columns = getTargetColumns();
+ if(!columns.isEmpty()) {
+ builder.append(" (").append(columns).append(')');
+ }
toRemoteDb(builder, getRemoteDbPath(), getRemoteDbType());
builder.append(NEWLINE);
List<String> values = getValues();
diff --git a/src/main/java/com/healthmarketscience/jackcess/query/AppendQuery.java b/src/main/java/com/healthmarketscience/jackcess/query/AppendQuery.java
index a62c286..ab4935c 100644
--- a/src/main/java/com/healthmarketscience/jackcess/query/AppendQuery.java
+++ b/src/main/java/com/healthmarketscience/jackcess/query/AppendQuery.java
@@ -30,6 +30,8 @@ public interface AppendQuery extends BaseSelectQuery
public String getTargetTable();
+ public List<String> getTargetColumns();
+
public String getRemoteDbPath();
public String getRemoteDbType();