TestsTested | ✓ |
LangLanguage | Objective C++Objective C++ |
License | BSD |
ReleasedLast Release | Dec 2014 |
Maintained by Alexander Dodatko.
Depends on: | |
ESLocale | ~> 1.1 |
ObjcScopedGuard | ~> 1.0 |
ESDatabaseWrapper | ~> 1.0 |
FMDB | ~> 2.0 |
This is a library for parsing simple *.CSV files.
The library does not fully comply to rfc4180 because we do not support quoted values.
The main goal is importing *.CSV data to the SQLite database with the minimal memory footprint.
License : BSD
The library performs importing of CSV files to SQLite tables. We made our best to make it use as little memory as possible.
The library does not fully comply to rfc4180 for speed and simplicity.
We do not support quoted values.
Here is an example of CSV importer usage :
-(void)testImportWithInvalidDefauls
{
NSString* csvPath_ = [ [ NSBundle bundleForClass: [ self class ] ] pathForResource: @"UnixTest3"
ofType: @"csv" ];
NSString* fullDatabasePath = @"1.sqlite";
NSDictionary* schema_ = @{
@"Date" : @"DATETIME",
@"Integer" : @"INTEGER",
@"Name" : @"VARCHAR",
@"Id" : @"VARCHAR",
@"TypeId" : @"INTEGER"
};
NSOrderedSet* primaryKey_ = [ NSOrderedSet orderedSetWithObjects: @"Date", @"Id", @"TypeId", nil ];
CsvDefaultValues* defaults_ = [ CsvDefaultValues new ];
[ defaults_ addDefaultValue: @""
forColumn: @"Name" ];
[ defaults_ addDefaultValue: @"10"
forColumn: @"TypeId" ];
CsvToSqlite* converter_ = [ [ CsvToSqlite alloc ] initWithDatabaseName: fullDatabasePath
dataFileName: csvPath_
databaseSchema: schema_
primaryKey: primaryKey_
defaultValues: defaults_
separatorChar: ';'
commentChar: '#'
lineReader: [ UnixLineReader new ]
dbWrapperClass: [ FMDatabase class ] ];
converter_.csvDateFormat = @"yyyyMMdd";
NSError* error_;
[ converter_ storeDataInTable: @"Campaigns"
error: &error_ ];
XCTAssertNotNil( error_, @"Unexpected error" );
}
Columns parsing is the largest bottleneck for this implementation of the CSV importer. For some datasets this step may be skipped.
In order to implement this, the original CSV line
Date , Id, Visits
2014-01-01, 10, 100500
is converted to the query below:
INSERT INTO [TrafficStats] - SQL Insert statement added
( Date, Id, Visits ) - Brackets added
VALUES - SQL keyword added
( '2014-01-01', '10', '100500' ) - Brackets and quotes added
yyyyMMdd
formatWe have measured the benchmarks for iPad2 which was the oldest and slowest model I could test against. We have measured the entire process of importing including
The numbers in the tables below are an average of 10 launches. Feel free doing any further research using the dodikk/CsvToSqlite-Profiling repository.
Date Format | Format Comment | Time |
---|---|---|
yyyy-MM-dd | ANSI format | 11 sec |
yyyyMMdd | "Compact" ANSI | 17 sec |
other | Using NSDateFormatter | 28 sec |
Date Format | Format Comment | Time |
---|---|---|
yyyy-MM-dd | ANSI format | 20 sec |
yyyyMMdd | "Compact" ANSI | 32 sec |
other | Using NSDateFormatter | 40 sec |
The recommended approach is using sub-projects. However, cocoapods users are welcome to enter the pod install CsvToSqlite
command
Make the library rfc4180 compliant. Start using davedelong / CHCSVParser for better CSV handling