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
ba549b89
Commit
ba549b89
authored
Dec 18, 2011
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better error message with invalid SQL.
Add IntegrityCheck helper.
parent
be3e6243
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
2 deletions
+46
-2
sqlite.go
sqlite.go
+38
-2
sqlite_test.go
sqlite_test.go
+8
-0
No files found.
sqlite.go
View file @
ba549b89
...
...
@@ -112,7 +112,7 @@ var errText = map[Errno]string{
101
:
"sqlite3_step() has finished executing"
,
}
func
(
c
*
Conn
)
error
(
rv
C
.
int
)
error
{
func
(
c
*
Conn
)
error
(
rv
C
.
int
,
detail
...
string
)
error
{
if
c
==
nil
||
c
.
db
==
nil
{
return
errors
.
New
(
"nil sqlite database"
)
}
...
...
@@ -122,6 +122,9 @@ func (c *Conn) error(rv C.int) error {
if
rv
==
21
{
// misuse
return
Errno
(
rv
)
}
if
len
(
detail
)
>
0
{
return
errors
.
New
(
Errno
(
rv
)
.
Error
()
+
": "
+
C
.
GoString
(
C
.
sqlite3_errmsg
(
c
.
db
))
+
" @ "
+
detail
[
0
])
}
return
errors
.
New
(
Errno
(
rv
)
.
Error
()
+
": "
+
C
.
GoString
(
C
.
sqlite3_errmsg
(
c
.
db
)))
}
...
...
@@ -413,7 +416,7 @@ func (c *Conn) Prepare(cmd string, args ...interface{}) (*Stmt, error) {
var
tail
*
C
.
char
rv
:=
C
.
sqlite3_prepare_v2
(
c
.
db
,
cmdstr
,
-
1
,
&
stmt
,
&
tail
)
if
rv
!=
C
.
SQLITE_OK
{
return
nil
,
c
.
error
(
rv
)
return
nil
,
c
.
error
(
rv
,
cmd
)
}
var
t
string
if
tail
!=
nil
&&
C
.
strlen
(
tail
)
>
0
{
...
...
@@ -1112,6 +1115,39 @@ func EnableSharedCache(b bool) {
C
.
sqlite3_enable_shared_cache
(
btocint
(
b
))
}
// Check database integrity
// Calls http://www.sqlite.org/pragma.html#pragma_integrity_check
// Or http://www.sqlite.org/pragma.html#pragma_quick_check
func
(
c
*
Conn
)
IntegrityCheck
(
max
int
,
quick
bool
)
error
{
var
pragma
string
if
quick
{
pragma
=
"quick"
}
else
{
pragma
=
"integrity"
}
s
,
err
:=
c
.
Prepare
(
fmt
.
Sprintf
(
"PRAGMA %s_check(%d)"
,
pragma
,
max
))
if
err
!=
nil
{
return
err
}
defer
s
.
Finalize
()
ok
,
err
:=
s
.
Next
()
if
err
!=
nil
{
return
err
}
if
!
ok
{
return
errors
.
New
(
"Integrity check failed (no result)"
)
}
var
msg
string
err
=
s
.
Scan
(
&
msg
)
if
err
!=
nil
{
return
err
}
if
msg
!=
"ok"
{
return
errors
.
New
(
msg
)
}
return
nil
}
// Must is a helper that wraps a call to a function returning (bool, os.Error)
// and panics if the error is non-nil.
func
Must
(
b
bool
,
err
error
)
bool
{
...
...
sqlite_test.go
View file @
ba549b89
...
...
@@ -52,6 +52,14 @@ func TestEnableFKey(t *testing.T) {
}
}
func
TestIntegrityCheck
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
if
err
:=
db
.
IntegrityCheck
(
1
,
true
);
err
!=
nil
{
t
.
Fatalf
(
"Error checking integrity of database: %s"
,
err
)
}
}
func
TestCreateTable
(
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