Menu

#131 AppendQueryImpl.toSQLString doesn't render the columns declaration

2.1.4
closed
None
1
2016-01-12
2016-01-11
No

Hi James, hi all,
I'm trying to make live the append queries.
All works fine as always in Jackcess except for a particular case.
In fact when the columns list is specified in a insert statement (in access), it's missed in the result of the AppendQueryImpl.toSQLString method.
e.g.,
insert into tableX (column1, column2) values([par1],[par2])in the db

becomes (as result of the AppendQueryImpl.toSQLString method)

insert into tableX values([par1],[par2])

Also I've found a temporary solution by extending the AppendQueryImpl class.
Just to save a bit of your time, here's the relevant code of that temporary solution:

protected void toSQLString(StringBuilder builder)
      {
        builder.append("INSERT INTO ");
        toOptionalQuotedExpr(builder, getTargetTable(), true);
        toRemoteDb(builder, getRemoteDbPath(), getRemoteDbType());
        builder.append(NEWLINE);
        List<String> values = getValues();
        if(!values.isEmpty()) {
          List<String> decl= getDeclaration();
          if(decl.size()>0){
            builder.append("(").append(getDeclaration()).append(")");
          }
          builder.append(" VALUES (").append(values).append(')');
        } else {
          toSQLSelectString(builder, true);
        }
      }

    private  List<String> getDeclaration() {
          return new RowFormatter(getDeclaration(getValueRows())) {
               @Override protected void format(StringBuilder builder, Row row) {
                        builder.append(row.name2);
                }
              }.format();
    }

    private List<Row> getDeclaration(List<Row> valueRows) {
        ArrayList<Row> ardc=new ArrayList<Row>();
        for(Row row:valueRows){
            if(row.name2!=null){
                ardc.add(row);
            }
        }
        return ardc;
    }

Discussion

  • James Ahlborn

    James Ahlborn - 2016-01-12
    • status: open --> closed
    • assigned_to: James Ahlborn
    • Group: Unassigned --> 2.1.4
     
  • James Ahlborn

    James Ahlborn - 2016-01-12

    Fixed in trunk, will be in the 2.1.4 release.

     
  • Marco Amadei

    Marco Amadei - 2016-01-12

    many thanks!

     

Log in to post a comment.

MongoDB Logo MongoDB