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
99c43b96
Commit
99c43b96
authored
Feb 18, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add binding to sqlite3_table_column_metadata.
parent
928f2264
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
0 deletions
+58
-0
meta.go
meta.go
+40
-0
meta_test.go
meta_test.go
+18
-0
No files found.
meta.go
View file @
99c43b96
...
...
@@ -12,6 +12,23 @@ package sqlite
static char *my_mprintf(char *zFormat, char *arg) {
return sqlite3_mprintf(zFormat, arg);
}
// just to get ride of warning
static int my_table_column_metadata(
sqlite3 *db,
const char *zDbName,
const char *zTableName,
const char *zColumnName,
char **pzDataType,
char **pzCollSeq,
int *pNotNull,
int *pPrimaryKey,
int *pAutoinc
) {
return sqlite3_table_column_metadata(db, zDbName, zTableName, zColumnName,
(char const **)pzDataType, (char const **)pzCollSeq, pNotNull, pPrimaryKey, pAutoinc);
}
*/
import
"C"
...
...
@@ -67,6 +84,8 @@ type Column struct {
NotNull
bool
DfltValue
string
// FIXME type ?
Pk
bool
Autoinc
bool
CollSeq
string
}
// Executes pragma 'table_info'
...
...
@@ -93,6 +112,27 @@ func (c *Conn) Columns(table string) ([]Column, error) {
return
columns
,
nil
}
func
(
c
*
Conn
)
Column
(
dbName
,
tableName
,
columnName
string
)
(
*
Column
,
error
)
{
var
zDbName
*
C
.
char
if
len
(
dbName
)
>
0
{
zDbName
=
C
.
CString
(
dbName
)
defer
C
.
free
(
unsafe
.
Pointer
(
zDbName
))
}
zTableName
:=
C
.
CString
(
tableName
)
defer
C
.
free
(
unsafe
.
Pointer
(
zTableName
))
zColumnName
:=
C
.
CString
(
columnName
)
defer
C
.
free
(
unsafe
.
Pointer
(
zColumnName
))
var
zDataType
,
zCollSeq
*
C
.
char
var
notNull
,
primaryKey
,
autoinc
C
.
int
rv
:=
C
.
my_table_column_metadata
(
c
.
db
,
zDbName
,
zTableName
,
zColumnName
,
&
zDataType
,
&
zCollSeq
,
&
notNull
,
&
primaryKey
,
&
autoinc
)
if
rv
!=
C
.
SQLITE_OK
{
return
nil
,
c
.
error
(
rv
)
}
return
&
Column
{
-
1
,
columnName
,
C
.
GoString
(
zDataType
),
notNull
==
1
,
""
,
primaryKey
==
1
,
autoinc
==
1
,
C
.
GoString
(
zCollSeq
)},
nil
}
// See Conn.ForeignKeys
type
ForeignKey
struct
{
Table
string
...
...
meta_test.go
View file @
99c43b96
...
...
@@ -61,6 +61,24 @@ func TestColumns(t *testing.T) {
}
}
func
TestColumn
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
createTable
(
db
,
t
)
column
,
err
:=
db
.
Column
(
""
,
"test"
,
"id"
)
checkNoError
(
t
,
err
,
"error getting column metadata: %s"
)
if
column
.
Name
!=
"id"
{
t
.
Errorf
(
"Wrong column name: 'id' <> %s"
,
column
.
Name
)
}
if
!
column
.
Pk
{
t
.
Errorf
(
"Expecting primary key flag to be true"
)
}
if
!
column
.
Autoinc
{
t
.
Errorf
(
"Expecting autoinc flag to be true"
)
}
}
func
TestForeignKeys
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
...
...
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