Skip to content

Commit 19c3832

Browse files
committed
refactor: sql server support selecting compatibility with lower versions
1 parent 16617a0 commit 19c3832

File tree

6 files changed

+46
-14
lines changed

6 files changed

+46
-14
lines changed

backend/apps/datasource/models/datasource.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class DatasourceConf(BaseModel):
120120
sheets: List = ''
121121
mode: str = ''
122122
timeout: int = 30
123+
lowVersion: bool = False
123124

124125
def to_dict(self):
125126
return {
@@ -134,7 +135,8 @@ def to_dict(self):
134135
"filename": self.filename,
135136
"sheets": self.sheets,
136137
"mode": self.mode,
137-
"timeout": self.timeout
138+
"timeout": self.timeout,
139+
"lowVersion": self.lowVersion
138140
}
139141

140142

backend/apps/db/db.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,28 @@ def get_extra_config(conf: DatasourceConf):
108108
def get_origin_connect(type: str, conf: DatasourceConf):
109109
extra_config_dict = get_extra_config(conf)
110110
if equals_ignore_case(type, "sqlServer"):
111-
return pymssql.connect(
112-
server=conf.host,
113-
port=str(conf.port),
114-
user=conf.username,
115-
password=conf.password,
116-
database=conf.database,
117-
timeout=conf.timeout,
118-
tds_version='7.0', # options: '4.2', '7.0', '8.0' ...,
119-
**extra_config_dict
120-
)
111+
# none or true, set tds_version = 7.0
112+
if conf.lowVersion is None or conf.lowVersion:
113+
return pymssql.connect(
114+
server=conf.host,
115+
port=str(conf.port),
116+
user=conf.username,
117+
password=conf.password,
118+
database=conf.database,
119+
timeout=conf.timeout,
120+
tds_version='7.0', # options: '4.2', '7.0', '8.0' ...,
121+
**extra_config_dict
122+
)
123+
else:
124+
return pymssql.connect(
125+
server=conf.host,
126+
port=str(conf.port),
127+
user=conf.username,
128+
password=conf.password,
129+
database=conf.database,
130+
timeout=conf.timeout,
131+
**extra_config_dict
132+
)
121133

122134

123135
# use sqlalchemy

frontend/src/i18n/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@
348348
"failed": "Connect failed"
349349
},
350350
"timeout": "Timeout(second)",
351-
"address": "Address"
351+
"address": "Address",
352+
"low_version": "Compatible with lower versions"
352353
},
353354
"sync_fields": "Sync Fields"
354355
},

frontend/src/i18n/ko-KR.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@
348348
"failed": "연결 실패"
349349
},
350350
"timeout": "쿼리 시간 초과(초)",
351-
"address": "주소"
351+
"address": "주소",
352+
"low_version": "낮은 버전 호환"
352353
},
353354
"sync_fields": "동기화된 테이블 구조"
354355
},

frontend/src/i18n/zh-CN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@
348348
"failed": "连接失败"
349349
},
350350
"timeout": "查询超时(秒)",
351-
"address": "地址"
351+
"address": "地址",
352+
"low_version": "兼容低版本"
352353
},
353354
"sync_fields": "同步表结构"
354355
},

frontend/src/views/ds/DatasourceForm.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ const form = ref<any>({
116116
sheets: [],
117117
mode: 'service_name',
118118
timeout: 30,
119+
lowVersion: false,
119120
})
120121
121122
const close = () => {
@@ -159,6 +160,10 @@ const initForm = (item: any, editTable: boolean = false) => {
159160
form.value.sheets = configuration.sheets
160161
form.value.mode = configuration.mode
161162
form.value.timeout = configuration.timeout ? configuration.timeout : 30
163+
form.value.lowVersion =
164+
configuration.lowVersion !== null && configuration.lowVersion !== undefined
165+
? configuration.lowVersion
166+
: true
162167
}
163168
164169
if (editTable) {
@@ -230,6 +235,7 @@ const initForm = (item: any, editTable: boolean = false) => {
230235
sheets: [],
231236
mode: 'service_name',
232237
timeout: 30,
238+
lowVersion: false,
233239
}
234240
}
235241
dialogVisible.value = true
@@ -317,6 +323,7 @@ const buildConf = () => {
317323
sheets: form.value.sheets,
318324
mode: form.value.mode,
319325
timeout: form.value.timeout,
326+
lowVersion: form.value.lowVersion,
320327
})
321328
)
322329
const obj = JSON.parse(JSON.stringify(form.value))
@@ -332,6 +339,7 @@ const buildConf = () => {
332339
delete obj.sheets
333340
delete obj.mode
334341
delete obj.timeout
342+
delete obj.lowVersion
335343
return obj
336344
}
337345
@@ -671,6 +679,13 @@ defineExpose({
671679
<el-radio value="sid">{{ t('ds.form.mode.sid') }}</el-radio>
672680
</el-radio-group>
673681
</el-form-item>
682+
<el-form-item
683+
v-if="form.type === 'sqlServer'"
684+
:label="t('ds.form.low_version')"
685+
prop="low_version"
686+
>
687+
<el-checkbox v-model="form.lowVersion" :label="t('ds.form.low_version')" />
688+
</el-form-item>
674689
<el-form-item v-if="form.type !== 'es'" :label="t('ds.form.extra_jdbc')">
675690
<el-input
676691
v-model="form.extraJdbc"

0 commit comments

Comments
 (0)