mithrandie/csvq-driver

driver: bad connection

pjebs opened this issue · 4 comments

pjebs commented

I keep getting driver: bad connection. I can't use it.

pjebs commented
package main

import (
	"context"
	"database/sql"
	"fmt"
	"time"

	_ "github.com/mithrandie/csvq-driver"
	// "github.com/dinedal/textql"
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()

	db, err := sql.Open("csvq", "/Users/xxx/GOPATH/src/github.com/xxx/sales/train.csv")
	if err != nil {
		panic(err)
	}
	defer db.Close()

	stmt := "SELECT Date, Sales FROM `train.csv` WHERE Store = '1'"

	rows, err := db.QueryContext(ctx, stmt)
	if err != nil {
		panic(err)  <--------- PANICS HERE: driver: bad connection  
	}
	defer rows.Close()

	for rows.Next() {
		var date string
		var sales float64
		if err := rows.Scan(&date, &sales); err != nil {
			panic(err)
		}

		fmt.Println(date, sales)
	}

	err = rows.Close()
	if err != nil {
		panic(err)
	}

}

pjebs commented

train.csv

"Store","DayOfWeek","Date","Sales","Customers","Open","Promo","StateHoliday","SchoolHoliday"
1,5,2015-07-31,5263,555,1,1,"0","1"
2,5,2015-07-31,6064,625,1,1,"0","1"
3,5,2015-07-31,8314,821,1,1,"0","1"
4,5,2015-07-31,13995,1498,1,1,"0","1"
5,5,2015-07-31,4822,559,1,1,"0","1"
6,5,2015-07-31,5651,589,1,1,"0","1"
7,5,2015-07-31,15344,1414,1,1,"0","1"
8,5,2015-07-31,8492,833,1,1,"0","1"
9,5,2015-07-31,8565,687,1,1,"0","1"
10,5,2015-07-31,7185,681,1,1,"0","1"
11,5,2015-07-31,10457,1236,1,1,"0","1"
12,5,2015-07-31,8959,962,1,1,"0","1"
13,5,2015-07-31,8821,568,1,1,"0","0"
14,5,2015-07-31,6544,710,1,1,"0","1"
15,5,2015-07-31,9191,766,1,1,"0","1"
16,5,2015-07-31,10231,979,1,1,"0","1"
17,5,2015-07-31,8430,946,1,1,"0","1"
18,5,2015-07-31,10071,936,1,1,"0","1"
19,5,2015-07-31,8234,718,1,1,"0","1"
pjebs commented

My mistake. Open required path to directory.

Sorry, code example in README was wrong. Fixed it. Thanks.