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
900751f4
Commit
900751f4
authored
Feb 20, 2018
by
gwenn
Committed by
GitHub
Feb 20, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14 from navytux/y/open-error
open: Fix error message
parents
3415a54c
0d47edb6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
8 deletions
+22
-8
sqlite.go
sqlite.go
+22
-8
No files found.
sqlite.go
View file @
900751f4
...
@@ -40,10 +40,23 @@ type OpenError struct {
...
@@ -40,10 +40,23 @@ type OpenError struct {
}
}
func
(
e
OpenError
)
Error
()
string
{
func
(
e
OpenError
)
Error
()
string
{
file
:=
e
.
Filename
if
file
==
""
{
file
=
"(temporary)"
}
s
:=
fmt
.
Sprintf
(
"%s: "
,
file
)
codeErr
:=
e
.
Code
.
Error
()
if
len
(
e
.
Msg
)
>
0
{
if
len
(
e
.
Msg
)
>
0
{
return
fmt
.
Sprintf
(
"%s (%s)"
,
e
.
Msg
,
e
.
Code
.
Error
())
s
+=
e
.
Msg
// error code and msg are often redundant but not always
// (see sqlite3ErrorWithMsg usages in SQLite3 sources)
if
codeErr
!=
e
.
Msg
{
s
+=
fmt
.
Sprintf
(
" (%s)"
,
codeErr
)
}
}
else
{
s
+=
codeErr
}
}
return
e
.
Code
.
Error
()
return
s
}
}
// ConnError is a wrapper for all SQLite connection related error.
// ConnError is a wrapper for all SQLite connection related error.
...
@@ -250,16 +263,17 @@ func OpenVfs(filename string, vfsname string, flags ...OpenFlag) (*Conn, error)
...
@@ -250,16 +263,17 @@ func OpenVfs(filename string, vfsname string, flags ...OpenFlag) (*Conn, error)
}
}
rv
:=
C
.
sqlite3_open_v2
(
cname
,
&
db
,
C
.
int
(
openFlags
),
vfs
)
rv
:=
C
.
sqlite3_open_v2
(
cname
,
&
db
,
C
.
int
(
openFlags
),
vfs
)
if
rv
!=
C
.
SQLITE_OK
{
if
rv
!=
C
.
SQLITE_OK
{
if
db
!=
nil
{
// try to extract futher details from db...
err
:=
OpenError
{
err
:=
OpenError
{
Code
:
Errno
(
rv
),
Code
:
Errno
(
rv
),
ExtendedCode
:
int
(
C
.
sqlite3_extended_errcode
(
db
)),
Msg
:
C
.
GoString
(
C
.
sqlite3_errmsg
(
db
)),
Filename
:
filename
,
Filename
:
filename
,
}
}
if
db
!=
nil
{
// try to extract futher details from db...
err
.
ExtendedCode
=
int
(
C
.
sqlite3_extended_errcode
(
db
))
err
.
Msg
=
C
.
GoString
(
C
.
sqlite3_errmsg
(
db
))
C
.
sqlite3_close
(
db
)
C
.
sqlite3_close
(
db
)
return
nil
,
err
return
nil
,
err
}
}
return
nil
,
Errno
(
rv
)
return
nil
,
err
}
}
if
db
==
nil
{
if
db
==
nil
{
return
nil
,
errors
.
New
(
"sqlite succeeded without returning a database"
)
return
nil
,
errors
.
New
(
"sqlite succeeded without returning a database"
)
...
...
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