public static String getSelectQuery ( ASpatialDb db , final TableLevel selectedTable , boolean geomFirst ) throws Exception { String tableName = selectedTable . tableName ; String letter = tableName . substring ( 0 , 1 ) ; List < String [ ] > tableColumns = db . getTableColumns ( tableName ) ; GeometryColumn geometryColumns = db . getGeometryColumnsForTable ( tableName ) ; String query = "SELECT " ; if ( geomFirst ) { // first geom List < String > nonGeomCols = new ArrayList < String > ( ) ; for ( int i = 0 ; i < tableColumns . size ( ) ; i ++ ) { String colName = tableColumns . get ( i ) [ 0 ] ; if ( geometryColumns != null && colName . equals ( geometryColumns . geometryColumnName ) ) { colName = letter + "." + colName + " as " + colName ; query += colName ; } else { nonGeomCols . add ( colName ) ; } } // then others for ( int i = 0 ; i < nonGeomCols . size ( ) ; i ++ ) { String colName = tableColumns . get ( i ) [ 0 ] ; query += "," + letter + "." + colName ; } } else { for ( int i = 0 ; i < tableColumns . size ( ) ; i ++ ) { if ( i > 0 ) query += "," ; String colName = tableColumns . get ( i ) [ 0 ] ; if ( geometryColumns != null && colName . equals ( geometryColumns . geometryColumnName ) ) { colName = letter + "." + colName + " as " + colName ; query += colName ; } else { query += letter + "." + colName ; } } } query += " FROM " + tableName + " " + letter ; return query ; }
Get a full select query from a table in the db .