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
c0e5c663
Commit
c0e5c663
authored
Dec 17, 2012
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensures pragma statements are not cached when using helpers.
parent
ec392678
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
9 deletions
+31
-9
README.md
README.md
+1
-0
pragma.go
pragma.go
+27
-8
sqlite_test.go
sqlite_test.go
+3
-1
No files found.
README.md
View file @
c0e5c663
Yet another SQLite binding based on:
-
original
[
Russ Cox's
](
http://code.google.com/p/gosqlite/
)
implementation,
-
the
[
Patrick Crosby's
](
https://github.com/patrickxb/fgosqlite/
)
fork.
This binding implements the "database/sql/driver" interface.
See
[
package documentation
](
http://go.pkgdoc.org/github.com/gwenn/gosqlite
)
.
...
...
pragma.go
View file @
c0e5c663
...
...
@@ -6,6 +6,7 @@ package sqlite
import
(
"fmt"
"io"
)
// IntegrityCheck checks database integrity.
...
...
@@ -21,7 +22,7 @@ func (c *Conn) IntegrityCheck(dbName string, max int, quick bool) error {
}
pragmaName
:=
fmt
.
Sprintf
(
"%s_check(%d)"
,
prefix
,
max
)
var
msg
string
err
:=
c
.
O
neValue
(
pragma
(
dbName
,
pragmaName
),
&
msg
)
err
:=
c
.
o
neValue
(
pragma
(
dbName
,
pragmaName
),
&
msg
)
if
err
!=
nil
{
return
err
}
...
...
@@ -36,7 +37,7 @@ func (c *Conn) IntegrityCheck(dbName string, max int, quick bool) error {
// (See http://sqlite.org/pragma.html#pragma_encoding)
func
(
c
*
Conn
)
Encoding
(
dbName
string
)
(
string
,
error
)
{
var
encoding
string
err
:=
c
.
O
neValue
(
pragma
(
dbName
,
"encoding"
),
&
encoding
)
err
:=
c
.
o
neValue
(
pragma
(
dbName
,
"encoding"
),
&
encoding
)
if
err
!=
nil
{
return
""
,
err
}
...
...
@@ -48,7 +49,7 @@ func (c *Conn) Encoding(dbName string) (string, error) {
// (See http://sqlite.org/pragma.html#pragma_schema_version)
func
(
c
*
Conn
)
SchemaVersion
(
dbName
string
)
(
int
,
error
)
{
var
version
int
err
:=
c
.
O
neValue
(
pragma
(
dbName
,
"schema_version"
),
&
version
)
err
:=
c
.
o
neValue
(
pragma
(
dbName
,
"schema_version"
),
&
version
)
if
err
!=
nil
{
return
-
1
,
err
}
...
...
@@ -67,7 +68,7 @@ func (c *Conn) SetRecursiveTriggers(dbName string, on bool) error {
// (See http://sqlite.org/pragma.html#pragma_journal_mode)
func
(
c
*
Conn
)
JournalMode
(
dbName
string
)
(
string
,
error
)
{
var
mode
string
err
:=
c
.
O
neValue
(
pragma
(
dbName
,
"journal_mode"
),
&
mode
)
err
:=
c
.
o
neValue
(
pragma
(
dbName
,
"journal_mode"
),
&
mode
)
if
err
!=
nil
{
return
""
,
err
}
...
...
@@ -79,7 +80,7 @@ func (c *Conn) JournalMode(dbName string) (string, error) {
// (See http://sqlite.org/pragma.html#pragma_journal_mode)
func
(
c
*
Conn
)
SetJournalMode
(
dbName
,
mode
string
)
(
string
,
error
)
{
var
newMode
string
err
:=
c
.
O
neValue
(
pragma
(
dbName
,
Mprintf
(
"journal_mode=%Q"
,
mode
)),
&
newMode
)
err
:=
c
.
o
neValue
(
pragma
(
dbName
,
Mprintf
(
"journal_mode=%Q"
,
mode
)),
&
newMode
)
if
err
!=
nil
{
return
""
,
err
}
...
...
@@ -91,7 +92,7 @@ func (c *Conn) SetJournalMode(dbName, mode string) (string, error) {
// (See http://sqlite.org/pragma.html#pragma_locking_mode)
func
(
c
*
Conn
)
LockingMode
(
dbName
string
)
(
string
,
error
)
{
var
mode
string
err
:=
c
.
O
neValue
(
pragma
(
dbName
,
"locking_mode"
),
&
mode
)
err
:=
c
.
o
neValue
(
pragma
(
dbName
,
"locking_mode"
),
&
mode
)
if
err
!=
nil
{
return
""
,
err
}
...
...
@@ -103,7 +104,7 @@ func (c *Conn) LockingMode(dbName string) (string, error) {
// (See http://sqlite.org/pragma.html#pragma_locking_mode)
func
(
c
*
Conn
)
SetLockingMode
(
dbName
,
mode
string
)
(
string
,
error
)
{
var
newMode
string
err
:=
c
.
O
neValue
(
pragma
(
dbName
,
Mprintf
(
"locking_mode=%Q"
,
mode
)),
&
newMode
)
err
:=
c
.
o
neValue
(
pragma
(
dbName
,
Mprintf
(
"locking_mode=%Q"
,
mode
)),
&
newMode
)
if
err
!=
nil
{
return
""
,
err
}
...
...
@@ -115,7 +116,7 @@ func (c *Conn) SetLockingMode(dbName, mode string) (string, error) {
// (See http://sqlite.org/pragma.html#pragma_synchronous)
func
(
c
*
Conn
)
Synchronous
(
dbName
string
)
(
int
,
error
)
{
var
mode
int
err
:=
c
.
O
neValue
(
pragma
(
dbName
,
"synchronous"
),
&
mode
)
err
:=
c
.
o
neValue
(
pragma
(
dbName
,
"synchronous"
),
&
mode
)
if
err
!=
nil
{
return
-
1
,
err
}
...
...
@@ -135,3 +136,21 @@ func pragma(dbName, pragmaName string) string {
}
return
Mprintf
(
"PRAGMA %Q."
+
pragmaName
,
dbName
)
}
func
(
c
*
Conn
)
oneValue
(
query
string
,
value
interface
{},
args
...
interface
{})
error
{
// no cache
s
,
err
:=
c
.
prepare
(
query
,
args
...
)
if
err
!=
nil
{
return
err
}
defer
func
()
{
s
.
Reset
()
s
.
finalize
()
}()
b
,
err
:=
s
.
Next
()
if
err
!=
nil
{
return
err
}
else
if
!
b
{
return
io
.
EOF
}
return
s
.
Scan
(
value
)
}
sqlite_test.go
View file @
c0e5c663
...
...
@@ -18,11 +18,13 @@ func checkNoError(t *testing.T, err error, format string) {
}
func
open
(
t
*
testing
.
T
)
*
Conn
{
db
,
err
:=
Open
(
":memory:"
,
OpenReadWrite
,
OpenCreate
,
OpenFullMutex
)
db
,
err
:=
Open
(
":memory:"
,
OpenReadWrite
,
OpenCreate
,
OpenFullMutex
/*OpenNoMutex*/
)
checkNoError
(
t
,
err
,
"couldn't open database file: %s"
)
if
db
==
nil
{
t
.
Fatal
(
"opened database is nil"
)
}
//db.SetLockingMode("", "exclusive")
//db.SetSynchronous("", 0)
//db.Profile(profile, t)
//db.Trace(trace, t)
//db.SetAuthorizer(authorizer, t)
...
...
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