0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

CSV import/export now supports spaces in field names SERVER-687

This commit is contained in:
Mathias Stearn 2010-03-01 14:03:29 -05:00
parent 3112a2d0ec
commit 05de70c790
2 changed files with 5 additions and 5 deletions

View File

@ -4,25 +4,25 @@ t = new ToolTest( "csv1" )
c = t.startDB( "foo" );
base = { a : 1 , b : "foo,bar" , c: 5 };
base = { a : 1 , b : "foo,bar" , c: 5, 'd d': 6 };
assert.eq( 0 , c.count() , "setup1" );
c.insert( base );
delete base._id
assert.eq( 1 , c.count() , "setup2" );
t.runTool( "export" , "--out" , t.extFile , "-d" , t.baseName , "-c" , "foo" , "--csv" , "-f" , "a,b,c" )
t.runTool( "export" , "--out" , t.extFile , "-d" , t.baseName , "-c" , "foo" , "--csv" , "-f" , "a,b,c,d d" )
c.drop()
assert.eq( 0 , c.count() , "after drop" )
t.runTool( "import" , "--file" , t.extFile , "-d" , t.baseName , "-c" , "foo" , "--type" , "csv" , "-f" , "a,b,c" );
t.runTool( "import" , "--file" , t.extFile , "-d" , t.baseName , "-c" , "foo" , "--type" , "csv" , "-f" , "a,b,c,d d" );
assert.soon( "2 == c.count()" , "restore 2" );
a = c.find().sort( { a : 1 } ).toArray();
delete a[0]._id
delete a[1]._id
assert.eq( tojson( { a : "a" , b : "b" , c : "c" } ) , tojson( a[1] ) , "csv parse 1" );
assert.eq( tojson( { a : "a" , b : "b" , c : "c" , 'd d': "d d"} ) , tojson( a[1] ) , "csv parse 1" );
assert.eq( tojson( base ) , tojson(a[0]) , "csv parse 0" )
c.drop()

View File

@ -212,7 +212,7 @@ namespace mongo {
pcrecpp::StringPiece input(fields_arg);
string f;
pcrecpp::RE re("([\\w\\.]+),?" );
pcrecpp::RE re("([\\w\\.\\s]+),?" );
while ( re.Consume( &input, &f ) ){
_fields.push_back( f );
b.append( f.c_str() , 1 );