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
6394bba8
Commit
6394bba8
authored
Feb 24, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Stmt#Busy method.
parent
e7464b51
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
7 deletions
+18
-7
sqlite.go
sqlite.go
+9
-7
sqlite_test.go
sqlite_test.go
+9
-0
No files found.
sqlite.go
View file @
6394bba8
...
...
@@ -68,7 +68,7 @@ func (e *ConnError) Filename() string {
return
e
.
c
.
Filename
}
func
(
e
*
ConnError
)
Error
()
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
)
}
else
if
len
(
e
.
msg
)
>
0
{
...
...
@@ -126,7 +126,7 @@ var (
ErrNotDB
error
=
Errno
(
C
.
SQLITE_NOTADB
)
/* File opened that is not a database file */
Row
=
Errno
(
C
.
SQLITE_ROW
)
/* sqlite3_step() has another row ready */
Done
=
Errno
(
C
.
SQLITE_DONE
)
/* sqlite3_step() has finished executing */
ErrSpecific
=
Errno
(
-
1
)
/*
Gosqlite
specific error */
ErrSpecific
=
Errno
(
-
1
)
/*
Wrapper
specific error */
)
var
errText
=
map
[
Errno
]
string
{
...
...
@@ -158,7 +158,7 @@ var errText = map[Errno]string{
C
.
SQLITE_NOTADB
:
"File opened that is not a database file"
,
Row
:
"sqlite3_step() has another row ready"
,
Done
:
"sqlite3_step() has finished executing"
,
ErrSpecific
:
"
Gosqlite
specific error"
,
ErrSpecific
:
"
Wrapper
specific error"
,
}
func
(
c
*
Conn
)
error
(
rv
C
.
int
,
details
...
string
)
error
{
...
...
@@ -587,6 +587,7 @@ func (s *Stmt) BindParameterCount() int {
}
// Index of a parameter with a given name (cached)
// The first host parameter has an index of 1, not 0.
// (See http://sqlite.org/c3ref/bind_parameter_index.html)
func
(
s
*
Stmt
)
BindParameterIndex
(
name
string
)
(
int
,
error
)
{
if
s
.
params
==
nil
{
...
...
@@ -601,7 +602,7 @@ func (s *Stmt) BindParameterIndex(name string) (int, error) {
defer
C
.
free
(
unsafe
.
Pointer
(
cname
))
index
=
int
(
C
.
sqlite3_bind_parameter_index
(
s
.
stmt
,
cname
))
if
index
==
0
{
return
-
1
,
s
.
specificError
(
"invalid parameter name: %s"
,
name
)
return
index
,
s
.
specificError
(
"invalid parameter name: %s"
,
name
)
}
s
.
params
[
name
]
=
index
return
index
,
nil
...
...
@@ -883,6 +884,7 @@ func (s *Stmt) SQL() string {
}
// Column index in a result set for a given column name
// The leftmost column is number 0.
// Must scan all columns (but result is cached).
// (See http://sqlite.org/c3ref/column_name.html)
func
(
s
*
Stmt
)
ColumnIndex
(
name
string
)
(
int
,
error
)
{
...
...
@@ -897,7 +899,7 @@ func (s *Stmt) ColumnIndex(name string) (int, error) {
if
ok
{
return
index
,
nil
}
return
0
,
s
.
specificError
(
"invalid column name: %s"
,
name
)
return
-
1
,
s
.
specificError
(
"invalid column name: %s"
,
name
)
}
// Returns true when column is null and Stmt.CheckNull is activated.
...
...
@@ -1206,9 +1208,9 @@ func (s *Stmt) checkTypeMismatch(source, target Type) error {
// Determine if a prepared statement has been reset
// (See http://sqlite.org/c3ref/stmt_busy.html)
/*
func (s *Stmt) Busy() bool {
func
(
s
*
Stmt
)
Busy
()
bool
{
return
C
.
sqlite3_stmt_busy
(
s
.
stmt
)
!=
0
}
*/
}
// Destroy a prepared statement
// (See http://sqlite.org/c3ref/finalize.html)
...
...
sqlite_test.go
View file @
6394bba8
...
...
@@ -129,6 +129,12 @@ func TestInsert(t *testing.T) {
if
i
!=
1000
{
t
.
Errorf
(
"count should be 1000, but it is %d"
,
i
)
}
if
Must
(
cs
.
Next
())
{
t
.
Fatal
(
"Only one row expected"
)
}
if
cs
.
Busy
()
{
t
.
Error
(
"Statement not reset"
)
}
}
func
TestInsertWithStatement
(
t
*
testing
.
T
)
{
...
...
@@ -166,6 +172,9 @@ func TestInsertWithStatement(t *testing.T) {
if
c
!=
1
{
t
.
Errorf
(
"insert error: %d but got 1"
,
c
)
}
if
s
.
Busy
()
{
t
.
Errorf
(
"Statement not reset"
)
}
}
checkNoError
(
t
,
db
.
Commit
(),
"Error: %s"
)
...
...
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