Code Monkey home page Code Monkey logo

Comments (11)

noborus avatar noborus commented on May 28, 2024 1

I just released version 0.7.4 for this issue.
Thank you.

from trdsql.

awrog avatar awrog commented on May 28, 2024 1

Works great!! Thanx

from trdsql.

noborus avatar noborus commented on May 28, 2024

As you said, the output of CSV is not flexible.

The encoding/csv is used for CSV output.
https://golang.org/pkg/encoding/csv/

In this package, it is output in double quotation only when necessary.

echo 'a,b,c"d'|trdsql -ocsv "SELECT * FROM -" 
a,b,"c""d"

If you really need it, I would like to be added to golang package CSV.

from trdsql.

noborus avatar noborus commented on May 28, 2024

I just released v0.6.1.
It can be used as a library.
You may be able to resolve this issue.
With the following code:

package main

import (
	"io"
	"log"
	"os"
	"strconv"
	"strings"

	"github.com/noborus/trdsql"
)

type QuoteWrite struct {
	writer io.Writer
}

func NewQuoteCSVWriter(w io.Writer) *QuoteWrite {
	return &QuoteWrite{
		writer: w,
	}
}

func (w *QuoteWrite) PreWrite(columns []string, types []string) error {
	return nil
}

func (w *QuoteWrite) WriteRow(values []interface{}, columns []string) error {
	qColumns := make([]string, len(values))
	for i, col := range values {
		qColumns[i] = strconv.Quote(trdsql.ValString(col))
	}
	_, err := w.writer.Write([]byte(strings.Join(qColumns, ",") + "\n"))
	return err
}
func (w *QuoteWrite) PostWrite() error {
	return nil
}

func main() {
	trd := trdsql.NewTRDSQL(
		trdsql.NewImporter(),
		trdsql.NewExporter(NewQuoteCSVWriter(os.Stdout)),
	)
	err := trd.Exec("SELECT * FROM testdata/test.csv")
	if err != nil {
		log.Fatal(err)
	}
}

from trdsql.

awrog avatar awrog commented on May 28, 2024

I really love to use trdsql, awful speed and possibilities!
In processing large log-files the lack of being able to generate output with quotes is bugging me

Here you state:

You can right now configure the separator character with -od
A similar one for quotes could be added

Could you please add this to possible -od output options?

from trdsql.

noborus avatar noborus commented on May 28, 2024

Thank you for your opinion.
Force quotes are not supported by the standard CSV module.
So, before adding the option, consider using another CSV writer or implementing one.

from trdsql.

awrog avatar awrog commented on May 28, 2024

So, before adding the option, consider using another CSV writer or implementing one.

It concerns the activitylog from Twillio SendGrid, so, no chance of getting it changed.

from trdsql.

noborus avatar noborus commented on May 28, 2024

Sorry. Change the 'encoding/csv' part.
For example, you can change https://github.com/tushar2708/altcsv to use.

I haven't decided yet what to do, but I'm considering changing it to not use encoding/csv.

diff --git a/output_csv.go b/output_csv.go
index 7b7b345..da337bd 100644
--- a/output_csv.go
+++ b/output_csv.go
@@ -1,12 +1,12 @@
 package trdsql
 
 import (
-       "encoding/csv"
+       "github.com/tushar2708/altcsv"
 )
 
 // CSVWriter provides methods of the Writer interface.
 type CSVWriter struct {
-       writer    *csv.Writer
+       writer    *altcsv.Writer
        results   []string
        outHeader bool
 }
@@ -15,8 +15,9 @@ type CSVWriter struct {
 func NewCSVWriter(writeOpts *WriteOpts) *CSVWriter {
        var err error
        w := &CSVWriter{}
-       w.writer = csv.NewWriter(writeOpts.OutStream)
+       w.writer = altcsv.NewWriter(writeOpts.OutStream)
        w.writer.Comma, err = delimiter(writeOpts.OutDelimiter)
+       w.writer.AllQuotes = true
        if err != nil {
                debug.Printf("%s\n", err)
        }

from trdsql.

noborus avatar noborus commented on May 28, 2024

I added a new option to address this issue (#118) .
I want your opinion on this option.
If the name or description of the added option is not appropriate, please indicate it.
Added are - oq and - oaq and - ocrlf.

from trdsql.

awrog avatar awrog commented on May 28, 2024

Looks fine to me.
I'll wait for a new release to test it.

from trdsql.

noborus avatar noborus commented on May 28, 2024

Looks fine to me.
I'll wait for a new release to test it.

Thank you very much.

from trdsql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.