|
102 | 102 | (case db-type |
103 | 103 | "h2" |
104 | 104 | [(str "MERGE INTO " table " (id, header, meta, val) " |
105 | | - "SELECT '" to "', header, meta, val FROM " table " WHERE id = '" from "';")] |
| 105 | + "SELECT ?, header, meta, val FROM " table " WHERE id = ?;") |
| 106 | + to from] |
106 | 107 | ("postgresql" "sqlite") |
107 | 108 | [(str "INSERT INTO " table " (id, header, meta, val) " |
108 | | - "SELECT '" to "', header, meta, val FROM " table " WHERE id = '" from "' " |
| 109 | + "SELECT ?, header, meta, val FROM " table " WHERE id = ? " |
109 | 110 | "ON CONFLICT (id) DO UPDATE " |
110 | | - "SET header = excluded.header, meta = excluded.meta, val = excluded.val;")] |
| 111 | + "SET header = excluded.header, meta = excluded.meta, val = excluded.val;") |
| 112 | + to from] |
111 | 113 | ("mssql" "sqlserver") |
112 | 114 | [(str "MERGE dbo." table " WITH (HOLDLOCK) AS tgt " |
113 | | - "USING (SELECT '" to "', header, meta, val FROM " table " WHERE id = '" from "') " |
| 115 | + "USING (SELECT ?, header, meta, val FROM " table " WHERE id = ?) " |
114 | 116 | "AS new (id, header, meta, val) " |
115 | | - "ON (tgt.id = new.id)" |
| 117 | + "ON (tgt.id = new.id) " |
116 | 118 | "WHEN MATCHED THEN UPDATE " |
117 | 119 | "SET tgt.header = new.header, tgt.meta = new.meta, tgt.val = new.val " |
118 | 120 | "WHEN NOT MATCHED THEN " |
119 | | - "INSERT (id, header, meta, val) VALUES (new.id, new.header, new.meta, new.val);")] |
| 121 | + "INSERT (id, header, meta, val) VALUES (new.id, new.header, new.meta, new.val);") |
| 122 | + to from] |
120 | 123 | "mysql" |
121 | 124 | [(str "REPLACE INTO " table " (id, header, meta, val) " |
122 | | - "SELECT '" to "', header, meta, val FROM " table " WHERE id = '" from "';")] |
| 125 | + "SELECT ?, header, meta, val FROM " table " WHERE id = ?;") |
| 126 | + to from] |
123 | 127 | [(str "MERGE INTO " table " AS tgt " |
124 | | - "USING (SELECT '" to "', header, meta, val FROM " table " WHERE id = '" from "') " |
| 128 | + "USING (SELECT ?, header, meta, val FROM " table " WHERE id = ?) " |
125 | 129 | "AS new (id, header, meta, val) " |
126 | | - "ON (tgt.id = new.id)" |
| 130 | + "ON (tgt.id = new.id) " |
127 | 131 | "WHEN MATCHED THEN UPDATE " |
128 | 132 | "SET tgt.header = new.header, tgt.meta = new.meta, tgt.val = new.val " |
129 | 133 | "WHEN NOT MATCHED THEN " |
130 | | - "INSERT (id, header, meta, val) VALUES (new.id, new.header, new.meta, new.val);")])) |
| 134 | + "INSERT (id, header, meta, val) VALUES (new.id, new.header, new.meta, new.val);") |
| 135 | + to from])) |
131 | 136 |
|
132 | 137 | (defn delete-statement [db-type table] |
133 | 138 | (case db-type |
|
145 | 150 |
|
146 | 151 | (defn change-row-id [connection table from to] |
147 | 152 | (jdbc/execute! connection |
148 | | - ["UPDATE " table " SET id = '" to "' WHERE id = '" from "';"])) |
| 153 | + [(str "UPDATE " table " SET id = ? WHERE id = ?;") to from])) |
149 | 154 |
|
150 | 155 | (defn read-field [db-type connection table id column & {:keys [binary? locked-cb] :or {binary? false}}] |
151 | 156 | (let [res (-> (jdbc/execute! connection |
152 | | - [(str "SELECT id," (name column) " FROM " table " WHERE id = '" id "';")] |
| 157 | + [(str "SELECT id," (name column) " FROM " table " WHERE id = ?;") id] |
153 | 158 | {:builder-fn rs/as-unqualified-lower-maps}) |
154 | 159 | first |
155 | 160 | column)] |
|
160 | 165 |
|
161 | 166 | (defn read-all [db-type connection table id] |
162 | 167 | (let [res (-> (jdbc/execute! connection |
163 | | - [(str "SELECT id, header, meta, val FROM " table " WHERE id = '" id "';")] |
| 168 | + [(str "SELECT id, header, meta, val FROM " table " WHERE id = ?;") id] |
164 | 169 | {:builder-fn rs/as-unqualified-lower-maps}) |
165 | 170 | first)] |
166 | 171 | (into {} (for [[k v] res] [k (if (= k :id) v (extract-bytes v db-type))])))) |
|
221 | 226 | (-delete-blob [_ store-key env] |
222 | 227 | (async+sync (:sync? env) *default-sync-translation* |
223 | 228 | (go-try- (jdbc/execute! connection |
224 | | - [(str "DELETE FROM " table " WHERE id = '" store-key "';")])))) |
| 229 | + [(str "DELETE FROM " table " WHERE id = ?;") store-key])))) |
225 | 230 | (-blob-exists? [_ store-key env] |
226 | 231 | (async+sync (:sync? env) *default-sync-translation* |
227 | 232 | (go-try- (let [res (jdbc/execute! connection |
228 | | - [(str "SELECT 1 FROM " table " WHERE id = '" store-key "';")])] |
| 233 | + [(str "SELECT 1 FROM " table " WHERE id = ?;") store-key])] |
229 | 234 | (not (nil? (first res))))))) |
230 | 235 | (-copy [_ from to env] |
231 | 236 | (async+sync (:sync? env) *default-sync-translation* |
|
0 commit comments