|
2 | 2 | # Date: 2025/6/25 |
3 | 3 |
|
4 | 4 | from typing import List, Dict |
| 5 | + |
5 | 6 | from apps.datasource.models.datasource import CoreField, CoreDatasource |
6 | 7 | from apps.db.constant import DB |
7 | 8 | from apps.system.models.system_variable_model import SystemVariable |
@@ -74,7 +75,7 @@ def transTreeItem(session: SessionDep, current_user: CurrentUser, item: Dict, ds |
74 | 75 |
|
75 | 76 | # do inner system variable |
76 | 77 | if sys_variable.type == 'system': |
77 | | - res = whereName + whereTerm + getSysVariableValue(sys_variable, current_user) |
| 78 | + res = whereName + whereTerm + getSysVariableValue(sys_variable, current_user, ds, field) |
78 | 79 | else: |
79 | 80 | # check user variable |
80 | 81 | user_variables = current_user.system_variables |
@@ -215,10 +216,17 @@ def userHaveVariable(user_variables: List, sys_variable: SystemVariable): |
215 | 216 | return False |
216 | 217 |
|
217 | 218 |
|
218 | | -def getSysVariableValue(sys_variable: SystemVariable, current_user: CurrentUser): |
| 219 | +def getSysVariableValue(sys_variable: SystemVariable, current_user: CurrentUser, ds: CoreDatasource, field: CoreField): |
| 220 | + v = None |
219 | 221 | if sys_variable.value[0] == 'name': |
220 | | - return current_user.name |
| 222 | + v = current_user.name |
221 | 223 | if sys_variable.value[0] == 'account': |
222 | | - return current_user.account |
| 224 | + v = current_user.account |
223 | 225 | if sys_variable.value[0] == 'email': |
224 | | - return current_user.email |
| 226 | + v = current_user.email |
| 227 | + |
| 228 | + if ds.type == 'sqlServer' and ( |
| 229 | + field.field_type == 'nchar' or field.field_type == 'NCHAR' or field.field_type == 'nvarchar' or field.field_type == 'NVARCHAR'): |
| 230 | + return f"N'{v}'" |
| 231 | + else: |
| 232 | + return f"'{v}'" |
0 commit comments