comparison src/main/java/org/monetdb/merovingian/Control.java @ 632:e2fd07352866

Fix Control protocol handling (contributed by Wouter Alink)
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Fri, 21 Jan 2022 10:43:44 +0100 (2022-01-21)
parents 0674e6fb4bdd
children 940e266eeccd
comparison
equal deleted inserted replaced
631:0674e6fb4bdd 632:e2fd07352866
181 response = in.readLine(); 181 response = in.readLine();
182 if (response == null) { 182 if (response == null) {
183 throw new MerovingianException("server closed the connection"); 183 throw new MerovingianException("server closed the connection");
184 } 184 }
185 185
186 if (!response.equals(RESPONSE_OK)) { 186 if (!response.substring(1).equals(RESPONSE_OK)) {
187 throw new MerovingianException(response); 187 throw new MerovingianException(response);
188 } 188 }
189 189
190 /* send command, form is simple: "<db> <cmd>\n" */ 190 /* send command, form is simple: "<db> <cmd>\n" */
191 out.print(database + " " + command + "\n"); 191 out.print(database + " " + command + "\n");
195 * follow the first line */ 195 * follow the first line */
196 response = in.readLine(); 196 response = in.readLine();
197 if (response == null) { 197 if (response == null) {
198 throw new MerovingianException("server closed the connection"); 198 throw new MerovingianException("server closed the connection");
199 } 199 }
200 if (!response.equals(RESPONSE_OK)) { 200 if (!response.substring(1).equals(RESPONSE_OK)) {
201 throw new MerovingianException(response); 201 throw new MerovingianException(response);
202 } 202 }
203 203
204 if (!hasOutput) 204 if (!hasOutput)
205 return null; 205 return null;
218 218
219 mout.writeLine(database + " " + command + "\n"); 219 mout.writeLine(database + " " + command + "\n");
220 ArrayList<String> l = new ArrayList<String>(); 220 ArrayList<String> l = new ArrayList<String>();
221 String tmpLine = min.readLine(); 221 String tmpLine = min.readLine();
222 LineType linetype = min.getLineType(); 222 LineType linetype = min.getLineType();
223 if (linetype == LineType.ERROR) 223 switch (linetype) {
224 case ERROR:
224 throw new MerovingianException(tmpLine.substring(6)); 225 throw new MerovingianException(tmpLine.substring(6));
225 if (linetype != LineType.RESULT) 226 case RESULT:
227 if (!tmpLine.substring(1).equals(RESPONSE_OK))
228 throw new MerovingianException(tmpLine);
229 break;
230 default:
226 throw new MerovingianException("unexpected line: " + tmpLine); 231 throw new MerovingianException("unexpected line: " + tmpLine);
227 if (!tmpLine.substring(1).equals(RESPONSE_OK)) 232 }
228 throw new MerovingianException(tmpLine.substring(1)); 233
229 tmpLine = min.readLine(); 234 boolean hasPrompt = false;
230 linetype = min.getLineType(); 235 while (!hasPrompt) {
231 while (linetype != LineType.PROMPT) {
232 if (linetype != LineType.RESULT)
233 throw new MerovingianException("unexpected line: " +
234 tmpLine);
235
236 l.add(tmpLine.substring(1));
237
238 tmpLine = min.readLine(); 236 tmpLine = min.readLine();
239 linetype = min.getLineType(); 237 linetype = min.getLineType();
238
239 switch (linetype) {
240 case PROMPT:
241 hasPrompt = true;
242 break;
243 case RESULT:
244 l.add(tmpLine.substring(1));
245 break;
246 default:
247 throw new MerovingianException("unexpected line: " + tmpLine);
248 }
240 } 249 }
241 250
242 ms.close(); 251 ms.close();
243 return l; 252 return l;
244 } 253 }