Commit 26471af
authored
fewer driver.ErrBadConn to prevent repeated queries (#302)
According to the database/sql/driver documentation, ErrBadConn should only
be used when the database was not affected. The driver restarts the same
query on a different connection, then.
The mysql driver did not follow this advice, so queries were repeated if
ErrBadConn is returned but a query succeeded.
This is fixed by changing most ErrBadConn errors to ErrInvalidConn.
The only valid returns of ErrBadConn are at the beginning of a database
interaction when no data was sent to the database yet.
Those valid cases are located the following funcs before attempting to write
to the network or if 0 bytes were written:
* Begin
* BeginTx
* Exec
* ExecContext
* Prepare
* PrepareContext
* Query
* QueryContext
Commit and Rollback could arguably also be on that list, but are left out as
some engines like MyISAM are not supporting transactions.
Tests in b/packets_test.go were changed because they simulate a read not
preceded by a write to the db. This cannot happen as the client has to send
the query first.1 parent 21d7e97 commit 26471af
File tree
5 files changed
+46
-28
lines changed5 files changed
+46
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
84 | 94 | | |
85 | 95 | | |
86 | 96 | | |
| |||
90 | 100 | | |
91 | 101 | | |
92 | 102 | | |
93 | | - | |
94 | | - | |
| 103 | + | |
95 | 104 | | |
96 | 105 | | |
97 | 106 | | |
| |||
142 | 151 | | |
143 | 152 | | |
144 | 153 | | |
145 | | - | |
| 154 | + | |
146 | 155 | | |
147 | 156 | | |
148 | 157 | | |
| |||
176 | 185 | | |
177 | 186 | | |
178 | 187 | | |
179 | | - | |
| 188 | + | |
180 | 189 | | |
181 | 190 | | |
182 | 191 | | |
| |||
314 | 323 | | |
315 | 324 | | |
316 | 325 | | |
317 | | - | |
| 326 | + | |
318 | 327 | | |
319 | 328 | | |
320 | 329 | | |
321 | 330 | | |
322 | 331 | | |
323 | 332 | | |
324 | | - | |
| 333 | + | |
325 | 334 | | |
326 | 335 | | |
327 | 336 | | |
| |||
390 | 399 | | |
391 | 400 | | |
392 | 401 | | |
393 | | - | |
| 402 | + | |
394 | 403 | | |
395 | 404 | | |
396 | 405 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
34 | 40 | | |
35 | 41 | | |
36 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
140 | 144 | | |
141 | 145 | | |
142 | 146 | | |
143 | | - | |
| 147 | + | |
144 | 148 | | |
145 | 149 | | |
146 | 150 | | |
| |||
274 | 278 | | |
275 | 279 | | |
276 | 280 | | |
277 | | - | |
| 281 | + | |
278 | 282 | | |
279 | 283 | | |
280 | 284 | | |
| |||
362 | 366 | | |
363 | 367 | | |
364 | 368 | | |
365 | | - | |
| 369 | + | |
366 | 370 | | |
367 | 371 | | |
368 | 372 | | |
| |||
381 | 385 | | |
382 | 386 | | |
383 | 387 | | |
384 | | - | |
| 388 | + | |
385 | 389 | | |
386 | 390 | | |
387 | 391 | | |
| |||
404 | 408 | | |
405 | 409 | | |
406 | 410 | | |
407 | | - | |
| 411 | + | |
408 | 412 | | |
409 | 413 | | |
410 | 414 | | |
| |||
425 | 429 | | |
426 | 430 | | |
427 | 431 | | |
428 | | - | |
| 432 | + | |
429 | 433 | | |
430 | 434 | | |
431 | 435 | | |
| |||
444 | 448 | | |
445 | 449 | | |
446 | 450 | | |
447 | | - | |
| 451 | + | |
448 | 452 | | |
449 | 453 | | |
450 | 454 | | |
| |||
465 | 469 | | |
466 | 470 | | |
467 | 471 | | |
468 | | - | |
| 472 | + | |
469 | 473 | | |
470 | 474 | | |
471 | 475 | | |
| |||
931 | 935 | | |
932 | 936 | | |
933 | 937 | | |
934 | | - | |
| 938 | + | |
935 | 939 | | |
936 | 940 | | |
937 | 941 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
252 | 251 | | |
253 | 252 | | |
254 | 253 | | |
255 | | - | |
256 | | - | |
| 254 | + | |
| 255 | + | |
257 | 256 | | |
258 | 257 | | |
259 | 258 | | |
| |||
264 | 263 | | |
265 | 264 | | |
266 | 265 | | |
267 | | - | |
268 | | - | |
| 266 | + | |
| 267 | + | |
269 | 268 | | |
270 | 269 | | |
271 | 270 | | |
| |||
277 | 276 | | |
278 | 277 | | |
279 | 278 | | |
280 | | - | |
281 | | - | |
| 279 | + | |
| 280 | + | |
282 | 281 | | |
283 | 282 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| |||
0 commit comments