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
17ef1633
Commit
17ef1633
authored
Jul 19, 2011
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moves backup api to its own file.
parent
50898ecf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
61 deletions
+79
-61
Makefile
Makefile
+2
-1
backup.go
backup.go
+77
-0
sqlite.go
sqlite.go
+0
-60
No files found.
Makefile
View file @
17ef1633
...
...
@@ -7,6 +7,7 @@ include $(GOROOT)/src/Make.inc
TARG
=
github.com/gwenn/sqlite
CGOFILES
=
\
sqlite.go
sqlite.go
\
backup.go
include
$(GOROOT)/src/Make.pkg
backup.go
0 → 100644
View file @
17ef1633
// 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.
// Package sqlite provides access to the SQLite library, version 3.
package
sqlite
/*
#include <sqlite3.h>
#include <stdlib.h>
*/
import
"C"
import
(
"os"
"time"
"unsafe"
)
func
NewBackup
(
dst
*
Conn
,
dstTable
string
,
src
*
Conn
,
srcTable
string
)
(
*
Backup
,
os
.
Error
)
{
dname
:=
C
.
CString
(
dstTable
)
sname
:=
C
.
CString
(
srcTable
)
defer
C
.
free
(
unsafe
.
Pointer
(
dname
))
defer
C
.
free
(
unsafe
.
Pointer
(
sname
))
sb
:=
C
.
sqlite3_backup_init
(
dst
.
db
,
dname
,
src
.
db
,
sname
)
if
sb
==
nil
{
return
nil
,
dst
.
error
(
C
.
sqlite3_errcode
(
dst
.
db
))
}
return
&
Backup
{
sb
,
dst
,
src
},
nil
}
type
Backup
struct
{
sb
*
C
.
sqlite3_backup
dst
,
src
*
Conn
}
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
{
return
nil
}
return
Errno
(
rv
)
}
type
BackupStatus
struct
{
Remaining
int
PageCount
int
}
func
(
b
*
Backup
)
Status
()
BackupStatus
{
return
BackupStatus
{
int
(
C
.
sqlite3_backup_remaining
(
b
.
sb
)),
int
(
C
.
sqlite3_backup_pagecount
(
b
.
sb
))}
}
func
(
b
*
Backup
)
Run
(
npage
int
,
sleepNs
int64
,
c
chan
<-
BackupStatus
)
os
.
Error
{
var
err
os
.
Error
for
{
err
=
b
.
Step
(
npage
)
if
err
!=
nil
{
break
}
if
c
!=
nil
{
c
<-
b
.
Status
()
}
time
.
Sleep
(
sleepNs
)
}
return
b
.
dst
.
error
(
C
.
sqlite3_errcode
(
b
.
dst
.
db
))
}
func
(
b
*
Backup
)
Close
()
os
.
Error
{
if
b
.
sb
==
nil
{
return
os
.
EINVAL
}
C
.
sqlite3_backup_finish
(
b
.
sb
)
b
.
sb
=
nil
return
nil
}
sqlite.go
View file @
17ef1633
...
...
@@ -34,7 +34,6 @@ import (
"fmt"
"os"
"reflect"
"time"
"unsafe"
)
...
...
@@ -166,65 +165,6 @@ func Open(filename string) (*Conn, os.Error) {
return
&
Conn
{
db
},
nil
}
func
NewBackup
(
dst
*
Conn
,
dstTable
string
,
src
*
Conn
,
srcTable
string
)
(
*
Backup
,
os
.
Error
)
{
dname
:=
C
.
CString
(
dstTable
)
sname
:=
C
.
CString
(
srcTable
)
defer
C
.
free
(
unsafe
.
Pointer
(
dname
))
defer
C
.
free
(
unsafe
.
Pointer
(
sname
))
sb
:=
C
.
sqlite3_backup_init
(
dst
.
db
,
dname
,
src
.
db
,
sname
)
if
sb
==
nil
{
return
nil
,
dst
.
error
(
C
.
sqlite3_errcode
(
dst
.
db
))
}
return
&
Backup
{
sb
,
dst
,
src
},
nil
}
type
Backup
struct
{
sb
*
C
.
sqlite3_backup
dst
,
src
*
Conn
}
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
{
return
nil
}
return
Errno
(
rv
)
}
type
BackupStatus
struct
{
Remaining
int
PageCount
int
}
func
(
b
*
Backup
)
Status
()
BackupStatus
{
return
BackupStatus
{
int
(
C
.
sqlite3_backup_remaining
(
b
.
sb
)),
int
(
C
.
sqlite3_backup_pagecount
(
b
.
sb
))}
}
func
(
b
*
Backup
)
Run
(
npage
int
,
sleepNs
int64
,
c
chan
<-
BackupStatus
)
os
.
Error
{
var
err
os
.
Error
for
{
err
=
b
.
Step
(
npage
)
if
err
!=
nil
{
break
}
if
c
!=
nil
{
c
<-
b
.
Status
()
}
time
.
Sleep
(
sleepNs
)
}
return
b
.
dst
.
error
(
C
.
sqlite3_errcode
(
b
.
dst
.
db
))
}
func
(
b
*
Backup
)
Close
()
os
.
Error
{
if
b
.
sb
==
nil
{
return
os
.
EINVAL
}
C
.
sqlite3_backup_finish
(
b
.
sb
)
b
.
sb
=
nil
return
nil
}
func
(
c
*
Conn
)
BusyTimeout
(
ms
int
)
os
.
Error
{
rv
:=
C
.
sqlite3_busy_timeout
(
c
.
db
,
C
.
int
(
ms
))
if
rv
==
0
{
...
...
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