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
4b894bab
Commit
4b894bab
authored
Feb 22, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change Conn#OneValue method signature.
parent
0c9e9523
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
24 deletions
+22
-24
cache.go
cache.go
+2
-2
function_test.go
function_test.go
+5
-3
pragma.go
pragma.go
+10
-13
pragma_test.go
pragma_test.go
+0
-1
sqlite.go
sqlite.go
+5
-5
No files found.
cache.go
View file @
4b894bab
...
...
@@ -10,8 +10,8 @@ import (
)
type
Cache
struct
{
m
sync
.
Mutex
l
*
list
.
List
m
sync
.
Mutex
l
*
list
.
List
MaxSize
int
// Cache turned off when MaxSize <= 0
}
...
...
function_test.go
View file @
4b894bab
...
...
@@ -22,7 +22,8 @@ func TestScalarFunction(t *testing.T) {
defer
db
.
Close
()
err
=
db
.
CreateScalarFunction
(
"half"
,
1
,
nil
,
half
,
nil
)
checkNoError
(
t
,
err
,
"couldn't create function: %s"
)
d
,
err
:=
db
.
OneValue
(
"select half(6)"
)
var
d
float64
err
=
db
.
OneValue
(
"select half(6)"
,
&
d
)
checkNoError
(
t
,
err
,
"couldn't retrieve result: %s"
)
if
d
!=
3.0
{
t
.
Errorf
(
"Expected %f but got %f"
,
3.0
,
d
)
...
...
@@ -115,9 +116,10 @@ func TestSumFunction(t *testing.T) {
defer
db
.
Close
()
err
=
db
.
CreateAggregateFunction
(
"mysum"
,
1
,
nil
,
sumStep
,
sumFinal
,
nil
)
checkNoError
(
t
,
err
,
"couldn't create function: %s"
)
i
,
err
:=
db
.
OneValue
(
"select mysum(i) from (select 2 as i union all select 2)"
)
var
i
int
err
=
db
.
OneValue
(
"select mysum(i) from (select 2 as i union all select 2)"
,
&
i
)
checkNoError
(
t
,
err
,
"couldn't execute statement: %s"
)
if
i
!=
int64
(
4
)
{
if
i
!=
4
{
t
.
Errorf
(
"Expected %d but got %v"
,
4
,
i
)
}
}
...
...
pragma.go
View file @
4b894bab
...
...
@@ -19,7 +19,8 @@ func (c *Conn) IntegrityCheck(max int, quick bool) error {
}
else
{
pragma
=
"integrity"
}
msg
,
err
:=
c
.
OneValue
(
fmt
.
Sprintf
(
"PRAGMA %s_check(%d)"
,
pragma
,
max
))
var
msg
string
err
:=
c
.
OneValue
(
fmt
.
Sprintf
(
"PRAGMA %s_check(%d)"
,
pragma
,
max
),
&
msg
)
if
err
!=
nil
{
return
err
}
...
...
@@ -33,25 +34,21 @@ func (c *Conn) IntegrityCheck(max int, quick bool) error {
// (See http://sqlite.org/pragma.html#pragma_encoding)
// TODO Make possible to specify the database-name (PRAGMA %Q.encoding)
func
(
c
*
Conn
)
Encoding
()
(
string
,
error
)
{
value
,
err
:=
c
.
OneValue
(
"PRAGMA encoding"
)
var
encoding
string
err
:=
c
.
OneValue
(
"PRAGMA encoding"
,
&
encoding
)
if
err
!=
nil
{
return
""
,
err
}
if
encoding
,
ok
:=
value
.
(
string
);
ok
{
return
encoding
,
nil
}
return
""
,
c
.
specificError
(
"Unexpected encoding (%v)"
,
value
)
return
encoding
,
nil
}
// (See http://sqlite.org/pragma.html#pragma_schema_version)
// TODO Make possible to specify the database-name (PRAGMA %Q.schema_version)
func
(
c
*
Conn
)
SchemaVersion
()
(
int64
,
error
)
{
value
,
err
:=
c
.
OneValue
(
"PRAGMA schema_version"
)
func
(
c
*
Conn
)
SchemaVersion
()
(
int
,
error
)
{
var
version
int
err
:=
c
.
OneValue
(
"PRAGMA schema_version"
,
&
version
)
if
err
!=
nil
{
return
-
1
,
err
}
if
version
,
ok
:=
value
.
(
int64
);
ok
{
return
version
,
nil
}
return
-
1
,
c
.
specificError
(
"Unexpected version (%v)"
,
value
)
}
\ No newline at end of file
return
version
,
nil
}
pragma_test.go
View file @
4b894bab
package
sqlite_test
import
(
// . "github.com/gwenn/gosqlite"
"testing"
)
...
...
sqlite.go
View file @
4b894bab
...
...
@@ -378,19 +378,19 @@ func (c *Conn) Exists(query string, args ...interface{}) (bool, error) {
// Use it with SELECT that returns only one row with only one column.
// Returns io.EOF when there is no row.
func
(
c
*
Conn
)
OneValue
(
query
string
,
args
...
interface
{})
(
interface
{},
error
)
{
func
(
c
*
Conn
)
OneValue
(
query
string
,
value
interface
{},
args
...
interface
{})
error
{
s
,
err
:=
c
.
Prepare
(
query
,
args
...
)
if
err
!=
nil
{
return
nil
,
err
return
err
}
defer
s
.
Finalize
()
b
,
err
:=
s
.
Next
()
if
err
!=
nil
{
return
nil
,
err
return
err
}
else
if
!
b
{
return
nil
,
io
.
EOF
return
io
.
EOF
}
return
s
.
Scan
Value
(
0
),
nil
return
s
.
Scan
(
value
)
}
// Count the number of rows modified
...
...
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