mirror of
https://github.com/nxshock/csv2db.git
synced 2024-11-27 03:31:00 +05:00
Fix database connection and default vales issues
This commit is contained in:
parent
fddb1895be
commit
6975794cad
@ -1,5 +1,5 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION = "0.1.0"
|
VERSION = "0.1.1"
|
||||||
)
|
)
|
||||||
|
32
main.go
32
main.go
@ -28,9 +28,9 @@ var app = &cli.App{
|
|||||||
Required: true,
|
Required: true,
|
||||||
TakesFile: true},
|
TakesFile: true},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "server",
|
Name: "server",
|
||||||
Usage: "database server address",
|
Usage: "database server address",
|
||||||
DefaultText: "127.0.0.1"},
|
Value: "127.0.0.1"},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "database",
|
Name: "database",
|
||||||
Usage: "database name",
|
Usage: "database name",
|
||||||
@ -44,9 +44,9 @@ var app = &cli.App{
|
|||||||
Usage: "list of field types in [sifdt ]+ format",
|
Usage: "list of field types in [sifdt ]+ format",
|
||||||
Required: true},
|
Required: true},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "comma",
|
Name: "comma",
|
||||||
Usage: `CSV file comma character (use 't' for tabs)`,
|
Usage: `CSV file comma character (use 't' for tabs)`,
|
||||||
DefaultText: ","},
|
Value: ","},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "create",
|
Name: "create",
|
||||||
Usage: "create table"},
|
Usage: "create table"},
|
||||||
@ -55,25 +55,28 @@ var app = &cli.App{
|
|||||||
Usage: "overwrite existing table"},
|
Usage: "overwrite existing table"},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "encoding",
|
Name: "encoding",
|
||||||
Usage: `CSV file charset ("utf8", "win1251")`},
|
Usage: `CSV file charset ("utf8", "win1251")`,
|
||||||
|
Value: "utf8"},
|
||||||
&cli.IntFlag{
|
&cli.IntFlag{
|
||||||
Name: "skiprows",
|
Name: "skiprows",
|
||||||
Usage: "number of rows to skip before read CSV file header"},
|
Usage: "number of rows to skip before read CSV file header"},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "dateformat",
|
Name: "dateformat",
|
||||||
Usage: "date format (Go style)",
|
Usage: "date format (Go style)",
|
||||||
DefaultText: "02.01.2006"},
|
Value: "02.01.2006"},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "timestampformat",
|
Name: "timestampformat",
|
||||||
Usage: "timestamp format (Go style)",
|
Usage: "timestamp format (Go style)",
|
||||||
DefaultText: "02.01.2006 15:04:05"},
|
Value: "02.01.2006 15:04:05"},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "unknowncolumnnames",
|
Name: "unknowncolumnnames",
|
||||||
Usage: "insert to table with unknown column names",
|
Usage: "insert to table with unknown column names",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
db, err := sql.Open("sqlserver", fmt.Sprintf("sqlserver://%s?database=%s", c.String("server"), c.String("database")))
|
var err error
|
||||||
|
|
||||||
|
db, err = sql.Open("sqlserver", fmt.Sprintf("sqlserver://%s?database=%s", c.String("server"), c.String("database")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("open database: %v", err)
|
return fmt.Errorf("open database: %v", err)
|
||||||
}
|
}
|
||||||
@ -107,6 +110,7 @@ func main() {
|
|||||||
|
|
||||||
func processReader(c *cli.Context, r io.Reader) error {
|
func processReader(c *cli.Context, r io.Reader) error {
|
||||||
var encoding Encoding
|
var encoding Encoding
|
||||||
|
fmt.Println(c.String("encoding"))
|
||||||
err := encoding.UnmarshalText([]byte(c.String("encoding")))
|
err := encoding.UnmarshalText([]byte(c.String("encoding")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("get decoder: %v", c.String("encoding"))
|
return fmt.Errorf("get decoder: %v", c.String("encoding"))
|
||||||
|
Loading…
Reference in New Issue
Block a user