Add table name validation

This commit is contained in:
nxshock 2023-01-13 22:21:28 +05:00
parent 06139693c6
commit 3606f38890

View File

@ -4,6 +4,7 @@ import (
"bufio" "bufio"
"database/sql" "database/sql"
"encoding/csv" "encoding/csv"
"errors"
"fmt" "fmt"
"io" "io"
"log" "log"
@ -74,6 +75,10 @@ var app = &cli.App{
}, },
}, },
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
if len(strings.Split(c.String("table"), ".")) != 2 {
return errors.New("table name must be in schema.name format")
}
var err error var err error
db, err = sql.Open("sqlserver", fmt.Sprintf("sqlserver://%s?database=%s", c.String("server"), c.String("database"))) db, err = sql.Open("sqlserver", fmt.Sprintf("sqlserver://%s?database=%s", c.String("server"), c.String("database")))