Hi,
I'd to deal with the same issue a couple of years ago.
This fact is (was??) that the ASCII file ingestion is not a part of SQL but a inner feature of SQLlite.
I made a workaround by hacking the SQLite source code.
The 'LOAD DATA' SQLite function actually reads the input file line by line and uses a prepared statement executed in batch mode
in batch mode to ingest them.
I wrote a similar (^C^V) algorithm in Java. The pseudo SQL statement
'LOAD DATA ' is trapped by a wrapper switching on that Java
code instead of using the SQLiteJDBC code.
That works fine and fast, but that requires a wrapper.
Below is the core of the code doing this task.
Hoping the could help, best regards
LM
<code>
/**
* @param connection
* @param tableName
* @param tableFile
* @throws Exception
*/
public void storeTable(Connection connection, String tableName, int ncols, String tableFile) throws Exception {
int nb_col=0;
if( ncols == -1 ) {
DatabaseMetaData meta = connection.getMetaData();
ResultSet rsColumns = meta.getColumns(null, null, tableName.toLowerCase(), null);
/*
* Only TYPE_FORWARD supported: must read all columns to get the size
*/
while( rsColumns.next() ) nb_col++;
rsColumns.close();
}
/*
* If the table is temporary, we must use the given column number (JDBC XERIAL weakness?)
*/
else {
nb_col = ncols;
}
String ps = "insert into " + tableName.toLowerCase() + " values (";
/*
* Build the prepared statement
*/
for( int i=0 ; i< nb_col ; i++ ) {
if( i > 0 ) ps += ",";
ps += "?";
}
ps += ")";
PreparedStatement prep = connection.prepareStatement(ps);
/*
* Maps file row in the prepared segment
*/
BufferedReader br = new BufferedReader(new FileReader(tableFile));
String str = "";
int line = 0;
while( (str = br.readLine()) != null ) {
line++;
String fs[] = str.split("\\t");
if( fs.length != nb_col ) {
QueryException.throwNewException(SaadaException.FILE_FORMAT, "Error at line " + line + " number
of values (" + fs.length + ") does not match the number of columns (" + nb_col + ")");
}
for( int i=0 ; i< nb_col; i++ ) {
if( "null".equals(fs[i]) )
prep.setObject(i+1, null);
else
prep.setObject(i+1, fs[i]);
}
prep.addBatch();
if( (line%5000) == 0 ) {
if (Messenger.debug_mode)
Messenger.printMsg(Messenger.DEBUG, "Store 5000 lines into the DB");
prep.executeBatch();
}
}
/*
* Load data
*/
if (Messenger.debug_mode)
Messenger.printMsg(Messenger.DEBUG, line + " lines stored");
prep.executeBatch();
prep.close();
(new File(tableFile)).delete();
}
<code>