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
27311031
Commit
27311031
authored
Aug 27, 2011
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix SetAuthorizer.
parent
3ecfccaf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
16 deletions
+51
-16
sqlite.go
sqlite.go
+2
-1
sqlite_test.go
sqlite_test.go
+1
-1
trace.go
trace.go
+48
-14
No files found.
sqlite.go
View file @
27311031
...
@@ -134,7 +134,8 @@ func (c *Conn) Error() os.Error {
...
@@ -134,7 +134,8 @@ func (c *Conn) Error() os.Error {
// Connection
// Connection
type
Conn
struct
{
type
Conn
struct
{
db
*
C
.
sqlite3
db
*
C
.
sqlite3
authorizer
*
sqliteAuthorizer
}
}
// Calls http://sqlite.org/c3ref/libversion.html
// Calls http://sqlite.org/c3ref/libversion.html
...
...
sqlite_test.go
View file @
27311031
...
@@ -11,7 +11,7 @@ func trace(d interface{}, t string) {
...
@@ -11,7 +11,7 @@ func trace(d interface{}, t string) {
fmt
.
Printf
(
"%s: %s
\n
"
,
d
,
t
)
fmt
.
Printf
(
"%s: %s
\n
"
,
d
,
t
)
}
}
func
authorizer
(
d
interface
{},
action
int
,
arg1
,
arg2
,
arg3
,
arg4
string
)
Auth
{
func
authorizer
(
d
interface
{},
action
Action
,
arg1
,
arg2
,
arg3
,
arg4
string
)
Auth
{
fmt
.
Printf
(
"%s: %d, %s, %s, %s, %s
\n
"
,
d
,
action
,
arg1
,
arg2
,
arg3
,
arg4
)
fmt
.
Printf
(
"%s: %d, %s, %s, %s, %s
\n
"
,
d
,
action
,
arg1
,
arg2
,
arg3
,
arg4
)
return
AUTH_OK
return
AUTH_OK
}
}
...
...
trace.go
View file @
27311031
...
@@ -25,7 +25,6 @@ static int goSqlite3SetAuthorizer(sqlite3 *db, void *pUserData) {
...
@@ -25,7 +25,6 @@ static int goSqlite3SetAuthorizer(sqlite3 *db, void *pUserData) {
import
"C"
import
"C"
import
(
import
(
"fmt"
"os"
"os"
"unsafe"
"unsafe"
)
)
...
@@ -54,13 +53,52 @@ func (c *Conn) Trace(f SqliteTrace, arg interface{}) {
...
@@ -54,13 +53,52 @@ func (c *Conn) Trace(f SqliteTrace, arg interface{}) {
}
}
type
Auth
int
type
Auth
int
const
(
const
(
AUTH_OK
Auth
=
C
.
SQLITE_OK
AUTH_OK
Auth
=
C
.
SQLITE_OK
AUTH_DENY
Auth
=
C
.
SQLITE_DENY
AUTH_DENY
Auth
=
C
.
SQLITE_DENY
AUTH_IGNORE
Auth
=
C
.
SQLITE_IGNORE
AUTH_IGNORE
Auth
=
C
.
SQLITE_IGNORE
)
)
type
SqliteAuthorizer
func
(
d
interface
{},
action
int
,
arg1
,
arg2
,
arg3
,
arg4
string
)
Auth
type
Action
int
const
(
CREATE_INDEX
Action
=
C
.
SQLITE_CREATE_INDEX
CREATE_TABLE
Action
=
C
.
SQLITE_CREATE_TABLE
CREATE_TEMP_INDEX
Action
=
C
.
SQLITE_CREATE_TEMP_INDEX
CREATE_TEMP_TABLE
Action
=
C
.
SQLITE_CREATE_TEMP_TABLE
CREATE_TEMP_TRIGGER
Action
=
C
.
SQLITE_CREATE_TEMP_TRIGGER
CREATE_TEMP_VIEW
Action
=
C
.
SQLITE_CREATE_TEMP_VIEW
CREATE_TRIGGER
Action
=
C
.
SQLITE_CREATE_TRIGGER
CREATE_VIEW
Action
=
C
.
SQLITE_CREATE_VIEW
DELETE
Action
=
C
.
SQLITE_DELETE
DROP_INDEX
Action
=
C
.
SQLITE_DROP_INDEX
DROP_TABLE
Action
=
C
.
SQLITE_DROP_TABLE
DROP_TEMP_INDEX
Action
=
C
.
SQLITE_DROP_TEMP_INDEX
DROP_TEMP_TABLE
Action
=
C
.
SQLITE_DROP_TEMP_TABLE
DROP_TEMP_TRIGGER
Action
=
C
.
SQLITE_DROP_TEMP_TRIGGER
DROP_TEMP_VIEW
Action
=
C
.
SQLITE_DROP_TEMP_VIEW
DROP_TRIGGER
Action
=
C
.
SQLITE_DROP_TRIGGER
DROP_VIEW
Action
=
C
.
SQLITE_DROP_VIEW
INSERT
Action
=
C
.
SQLITE_INSERT
PRAGMA
Action
=
C
.
SQLITE_PRAGMA
READ
Action
=
C
.
SQLITE_READ
SELECT
Action
=
C
.
SQLITE_SELECT
TRANSACTION
Action
=
C
.
SQLITE_TRANSACTION
UPDATE
Action
=
C
.
SQLITE_UPDATE
ATTACH
Action
=
C
.
SQLITE_ATTACH
DETACH
Action
=
C
.
SQLITE_DETACH
ALTER_TABLE
Action
=
C
.
SQLITE_ALTER_TABLE
REINDEX
Action
=
C
.
SQLITE_REINDEX
ANALYZE
Action
=
C
.
SQLITE_ANALYZE
CREATE_VTABLE
Action
=
C
.
SQLITE_CREATE_VTABLE
DROP_VTABLE
Action
=
C
.
SQLITE_DROP_VTABLE
FUNCTION
Action
=
C
.
SQLITE_FUNCTION
SAVEPOINT
Action
=
C
.
SQLITE_SAVEPOINT
COPY
Action
=
C
.
SQLITE_COPY
)
type
SqliteAuthorizer
func
(
d
interface
{},
action
Action
,
arg1
,
arg2
,
arg3
,
arg4
string
)
Auth
type
sqliteAuthorizer
struct
{
type
sqliteAuthorizer
struct
{
f
SqliteAuthorizer
f
SqliteAuthorizer
...
@@ -69,22 +107,18 @@ type sqliteAuthorizer struct {
...
@@ -69,22 +107,18 @@ type sqliteAuthorizer struct {
//export goXAuth
//export goXAuth
func
goXAuth
(
pUserData
unsafe
.
Pointer
,
action
C
.
int
,
arg1
,
arg2
,
arg3
,
arg4
*
C
.
char
)
C
.
int
{
func
goXAuth
(
pUserData
unsafe
.
Pointer
,
action
C
.
int
,
arg1
,
arg2
,
arg3
,
arg4
*
C
.
char
)
C
.
int
{
var
result
Auth
arg
:=
(
*
sqliteAuthorizer
)(
pUserData
)
if
pUserData
!=
nil
{
result
:=
arg
.
f
(
arg
.
d
,
Action
(
action
),
C
.
GoString
(
arg1
),
C
.
GoString
(
arg2
),
C
.
GoString
(
arg3
),
C
.
GoString
(
arg4
))
arg
:=
(
*
sqliteAuthorizer
)(
pUserData
)
result
=
arg
.
f
(
arg
.
d
,
int
(
action
),
C
.
GoString
(
arg1
),
C
.
GoString
(
arg2
),
C
.
GoString
(
arg3
),
C
.
GoString
(
arg4
))
}
else
{
fmt
.
Printf
(
"ERROR - %v
\n
"
,
pUserData
)
result
=
AUTH_OK
}
return
C
.
int
(
result
)
return
C
.
int
(
result
)
}
}
// Calls http://sqlite.org/c3ref/set_authorizer.html
// Calls http://sqlite.org/c3ref/set_authorizer.html
func
(
c
*
Conn
)
SetAuthorizer
(
f
SqliteAuthorizer
,
arg
interface
{})
os
.
Error
{
func
(
c
*
Conn
)
SetAuthorizer
(
f
SqliteAuthorizer
,
arg
interface
{})
os
.
Error
{
if
f
==
nil
{
if
f
==
nil
{
c
.
authorizer
=
nil
return
c
.
error
(
C
.
sqlite3_set_authorizer
(
c
.
db
,
nil
,
nil
))
return
c
.
error
(
C
.
sqlite3_set_authorizer
(
c
.
db
,
nil
,
nil
))
}
}
pArg
:=
unsafe
.
Pointer
(
&
sqliteAuthorizer
{
f
,
arg
})
// To make sure it is not gced, keep a reference in the connection.
return
c
.
error
(
C
.
goSqlite3SetAuthorizer
(
c
.
db
,
pArg
))
c
.
authorizer
=
&
sqliteAuthorizer
{
f
,
arg
}
return
c
.
error
(
C
.
goSqlite3SetAuthorizer
(
c
.
db
,
unsafe
.
Pointer
(
c
.
authorizer
)))
}
}
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