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

View File

@@ -2,8 +2,8 @@
ENV = 'development'
# base api
# VUE_APP_BASE_API = 'http://local.zyplayer.com:8083/zyplayer-doc-manage'
VUE_APP_BASE_API = 'http://doc.zyplayer.com/zyplayer-doc-manage'
VUE_APP_BASE_API = 'http://local.zyplayer.com:8083/zyplayer-doc-manage'
# VUE_APP_BASE_API = 'http://doc.zyplayer.com/zyplayer-doc-manage'
VUE_CLI_BABEL_TRANSPILE_MODULES = true

View File

@@ -18,8 +18,10 @@ export default {
let values = '';
dataCols.forEach(col => {
if (values.length > 0) values += ', ';
let val = item[col.prop] || '';
if (typeof val === 'number' && !isNaN(val)) {
let val = item[col.prop];
if (val === undefined || val === null || isNaN(val)) {
values += "null";
} else if (typeof val === 'number' && !isNaN(val)) {
values += val;
} else {
val = String(val).replaceAll('\'', '\'\'');
@@ -38,19 +40,22 @@ export default {
choiceData.forEach(item => {
let values = '', where = '';
dataCols.forEach(col => {
let val = item[col.prop] || '';
let val = item[col.prop];
if (condition.indexOf(col.prop) >= 0) {
if (typeof val === 'number' && !isNaN(val)) {
if (where.length > 0) where += ' and ';
if (where.length > 0) where += ' and ';
if (val === undefined || val === null || isNaN(val)) {
where += col.prop + ' = null';
} else if (typeof val === 'number' && !isNaN(val)) {
where += col.prop + ' = ' + val;
} else {
if (where.length > 0) where += ' and ';
where += col.prop + ' = ' + "'" + val + "'";
}
} else {
if (values.length > 0) values += ', ';
values += col.prop + '=';
if (typeof val === 'number' && !isNaN(val)) {
if (val === undefined || val === null || isNaN(val)) {
values += "null";
} else if (typeof val === 'number' && !isNaN(val)) {
values += val;
} else {
val = String(val).replaceAll('\'', '\'\'');

View File

@@ -18,8 +18,10 @@ export default {
let values = '';
dataCols.forEach(col => {
if (values.length > 0) values += ', ';
let val = item[col.prop] || '';
if (typeof val === 'number' && !isNaN(val)) {
let val = item[col.prop];
if (val === undefined || val === null || isNaN(val)) {
values += "null";
} else if (typeof val === 'number' && !isNaN(val)) {
values += val;
} else {
val = String(val).replaceAll('\'', '\'\'');
@@ -38,19 +40,22 @@ export default {
choiceData.forEach(item => {
let values = '', where = '';
dataCols.forEach(col => {
let val = item[col.prop] || '';
let val = item[col.prop];
if (condition.indexOf(col.prop) >= 0) {
if (typeof val === 'number' && !isNaN(val)) {
if (where.length > 0) where += ' and ';
if (where.length > 0) where += ' and ';
if (val === undefined || val === null || isNaN(val)) {
where += col.prop + ' = null';
} else if (typeof val === 'number' && !isNaN(val)) {
where += col.prop + ' = ' + val;
} else {
if (where.length > 0) where += ' and ';
where += col.prop + ' = ' + "'" + val + "'";
}
} else {
if (values.length > 0) values += ', ';
values += col.prop + '=';
if (typeof val === 'number' && !isNaN(val)) {
if (val === undefined || val === null || isNaN(val)) {
values += "null";
} else if (typeof val === 'number' && !isNaN(val)) {
values += val;
} else {
val = String(val).replaceAll('\'', '\'\'');