public static String getSQLColumnTypes ( DbaseFileHeader header , boolean isH2Database ) throws IOException { StringBuilder stringBuilder = new StringBuilder ( ) ; for ( int idColumn = 0 ; idColumn < header . getNumFields ( ) ; idColumn ++ ) { if ( idColumn > 0 ) { stringBuilder . append ( ", " ) ; } String fieldName = TableLocation . capsIdentifier ( header . getFieldName ( idColumn ) , isH2Database ) ; stringBuilder . append ( TableLocation . quoteIdentifier ( fieldName , isH2Database ) ) ; stringBuilder . append ( " " ) ; switch ( header . getFieldType ( idColumn ) ) { // (L)logical (T,t,F,f,Y,y,N,n) case ' ' : case ' ' : stringBuilder . append ( "BOOLEAN" ) ; break ; // (C)character (String) case ' ' : case ' ' : stringBuilder . append ( "VARCHAR(" ) ; // Append size int length = header . getFieldLength ( idColumn ) ; stringBuilder . append ( String . valueOf ( length ) ) ; stringBuilder . append ( ")" ) ; break ; // (D)date (Date) case ' ' : case ' ' : stringBuilder . append ( "DATE" ) ; break ; // (F)floating (Double) case ' ' : case ' ' : if ( ( header . getFieldDecimalCount ( idColumn ) == 0 ) ) { if ( ( header . getFieldLength ( idColumn ) >= 0 ) && ( header . getFieldLength ( idColumn ) < 10 ) ) { stringBuilder . append ( "INT4" ) ; } else { stringBuilder . append ( "INT8" ) ; } } else { stringBuilder . append ( "FLOAT8" ) ; } break ; case ' ' : case ' ' : // floating point number case ' ' : case ' ' : // floating point number stringBuilder . append ( "FLOAT8" ) ; break ; default : throw new IOException ( "Unknown DBF field type " + header . getFieldType ( idColumn ) ) ; } } return stringBuilder . toString ( ) ; }
Return SQL Columns declaration