|
8 | 8 | "github.com/icinga/icinga-go-library/strcase" |
9 | 9 | "github.com/icinga/icinga-go-library/types" |
10 | 10 | "github.com/pkg/errors" |
| 11 | + "strconv" |
11 | 12 | ) |
12 | 13 |
|
13 | 14 | // CantPerformQuery wraps the given error with the specified query that cannot be executed. |
@@ -50,29 +51,17 @@ func SplitOnDupId[T IDer]() com.BulkChunkSplitPolicy[T] { |
50 | 51 | // |
51 | 52 | // https://mariadb.com/kb/en/galera-cluster-system-variables/#wsrep_sync_wait |
52 | 53 | func setGaleraOpts(ctx context.Context, conn driver.Conn, wsrepSyncWait int64) error { |
53 | | - const galeraOpts = "SET SESSION wsrep_sync_wait=?" |
| 54 | + galeraOpts := "SET SESSION wsrep_sync_wait=" + strconv.FormatInt(wsrepSyncWait, 10) |
54 | 55 |
|
55 | | - stmt, err := conn.(driver.ConnPrepareContext).PrepareContext(ctx, galeraOpts) |
| 56 | + _, err := conn.(driver.ExecerContext).ExecContext(ctx, galeraOpts, nil) |
56 | 57 | if err != nil { |
57 | 58 | if errors.Is(err, &mysql.MySQLError{Number: 1193}) { // Unknown system variable |
58 | 59 | return nil |
59 | 60 | } |
60 | 61 |
|
61 | | - return errors.Wrap(err, "cannot prepare "+galeraOpts) |
62 | | - } |
63 | | - // This is just for an unexpected exit and any returned error can safely be ignored and in case |
64 | | - // of the normal function exit, the stmt is closed manually, and its error is handled gracefully. |
65 | | - defer func() { _ = stmt.Close() }() |
66 | | - |
67 | | - _, err = stmt.(driver.StmtExecContext).ExecContext(ctx, []driver.NamedValue{{Value: wsrepSyncWait}}) |
68 | | - if err != nil { |
69 | 62 | return errors.Wrap(err, "cannot execute "+galeraOpts) |
70 | 63 | } |
71 | 64 |
|
72 | | - if err = stmt.Close(); err != nil { |
73 | | - return errors.Wrap(err, "cannot close prepared statement "+galeraOpts) |
74 | | - } |
75 | | - |
76 | 65 | return nil |
77 | 66 | } |
78 | 67 |
|
|
0 commit comments