Anonymous avatar Anonymous committed b7628e9

Put the create and update sql scripts inside transactions.

Fixes BUGZID: 1507. Also correct ON_ERROR_STOP to use "on" instead of "1".

Comments (0)

Files changed (1)

org/nrg/xdat/XDAT.java

 	    sb.append("-- Generated SQL File for updating an existing XNAT database.\n");
 	    sb.append("-- This script is created by the update XNAT feature, which reviews an existing database and only specifies create statements for missing TABLES and COLUMNS.  It will also drop and recreate any necessary functions or views.\n");
 	    
-	    sb.append("-- If you are running from pgAdmin, remove the following line to stop on errors (pgAdmin does not recognize the statement)");
-	    sb.append("\n\\set ON_ERROR_STOP 1;");
+	    sb.append("-- If you are running from pgAdmin, remove the following line to stop on errors (pgAdmin does not recognize the statement)\n");
+	    sb.append("\\set ON_ERROR_STOP on;\n");
+	    sb.append("\n-- start transaction (if an error occurs, the database will be rolled back to its state before this file was executed)\n");
+	    sb.append("BEGIN;\n");
 	    
 	    Iterator iter = SQLUpdateGenerator.GetSQLCreate().iterator();
 	    while (iter.hasNext())
 	    {
 	        sb.append(iter.next() +"\n--BR\n");
 	    }
+	    sb.append("\n-- commit transaction\n");
+	    sb.append("COMMIT;");
 		FileUtils.OutputToFile(sb.toString(),file);
 		
 		logger.info("File Created: " + file);
 	    StringBuffer sb =new StringBuffer();
 	    sb.append("-- Generated SQL File for creating an XNAT database from scratch.\n");
 	    
-	    sb.append("-- If you are running from pgAdmin, remove the following line to stop on errors (pgAdmin does not recognize the statement)");
-	    sb.append("\n\\set ON_ERROR_STOP 1;");
+	    sb.append("-- If you are running from pgAdmin, remove the following line to stop on errors (pgAdmin does not recognize the statement)\n");
+	    sb.append("\\set ON_ERROR_STOP on;\n");
+	    sb.append("\n-- start transaction (if an error occurs, the database will be rolled back to its state before this file was executed)\n");
+	    sb.append("BEGIN;\n");
 	    
 	    Iterator iter = SQLCreateGenerator.GetSQLCreate().iterator();
 	    while (iter.hasNext())
 	    {
 	        sb.append(iter.next() +"\n--BR\n");
 	    }
+	    sb.append("\n-- commit transaction\n");
+	    sb.append("COMMIT;");
 		FileUtils.OutputToFile(sb.toString(),file);
 		
 		ViewManager.OutputFieldNames();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.