Squashman wrote:Still want to get around to trying this out but it is still way over my head on how it all works. Can you post an example of a schema.ini and how I would use that schema.ini to run the bat file?
Thanks
OK. Basic example. Say you've got a directory containing a file called "test.tsv" with the following tab-delimited data:
Code: Select all
year make model color worth
2015 Toyota Tacoma black $32,000.00
2008 Dodge Ram silver $18,500.00
1999 Chevy Silverado red 6-pack of beer
If you were to simply:
Code: Select all
csv.bat /d tab select * from test.tsv
... the 1999 Chevy Silverado "worth" value would be output as "undefined", because the column is assumed to be currency; and "6-pack of beer" isn't decipherable under that constraint. Now, say you'd prefer the data type of the
worth column to be a string, rather than currency. In this case, you'd need to generate a Schema.ini. To do this, you can let the script auto generate it for you with the
/s switch.
When it's done, a Schema.ini will have been generated for every text file in the directory. Open it and find the section for test.tsv. Change the data type for column 5 to "Text" (or
whatever other data type you feel is appropriate), then save the change. Your modified Schema.ini will look like this:
Code: Select all
[test.tsv]
ColNameHeader=True
CharacterSet=1252
Format=TabDelimited
Col1=year Integer
Col2=make Char Width 255
Col3=model Char Width 255
Col4=color Char Width 255
Col5=worth Text
And the next time you run the query:
... the 99 Silverado's "6-pack of beer" value will be preserved. Also note that generating Schema.ini allows you to omit the
/d tab arguments from the command line. Since the delimiter is specified within Schema.ini, it no longer needs to be specified as an argument to the batch script.
Anyway, hope this helps!