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
d9b115e3
Commit
d9b115e3
authored
Jul 23, 2011
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor ForeignKey struct.
parent
30d005b4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
11 deletions
+17
-11
backup.go
backup.go
+1
-1
meta.go
meta.go
+15
-9
sqlite_test.go
sqlite_test.go
+1
-1
No files found.
backup.go
View file @
d9b115e3
...
...
@@ -37,7 +37,7 @@ type Backup struct {
func
(
b
*
Backup
)
Step
(
npage
int
)
os
.
Error
{
rv
:=
C
.
sqlite3_backup_step
(
b
.
sb
,
C
.
int
(
npage
))
if
rv
==
0
||
Errno
(
rv
)
==
ErrBusy
||
Errno
(
rv
)
==
ErrLocked
{
if
rv
==
C
.
SQLITE_OK
||
Errno
(
rv
)
==
ErrBusy
||
Errno
(
rv
)
==
ErrLocked
{
return
nil
}
return
Errno
(
rv
)
...
...
meta.go
View file @
d9b115e3
...
...
@@ -70,27 +70,33 @@ func (c *Conn) Columns(table string) ([]Column, os.Error) {
}
type
ForeignKey
struct
{
Id
int
Seq
int
Table
string
From
string
To
string
From
[]
string
To
[]
string
}
func
(
c
*
Conn
)
ForeignKeys
(
table
string
)
(
[]
ForeignKey
,
os
.
Error
)
{
func
(
c
*
Conn
)
ForeignKeys
(
table
string
)
(
map
[
int
]
*
ForeignKey
,
os
.
Error
)
{
s
,
err
:=
c
.
Prepare
(
Mprintf
(
"pragma foreign_key_list(%Q)"
,
table
))
if
err
!=
nil
{
return
nil
,
err
}
var
fks
[]
ForeignKey
=
make
([]
ForeignKey
,
0
,
20
)
var
fks
=
make
(
map
[
int
]
*
ForeignKey
)
var
ok
bool
var
id
,
seq
int
var
ref
,
from
,
to
string
for
ok
,
err
=
s
.
Next
();
ok
;
ok
,
err
=
s
.
Next
()
{
fk
:=
ForeignKey
{}
err
=
s
.
NamedScan
(
"id"
,
&
fk
.
Id
,
"seq"
,
&
fk
.
Seq
,
"table"
,
&
fk
.
Table
,
"from"
,
&
fk
.
From
,
"to"
,
&
fk
.
To
)
err
=
s
.
NamedScan
(
"id"
,
&
id
,
"seq"
,
&
seq
,
"table"
,
&
ref
,
"from"
,
&
from
,
"to"
,
&
to
)
if
err
!=
nil
{
return
nil
,
err
}
fks
=
append
(
fks
,
fk
)
fk
,
ex
:=
fks
[
id
]
if
!
ex
{
fk
=
&
ForeignKey
{
Table
:
ref
}
fks
[
id
]
=
fk
}
// TODO Ensure columns are appended in the correct order...
fk
.
From
=
append
(
fk
.
From
,
from
)
fk
.
To
=
append
(
fk
.
To
,
to
)
}
if
err
!=
nil
{
return
nil
,
err
...
...
sqlite_test.go
View file @
d9b115e3
...
...
@@ -255,7 +255,7 @@ func TestForeignKeys(t *testing.T) {
t
.
Fatalf
(
"Expected 1 FK <> %d"
,
len
(
fks
))
}
fk
:=
fks
[
0
]
if
fk
.
From
!=
"parentId"
||
fk
.
Table
!=
"parent"
||
fk
.
To
!=
"id"
{
if
fk
.
From
[
0
]
!=
"parentId"
||
fk
.
Table
!=
"parent"
||
fk
.
To
[
0
]
!=
"id"
{
t
.
Errorf
(
"Unexpected FK data: %#v"
,
fk
)
}
}
...
...
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