|
1 | 1 | # CSVtoSQL |
2 | 2 |
|
| 3 | +## Description |
| 4 | + |
3 | 5 | This little dirty application will help you to convert CSV file into set of SQL commands. |
4 | 6 | To do that you can |
5 | 7 |
|
6 | 8 | - provide input file in csv format |
7 | 9 | - define template file which store template for each row |
8 | | -- CSVtoSQL till generate ouput file where set of commands will be saved > later you can use for example osql to execute this statements |
| 10 | +- CSVtoSQL will generate ouput file where set of commands will be saved |
| 11 | +- later you can use for example osql to execute this statements |
9 | 12 |
|
| 13 | +## Options |
10 | 14 |
|
| 15 | +~~~ |
11 | 16 | Options: |
12 | | - |
13 | 17 | -i, --input (Default: input.csv) CSV file to be processedv |
14 | 18 |
|
15 | 19 | -o, --output (Default: output.sql) FILE with Output |
16 | 20 |
|
17 | | - -t, --template Required. (Default: template.txt) FILE with template . |
18 | | - Sample Template text insert into test (xxx,yyy) values |
19 | | - ( {1},{2}) |
| 21 | + -t, --template Required. (Default: template.txt) Template file where |
| 22 | + data will be replaced form input file . Sample Template |
| 23 | + text insert into mytable (column1,column2) values |
| 24 | + ({0},{1}) |
20 | 25 |
|
21 | | - -s, --csvseparator (Default: ,) CSV Separator |
| 26 | + -s, --csvseparator (Default: ,) CSV Separator any char or - tabulator |
| 27 | +
|
| 28 | + -l, --line (Default: 2) Start form Line |
22 | 29 |
|
23 | 30 | --help Display this help screen. |
| 31 | +~~~ |
24 | 32 |
|
25 | | - |
26 | | - |
27 | | -SAMPLE Command line |
28 | 33 |
|
| 34 | +## SAMPLE Command line |
| 35 | + |
| 36 | +Use tab character as column separator |
| 37 | +~~~ |
29 | 38 | CSVtoSQL.exe -t template.txt -i input.csv -s \t |
| 39 | +~~~ |
| 40 | + |
| 41 | +All parameters provided |
| 42 | +~~~ |
| 43 | +CSVtoSQL.exe -t mytemplate.txt -i data.csv -s \t -o myoutputfile.sql -l 4 |
| 44 | +~~~ |
| 45 | + |
| 46 | +## SAMPLE FLOW |
| 47 | +Each row and column in csv is processed using temaplte file |
| 48 | + |
| 49 | +### Sample data file data.csv |
| 50 | +~~~ |
| 51 | +header,header |
| 52 | +column1row1,column2row1 |
| 53 | +column1row2,column2row2 |
| 54 | +column1row3,column2row3 |
| 55 | +~~~ |
| 56 | + |
| 57 | +### sample template mytemplate.txt |
| 58 | +~~~ |
| 59 | +insert into mytable (column1,column2) values ('{0}','{1}'); |
| 60 | +~~~ |
| 61 | + |
| 62 | +###Command |
| 63 | +~~~ |
| 64 | +CSVtoSQL.exe -t mytemplate.txt -i data.csv |
| 65 | +~~~ |
| 66 | + |
| 67 | +###RESULT output.sql |
| 68 | +~~~ |
| 69 | +insert into mytable (column1,column2) values ('column1row1','column2row1'); |
| 70 | +insert into mytable (column1,column2) values ('column1row2','column2row2'); |
| 71 | +insert into mytable (column1,column2) values ('column1row3','column2row3'); |
| 72 | +~~~ |
| 73 | + |
| 74 | + |
| 75 | + |
0 commit comments