=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java' --- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java 2013-05-07 08:37:33 +0000 +++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java 2013-05-24 14:48:40 +0000 @@ -139,11 +139,7 @@ public boolean pruneTable( String tableName ) { - final String sql = "select * from " + tableName + " limit 1"; - - final boolean hasRows = jdbcTemplate.queryForRowSet( sql ).next(); - - if ( !hasRows ) + if ( !hasRows( tableName ) ) { final String sqlDrop = "drop table " + tableName; @@ -192,6 +188,23 @@ // ------------------------------------------------------------------------- /** + * Indicates whether the given table exists and has at least one row. + */ + protected boolean hasRows( String tableName ) + { + final String sql = "select * from " + tableName + " limit 1"; + + try + { + return jdbcTemplate.queryForRowSet( sql ).next(); + } + catch ( BadSqlGrammarException ex ) + { + return false; + } + } + + /** * Executes a SQL statement. Ignores existing tables/indexes when attempting * to create new. */