@@ -263,7 +263,7 @@ private String generateChangeSummary(UpdateFilePathsForm form)
263263 "The following SQL will be executed. Please check carefully before hitting confirm:" +
264264 "<br>" +
265265 "<pre>" +
266- getSql (form , true ) +
266+ getSql (form ) +
267267 "</pre>" +
268268 "<br>" +
269269 "Note: if the URL of the folder changed you may also want to execute something like the following (manually):<br>" +
@@ -296,42 +296,31 @@ private String ensureSlashes(String input)
296296 return input ;
297297 }
298298
299- private String getSql (UpdateFilePathsForm form , boolean calculateCounts )
299+ private SQLFragment getSql (UpdateFilePathsForm form )
300300 {
301301 // Ensure start/end with slash:
302302 String sourcePrefix = ensureSlashes (form .getSourcePrefix ());
303303 String replacementPrefix = ensureSlashes (form .getReplacementPrefix ());
304304
305- StringBuilder sql = new StringBuilder ();
305+ SQLFragment sql = new SQLFragment ();
306306
307- if (calculateCounts )
308- {
309- int count = new SqlExecutor (DbScope .getLabKeyScope ()).execute (new SQLFragment ("SELECT count(*) FROM Exp.Data WHERE DataFileUrl like 'file://" + sourcePrefix + "%'" ));
310- sql .append ("--Matching rows: " + count + "\n " );
311- }
312-
313- sql .append ("UPDATE Exp.Data SET DataFileUrl = replace(DataFileUrl, 'file://" + sourcePrefix + "', 'file://" + replacementPrefix + "') " );
314- sql .append ("WHERE DataFileUrl like 'file://" + sourcePrefix + "%';\n " );
307+ sql .append ("UPDATE Exp.Data SET DataFileUrl = replace(DataFileUrl, " ).appendValue ("file://" + sourcePrefix ).append (", " ).appendValue ("file://" + replacementPrefix ).append (") " );
308+ sql .append ("WHERE DataFileUrl like " ).appendValue ("file://" + sourcePrefix + "%" ).append ("\n " );
315309
316- if (calculateCounts )
317- {
318- int count = new SqlExecutor (DbScope .getLabKeyScope ()).execute (new SQLFragment ("SELECT count(*) FROM pipeline.StatusFiles WHERE FilePath like '" + sourcePrefix + "%'" ));
319- sql .append ("--Matching rows: " + count + "\n " );
320- }
321- sql .append ("UPDATE pipeline.StatusFiles SET FilePath = replace(FilePath, '" + sourcePrefix + "', '" + replacementPrefix + "') " );
322- sql .append ("WHERE FilePath like '" + sourcePrefix + "%';" );
310+ sql .append ("UPDATE pipeline.StatusFiles SET FilePath = replace(FilePath, " ).appendValue (sourcePrefix ).append (", " ).appendValue (replacementPrefix ).append (" " );
311+ sql .append ("WHERE FilePath like " ).appendValue (sourcePrefix + "%" );
323312
324- return sql . toString () ;
313+ return sql ;
325314 }
326315 @ Override
327316 public boolean handlePost (UpdateFilePathsForm form , BindException errors ) throws Exception
328317 {
329318 if (form .isUpdateDatabase ())
330319 {
331- String sql = getSql (form , false );
320+ SQLFragment sql = getSql (form );
332321
333322 SqlExecutor se = new SqlExecutor (DbScope .getLabKeyScope ());
334- se .execute (new SQLFragment ( sql ) );
323+ se .execute (sql );
335324 }
336325
337326 return true ;
0 commit comments