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
6f513732
Commit
6f513732
authored
Dec 25, 2011
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve error handling by giving access to details.
parent
1624e5b0
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
221 additions
and
141 deletions
+221
-141
.gitignore
.gitignore
+1
-0
driver.go
driver.go
+0
-1
sqlite.go
sqlite.go
+156
-116
sqlite_test.go
sqlite_test.go
+61
-23
trace.go
trace.go
+2
-0
trace_test.go
trace_test.go
+1
-1
No files found.
.gitignore
View file @
6f513732
...
@@ -4,3 +4,4 @@ _testmain.go
...
@@ -4,3 +4,4 @@ _testmain.go
_obj
_obj
_test
_test
*.swp
*.swp
_cgo_*
\ No newline at end of file
driver.go
View file @
6f513732
...
@@ -15,7 +15,6 @@ func init() {
...
@@ -15,7 +15,6 @@ func init() {
}
}
type
Driver
struct
{
type
Driver
struct
{
}
}
type
connImpl
struct
{
type
connImpl
struct
{
c
*
Conn
c
*
Conn
...
...
sqlite.go
View file @
6f513732
This diff is collapsed.
Click to expand it.
sqlite_test.go
View file @
6f513732
...
@@ -2,6 +2,7 @@ package sqlite_test
...
@@ -2,6 +2,7 @@ package sqlite_test
import
(
import
(
.
"github.com/gwenn/gosqlite"
.
"github.com/gwenn/gosqlite"
"reflect"
"strings"
"strings"
"testing"
"testing"
)
)
...
@@ -53,6 +54,14 @@ func TestEnableFKey(t *testing.T) {
...
@@ -53,6 +54,14 @@ func TestEnableFKey(t *testing.T) {
}
}
}
}
func
TestEnableExtendedResultCodes
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
if
err
:=
db
.
EnableExtendedResultCodes
(
true
);
err
!=
nil
{
t
.
Fatalf
(
"cannot enabled extended result codes: %s"
,
err
)
}
}
func
TestIntegrityCheck
(
t
*
testing
.
T
)
{
func
TestIntegrityCheck
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
db
:=
open
(
t
)
defer
db
.
Close
()
defer
db
.
Close
()
...
@@ -106,7 +115,7 @@ func TestInsert(t *testing.T) {
...
@@ -106,7 +115,7 @@ func TestInsert(t *testing.T) {
}
}
c
:=
db
.
Changes
()
c
:=
db
.
Changes
()
if
c
!=
1
{
if
c
!=
1
{
t
.
Errorf
(
"insert error: %d
<>
1"
,
c
)
t
.
Errorf
(
"insert error: %d
but got
1"
,
c
)
}
}
}
}
if
err
:=
db
.
Commit
();
err
!=
nil
{
if
err
:=
db
.
Commit
();
err
!=
nil
{
...
@@ -115,7 +124,7 @@ func TestInsert(t *testing.T) {
...
@@ -115,7 +124,7 @@ func TestInsert(t *testing.T) {
lastId
:=
db
.
LastInsertRowid
()
lastId
:=
db
.
LastInsertRowid
()
if
lastId
!=
1000
{
if
lastId
!=
1000
{
t
.
Errorf
(
"last insert row id error: %d
<>
1000"
,
lastId
)
t
.
Errorf
(
"last insert row id error: %d
but got
1000"
,
lastId
)
}
}
cs
,
_
:=
db
.
Prepare
(
"SELECT COUNT(*) FROM test"
)
cs
,
_
:=
db
.
Prepare
(
"SELECT COUNT(*) FROM test"
)
...
@@ -123,11 +132,11 @@ func TestInsert(t *testing.T) {
...
@@ -123,11 +132,11 @@ func TestInsert(t *testing.T) {
paramCount
:=
cs
.
BindParameterCount
()
paramCount
:=
cs
.
BindParameterCount
()
if
paramCount
!=
0
{
if
paramCount
!=
0
{
t
.
Errorf
(
"bind parameter count error: %d
<>
0"
,
paramCount
)
t
.
Errorf
(
"bind parameter count error: %d
but got
0"
,
paramCount
)
}
}
columnCount
:=
cs
.
ColumnCount
()
columnCount
:=
cs
.
ColumnCount
()
if
columnCount
!=
1
{
if
columnCount
!=
1
{
t
.
Errorf
(
"column count error: %d
<>
1"
,
columnCount
)
t
.
Errorf
(
"column count error: %d
but got
1"
,
columnCount
)
}
}
if
!
Must
(
cs
.
Next
())
{
if
!
Must
(
cs
.
Next
())
{
...
@@ -162,15 +171,15 @@ func TestInsertWithStatement(t *testing.T) {
...
@@ -162,15 +171,15 @@ func TestInsertWithStatement(t *testing.T) {
paramCount
:=
s
.
BindParameterCount
()
paramCount
:=
s
.
BindParameterCount
()
if
paramCount
!=
3
{
if
paramCount
!=
3
{
t
.
Errorf
(
"bind parameter count error: %d
<>
3"
,
paramCount
)
t
.
Errorf
(
"bind parameter count error: %d
but got
3"
,
paramCount
)
}
}
firstParamName
,
berr
:=
s
.
BindParameterName
(
1
)
firstParamName
,
berr
:=
s
.
BindParameterName
(
1
)
if
firstParamName
!=
":f"
{
if
firstParamName
!=
":f"
{
t
.
Errorf
(
"bind parameter name error: %s
<>
':f' (%s)"
,
firstParamName
,
berr
)
t
.
Errorf
(
"bind parameter name error: %s
but got
':f' (%s)"
,
firstParamName
,
berr
)
}
}
lastParamIndex
,
berr
:=
s
.
BindParameterIndex
(
":s"
)
lastParamIndex
,
berr
:=
s
.
BindParameterIndex
(
":s"
)
if
lastParamIndex
!=
3
{
if
lastParamIndex
!=
3
{
t
.
Errorf
(
"bind parameter name error: %d
<>
3 (%s)"
,
lastParamIndex
,
berr
)
t
.
Errorf
(
"bind parameter name error: %d
but got
3 (%s)"
,
lastParamIndex
,
berr
)
}
}
db
.
Begin
()
db
.
Begin
()
...
@@ -180,7 +189,7 @@ func TestInsertWithStatement(t *testing.T) {
...
@@ -180,7 +189,7 @@ func TestInsertWithStatement(t *testing.T) {
t
.
Fatalf
(
"insert error: %s"
,
ierr
)
t
.
Fatalf
(
"insert error: %s"
,
ierr
)
}
}
if
c
!=
1
{
if
c
!=
1
{
t
.
Errorf
(
"insert error: %d
<>
1"
,
c
)
t
.
Errorf
(
"insert error: %d
but got
1"
,
c
)
}
}
}
}
...
@@ -209,11 +218,11 @@ func TestInsertWithStatement(t *testing.T) {
...
@@ -209,11 +218,11 @@ func TestInsertWithStatement(t *testing.T) {
defer
rs
.
Finalize
()
defer
rs
.
Finalize
()
columnCount
:=
rs
.
ColumnCount
()
columnCount
:=
rs
.
ColumnCount
()
if
columnCount
!=
3
{
if
columnCount
!=
3
{
t
.
Errorf
(
"column count error: %d
<>
3"
,
columnCount
)
t
.
Errorf
(
"column count error: %d
but got
3"
,
columnCount
)
}
}
secondColumnName
:=
rs
.
ColumnName
(
1
)
secondColumnName
:=
rs
.
ColumnName
(
1
)
if
secondColumnName
!=
"int_num"
{
if
secondColumnName
!=
"int_num"
{
t
.
Errorf
(
"column name error: %s
<>
'int_num'"
,
secondColumnName
)
t
.
Errorf
(
"column name error: %s
but got
'int_num'"
,
secondColumnName
)
}
}
if
Must
(
rs
.
Next
())
{
if
Must
(
rs
.
Next
())
{
...
@@ -222,13 +231,13 @@ func TestInsertWithStatement(t *testing.T) {
...
@@ -222,13 +231,13 @@ func TestInsertWithStatement(t *testing.T) {
var
sstr
string
var
sstr
string
rs
.
Scan
(
&
fnum
,
&
inum
,
&
sstr
)
rs
.
Scan
(
&
fnum
,
&
inum
,
&
sstr
)
if
fnum
!=
0
{
if
fnum
!=
0
{
t
.
Errorf
(
"Expected 0
<>
%f
\n
"
,
fnum
)
t
.
Errorf
(
"Expected 0
but got
%f
\n
"
,
fnum
)
}
}
if
inum
!=
0
{
if
inum
!=
0
{
t
.
Errorf
(
"Expected 0
<>
%d
\n
"
,
inum
)
t
.
Errorf
(
"Expected 0
but got
%d
\n
"
,
inum
)
}
}
if
sstr
!=
"hello"
{
if
sstr
!=
"hello"
{
t
.
Errorf
(
"Expected 'hello'
<>
%s
\n
"
,
sstr
)
t
.
Errorf
(
"Expected 'hello'
but got
%s
\n
"
,
sstr
)
}
}
}
}
if
Must
(
rs
.
Next
())
{
if
Must
(
rs
.
Next
())
{
...
@@ -237,13 +246,13 @@ func TestInsertWithStatement(t *testing.T) {
...
@@ -237,13 +246,13 @@ func TestInsertWithStatement(t *testing.T) {
var
sstr
string
var
sstr
string
rs
.
NamedScan
(
"a_string"
,
&
sstr
,
"float_num"
,
&
fnum
,
"int_num"
,
&
inum
)
rs
.
NamedScan
(
"a_string"
,
&
sstr
,
"float_num"
,
&
fnum
,
"int_num"
,
&
inum
)
if
fnum
!=
3.14
{
if
fnum
!=
3.14
{
t
.
Errorf
(
"Expected 3.14
<>
%f
\n
"
,
fnum
)
t
.
Errorf
(
"Expected 3.14
but got
%f
\n
"
,
fnum
)
}
}
if
inum
!=
1
{
if
inum
!=
1
{
t
.
Errorf
(
"Expected 1
<>
%d
\n
"
,
inum
)
t
.
Errorf
(
"Expected 1
but got
%d
\n
"
,
inum
)
}
}
if
sstr
!=
"hello"
{
if
sstr
!=
"hello"
{
t
.
Errorf
(
"Expected 'hello'
<>
%s
\n
"
,
sstr
)
t
.
Errorf
(
"Expected 'hello'
but got
%s
\n
"
,
sstr
)
}
}
}
}
if
999
!=
rs
.
Status
(
STMTSTATUS_FULLSCAN_STEP
,
false
)
{
if
999
!=
rs
.
Status
(
STMTSTATUS_FULLSCAN_STEP
,
false
)
{
...
@@ -305,7 +314,7 @@ func TestBlob(t *testing.T) {
...
@@ -305,7 +314,7 @@ func TestBlob(t *testing.T) {
t
.
Fatalf
(
"blob read error: %s"
,
err
)
t
.
Fatalf
(
"blob read error: %s"
,
err
)
}
}
if
n
!=
10
{
if
n
!=
10
{
t
.
Fatalf
(
"Expected 10 bytes
<>
%d"
,
n
)
t
.
Fatalf
(
"Expected 10 bytes
but got
%d"
,
n
)
}
}
//fmt.Printf("%#v\n", content)
//fmt.Printf("%#v\n", content)
br
.
Close
()
br
.
Close
()
...
@@ -328,19 +337,19 @@ func TestScanColumn(t *testing.T) {
...
@@ -328,19 +337,19 @@ func TestScanColumn(t *testing.T) {
if
null
{
if
null
{
t
.
Errorf
(
"Expected not null value"
)
t
.
Errorf
(
"Expected not null value"
)
}
else
if
i1
!=
1
{
}
else
if
i1
!=
1
{
t
.
Errorf
(
"Expected 1
<>
%d
\n
"
,
i1
)
t
.
Errorf
(
"Expected 1
but got
%d
\n
"
,
i1
)
}
}
null
=
Must
(
s
.
ScanByIndex
(
1
,
&
i2
/*, true*/
))
null
=
Must
(
s
.
ScanByIndex
(
1
,
&
i2
/*, true*/
))
if
!
null
{
if
!
null
{
t
.
Errorf
(
"Expected null value"
)
t
.
Errorf
(
"Expected null value"
)
}
else
if
i2
!=
0
{
}
else
if
i2
!=
0
{
t
.
Errorf
(
"Expected 0
<>
%d
\n
"
,
i2
)
t
.
Errorf
(
"Expected 0
but got
%d
\n
"
,
i2
)
}
}
null
=
Must
(
s
.
ScanByIndex
(
2
,
&
i3
/*, true*/
))
null
=
Must
(
s
.
ScanByIndex
(
2
,
&
i3
/*, true*/
))
if
null
{
if
null
{
t
.
Errorf
(
"Expected not null value"
)
t
.
Errorf
(
"Expected not null value"
)
}
else
if
i3
!=
0
{
}
else
if
i3
!=
0
{
t
.
Errorf
(
"Expected 0
<>
%d
\n
"
,
i3
)
t
.
Errorf
(
"Expected 0
but got
%d
\n
"
,
i3
)
}
}
}
}
...
@@ -361,19 +370,48 @@ func TestNamedScanColumn(t *testing.T) {
...
@@ -361,19 +370,48 @@ func TestNamedScanColumn(t *testing.T) {
if
null
{
if
null
{
t
.
Errorf
(
"Expected not null value"
)
t
.
Errorf
(
"Expected not null value"
)
}
else
if
i1
!=
1
{
}
else
if
i1
!=
1
{
t
.
Errorf
(
"Expected 1
<>
%d
\n
"
,
i1
)
t
.
Errorf
(
"Expected 1
but got
%d
\n
"
,
i1
)
}
}
null
=
Must
(
s
.
ScanByName
(
"i2"
,
&
i2
/*, true*/
))
null
=
Must
(
s
.
ScanByName
(
"i2"
,
&
i2
/*, true*/
))
if
!
null
{
if
!
null
{
t
.
Errorf
(
"Expected null value"
)
t
.
Errorf
(
"Expected null value"
)
}
else
if
i2
!=
0
{
}
else
if
i2
!=
0
{
t
.
Errorf
(
"Expected 0
<>
%d
\n
"
,
i2
)
t
.
Errorf
(
"Expected 0
but got
%d
\n
"
,
i2
)
}
}
null
=
Must
(
s
.
ScanByName
(
"i3"
,
&
i3
/*, true*/
))
null
=
Must
(
s
.
ScanByName
(
"i3"
,
&
i3
/*, true*/
))
if
null
{
if
null
{
t
.
Errorf
(
"Expected not null value"
)
t
.
Errorf
(
"Expected not null value"
)
}
else
if
i3
!=
0
{
}
else
if
i3
!=
0
{
t
.
Errorf
(
"Expected 0 <> %d
\n
"
,
i3
)
t
.
Errorf
(
"Expected 0 but got %d
\n
"
,
i3
)
}
}
func
TestScanCheck
(
t
*
testing
.
T
)
{
db
:=
open
(
t
)
defer
db
.
Close
()
s
,
err
:=
db
.
Prepare
(
"select 'hello'"
)
if
err
!=
nil
{
t
.
Fatalf
(
"prepare error: %s"
,
err
)
}
defer
s
.
Finalize
()
if
!
Must
(
s
.
Next
())
{
t
.
Fatal
(
"no result"
)
}
var
i
int
_
,
err
=
s
.
ScanByIndex
(
0
,
&
i
)
if
serr
,
ok
:=
err
.
(
*
StmtError
);
ok
{
if
serr
.
Filename
()
!=
""
{
t
.
Errorf
(
"Expected '' but got '%s'"
,
serr
.
Filename
())
}
if
serr
.
Code
()
!=
ErrSpecific
{
t
.
Errorf
(
"Expected %s but got %s"
,
ErrSpecific
,
serr
.
Code
())
}
if
serr
.
SQL
()
!=
s
.
SQL
()
{
t
.
Errorf
(
"Expected %s but got %s"
,
s
.
SQL
(),
serr
.
SQL
())
}
}
else
{
t
.
Errorf
(
"Expected StmtError but got %s"
,
reflect
.
TypeOf
(
err
))
}
}
}
}
...
...
trace.go
View file @
6f513732
...
@@ -265,6 +265,7 @@ func (s *Stmt) Status(op StmtStatus, reset bool) int {
...
@@ -265,6 +265,7 @@ func (s *Stmt) Status(op StmtStatus, reset bool) int {
func
MemoryUsed
()
int64
{
func
MemoryUsed
()
int64
{
return
int64
(
C
.
sqlite3_memory_used
())
return
int64
(
C
.
sqlite3_memory_used
())
}
}
// Memory allocator statistics
// Memory allocator statistics
// Calls sqlite3_memory_highwater: http://sqlite.org/c3ref/memory_highwater.html
// Calls sqlite3_memory_highwater: http://sqlite.org/c3ref/memory_highwater.html
func
MemoryHighwater
(
reset
bool
)
int64
{
func
MemoryHighwater
(
reset
bool
)
int64
{
...
@@ -276,6 +277,7 @@ func MemoryHighwater(reset bool) int64 {
...
@@ -276,6 +277,7 @@ func MemoryHighwater(reset bool) int64 {
func
SoftHeapLimit
()
int64
{
func
SoftHeapLimit
()
int64
{
return
SetSoftHeapLimit
(
-
1
)
return
SetSoftHeapLimit
(
-
1
)
}
}
// Impose a limit on heap size
// Impose a limit on heap size
// Calls http://sqlite.org/c3ref/soft_heap_limit64.html
// Calls http://sqlite.org/c3ref/soft_heap_limit64.html
func
SetSoftHeapLimit
(
n
int64
)
int64
{
func
SetSoftHeapLimit
(
n
int64
)
int64
{
...
...
trace_test.go
View file @
6f513732
...
@@ -20,7 +20,7 @@ func authorizer(d interface{}, action Action, arg1, arg2, dbName, triggerName st
...
@@ -20,7 +20,7 @@ func authorizer(d interface{}, action Action, arg1, arg2, dbName, triggerName st
}
}
func
profile
(
d
interface
{},
sql
string
,
nanoseconds
uint64
)
{
func
profile
(
d
interface
{},
sql
string
,
nanoseconds
uint64
)
{
//fmt.Printf("%s: %s = %d µs\n", d, sql, nanoseconds/1
0
e3)
//fmt.Printf("%s: %s = %d µs\n", d, sql, nanoseconds/1e3)
}
}
func
progressHandler
(
d
interface
{})
bool
{
func
progressHandler
(
d
interface
{})
bool
{
...
...
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