Skip to content

Commit 38be008

Browse files
authored
fix: logquery (#490)
* fix: escape for like, semantic_type * fix: no time
1 parent f82625f commit 38be008

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/store/modules/logquery/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ const useLogQueryStore = defineStore('logQuery', () => {
5151
const multipleRe = /timestamp\((\d)\)/
5252
const getTsColumn = (tableName: string) => {
5353
const fields = tableMap.value[tableName] || []
54-
const field = fields.filter((column) => column.data_type.toLowerCase().indexOf('timestamp') > -1)[0]
54+
const tsColumns = fields.filter((column) => column.data_type.toLowerCase().indexOf('timestamp') > -1)
55+
const tsIndexColumns = tsColumns.filter((column) => column.semantic_type === 'TIMESTAMP')
56+
const field = tsIndexColumns.length ? tsIndexColumns[0] : tsColumns[0]
5557
if (!field) {
5658
return null
5759
}
@@ -198,7 +200,8 @@ const useLogQueryStore = defineStore('logQuery', () => {
198200
table_name,
199201
table_schema,
200202
column_name,
201-
data_type
203+
data_type,
204+
semantic_type
202205
FROM
203206
information_schema.columns
204207
${where}
@@ -219,6 +222,7 @@ const useLogQueryStore = defineStore('logQuery', () => {
219222
name: row[2],
220223
data_type: row[3],
221224
label: row[2],
225+
semantic_type: row[4],
222226
})
223227
}
224228
tableMap.value = tmp
@@ -233,15 +237,14 @@ const useLogQueryStore = defineStore('logQuery', () => {
233237
return value
234238
.replace(/\\/g, '\\\\') // Escape backslashes
235239
.replace(/'/g, "''") // Escape single quotes by doubling
236-
.replace(/"/g, '\\"') // Escape double quotes (if needed)
237240
.replace(/\n/g, '\\n') // Escape newline
238241
.replace(/\r/g, '\\r') // Escape carriage return
239242
}
240243

241244
function singleCondition(condition: Condition) {
242245
const column = condition.field
243246
const columnType = getColumnOpType(column.data_type)
244-
247+
const conditionVal = escapeSqlString(condition.value)
245248
let columnName = condition.field.name
246249
if (columnName.toUpperCase() !== columnName && columnName.toLowerCase() !== columnName) {
247250
columnName = `"${columnName}"`
@@ -252,7 +255,7 @@ const useLogQueryStore = defineStore('logQuery', () => {
252255
}
253256
if (condition.op === 'like') {
254257
// return `MATCHES(${columnName},'"${escapeSqlString(condition.value)}"')`
255-
return `${columnName} like '%${condition.value}%'`
258+
return `${columnName} like '%${conditionVal}%'`
256259
}
257260
if (['contains', 'not contains', 'match sequence'].indexOf(condition.op) > -1) {
258261
let val = escapeSqlString(condition.value)

src/views/dashboard/logs/query/Toolbar.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@
112112
if (tsColumn.value) {
113113
const { multiple } = tsColumn.value
114114
const [start, end] = getRelativeRange(multiple)
115-
editingSql.value = addTsCondition(editingSql.value, tsColumn.value.name, start, end)
115+
if (start && end) {
116+
editingSql.value = addTsCondition(editingSql.value, tsColumn.value.name, start, end)
117+
}
116118
}
117119
editingSql.value = processSQL(editingSql.value, tsColumn.value?.name, limit.value)
118120
}

src/views/dashboard/logs/query/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export type ColumnType = {
22
name: string
33
data_type: string
44
label: string
5+
semantic_type: string
56
}
67

78
export type Condition = {

0 commit comments

Comments
 (0)