Skip to content

Commit

Permalink
closed #48 : Escape character should be added to PGSQL queries
Browse files Browse the repository at this point in the history
  • Loading branch information
JARVIS SONG committed Dec 23, 2016
1 parent ad173a2 commit 8708d5d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public final String quote(String name) {
}
}

public String wrapTableName(String tableName) {
return tableName;
}

public boolean supportsSequences() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public PostgreSQLDialect() {
super();
}

@Override
public String wrapTableName(String tableName) {
return "\"" + tableName + "\"";
}

@Override
public String getDatabaseId() {
return "postgresql";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void doWithPersistentProperty(PersistentProperty<?> pp) {

public String buildFrom(boolean basic) {
StringBuilder builder = new StringBuilder();
builder.append(persistentEntity.getTableName()).append(" ").append(quota(persistentEntity.getEntityName()));
builder.append(dialect.wrapTableName(persistentEntity.getTableName())).append(" ").append(quota(persistentEntity.getEntityName()));
if (!basic) {
builder.append(buildLeftOuterJoin());
}
Expand All @@ -268,7 +268,7 @@ private String buildLeftOuterJoin() {
public void doWithAssociation(Association<? extends PersistentProperty<?>> ass) {
if ((ass instanceof MybatisManyToOneAssociation)) {
final MybatisManyToOneAssociation association = (MybatisManyToOneAssociation) ass;
builder.append(" left outer join ").append(association.getObversePersistentEntity().getTableName()).append(" ").append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName()))
builder.append(" left outer join ").append(dialect.wrapTableName(association.getObversePersistentEntity().getTableName())).append(" ").append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName()))
.append(" on ").append(quota(persistentEntity.getEntityName())).append(".").append(association.getJoinColumnName())
.append("=").append(quota(persistentEntity.getEntityName() + "." + association.getInverse().getName())).append(".").append(association.getJoinReferencedColumnName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private String render() throws IOException {
builder.append("<mapper namespace=\"" + domainClass.getName() + "\">");

if (!isFragmentExist("TABLE_NAME")) {
builder.append("<sql id=\"TABLE_NAME\">" + persistentEntity.getTableName() + "</sql>");
builder.append("<sql id=\"TABLE_NAME\">" + dialect.wrapTableName(persistentEntity.getTableName()) + "</sql>");
}
if (dialect.supportsSequences()) {
if (!isFragmentExist("SEQUENCE")) {
Expand Down Expand Up @@ -182,7 +182,7 @@ private void buildUpdateSQL(final StringBuilder builder) {
return;
}
builder.append("<update id=\"_update\" parameterType=\"" + domainClass.getName() + "\" lang=\"XML\">");
builder.append("update ").append(persistentEntity.getTableName());
builder.append("update ").append(dialect.wrapTableName(persistentEntity.getTableName()));
builder.append("<set>");

persistentEntity.doWithProperties(new SimplePropertyHandler() {
Expand Down Expand Up @@ -356,7 +356,7 @@ private void buildFindByPager(StringBuilder builder) {
}

private void buildDeleteAll(StringBuilder builder) {
builder.append("<delete id=\"_deleteAll\">truncate table " + persistentEntity.getTableName() + " </delete>");
builder.append("<delete id=\"_deleteAll\">truncate table " +dialect.wrapTableName( persistentEntity.getTableName() )+ " </delete>");
}

private void buildDeleteById(final StringBuilder builder) {
Expand Down Expand Up @@ -558,7 +558,7 @@ private void buildInsertSQL(final StringBuilder builder) {
IdentityColumnSupport identityColumnSupport = dialect.getIdentityColumnSupport();
if (idProperty.getIdGenerationType() == IDENTITY || (idProperty.getIdGenerationType() == AUTO && identityColumnSupport.supportsIdentityColumns())) {
builder.append("<selectKey keyProperty=\"" + idProperty.getName() + "\" resultType=\"" + idProperty.getActualType().getName() + "\" order=\"AFTER\">");
builder.append(dialect.getIdentityColumnSupport().getIdentitySelectString(persistentEntity.getTableName(), idProperty.getColumnName(), idProperty.getJdbcType().TYPE_CODE));
builder.append(dialect.getIdentityColumnSupport().getIdentitySelectString(dialect.wrapTableName(persistentEntity.getTableName()), idProperty.getColumnName(), idProperty.getJdbcType().TYPE_CODE));
builder.append("</selectKey>");
} else if (idProperty.getIdGenerationType() == SEQUENCE || (idProperty.getIdGenerationType() == AUTO && dialect.supportsSequences())) {
builder.append("<selectKey keyProperty=\"" + idProperty.getName() + "\" resultType=\"" + idProperty.getActualType().getName() + "\" order=\"BEFORE\">");
Expand All @@ -568,7 +568,7 @@ private void buildInsertSQL(final StringBuilder builder) {
}
builder.append("<![CDATA[");

builder.append("insert into ").append(persistentEntity.getTableName()).append("(");
builder.append("insert into ").append(dialect.wrapTableName(persistentEntity.getTableName())).append("(");


persistentEntity.doWithProperties(new SimplePropertyHandler() {
Expand Down

0 comments on commit 8708d5d

Please sign in to comment.