fix:值为null时导出的SQL语句使用null,而非空字符串

This commit is contained in:
暮光:城中城
2021-12-26 22:24:24 +08:00
parent 208826df62
commit 990c2379ff
10 changed files with 49 additions and 33 deletions

View File

@@ -87,10 +87,11 @@ public class BaseDownloadService implements DownloadService {
for (TableColumnDescDto dataCol : dataCols) {
if (values.length() > 0) values.append(", ");
Object val = item.get(dataCol.getName());
if (this.isNumber(dataCol.getType())) {
if (val == null) {
values.append("null");
} else if (this.isNumber(dataCol.getType())) {
values.append(val);
} else {
val = (val == null) ? "" : val;
val = val.toString().replaceAll("'", "''");
values.append("'").append(val).append("'");
}
@@ -121,20 +122,22 @@ public class BaseDownloadService implements DownloadService {
for (TableColumnDescDto dataCol : dataCols) {
Object val = item.get(dataCol.getName());
if (conditionSet.contains(dataCol.getName())) {
if (this.isNumber(dataCol.getType())) {
if (where.length() > 0) where.append(" and ");
if (where.length() > 0) where.append(" and ");
if (val == null) {
where.append(dataCol.getName()).append(" = null");
} else if (this.isNumber(dataCol.getType())) {
where.append(dataCol.getName()).append(" = ").append(val);
} else {
if (where.length() > 0) where.append(" and ");
where.append(dataCol.getName()).append(" = ").append("'").append(val).append("'");
}
} else {
if (values.length() > 0) values.append(", ");
values.append(dataCol.getName()).append("=");
if (this.isNumber(dataCol.getType())) {
if (val == null) {
values.append("null");
} else if (this.isNumber(dataCol.getType())) {
values.append(val);
} else {
val = (val == null) ? "" : val;
val = val.toString().replaceAll("'", "''");
values.append("'").append(val).append("'");
}

View File

@@ -78,10 +78,11 @@ public class SqlserverDownloadService implements DownloadService {
for (TableColumnDescDto dataCol : dataCols) {
if (values.length() > 0) values.append(", ");
Object val = item.get(dataCol.getName());
if (this.isNumber(dataCol.getType())) {
if (val == null) {
values.append("null");
} else if (this.isNumber(dataCol.getType())) {
values.append(val);
} else {
val = (val == null) ? "" : val;
val = val.toString().replaceAll("'", "''");
values.append("'").append(val).append("'");
}
@@ -112,20 +113,22 @@ public class SqlserverDownloadService implements DownloadService {
for (TableColumnDescDto dataCol : dataCols) {
Object val = item.get(dataCol.getName());
if (conditionSet.contains(dataCol.getName())) {
if (this.isNumber(dataCol.getType())) {
if (where.length() > 0) where.append(" and ");
if (where.length() > 0) where.append(" and ");
if (val == null) {
where.append(dataCol.getName()).append(" = null");
} else if (this.isNumber(dataCol.getType())) {
where.append(dataCol.getName()).append(" = ").append(val);
} else {
if (where.length() > 0) where.append(" and ");
where.append(dataCol.getName()).append(" = ").append("'").append(val).append("'");
}
} else {
if (values.length() > 0) values.append(", ");
values.append(dataCol.getName()).append("=");
if (this.isNumber(dataCol.getType())) {
if (val == null) {
values.append("null");
} else if (this.isNumber(dataCol.getType())) {
values.append(val);
} else {
val = (val == null) ? "" : val;
val = val.toString().replaceAll("'", "''");
values.append("'").append(val).append("'");
}

View File

@@ -1 +1 @@
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon-db.png><title>数据库文档管理</title><link href=css/chunk-vendors.8924efc6.css rel=preload as=style><link href=css/index.ba19e721.css rel=preload as=style><link href=js/chunk-vendors.03a07ec5.js rel=preload as=script><link href=js/index.a287c663.js rel=preload as=script><link href=css/chunk-vendors.8924efc6.css rel=stylesheet><link href=css/index.ba19e721.css rel=stylesheet></head><body><noscript><strong>We're sorry but zyplayer-db-ui doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.03a07ec5.js></script><script src=js/index.a287c663.js></script></body></html>
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon-db.png><title>数据库文档管理</title><link href=css/chunk-vendors.8924efc6.css rel=preload as=style><link href=css/index.2a7107f3.css rel=preload as=style><link href=js/chunk-vendors.d7df6d0f.js rel=preload as=script><link href=js/index.93605a0f.js rel=preload as=script><link href=css/chunk-vendors.8924efc6.css rel=stylesheet><link href=css/index.2a7107f3.css rel=stylesheet></head><body><noscript><strong>We're sorry but zyplayer-db-ui doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.d7df6d0f.js></script><script src=js/index.93605a0f.js></script></body></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long