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
e67326dc
Commit
e67326dc
authored
Nov 28, 2013
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improves error handling.
parent
b034ade0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
14 deletions
+17
-14
function.go
function.go
+1
-1
sqlite.go
sqlite.go
+7
-7
sqlite_test.go
sqlite_test.go
+2
-1
stmt.go
stmt.go
+4
-4
stmt_test.go
stmt_test.go
+3
-1
No files found.
function.go
View file @
e67326dc
...
...
@@ -117,7 +117,7 @@ func (c *FunctionContext) Result(r interface{}) {
case
Errno
:
c
.
ResultErrorCode
(
r
)
default
:
panic
(
fmt
.
Sprintf
(
"unsupported type in Result: %
s
"
,
reflect
.
TypeOf
(
r
)))
panic
(
fmt
.
Sprintf
(
"unsupported type in Result: %
q
"
,
reflect
.
TypeOf
(
r
)))
}
}
...
...
sqlite.go
View file @
e67326dc
...
...
@@ -30,9 +30,9 @@ import (
type
ConnError
struct
{
c
*
Conn
code
Errno
msg
string
details
string
code
Errno
// thread safe error code
msg
string
// it might be the case that a second error occurs on a separate thread in between the time of the first error and the call to retrieve this message.
details
string
// contextual informations, thread safe
}
func
(
e
*
ConnError
)
Code
()
Errno
{
...
...
@@ -51,9 +51,9 @@ func (e *ConnError) Filename() string {
func
(
e
*
ConnError
)
Error
()
string
{
// FIXME code.Error() & e.msg are often redundant...
if
len
(
e
.
details
)
>
0
{
return
fmt
.
Sprintf
(
"%s
; %s (%s)"
,
e
.
code
.
Error
(),
e
.
msg
,
e
.
details
)
return
fmt
.
Sprintf
(
"%s
(%s) (%s)"
,
e
.
msg
,
e
.
details
,
e
.
code
.
Error
()
)
}
else
if
len
(
e
.
msg
)
>
0
{
return
fmt
.
Sprintf
(
"%s
; %s"
,
e
.
code
.
Error
(),
e
.
msg
)
return
fmt
.
Sprintf
(
"%s
(%s)"
,
e
.
msg
,
e
.
code
.
Error
()
)
}
return
e
.
code
.
Error
()
}
...
...
@@ -66,7 +66,7 @@ func (e Errno) Error() string {
if
e
==
ErrSpecific
{
s
=
"Wrapper specific error"
}
else
{
s
=
C
.
GoString
(
C
.
sqlite3_errstr
(
C
.
int
(
e
)))
s
=
C
.
GoString
(
C
.
sqlite3_errstr
(
C
.
int
(
e
)))
// thread safe
}
if
s
==
""
{
return
fmt
.
Sprintf
(
"errno %d"
,
int
(
e
))
...
...
@@ -297,7 +297,7 @@ func (c *Conn) Readonly(dbName string) (bool, error) {
defer
C
.
free
(
unsafe
.
Pointer
(
cname
))
rv
:=
C
.
sqlite3_db_readonly
(
c
.
db
,
cname
)
if
rv
==
-
1
{
return
false
,
c
.
error
(
C
.
SQLITE_ERROR
,
fmt
.
Sprintf
(
"%q is not the name of a database"
,
dbName
)
)
return
false
,
c
.
specificError
(
"%q is not the name of a database"
,
dbName
)
}
return
rv
==
1
,
nil
}
...
...
sqlite_test.go
View file @
e67326dc
...
...
@@ -196,7 +196,7 @@ func TestConnExecWithSelect(t *testing.T) {
err
:=
db
.
Exec
(
"SELECT 1"
)
assert
.
T
(
t
,
err
!=
nil
,
"error expected"
)
if
serr
,
ok
:=
err
.
(
*
StmtError
);
ok
{
assert
.
Equal
(
t
,
Row
,
serr
.
Code
())
assert
.
Equal
(
t
,
ErrSpecific
,
serr
.
Code
())
}
else
{
t
.
Errorf
(
"Expected StmtError but got %s"
,
reflect
.
TypeOf
(
err
))
}
...
...
@@ -244,6 +244,7 @@ func TestExecMisuse(t *testing.T) {
createTable
(
db
,
t
)
err
:=
db
.
Exec
(
"INSERT INTO test VALUES (?, ?, ?, ?); INSERT INTO test VALUES (?, ?, ?, ?)"
,
0
,
273.1
,
1
,
"test"
)
assert
.
T
(
t
,
err
!=
nil
,
"exec misuse expected"
)
//println(err.Error())
}
func
TestTransaction
(
t
*
testing
.
T
)
{
...
...
stmt.go
View file @
e67326dc
...
...
@@ -159,7 +159,7 @@ func (s *Stmt) exec() error {
err
:=
Errno
(
rv
)
if
err
!=
Done
{
if
err
==
Row
{
return
s
.
error
(
rv
,
"Don't use exec with anything that returns data such as SELECT"
)
return
s
.
specificError
(
"Don't use exec with anything that returns data such as SELECT"
)
}
return
s
.
error
(
rv
,
"Stmt.exec"
)
}
...
...
@@ -603,7 +603,7 @@ func (s *Stmt) ColumnIndex(name string) (int, error) {
if
ok
{
return
index
,
nil
}
return
-
1
,
s
.
specificError
(
"invalid column name: %
s
"
,
name
)
return
-
1
,
s
.
specificError
(
"invalid column name: %
q
"
,
name
)
}
// ScanByName scans result value from a query.
...
...
@@ -1059,14 +1059,14 @@ func (s *Stmt) checkTypeMismatch(source, target Type) error {
case
Text
:
fallthrough
case
Blob
:
return
s
.
specificError
(
"type mismatch, source %
s vs target %s
"
,
source
,
target
)
return
s
.
specificError
(
"type mismatch, source %
q vs target %q
"
,
source
,
target
)
}
case
Float
:
switch
source
{
case
Text
:
fallthrough
case
Blob
:
return
s
.
specificError
(
"type mismatch, source %
s vs target %s
"
,
source
,
target
)
return
s
.
specificError
(
"type mismatch, source %
q vs target %q
"
,
source
,
target
)
}
}
return
nil
...
...
stmt_test.go
View file @
e67326dc
...
...
@@ -137,6 +137,7 @@ func TestNamedScanColumn(t *testing.T) {
_
,
err
=
s
.
ScanByName
(
"invalid"
,
&
i1
)
assert
.
T
(
t
,
err
!=
nil
,
"expected invalid name"
)
//println(err.Error())
}
func
TestScanCheck
(
t
*
testing
.
T
)
{
...
...
@@ -270,8 +271,9 @@ func TestStmtExecWithSelect(t *testing.T) {
err
=
s
.
Exec
()
assert
.
T
(
t
,
err
!=
nil
,
"error expected"
)
//println(err.Error())
if
serr
,
ok
:=
err
.
(
*
StmtError
);
ok
{
assert
.
Equal
(
t
,
Row
,
serr
.
Code
())
assert
.
Equal
(
t
,
ErrSpecific
,
serr
.
Code
())
}
else
{
t
.
Errorf
(
"Expected StmtError but got %s"
,
reflect
.
TypeOf
(
err
))
}
...
...
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