|
6 | 6 | package common |
7 | 7 |
|
8 | 8 | const ( |
9 | | - MysqlKeywordEscapeChar = "`" |
10 | | - PostgresKeywordEscapeChar = `"` |
| 9 | + MysqlKeywordEscapeCharStart = "`" |
| 10 | + MysqlKeywordEscapeCharEnd = "`" |
| 11 | + MysqlEscapeKeywordEscapeCharStart = "`" |
| 12 | + MysqlEscapeKeywordEscapeCharEnd = "`" |
11 | 13 |
|
12 | | - MysqlEscapeKeywordEscapeChar = "`" |
13 | | - PostgresEscapeKeywordEscapeChar = `\"` |
| 14 | + PostgresKeywordEscapeCharStart = `"` |
| 15 | + PostgresKeywordEscapeCharEnd = `"` |
| 16 | + PostgresEscapeKeywordEscapeCharStart = `\"` |
| 17 | + PostgresEscapeKeywordEscapeCharEnd = `\"` |
| 18 | + |
| 19 | + SqlServerKeywordEscapeCharStart = `[` |
| 20 | + SqlServerKeywordEscapeCharEnd = `]` |
| 21 | + SqlServerEscapeKeywordEscapeCharStart = `[` |
| 22 | + SqlServerEscapeKeywordEscapeCharEnd = `]` |
| 23 | + |
| 24 | + DummyKeywordEscapeCharStart = "" |
| 25 | + DummyKeywordEscapeCharEnd = "" |
| 26 | + DummyEscapeKeywordEscapeCharStart = "" |
| 27 | + DummyEscapeKeywordEscapeCharEnd = "" |
14 | 28 | ) |
15 | 29 |
|
16 | | -var KeywordEscapeChar = MysqlKeywordEscapeChar |
17 | | -var EscapeKeywordEscapeChar = MysqlEscapeKeywordEscapeChar |
| 30 | +var KeywordEscapeCharStart = DummyKeywordEscapeCharStart |
| 31 | +var KeywordEscapeCharEnd = DummyKeywordEscapeCharEnd |
| 32 | +var EscapeKeywordEscapeCharStart = DummyEscapeKeywordEscapeCharStart |
| 33 | +var EscapeKeywordEscapeCharEnd = DummyEscapeKeywordEscapeCharEnd |
18 | 34 |
|
19 | 35 | type KeywordFormatter func(string) string |
20 | 36 |
|
21 | 37 | var KwFormatter = CommonKeywordFormatter |
22 | 38 |
|
23 | 39 | func CommonKeywordFormatter(src string) string { |
24 | | - return KeywordEscapeChar + src + KeywordEscapeChar |
| 40 | + return KeywordEscapeCharStart + src + KeywordEscapeCharEnd |
25 | 41 | } |
26 | 42 |
|
27 | 43 | func CommonEscapeKeywordFormatter(src string) string { |
28 | | - return EscapeKeywordEscapeChar + src + EscapeKeywordEscapeChar |
| 44 | + return EscapeKeywordEscapeCharStart + src + EscapeKeywordEscapeCharEnd |
29 | 45 | } |
30 | 46 |
|
31 | 47 | func SelectKeywordFormatter(driver string) { |
32 | | - if driver == "postgres" { |
33 | | - KeywordEscapeChar = PostgresKeywordEscapeChar |
34 | | - EscapeKeywordEscapeChar = PostgresEscapeKeywordEscapeChar |
| 48 | + if driver == "mysql" { |
| 49 | + KeywordEscapeCharStart = MysqlKeywordEscapeCharStart |
| 50 | + KeywordEscapeCharEnd = MysqlKeywordEscapeCharEnd |
| 51 | + EscapeKeywordEscapeCharStart = MysqlEscapeKeywordEscapeCharStart |
| 52 | + EscapeKeywordEscapeCharEnd = MysqlEscapeKeywordEscapeCharEnd |
| 53 | + } else if driver == "mssql" || driver == "adodb" { |
| 54 | + KeywordEscapeCharStart = SqlServerKeywordEscapeCharStart |
| 55 | + KeywordEscapeCharEnd = SqlServerKeywordEscapeCharEnd |
| 56 | + EscapeKeywordEscapeCharStart = SqlServerEscapeKeywordEscapeCharStart |
| 57 | + EscapeKeywordEscapeCharEnd = SqlServerEscapeKeywordEscapeCharEnd |
35 | 58 | } else { |
36 | | - KeywordEscapeChar = MysqlKeywordEscapeChar |
37 | | - EscapeKeywordEscapeChar = MysqlEscapeKeywordEscapeChar |
| 59 | + KeywordEscapeCharStart = PostgresKeywordEscapeCharStart |
| 60 | + KeywordEscapeCharEnd = PostgresKeywordEscapeCharEnd |
| 61 | + EscapeKeywordEscapeCharStart = PostgresEscapeKeywordEscapeCharStart |
| 62 | + EscapeKeywordEscapeCharEnd = PostgresEscapeKeywordEscapeCharEnd |
38 | 63 | } |
39 | 64 | } |
0 commit comments