Skip to content

Commit

Permalink
Merge pull request #301 from noborus/add-debug-print
Browse files Browse the repository at this point in the history
Add the Debug.print function
  • Loading branch information
noborus authored Jan 1, 2025
2 parents 23e31c7 + 0814c76 commit bfe7df7
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 19 deletions.
6 changes: 3 additions & 3 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (db *DB) CreateTableContext(ctx context.Context, tableName string, columnNa
}

query := db.queryCreateTable(tableName, columnNames, columnTypes, isTemporary)
debug.Printf(query)
debug.Print(query)
_, err := db.Tx.ExecContext(ctx, query)
return err
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func (db *DB) ImportContext(ctx context.Context, tableName string, columnNames [
// copyImport adds rows to a table with the COPY clause (PostgreSQL only).
func (db *DB) copyImport(ctx context.Context, table *importTable, reader Reader) error {
query := queryCopy(table)
debug.Printf(query)
debug.Print(query)

stmt, err := db.Tx.PrepareContext(ctx, query)
if err != nil {
Expand Down Expand Up @@ -299,7 +299,7 @@ func (db *DB) bulkStmtOpen(ctx context.Context, table *importTable, stmt *sql.St

func (db *DB) insertPrepare(ctx context.Context, table *importTable) (*sql.Stmt, error) {
query := queryInsert(table)
debug.Printf(query)
debug.Print(query)

stmt, err := db.Tx.PrepareContext(ctx, query)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ func (d debugT) Printf(format string, args ...any) {
log.Printf(format, args...)
}
}

func (d debugT) Print(args ...any) {
if d {
log.Print(args...)
}
}
2 changes: 1 addition & 1 deletion exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (e *WriteFormat) exportContext(ctx context.Context, db *DB, query string) e
if query == "" {
return ErrNoStatement
}
debug.Printf(query)
debug.Print(query)

if db.isExecContext(query) {
return db.OtherExecContext(ctx, query)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ require (
golang.org/x/sys v0.28.0 // indirect
gonum.org/v1/gonum v0.15.1 // indirect
modernc.org/gc/v3 v3.0.0-20241223112719-96e2e1e4408d // indirect
modernc.org/libc v1.61.5 // indirect
modernc.org/libc v1.61.6 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.8.0 // indirect
modernc.org/strutil v1.2.0 // indirect
modernc.org/strutil v1.2.1 // indirect
modernc.org/token v1.1.0 // indirect
)

Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
modernc.org/cc/v4 v4.24.1 h1:mLykA8iIlZ/SZbwI2JgYIURXQMSgmOb/+5jaielxPi4=
modernc.org/cc/v4 v4.24.1/go.mod h1:T1lKJZhXIi2VSqGBiB4LIbKs9NsKTbUXj4IDrmGqtTI=
modernc.org/cc/v4 v4.24.2 h1:uektamHbSXU7egelXcyVpMaaAsrRH4/+uMKUQAQUdOw=
modernc.org/cc/v4 v4.24.2/go.mod h1:T1lKJZhXIi2VSqGBiB4LIbKs9NsKTbUXj4IDrmGqtTI=
modernc.org/ccgo/v4 v4.23.5 h1:6uAwu8u3pnla3l/+UVUrDDO1HIGxHTYmFH6w+X9nsyw=
modernc.org/ccgo/v4 v4.23.5/go.mod h1:FogrWfBdzqLWm1ku6cfr4IzEFouq2fSAPf6aSAHdAJQ=
modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE=
Expand All @@ -118,8 +118,8 @@ modernc.org/gc/v2 v2.6.0 h1:Tiw3pezQj7PfV8k4Dzyu/vhRHR2e92kOXtTFU8pbCl4=
modernc.org/gc/v2 v2.6.0/go.mod h1:wzN5dK1AzVGoH6XOzc3YZ+ey/jPgYHLuVckd62P0GYU=
modernc.org/gc/v3 v3.0.0-20241223112719-96e2e1e4408d h1:d0JExN5U5FjUVHCP6L9DIlLJBZveR6KUM4AvfDUL3+k=
modernc.org/gc/v3 v3.0.0-20241223112719-96e2e1e4408d/go.mod h1:qBSLm/exCqouT2hrfyTKikWKG9IPq8EoX5fS00l3jqk=
modernc.org/libc v1.61.5 h1:WzsPUvWl2CvsRmk2foyWWHUEUmQ2iW4oFyWOVR0O5ho=
modernc.org/libc v1.61.5/go.mod h1:llBdEGIywhnRgAFuTF+CWaKV8/2bFgACcQZTXhkAuAM=
modernc.org/libc v1.61.6 h1:L2jW0wxHPCyHK0YSHaGaVlY0WxjpG/TTVdg6gRJOPqw=
modernc.org/libc v1.61.6/go.mod h1:G+DzuaCcReUYYg4nNSfigIfTDCENdj9EByglvaRx53A=
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E=
Expand All @@ -130,7 +130,7 @@ modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc=
modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss=
modernc.org/sqlite v1.34.4 h1:sjdARozcL5KJBvYQvLlZEmctRgW9xqIZc2ncN7PU0P8=
modernc.org/sqlite v1.34.4/go.mod h1:3QQFCG2SEMtc2nv+Wq4cQCH7Hjcg+p/RMlS1XK+zwbk=
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
2 changes: 1 addition & 1 deletion importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TableNames(parsedQuery []string) (map[string]string, []int) {
debug.Printf("[%s]", strings.Join(parsedQuery, "]["))
for i, w := range parsedQuery {
switch {
case strings.Contains(" \t\r\n;=", w): // nolint // Because each character is parsed by SQLFields.
case strings.Contains(" \t\r\n;=", w): //nolint // Because each character is parsed by SQLFields.
continue
case strings.EqualFold(w, "FROM"),
strings.EqualFold(w, "*FROM"),
Expand Down
2 changes: 1 addition & 1 deletion input_csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func NewCSVReader(reader io.Reader, opts *ReadOpts) (*CSVReader, error) {
return r, err
}
r.setColumnType()
debug.Printf(err.Error())
debug.Print(err.Error())
return r, nil
}
rows := make([]string, len(row))
Expand Down
2 changes: 1 addition & 1 deletion input_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func NewJSONReader(reader io.Reader, opts *ReadOpts) (*JSONReader, error) {
if !errors.Is(err, io.EOF) {
return r, fmt.Errorf("%w: %s", ErrInvalidJSON, err)
}
debug.Printf(err.Error())
debug.Print(err.Error())
return r, nil
}

Expand Down
2 changes: 1 addition & 1 deletion input_ltsv.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewLTSVReader(reader io.Reader, opts *ReadOpts) (*LTSVReader, error) {
return r, err
}
r.setColumnType()
debug.Printf(err.Error())
debug.Print(err.Error())
return r, nil
}

Expand Down
4 changes: 2 additions & 2 deletions input_tbln.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewTBLNReader(reader io.Reader, opts *ReadOpts) (*TBLNRead, error) {
if !errors.Is(err, io.EOF) {
return r, err
}
debug.Printf(err.Error())
debug.Print(err.Error())
return r, nil
}

Expand Down Expand Up @@ -69,7 +69,7 @@ func NewTBLNReader(reader io.Reader, opts *ReadOpts) (*TBLNRead, error) {
if !errors.Is(err, io.EOF) {
return r, err
}
debug.Printf(err.Error())
debug.Print(err.Error())
return r, nil
}
r.preRead = append(r.preRead, r.recToRow(rec))
Expand Down
2 changes: 1 addition & 1 deletion input_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (r *YAMLReader) yamlParse(opts *ReadOpts) error {
if !errors.Is(err, io.EOF) {
return fmt.Errorf("%w: %s", ErrInvalidYAML, err)
}
debug.Printf(err.Error())
debug.Print(err.Error())
return nil
}

Expand Down

0 comments on commit bfe7df7

Please sign in to comment.