1. John Paulett
  2. xdat_core_1_4

Commits

John Paulett  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".

  • Participants
  • Parent commits 6c5b2a9
  • Branches default

Comments (0)

Files changed (1)

File org/nrg/xdat/XDAT.java

View file
 	    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();