Commit 8667efa8 authored by gwenn's avatar gwenn

Fix some godoc and test import affinity.

parent 3b46764d
......@@ -22,6 +22,9 @@ type csvModule struct {
// args[1] => db name
// args[2] => table name
// TODO http://www.ch-werner.de/sqliteodbc/html/csvtable_8c.html make possible to specify the column/type name
// TODO https://github.com/karbarcca/SQLite.jl & infer
func (m csvModule) Create(c *Conn, args []string) (VTab, error) {
if len(args) < 4 {
return nil, errors.New("no CSV file specified")
......@@ -234,7 +237,7 @@ func LoadCsvModule(db *Conn) error {
return db.CreateModule("csv", csvModule{})
}
// ExportTableToCSV export table or view content to CSV.
// ExportTableToCSV exports table or view content to CSV.
// 'headers' flag turns output of headers on or off.
// NULL values are output as specified by 'nullvalue' parameter.
func (db *Conn) ExportTableToCSV(dbName, table string, nullvalue string, headers bool, w *yacr.Writer) error {
......@@ -252,7 +255,7 @@ func (db *Conn) ExportTableToCSV(dbName, table string, nullvalue string, headers
return s.ExportToCSV(nullvalue, headers, w)
}
// ExportToCSV export statement result to CSV.
// ExportToCSV exports statement result to CSV.
// 'headers' flag turns output of headers on or off.
// NULL values are output as specified by 'nullvalue' parameter.
func (s *Stmt) ExportToCSV(nullvalue string, headers bool, w *yacr.Writer) error {
......@@ -310,7 +313,7 @@ func (ic ImportConfig) getType(i int) string {
return ""
}
// ImportCSV import CSV data into the specified table (which may not exist yet).
// ImportCSV imports CSV data into the specified table (which may not exist yet).
// Code is adapted from .import command implementation in SQLite3 shell sources.
func (db *Conn) ImportCSV(in io.Reader, ic ImportConfig, dbName, table string) error {
columns, err := db.Columns(dbName, table)
......
......@@ -8,6 +8,7 @@ import (
"bytes"
"fmt"
"os"
"strings"
"testing"
"github.com/bmizerany/assert"
......@@ -65,6 +66,36 @@ func TestImportCSV(t *testing.T) {
checkNoError(t, err, "error while importing CSV file: %s")
}
func TestImportAffinity(t *testing.T) {
db := open(t)
defer checkClose(db, t)
r := strings.NewReader("t,i,r,b,n\n123,123,123,123,123")
ic := ImportConfig{
Name: "test",
Separator: ',',
Headers: true,
Types: []Affinity{Textual, Integral, Real, None, Numerical},
Log: os.Stderr,
}
err := db.ImportCSV(r, ic, "", "test")
checkNoError(t, err, "error while importing CSV file: %s")
err = db.Select("SELECT typeof(t), typeof(i), typeof(r), typeof(b), typeof(n) from test", func(s *Stmt) error {
tot, _ := s.ScanText(0)
assert.Equal(t, "text", tot)
toi, _ := s.ScanText(1)
assert.Equal(t, "integer", toi)
tor, _ := s.ScanText(2)
assert.Equal(t, "real", tor)
tob, _ := s.ScanText(3)
assert.Equal(t, "text", tob)
ton, _ := s.ScanText(4)
assert.Equal(t, "integer", ton)
return nil
})
checkNoError(t, err, "error while selecting: %s")
}
func TestExportTableToCSV(t *testing.T) {
db := open(t)
defer checkClose(db, t)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment