forked from patrickxb/fgosqlite
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmeta_extra_test.go
99 lines (83 loc) · 3 KB
/
meta_extra_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build all
package sqlite_test
import (
"strings"
"testing"
"github.com/bmizerany/assert"
. "github.com/gwenn/gosqlite"
)
func TestColumn(t *testing.T) {
db := open(t)
defer checkClose(db, t)
createTable(db, t)
column, err := db.Column("", "test", "id")
checkNoError(t, err, "error getting column metadata: %s")
assert.Equal(t, "id", column.Name, "column name")
assert.Equal(t, 1, column.Pk, "primary key index")
assert.T(t, !column.Autoinc, "expecting autoinc flag to be false")
column, err = db.Column("main", "test", "id")
checkNoError(t, err, "error getting column metadata: %s")
column, err = db.Column("", "test", "bim")
assert.T(t, err != nil, "expected error")
assert.T(t, err.Error() != "")
//println(err.Error())
}
func TestColumnMetadata(t *testing.T) {
db := open(t)
defer checkClose(db, t)
s, err := db.Prepare("SELECT name AS table_name FROM sqlite_master")
check(err)
defer checkFinalize(s, t)
databaseName := s.ColumnDatabaseName(0)
assert.Equal(t, "main", databaseName, "database name")
tableName := s.ColumnTableName(0)
assert.Equal(t, "sqlite_master", tableName, "table name")
originName := s.ColumnOriginName(0)
assert.Equal(t, "name", originName, "origin name")
declType := s.ColumnDeclaredType(0)
assert.T(t, strings.EqualFold("text", declType), "declared type")
affinity := s.ColumnTypeAffinity(0)
assert.Equal(t, Textual, affinity, "affinity")
}
func TestColumnMetadataOnView(t *testing.T) {
db := open(t)
defer checkClose(db, t)
createTable(db, t)
err := db.FastExec("CREATE VIEW vtest AS SELECT * FROM test")
checkNoError(t, err, "error creating view: %s")
s, err := db.Prepare("SELECT a_string AS str FROM vtest")
check(err)
defer checkFinalize(s, t)
databaseName := s.ColumnDatabaseName(0)
assert.Equal(t, "main", databaseName, "database name")
tableName := s.ColumnTableName(0)
assert.Equal(t, "test", tableName, "table name")
originName := s.ColumnOriginName(0)
assert.Equal(t, "a_string", originName, "origin name")
declType := s.ColumnDeclaredType(0)
assert.Equal(t, "TEXT", declType, "declared type")
affinity := s.ColumnTypeAffinity(0)
assert.Equal(t, Textual, affinity, "affinity")
}
func TestColumnMetadataOnExpr(t *testing.T) {
db := open(t)
defer checkClose(db, t)
err := db.FastExec("CREATE VIEW vtest AS SELECT date('now') as tic")
checkNoError(t, err, "error creating view: %s")
s, err := db.Prepare("SELECT tic FROM vtest")
check(err)
defer checkFinalize(s, t)
databaseName := s.ColumnDatabaseName(0)
assert.Equal(t, "", databaseName, "database name")
tableName := s.ColumnTableName(0)
assert.Equal(t, "", tableName, "table name")
originName := s.ColumnOriginName(0)
assert.Equal(t, "", originName, "origin name")
declType := s.ColumnDeclaredType(0)
assert.Equal(t, "", declType, "declared type")
affinity := s.ColumnTypeAffinity(0)
assert.Equal(t, None, affinity, "affinity")
}