← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2040: Fixed bug <627977> Exception when adding a new data set section by drop 'title' column in 'Sectio...

 

------------------------------------------------------------
revno: 2040
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Thu 2010-09-02 01:39:06 +0700
message:
  Fixed bug <627977> Exception when adding a new data set section by drop 'title' column in 'Section' table
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2010-08-31 14:34:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2010-09-01 18:39:06 +0000
@@ -28,6 +28,8 @@
  */
 
 import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -135,7 +137,8 @@
         // dataelementcategoryoption
         executeSql( "ALTER TABLE dataelementcategoryoption DROP CONSTRAINT fk_dataelement_categoryid" );
         // executeSql(
-        // "ALTER TABLE dataelementcategoryoption DROP CONSTRAINT dataelementcategoryoption_name_key"
+        // "ALTER TABLE dataelementcategoryoption DROP CONSTRAINT
+        // dataelementcategoryoption_name_key"
         // ); will be maintained in transition period
         executeSql( "ALTER TABLE dataelementcategoryoption DROP CONSTRAINT dataelementcategoryoption_shortname_key" );
 
@@ -175,6 +178,22 @@
             executeSql( "DROP TABLE dataentryformassociation" );
         }
 
+        // Working on Section table
+        if ( isColumnExist( "section", "title" ) )
+        {
+            executeSql( "ALTER TABLE section DROP COLUMN title;" );
+
+            log.info( "Successfully, removed column 'title' from table 'section'" );
+        }
+
+        // Working on ConceptName
+        /*if ( isColumnExist( "dataelementcategory", "conceptname" ) )
+        {
+            executeSql( "ALTER TABLE dataelementcategory DROP COLUMN conceptname;" );
+
+            log.info( "Successfully, removed column 'conceptname' from table 'dataelementcategory'" );
+        }*/
+
         log.info( "Tables updated" );
     }
 
@@ -305,9 +324,9 @@
                 }
                 return true;
             }
-            
+
             return false;
-          
+
         }
         catch ( Exception ex )
         {
@@ -350,4 +369,35 @@
         }
 
     }
+
+    /*
+     * Ex: table "dataelementcategory", columnName is "conceptname"
+     */
+    private boolean isColumnExist( String table, String columnName )
+    {
+        final StatementHolder holder = statementManager.getHolder();
+
+        try
+        {
+            ResultSet rs = holder.getStatement().executeQuery( "SELECT * FROM " + table + " LIMIT 1;" );
+            ResultSetMetaData rsmd = rs.getMetaData();
+
+            int columnNo = rsmd.getColumnCount();
+
+            if ( columnNo > 0 )
+            {
+                return rsmd.getColumnName( columnNo - 1 ).equalsIgnoreCase( columnName );
+            }
+        }
+        catch ( SQLException e )
+        {
+            log.debug( e );
+        }
+        finally
+        {
+            holder.close();
+        }
+
+        return false;
+    }
 }