convertQuery takes the given Postgres query, and converts it as an ast.ConvertedQuery that will work with the handler. If the query string contains multiple queries, then multiple ConvertedQuery will be returned.
(query string)
| 1149 | // convertQuery takes the given Postgres query, and converts it as an ast.ConvertedQuery that will work with the handler. |
| 1150 | // If the query string contains multiple queries, then multiple ConvertedQuery will be returned. |
| 1151 | func (h *ConnectionHandler) convertQuery(query string) ([]ConvertedQuery, error) { |
| 1152 | s, err := parser.Parse(query) |
| 1153 | if err != nil { |
| 1154 | return nil, err |
| 1155 | } |
| 1156 | if len(s) == 0 { |
| 1157 | return []ConvertedQuery{{String: query}}, nil |
| 1158 | } |
| 1159 | converted := make([]ConvertedQuery, len(s)) |
| 1160 | for i := range s { |
| 1161 | vitessAST, err := ast.Convert(s[i]) |
| 1162 | stmtTag := s[i].AST.StatementTag() |
| 1163 | if err != nil { |
| 1164 | return nil, err |
| 1165 | } |
| 1166 | if vitessAST == nil { |
| 1167 | converted[i] = ConvertedQuery{ |
| 1168 | String: s[i].AST.String(), |
| 1169 | StatementTag: stmtTag, |
| 1170 | } |
| 1171 | } else { |
| 1172 | converted[i] = ConvertedQuery{ |
| 1173 | String: query, |
| 1174 | AST: vitessAST, |
| 1175 | StatementTag: stmtTag, |
| 1176 | } |
| 1177 | } |
| 1178 | } |
| 1179 | return converted, nil |
| 1180 | } |
| 1181 | |
| 1182 | // discardAll handles the DISCARD ALL command |
| 1183 | func (h *ConnectionHandler) discardAll(query ConvertedQuery) error { |
no test coverage detected