Fix database connection and default vales issues

This commit is contained in:
nxshock 2022-10-11 18:03:15 +05:00
parent fddb1895be
commit 6975794cad
2 changed files with 19 additions and 15 deletions

View File

@ -1,5 +1,5 @@
package main
const (
VERSION = "0.1.0"
VERSION = "0.1.1"
)

16
main.go
View File

@ -30,7 +30,7 @@ var app = &cli.App{
&cli.StringFlag{
Name: "server",
Usage: "database server address",
DefaultText: "127.0.0.1"},
Value: "127.0.0.1"},
&cli.StringFlag{
Name: "database",
Usage: "database name",
@ -46,7 +46,7 @@ var app = &cli.App{
&cli.StringFlag{
Name: "comma",
Usage: `CSV file comma character (use 't' for tabs)`,
DefaultText: ","},
Value: ","},
&cli.BoolFlag{
Name: "create",
Usage: "create table"},
@ -55,25 +55,28 @@ var app = &cli.App{
Usage: "overwrite existing table"},
&cli.StringFlag{
Name: "encoding",
Usage: `CSV file charset ("utf8", "win1251")`},
Usage: `CSV file charset ("utf8", "win1251")`,
Value: "utf8"},
&cli.IntFlag{
Name: "skiprows",
Usage: "number of rows to skip before read CSV file header"},
&cli.StringFlag{
Name: "dateformat",
Usage: "date format (Go style)",
DefaultText: "02.01.2006"},
Value: "02.01.2006"},
&cli.StringFlag{
Name: "timestampformat",
Usage: "timestamp format (Go style)",
DefaultText: "02.01.2006 15:04:05"},
Value: "02.01.2006 15:04:05"},
&cli.BoolFlag{
Name: "unknowncolumnnames",
Usage: "insert to table with unknown column names",
},
},
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 {
return fmt.Errorf("open database: %v", err)
}
@ -107,6 +110,7 @@ func main() {
func processReader(c *cli.Context, r io.Reader) error {
var encoding Encoding
fmt.Println(c.String("encoding"))
err := encoding.UnmarshalText([]byte(c.String("encoding")))
if err != nil {
return fmt.Errorf("get decoder: %v", c.String("encoding"))