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
6bc819a9
Commit
6bc819a9
authored
Mar 23, 2014
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace ConnError/StmtError pointer by simple value.
parent
3cb36f53
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
23 additions
and
20 deletions
+23
-20
.travis.yml
.travis.yml
+0
-1
busy_test.go
busy_test.go
+2
-2
driver.go
driver.go
+4
-1
sqlite.go
sqlite.go
+7
-7
sqlite_test.go
sqlite_test.go
+2
-2
stmt.go
stmt.go
+3
-3
stmt_test.go
stmt_test.go
+3
-4
trace.go
trace.go
+2
-0
No files found.
.travis.yml
View file @
6bc819a9
language
:
go
go
:
-
1.1
-
tip
before_install
:
-
echo "yes" | sudo add-apt-repository ppa:travis-ci/sqlite3
...
...
busy_test.go
View file @
6bc819a9
...
...
@@ -31,7 +31,7 @@ func TestInterrupt(t *testing.T) {
t
.
Fatalf
(
"got %v; want interrupt"
,
err
)
}
//println(err.Error())
if
se
,
ok
:=
err
.
(
*
StmtError
);
!
ok
||
se
.
Code
()
!=
ErrInterrupt
{
if
se
,
ok
:=
err
.
(
StmtError
);
!
ok
||
se
.
Code
()
!=
ErrInterrupt
{
t
.
Errorf
(
"got %#v; want interrupt"
,
err
)
}
}
...
...
@@ -58,7 +58,7 @@ func TestDefaultBusy(t *testing.T) {
if
err
==
nil
{
t
.
Fatalf
(
"got %v; want lock"
,
err
)
}
if
se
,
ok
:=
err
.
(
*
StmtError
);
!
ok
||
se
.
Code
()
!=
ErrBusy
{
if
se
,
ok
:=
err
.
(
StmtError
);
!
ok
||
se
.
Code
()
!=
ErrBusy
{
t
.
Fatalf
(
"got %#v; want lock"
,
err
)
}
}
...
...
driver.go
View file @
6bc819a9
...
...
@@ -86,7 +86,7 @@ func (d *impl) Open(name string) (driver.Conn, error) {
// Unwrap gives access to underlying driver connection.
func
Unwrap
(
db
*
sql
.
DB
)
*
Conn
{
_
,
err
:=
db
.
Exec
(
"unwrap"
)
if
cerr
,
ok
:=
err
.
(
*
ConnError
);
ok
{
if
cerr
,
ok
:=
err
.
(
ConnError
);
ok
{
return
cerr
.
c
}
return
nil
...
...
@@ -99,6 +99,9 @@ func (c *conn) Exec(query string, args []driver.Value) (driver.Result, error) {
return
nil
,
driver
.
ErrBadConn
}
if
len
(
args
)
==
0
{
if
query
==
"unwrap"
{
return
nil
,
ConnError
{
c
:
c
.
c
}
}
if
err
:=
c
.
c
.
FastExec
(
query
);
err
!=
nil
{
return
nil
,
err
}
...
...
sqlite.go
View file @
6bc819a9
...
...
@@ -32,23 +32,23 @@ type ConnError struct {
}
// Code returns the original SQLite error code (or -1 for errors generated by the Go wrapper)
func
(
e
*
ConnError
)
Code
()
Errno
{
func
(
e
ConnError
)
Code
()
Errno
{
return
e
.
code
}
// ExtendedCode returns the SQLite extended error code.
// (See http://www.sqlite.org/c3ref/errcode.html)
// FIXME 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 this method.
func
(
e
*
ConnError
)
ExtendedCode
()
int
{
func
(
e
ConnError
)
ExtendedCode
()
int
{
return
int
(
C
.
sqlite3_extended_errcode
(
e
.
c
.
db
))
}
// Filename returns database file name from which the error comes from.
func
(
e
*
ConnError
)
Filename
()
string
{
func
(
e
ConnError
)
Filename
()
string
{
return
e
.
c
.
Filename
(
"main"
)
}
func
(
e
*
ConnError
)
Error
()
string
{
// FIXME code.Error() & e.msg are often redundant...
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
.
msg
,
e
.
details
,
e
.
code
.
Error
())
}
else
if
len
(
e
.
msg
)
>
0
{
...
...
@@ -115,7 +115,7 @@ func (c *Conn) error(rv C.int, details ...string) error {
if
rv
==
C
.
SQLITE_OK
{
return
nil
}
err
:=
&
ConnError
{
c
:
c
,
code
:
Errno
(
rv
),
msg
:
C
.
GoString
(
C
.
sqlite3_errmsg
(
c
.
db
))}
err
:=
ConnError
{
c
:
c
,
code
:
Errno
(
rv
),
msg
:
C
.
GoString
(
C
.
sqlite3_errmsg
(
c
.
db
))}
if
len
(
details
)
>
0
{
err
.
details
=
details
[
0
]
}
...
...
@@ -123,7 +123,7 @@ func (c *Conn) error(rv C.int, details ...string) error {
}
func
(
c
*
Conn
)
specificError
(
msg
string
,
a
...
interface
{})
error
{
return
&
ConnError
{
c
:
c
,
code
:
ErrSpecific
,
msg
:
fmt
.
Sprintf
(
msg
,
a
...
)}
return
ConnError
{
c
:
c
,
code
:
ErrSpecific
,
msg
:
fmt
.
Sprintf
(
msg
,
a
...
)}
}
// LastError returns the error for the most recent failed sqlite3_* API call associated with a database connection.
...
...
@@ -136,7 +136,7 @@ func (c *Conn) LastError() error {
if
errorCode
==
C
.
SQLITE_OK
{
return
nil
}
return
&
ConnError
{
c
:
c
,
code
:
Errno
(
errorCode
),
msg
:
C
.
GoString
(
C
.
sqlite3_errmsg
(
c
.
db
))}
return
ConnError
{
c
:
c
,
code
:
Errno
(
errorCode
),
msg
:
C
.
GoString
(
C
.
sqlite3_errmsg
(
c
.
db
))}
}
// Conn represents a database connection handle.
...
...
sqlite_test.go
View file @
6bc819a9
...
...
@@ -193,7 +193,7 @@ func TestConnExecWithSelect(t *testing.T) {
err
:=
db
.
Exec
(
"SELECT 1"
)
assert
.
T
(
t
,
err
!=
nil
,
"error expected"
)
if
serr
,
ok
:=
err
.
(
*
StmtError
);
ok
{
if
serr
,
ok
:=
err
.
(
StmtError
);
ok
{
assert
.
Equal
(
t
,
ErrSpecific
,
serr
.
Code
())
}
else
{
t
.
Errorf
(
"got %s; want StmtError"
,
reflect
.
TypeOf
(
err
))
...
...
@@ -270,7 +270,7 @@ func TestCommitMisuse(t *testing.T) {
err
:=
db
.
Commit
()
assert
.
T
(
t
,
err
!=
nil
,
"error expected"
)
if
cerr
,
ok
:=
err
.
(
*
ConnError
);
ok
{
if
cerr
,
ok
:=
err
.
(
ConnError
);
ok
{
assert
.
Equal
(
t
,
ErrError
,
cerr
.
Code
())
assert
.
Equal
(
t
,
1
,
cerr
.
ExtendedCode
())
}
else
{
...
...
stmt.go
View file @
6bc819a9
...
...
@@ -48,7 +48,7 @@ type StmtError struct {
}
// SQL returns the SQL associated with the prepared statement in error.
func
(
e
*
StmtError
)
SQL
()
string
{
func
(
e
StmtError
)
SQL
()
string
{
return
e
.
s
.
SQL
()
}
...
...
@@ -63,11 +63,11 @@ func (s *Stmt) error(rv C.int, details ...string) error {
if
len
(
details
)
>
0
{
err
.
details
=
details
[
0
]
}
return
&
StmtError
{
err
,
s
}
return
StmtError
{
err
,
s
}
}
func
(
s
*
Stmt
)
specificError
(
msg
string
,
a
...
interface
{})
error
{
return
&
StmtError
{
ConnError
{
c
:
s
.
c
,
code
:
ErrSpecific
,
msg
:
fmt
.
Sprintf
(
msg
,
a
...
)},
s
}
return
StmtError
{
ConnError
{
c
:
s
.
c
,
code
:
ErrSpecific
,
msg
:
fmt
.
Sprintf
(
msg
,
a
...
)},
s
}
}
// CheckTypeMismatch enables type check in Scan methods (default true)
...
...
stmt_test.go
View file @
6bc819a9
...
...
@@ -176,7 +176,7 @@ func TestScanCheck(t *testing.T) {
assert
.
T
(
t
,
checkStep
(
t
,
s
))
var
i
int
_
,
err
=
s
.
ScanByIndex
(
0
,
&
i
)
if
serr
,
ok
:=
err
.
(
*
StmtError
);
ok
{
if
serr
,
ok
:=
err
.
(
StmtError
);
ok
{
assert
.
Equal
(
t
,
""
,
serr
.
Filename
())
assert
.
Equal
(
t
,
ErrSpecific
,
serr
.
Code
())
assert
.
Equal
(
t
,
s
.
SQL
(),
serr
.
SQL
())
...
...
@@ -318,7 +318,6 @@ func TestStmtWithClosedDb(t *testing.T) {
s
,
err
:=
db
.
Prepare
(
"SELECT 1"
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
assert
.
Equal
(
t
,
db
,
s
.
Conn
(),
"conn"
)
defer
s
.
Finalize
()
err
=
db
.
Close
()
checkNoError
(
t
,
err
,
"close error: %s"
)
...
...
@@ -339,7 +338,7 @@ func TestStmtExecWithSelect(t *testing.T) {
err
=
s
.
Exec
()
assert
.
T
(
t
,
err
!=
nil
,
"error expected"
)
//println(err.Error())
if
serr
,
ok
:=
err
.
(
*
StmtError
);
ok
{
if
serr
,
ok
:=
err
.
(
StmtError
);
ok
{
assert
.
Equal
(
t
,
ErrSpecific
,
serr
.
Code
())
}
else
{
t
.
Errorf
(
"got %s; want StmtError"
,
reflect
.
TypeOf
(
err
))
...
...
@@ -384,7 +383,7 @@ func TestStmtSelectWithInsert(t *testing.T) {
exists
,
err
:=
s
.
SelectOneRow
()
assert
.
T
(
t
,
err
!=
nil
,
"error expected"
)
//println(err.Error())
if
serr
,
ok
:=
err
.
(
*
StmtError
);
ok
{
if
serr
,
ok
:=
err
.
(
StmtError
);
ok
{
assert
.
Equal
(
t
,
ErrSpecific
,
serr
.
Code
())
}
else
{
t
.
Errorf
(
"got %s; want StmtError"
,
reflect
.
TypeOf
(
err
))
...
...
trace.go
View file @
6bc819a9
...
...
@@ -391,6 +391,8 @@ func ConfigLog(f Logger, udp interface{}) error {
return
Errno
(
rv
)
}
// ExplainQueryPlan outputs the corresponding EXPLAIN QUERY PLAN report to the specified writer
// (See http://sqlite.org/eqp.html)
func
(
s
*
Stmt
)
ExplainQueryPlan
(
w
io
.
Writer
)
error
{
sql
:=
s
.
SQL
()
if
len
(
sql
)
==
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