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
4eef7ca9
Commit
4eef7ca9
authored
Aug 27, 2011
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds support to open flags.
parent
5622cb51
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
10 deletions
+26
-10
sqlite.go
sqlite.go
+25
-9
sqlite_test.go
sqlite_test.go
+1
-1
No files found.
sqlite.go
View file @
4eef7ca9
...
...
@@ -143,23 +143,39 @@ func Version() string {
return
C
.
GoString
(
p
)
}
// ':memory:' for memory db
// '' for temp db
type
OpenFlag
int
const
(
OPEN_READONLY
OpenFlag
=
C
.
SQLITE_OPEN_READONLY
OPEN_READWRITE
OpenFlag
=
C
.
SQLITE_OPEN_READWRITE
OPEN_CREATE
OpenFlag
=
C
.
SQLITE_OPEN_CREATE
OPEN_URI
OpenFlag
=
C
.
SQLITE_OPEN_URI
OPEN_NOMUTEX
OpenFlag
=
C
.
SQLITE_OPEN_NOMUTEX
OPEN_FULLMUTEX
OpenFlag
=
C
.
SQLITE_OPEN_FULLMUTEX
OPEN_SHAREDCACHE
OpenFlag
=
C
.
SQLITE_OPEN_SHAREDCACHE
OPEN_PRIVATECACHE
OpenFlag
=
C
.
SQLITE_OPEN_PRIVATECACHE
)
// ":memory:" for memory db
// "" for temp file db
// Calls sqlite3_open_v2: http://sqlite.org/c3ref/open.html
func
Open
(
filename
string
)
(
*
Conn
,
os
.
Error
)
{
// TODO flags parameter + constants
func
Open
(
filename
string
,
flags
...
OpenFlag
)
(
*
Conn
,
os
.
Error
)
{
if
C
.
sqlite3_threadsafe
()
==
0
{
return
nil
,
os
.
NewError
(
"sqlite library was not compiled for thread-safe operation"
)
}
var
openFlags
int
if
len
(
flags
)
>
0
{
for
_
,
flag
:=
range
flags
{
openFlags
|=
int
(
flag
)
}
}
else
{
openFlags
=
C
.
SQLITE_OPEN_FULLMUTEX
|
C
.
SQLITE_OPEN_READWRITE
|
C
.
SQLITE_OPEN_CREATE
}
var
db
*
C
.
sqlite3
name
:=
C
.
CString
(
filename
)
defer
C
.
free
(
unsafe
.
Pointer
(
name
))
rv
:=
C
.
sqlite3_open_v2
(
name
,
&
db
,
C
.
SQLITE_OPEN_FULLMUTEX
|
C
.
SQLITE_OPEN_READWRITE
|
C
.
SQLITE_OPEN_CREATE
|
C
.
SQLITE_OPEN_URI
,
nil
)
rv
:=
C
.
sqlite3_open_v2
(
name
,
&
db
,
C
.
int
(
openFlags
),
nil
)
if
rv
!=
C
.
SQLITE_OK
{
if
db
!=
nil
{
C
.
sqlite3_close
(
db
)
...
...
sqlite_test.go
View file @
4eef7ca9
...
...
@@ -17,7 +17,7 @@ func authorizer(d interface{}, action int, arg1, arg2, arg3, arg4 string) int {
}
func
open
(
t
*
testing
.
T
)
*
Conn
{
db
,
err
:=
Open
(
""
)
db
,
err
:=
Open
(
""
,
OPEN_READWRITE
,
OPEN_CREATE
,
OPEN_FULLMUTEX
,
OPEN_URI
)
if
err
!=
nil
{
t
.
Fatalf
(
"couldn't open database file: %s"
,
err
)
}
...
...
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