29
29
public class PostgreSqlDialect extends Dialect {
30
30
31
31
public String forTableInfoBuilderDoBuildTableInfo (String tableName ) {
32
- return "select * from " + tableName + " where 1 = 2" ;
32
+ return "select * from \" " + tableName + " \ " where 1 = 2" ;
33
33
}
34
34
35
35
public void forModelSave (TableInfo tableInfo , Map <String , Object > attrs , StringBuilder sql , List <Object > paras ) {
36
- sql .append ("insert into " ).append (tableInfo .getTableName ()).append ("(" );
36
+ sql .append ("insert into \" " ).append (tableInfo .getTableName ()).append (" \ " (" );
37
37
StringBuilder temp = new StringBuilder (") values(" );
38
38
for (Entry <String , Object > e : attrs .entrySet ()) {
39
39
String colName = e .getKey ();
@@ -42,7 +42,7 @@ public void forModelSave(TableInfo tableInfo, Map<String, Object> attrs, StringB
42
42
sql .append (", " );
43
43
temp .append (", " );
44
44
}
45
- sql .append (colName );
45
+ sql .append (" \" " ). append ( colName ). append ( " \" " );
46
46
temp .append ("?" );
47
47
paras .add (e .getValue ());
48
48
}
@@ -53,24 +53,24 @@ public void forModelSave(TableInfo tableInfo, Map<String, Object> attrs, StringB
53
53
public String forModelDeleteById (TableInfo tInfo ) {
54
54
String pKey = tInfo .getPrimaryKey ();
55
55
StringBuilder sql = new StringBuilder (45 );
56
- sql .append ("delete from " );
56
+ sql .append ("delete from \" " );
57
57
sql .append (tInfo .getTableName ());
58
- sql .append (" where " ).append (pKey ).append (" = ?" );
58
+ sql .append ("\" where \" " ).append (pKey ).append (" \ " = ?" );
59
59
return sql .toString ();
60
60
}
61
61
62
62
public void forModelUpdate (TableInfo tableInfo , Map <String , Object > attrs , Set <String > modifyFlag , String pKey , Object id , StringBuilder sql , List <Object > paras ) {
63
- sql .append ("update " ).append (tableInfo .getTableName ()).append (" set " );
63
+ sql .append ("update \" " ).append (tableInfo .getTableName ()).append (" \ " set " );
64
64
for (Entry <String , Object > e : attrs .entrySet ()) {
65
65
String colName = e .getKey ();
66
66
if (!pKey .equalsIgnoreCase (colName ) && modifyFlag .contains (colName ) && tableInfo .hasColumnLabel (colName )) {
67
67
if (paras .size () > 0 )
68
68
sql .append (", " );
69
- sql .append (colName ).append (" = ? " );
69
+ sql .append (" \" " ). append ( colName ).append (" \ " = ? " );
70
70
paras .add (e .getValue ());
71
71
}
72
72
}
73
- sql .append (" where " ).append (pKey ).append (" = ?" );
73
+ sql .append (" where \" " ).append (pKey ).append (" \ " = ?" );
74
74
paras .add (id );
75
75
}
76
76
@@ -84,12 +84,14 @@ public String forModelFindById(TableInfo tInfo, String columns) {
84
84
for (int i =0 ; i <columnsArray .length ; i ++) {
85
85
if (i > 0 )
86
86
sql .append (", " );
87
+ sql .append ("\" " );
87
88
sql .append (columnsArray [i ].trim ());
89
+ sql .append ("\" " );
88
90
}
89
91
}
90
- sql .append (" from " );
92
+ sql .append (" from \" " );
91
93
sql .append (tInfo .getTableName ());
92
- sql .append (" where " ).append (tInfo .getPrimaryKey ()).append (" = ?" );
94
+ sql .append ("\" where \" " ).append (tInfo .getPrimaryKey ()).append (" \ " = ?" );
93
95
return sql .toString ();
94
96
}
95
97
@@ -103,25 +105,25 @@ public String forDbFindById(String tableName, String primaryKey, String columns)
103
105
for (int i =0 ; i <columnsArray .length ; i ++) {
104
106
if (i > 0 )
105
107
sql .append (", " );
106
- sql .append (columnsArray [i ].trim ());
108
+ sql .append (" \" " ). append ( columnsArray [i ].trim ()). append ( " \" " );
107
109
}
108
110
}
109
- sql .append (" from " );
111
+ sql .append (" from \" " );
110
112
sql .append (tableName .trim ());
111
- sql .append (" where " ).append (primaryKey ).append (" = ?" );
113
+ sql .append ("\" where \" " ).append (primaryKey ).append (" \ " = ?" );
112
114
return sql .toString ();
113
115
}
114
116
115
117
public String forDbDeleteById (String tableName , String primaryKey ) {
116
- StringBuilder sql = new StringBuilder ("delete from " );
118
+ StringBuilder sql = new StringBuilder ("delete from \" " );
117
119
sql .append (tableName .trim ());
118
- sql .append (" where " ).append (primaryKey ).append (" = ?" );
120
+ sql .append ("\" where \" " ).append (primaryKey ).append (" \ " = ?" );
119
121
return sql .toString ();
120
122
}
121
123
122
124
public void forDbSave (StringBuilder sql , List <Object > paras , String tableName , Record record ) {
123
- sql .append ("insert into " );
124
- sql .append (tableName .trim ()).append ("(" );
125
+ sql .append ("insert into \" " );
126
+ sql .append (tableName .trim ()).append ("\" (" );
125
127
StringBuilder temp = new StringBuilder ();
126
128
temp .append (") values(" );
127
129
@@ -130,26 +132,26 @@ public void forDbSave(StringBuilder sql, List<Object> paras, String tableName, R
130
132
sql .append (", " );
131
133
temp .append (", " );
132
134
}
133
- sql .append (e .getKey ());
135
+ sql .append (" \" " ). append ( e .getKey ()). append ( " \" " );
134
136
temp .append ("?" );
135
137
paras .add (e .getValue ());
136
138
}
137
139
sql .append (temp .toString ()).append (")" );
138
140
}
139
141
140
142
public void forDbUpdate (String tableName , String primaryKey , Object id , Record record , StringBuilder sql , List <Object > paras ) {
141
- sql .append ("update " ).append (tableName .trim ()).append (" set " );
143
+ sql .append ("update \" " ).append (tableName .trim ()).append (" \ " set " );
142
144
for (Entry <String , Object > e : record .getColumns ().entrySet ()) {
143
145
String colName = e .getKey ();
144
146
if (!primaryKey .equalsIgnoreCase (colName )) {
145
147
if (paras .size () > 0 ) {
146
148
sql .append (", " );
147
149
}
148
- sql .append (colName ).append (" = ? " );
150
+ sql .append (" \" " ). append ( colName ).append (" \ " = ? " );
149
151
paras .add (e .getValue ());
150
152
}
151
153
}
152
- sql .append (" where " ).append (primaryKey ).append (" = ?" );
154
+ sql .append (" where \" " ).append (primaryKey ).append (" \ " = ?" );
153
155
paras .add (id );
154
156
}
155
157
0 commit comments