Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gosqlite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gosqlite
Commits
b8b93a7a
Commit
b8b93a7a
authored
Mar 01, 2014
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test metadata on view and expression.
parent
3de617b3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
4 deletions
+49
-4
meta.go
meta.go
+3
-3
meta_test.go
meta_test.go
+46
-1
No files found.
meta.go
View file @
b8b93a7a
...
...
@@ -96,6 +96,7 @@ func (c *Conn) Views(dbName string, temp bool) ([]string, error) {
}
// Indexes returns indexes from 'sqlite_master'/'sqlite_temp_master'.
// As the index name is unique by database, (index name, table name) couples are returned.
func
(
c
*
Conn
)
Indexes
(
dbName
string
,
temp
bool
)
(
map
[
string
]
string
,
error
)
{
var
sql
string
if
len
(
dbName
)
==
0
{
...
...
@@ -137,7 +138,7 @@ type Column struct {
CollSeq
string
}
// Columns returns a description for each column in the named table.
// Columns returns a description for each column in the named table
/view
.
// Column.Autoinc and Column.CollSeq are left unspecified.
// (See http://www.sqlite.org/pragma.html#pragma_table_info)
func
(
c
*
Conn
)
Columns
(
dbName
,
table
string
)
([]
Column
,
error
)
{
...
...
@@ -167,7 +168,7 @@ func (c *Conn) Columns(dbName, table string) ([]Column, error) {
return
columns
,
nil
}
// Column extracts metadata about a column of a table.
// Column extracts metadata about a column of a table
(doesn't work with view)
.
// Column.Cid and Column.DfltValue are left unspecified.
// (See http://sqlite.org/c3ref/table_column_metadata.html)
func
(
c
*
Conn
)
Column
(
dbName
,
tableName
,
columnName
string
)
(
*
Column
,
error
)
{
...
...
@@ -187,7 +188,6 @@ func (c *Conn) Column(dbName, tableName, columnName string) (*Column, error) {
if
rv
!=
C
.
SQLITE_OK
{
return
nil
,
c
.
error
(
rv
,
fmt
.
Sprintf
(
"Conn.Column(db: %q, tbl: %q, col: %q)"
,
dbName
,
tableName
,
columnName
))
}
// TODO How to avoid copy?
return
&
Column
{
-
1
,
columnName
,
C
.
GoString
(
zDataType
),
notNull
==
1
,
""
,
int
(
primaryKey
),
autoinc
==
1
,
C
.
GoString
(
zCollSeq
)},
nil
}
...
...
meta_test.go
View file @
b8b93a7a
...
...
@@ -57,7 +57,7 @@ func TestViews(t *testing.T) {
checkNoError
(
t
,
err
,
"error looking for views: %s"
)
assert
.
Equal
(
t
,
0
,
len
(
views
),
"table count"
)
err
=
db
.
FastExec
(
"CREATE VIEW myview AS SELECT 1"
)
checkNoError
(
t
,
err
,
"error creating
for views
: %s"
)
checkNoError
(
t
,
err
,
"error creating
view
: %s"
)
views
,
err
=
db
.
Views
(
""
,
false
)
checkNoError
(
t
,
err
,
"error looking for views: %s"
)
assert
.
Equal
(
t
,
1
,
len
(
views
),
"table count"
)
...
...
@@ -171,3 +171,48 @@ func TestColumnMetadata(t *testing.T) {
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"
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment