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
ebcb34c3
Commit
ebcb34c3
authored
May 22, 2014
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Golint
parent
3178e848
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
54 additions
and
43 deletions
+54
-43
config.go
config.go
+1
-0
csv.go
csv.go
+3
-2
hook.c
hook.c
+1
-1
hook.go
hook.go
+3
-3
hook_test.go
hook_test.go
+3
-3
intarray.go
intarray.go
+9
-9
limit.go
limit.go
+1
-0
meta.go
meta.go
+1
-0
pool.go
pool.go
+2
-2
pragma.go
pragma.go
+7
-7
pragma_test.go
pragma_test.go
+10
-10
sqlite.go
sqlite.go
+3
-0
stmt.go
stmt.go
+1
-0
stmt_test.go
stmt_test.go
+2
-2
trace.go
trace.go
+3
-0
vtab.go
vtab.go
+2
-2
vtab_test.go
vtab_test.go
+2
-2
No files found.
config.go
View file @
ebcb34c3
...
...
@@ -24,6 +24,7 @@ import "unsafe"
// See ConfigThreadingMode
type
ThreadingMode
int32
// SQLite threading modes
const
(
SingleThread
ThreadingMode
=
C
.
SQLITE_CONFIG_SINGLETHREAD
MultiThread
ThreadingMode
=
C
.
SQLITE_CONFIG_MULTITHREAD
...
...
csv.go
View file @
ebcb34c3
...
...
@@ -210,7 +210,7 @@ func (vc *csvTabCursor) Next() error {
}
return
err
}
func
(
vc
*
csvTabCursor
)
E
of
()
bool
{
func
(
vc
*
csvTabCursor
)
E
OF
()
bool
{
return
vc
.
vTab
.
eof
}
func
(
vc
*
csvTabCursor
)
Column
(
c
*
Context
,
col
int
)
error
{
...
...
@@ -254,7 +254,7 @@ func (db *Conn) ExportTableToCSV(dbName, table string, nullvalue string, headers
return
s
.
ExportToCSV
(
nullvalue
,
headers
,
w
)
}
// ExportT
ableT
oCSV export statement result to CSV.
// ExportToCSV export statement result to CSV.
// 'headers' flag turns output of headers on or off.
// NULL values are output as specified by 'nullvalue' parameter.
func
(
s
*
Stmt
)
ExportToCSV
(
nullvalue
string
,
headers
bool
,
w
*
yacr
.
Writer
)
error
{
...
...
@@ -283,6 +283,7 @@ func (s *Stmt) ExportToCSV(nullvalue string, headers bool, w *yacr.Writer) error
return
w
.
Err
()
}
// ImportConfig gathers import parameters.
type
ImportConfig
struct
{
Name
string
// the name of the input; used only for error reports
Separator
byte
// CSV separator
...
...
hook.c
View file @
ebcb34c3
...
...
@@ -18,7 +18,7 @@ void* goSqlite3RollbackHook(sqlite3 *db, void *udp) {
return
sqlite3_rollback_hook
(
db
,
goXRollbackHook
,
udp
);
}
extern
void
goXUpdateHook
(
void
*
udp
,
int
action
,
char
const
*
dbName
,
char
const
*
tableName
,
sqlite3_int64
rowI
d
);
extern
void
goXUpdateHook
(
void
*
udp
,
int
action
,
char
const
*
dbName
,
char
const
*
tableName
,
sqlite3_int64
rowI
D
);
void
*
goSqlite3UpdateHook
(
sqlite3
*
db
,
void
*
udp
)
{
return
sqlite3_update_hook
(
db
,
goXUpdateHook
,
udp
);
...
...
hook.go
View file @
ebcb34c3
...
...
@@ -74,7 +74,7 @@ func (c *Conn) RollbackHook(f RollbackHook, udp interface{}) {
}
// UpdateHook is the callback function signature.
type
UpdateHook
func
(
udp
interface
{},
a
Action
,
dbName
,
tableName
string
,
rowI
d
int64
)
type
UpdateHook
func
(
udp
interface
{},
a
Action
,
dbName
,
tableName
string
,
rowI
D
int64
)
type
sqliteUpdateHook
struct
{
f
UpdateHook
...
...
@@ -82,9 +82,9 @@ type sqliteUpdateHook struct {
}
//export goXUpdateHook
func
goXUpdateHook
(
udp
unsafe
.
Pointer
,
action
int
,
dbName
,
tableName
*
C
.
char
,
rowI
d
C
.
sqlite3_int64
)
{
func
goXUpdateHook
(
udp
unsafe
.
Pointer
,
action
int
,
dbName
,
tableName
*
C
.
char
,
rowI
D
C
.
sqlite3_int64
)
{
arg
:=
(
*
sqliteUpdateHook
)(
udp
)
arg
.
f
(
arg
.
udp
,
Action
(
action
),
C
.
GoString
(
dbName
),
C
.
GoString
(
tableName
),
int64
(
rowI
d
))
arg
.
f
(
arg
.
udp
,
Action
(
action
),
C
.
GoString
(
dbName
),
C
.
GoString
(
tableName
),
int64
(
rowI
D
))
}
// UpdateHook registers a callback to be invoked each time a row is updated,
...
...
hook_test.go
View file @
ebcb34c3
...
...
@@ -27,11 +27,11 @@ func rollbackHook(d interface{}) {
}
}
func
updateHook
(
d
interface
{},
a
Action
,
dbName
,
tableName
string
,
rowI
d
int64
)
{
func
updateHook
(
d
interface
{},
a
Action
,
dbName
,
tableName
string
,
rowI
D
int64
)
{
if
t
,
ok
:=
d
.
(
*
testing
.
T
);
ok
{
t
.
Logf
(
"UPD: %d, %s.%s.%d
\n
"
,
a
,
dbName
,
tableName
,
rowI
d
)
t
.
Logf
(
"UPD: %d, %s.%s.%d
\n
"
,
a
,
dbName
,
tableName
,
rowI
D
)
}
else
{
fmt
.
Printf
(
"%s: %d, %s.%s.%d
\n
"
,
d
,
a
,
dbName
,
tableName
,
rowI
d
)
fmt
.
Printf
(
"%s: %d, %s.%s.%d
\n
"
,
d
,
a
,
dbName
,
tableName
,
rowI
D
)
}
}
...
...
intarray.go
View file @
ebcb34c3
...
...
@@ -8,7 +8,7 @@ package sqlite
import
"fmt"
//
This
is the Go-language interface definition for the "intarray" or
//
IntArray
is the Go-language interface definition for the "intarray" or
// integer array virtual table for SQLite.
//
// The intarray virtual table is designed to facilitate using an
...
...
@@ -89,17 +89,17 @@ func (m *intArray) Connect(c *Conn, args []string) (VTab, error) {
func
(
m
*
intArray
)
DestroyModule
()
{
}
func
(
v
*
intArray
)
BestIndex
()
error
{
func
(
m
*
intArray
)
BestIndex
()
error
{
return
nil
}
func
(
v
*
intArray
)
Disconnect
()
error
{
func
(
m
*
intArray
)
Disconnect
()
error
{
return
nil
}
func
(
v
*
intArray
)
Destroy
()
error
{
func
(
m
*
intArray
)
Destroy
()
error
{
return
nil
}
func
(
v
*
intArray
)
Open
()
(
VTabCursor
,
error
)
{
return
&
intArrayVTabCursor
{
v
,
0
},
nil
func
(
m
*
intArray
)
Open
()
(
VTabCursor
,
error
)
{
return
&
intArrayVTabCursor
{
m
,
0
},
nil
}
type
intArrayVTabCursor
struct
{
...
...
@@ -118,7 +118,7 @@ func (vc *intArrayVTabCursor) Next() error {
vc
.
i
++
return
nil
}
func
(
vc
*
intArrayVTabCursor
)
E
of
()
bool
{
func
(
vc
*
intArrayVTabCursor
)
E
OF
()
bool
{
return
vc
.
i
>=
len
(
vc
.
vTab
.
content
)
}
func
(
vc
*
intArrayVTabCursor
)
Column
(
c
*
Context
,
col
int
)
error
{
...
...
@@ -157,6 +157,6 @@ func (c *Conn) CreateIntArray(name string) (IntArray, error) {
// The array of integers bound must be unchanged for the duration of
// any query against the corresponding virtual table. If the integer
// array does change or is deallocated undefined behavior will result.
func
(
ia
*
intArray
)
Bind
(
elements
[]
int64
)
{
ia
.
content
=
elements
func
(
m
*
intArray
)
Bind
(
elements
[]
int64
)
{
m
.
content
=
elements
}
limit.go
View file @
ebcb34c3
...
...
@@ -15,6 +15,7 @@ import "C"
// (See http://www.sqlite.org/c3ref/c_limit_attached.html)
type
Limit
int32
// Run-time limit categories
const
(
LimitLength
Limit
=
C
.
SQLITE_LIMIT_LENGTH
// The maximum size of any string or BLOB or table row, in bytes.
LimitColumn
Limit
=
C
.
SQLITE_LIMIT_COLUMN
...
...
meta.go
View file @
ebcb34c3
...
...
@@ -228,6 +228,7 @@ func (s *Stmt) ColumnDeclaredType(index int) string {
// Affinity enumerates SQLite column type affinity
type
Affinity
string
// SQLite column type affinities
const
(
Integral
=
Affinity
(
"INTEGER"
)
// Integer affinity
Real
=
Affinity
(
"REAL"
)
...
...
pool.go
View file @
ebcb34c3
...
...
@@ -11,7 +11,7 @@ import (
"time"
)
//
A
dapted from https://code.google.com/p/vitess/source/browse/go/pools/roundrobin.go
//
Pool a
dapted from https://code.google.com/p/vitess/source/browse/go/pools/roundrobin.go
type
Pool
struct
{
mu
sync
.
Mutex
available
*
sync
.
Cond
...
...
@@ -144,7 +144,7 @@ func (p *Pool) IsClosed() bool {
return
p
.
factory
==
nil
}
// Set
c
apacity changes the capacity of the pool.
// Set
C
apacity changes the capacity of the pool.
// You can use it to expand or shrink.
func
(
p
*
Pool
)
SetCapacity
(
capacity
int
)
{
p
.
mu
.
Lock
()
...
...
pragma.go
View file @
ebcb34c3
...
...
@@ -138,9 +138,9 @@ func (c *Conn) SetSynchronous(dbName string, mode int) error {
// FkViolation is the description of one foreign key constraint violation.
type
FkViolation
struct
{
Table
string
RowI
d
int64
RowI
D
int64
Parent
string
FkI
d
int
FkI
D
int
}
// ForeignKeyCheck checks the database, or the table, for foreign key constraints that are violated
...
...
@@ -172,7 +172,7 @@ func (c *Conn) ForeignKeyCheck(dbName, table string) ([]FkViolation, error) {
var
violations
=
make
([]
FkViolation
,
0
,
20
)
err
=
s
.
execQuery
(
func
(
s
*
Stmt
)
(
err
error
)
{
v
:=
FkViolation
{}
if
err
=
s
.
Scan
(
&
v
.
Table
,
&
v
.
RowI
d
,
&
v
.
Parent
,
&
v
.
FkId
);
err
!=
nil
{
if
err
=
s
.
Scan
(
&
v
.
Table
,
&
v
.
RowI
D
,
&
v
.
Parent
,
&
v
.
FkID
);
err
!=
nil
{
return
}
violations
=
append
(
violations
,
v
)
...
...
@@ -203,10 +203,10 @@ func (c *Conn) SetQueryOnly(dbName string, mode bool) error {
return
c
.
FastExec
(
pragma
(
dbName
,
fmt
.
Sprintf
(
"query_only=%t"
,
mode
)))
}
// ApplicationI
d
queries the "Application ID" integer located into the database header.
// ApplicationI
D
queries the "Application ID" integer located into the database header.
// Database name is optional (default is 'main').
// (See http://sqlite.org/pragma.html#pragma_application_id)
func
(
c
*
Conn
)
ApplicationI
d
(
dbName
string
)
(
int
,
error
)
{
func
(
c
*
Conn
)
ApplicationI
D
(
dbName
string
)
(
int
,
error
)
{
var
id
int
err
:=
c
.
oneValue
(
pragma
(
dbName
,
"application_id"
),
&
id
)
if
err
!=
nil
{
...
...
@@ -215,10 +215,10 @@ func (c *Conn) ApplicationId(dbName string) (int, error) {
return
id
,
nil
}
// SetApplicationI
d
changes the "Application ID".
// SetApplicationI
D
changes the "Application ID".
// Database name is optional (default is 'main').
// (See http://sqlite.org/pragma.html#pragma_application_id)
func
(
c
*
Conn
)
SetApplicationI
d
(
dbName
string
,
id
int
)
error
{
func
(
c
*
Conn
)
SetApplicationI
D
(
dbName
string
,
id
int
)
error
{
return
c
.
FastExec
(
pragma
(
dbName
,
fmt
.
Sprintf
(
"application_id=%d"
,
id
)))
}
...
...
pragma_test.go
View file @
ebcb34c3
...
...
@@ -128,7 +128,7 @@ func TestQueryOnly(t *testing.T) {
assert
.
T
(
t
,
err
!=
nil
)
}
func
TestApplicationI
d
(
t
*
testing
.
T
)
{
func
TestApplicationI
D
(
t
*
testing
.
T
)
{
if
VersionNumber
()
<
3007017
{
return
}
...
...
@@ -136,18 +136,18 @@ func TestApplicationId(t *testing.T) {
db
:=
open
(
t
)
defer
checkClose
(
db
,
t
)
appI
d
,
err
:=
db
.
ApplicationId
(
""
)
appI
D
,
err
:=
db
.
ApplicationID
(
""
)
checkNoError
(
t
,
err
,
"error getting application Id: %s"
)
assert
.
Equalf
(
t
,
0
,
appI
d
,
"got: %d; want: %d"
,
appId
,
0
)
assert
.
Equalf
(
t
,
0
,
appI
D
,
"got: %d; want: %d"
,
appID
,
0
)
err
=
db
.
SetApplicationI
d
(
""
,
123
)
err
=
db
.
SetApplicationI
D
(
""
,
123
)
checkNoError
(
t
,
err
,
"error setting application Id: %s"
)
appI
d
,
err
=
db
.
ApplicationId
(
""
)
appI
D
,
err
=
db
.
ApplicationID
(
""
)
checkNoError
(
t
,
err
,
"error getting application Id: %s"
)
assert
.
Equalf
(
t
,
123
,
appI
d
,
"got: %d; want: %d"
,
appId
,
123
)
assert
.
Equalf
(
t
,
123
,
appI
D
,
"got: %d; want: %d"
,
appID
,
123
)
_
,
err
=
db
.
ApplicationI
d
(
"bim"
)
_
,
err
=
db
.
ApplicationI
D
(
"bim"
)
assert
.
T
(
t
,
err
!=
nil
)
}
...
...
@@ -176,11 +176,11 @@ func TestForeignKeyCheck(t *testing.T) {
checkNoError
(
t
,
err
,
"error while checking FK: %s"
)
assert
.
Equal
(
t
,
1
,
len
(
vs
),
"one FK violation expected"
)
v
:=
vs
[
0
]
assert
.
Equal
(
t
,
FkViolation
{
Table
:
"tree"
,
RowI
d
:
4
,
Parent
:
"tree"
,
FkId
:
0
},
v
)
assert
.
Equal
(
t
,
FkViolation
{
Table
:
"tree"
,
RowI
D
:
4
,
Parent
:
"tree"
,
FkID
:
0
},
v
)
fks
,
err
:=
db
.
ForeignKeys
(
""
,
"tree"
)
checkNoError
(
t
,
err
,
"error while loading FK: %s"
)
fk
,
ok
:=
fks
[
v
.
FkI
d
]
assert
.
Tf
(
t
,
ok
,
"no FK with id: %d"
,
v
.
FkI
d
)
fk
,
ok
:=
fks
[
v
.
FkI
D
]
assert
.
Tf
(
t
,
ok
,
"no FK with id: %d"
,
v
.
FkI
D
)
assert
.
Equal
(
t
,
&
ForeignKey
{
Table
:
"tree"
,
From
:
[]
string
{
"parentId"
},
To
:
[]
string
{
"id"
}},
fk
)
mvs
,
err
:=
db
.
ForeignKeyCheck
(
"main"
,
"tree"
)
...
...
sqlite.go
View file @
ebcb34c3
...
...
@@ -73,6 +73,7 @@ func (e Errno) Error() string {
return
s
}
// SQLite result codes
const
(
ErrError
=
Errno
(
C
.
SQLITE_ERROR
)
/* SQL error or missing database */
ErrInternal
=
Errno
(
C
.
SQLITE_INTERNAL
)
/* Internal logic error in SQLite */
...
...
@@ -180,6 +181,7 @@ func VersionNumber() int32 {
// OpenFlag enumerates flags for file open operations
type
OpenFlag
int32
// Flags for file open operations
const
(
OpenReadOnly
OpenFlag
=
C
.
SQLITE_OPEN_READONLY
OpenReadWrite
OpenFlag
=
C
.
SQLITE_OPEN_READWRITE
...
...
@@ -386,6 +388,7 @@ func (c *Conn) GetAutocommit() bool {
// See Conn.BeginTransaction
type
TransactionType
uint8
// Transaction types
const
(
Deferred
TransactionType
=
0
Immediate
TransactionType
=
1
...
...
stmt.go
View file @
ebcb34c3
...
...
@@ -514,6 +514,7 @@ func (t Type) String() string {
return
typeText
[
t
]
}
// SQLite fundamental datatypes
const
(
Integer
=
Type
(
C
.
SQLITE_INTEGER
)
Float
=
Type
(
C
.
SQLITE_FLOAT
)
...
...
stmt_test.go
View file @
ebcb34c3
...
...
@@ -481,9 +481,9 @@ func TestInsertMisuse(t *testing.T) {
ois
,
err
:=
db
.
Prepare
(
"PRAGMA shrink_memory"
)
checkNoError
(
t
,
err
,
"prepare error: %s"
)
defer
checkFinalize
(
ois
,
t
)
rowI
d
,
err
:=
ois
.
Insert
()
rowI
D
,
err
:=
ois
.
Insert
()
checkNoError
(
t
,
err
,
"insert error: %s"
)
assert
.
Equal
(
t
,
int64
(
-
1
),
rowI
d
)
assert
.
Equal
(
t
,
int64
(
-
1
),
rowI
D
)
}
func
TestScanValues
(
t
*
testing
.
T
)
{
...
...
trace.go
View file @
ebcb34c3
...
...
@@ -91,6 +91,7 @@ func (c *Conn) Profile(f Profiler, udp interface{}) {
// Auth enumerates Authorizer return codes
type
Auth
int32
// Authorizer return codes
const
(
AuthOk
Auth
=
C
.
SQLITE_OK
AuthDeny
Auth
=
C
.
SQLITE_DENY
...
...
@@ -100,6 +101,7 @@ const (
// Action enumerates Authorizer action codes
type
Action
int32
// Authorizer action codes
const
(
CreateIndex
Action
=
C
.
SQLITE_CREATE_INDEX
CreateTable
Action
=
C
.
SQLITE_CREATE_TABLE
...
...
@@ -299,6 +301,7 @@ func (c *Conn) ProgressHandler(f ProgressHandler, numOps int32, udp interface{})
// StmtStatus enumerates status parameters for prepared statements
type
StmtStatus
int32
// status counters for prepared statements
const
(
StmtStatusFullScanStep
StmtStatus
=
C
.
SQLITE_STMTSTATUS_FULLSCAN_STEP
StmtStatusSort
StmtStatus
=
C
.
SQLITE_STMTSTATUS_SORT
...
...
vtab.go
View file @
ebcb34c3
...
...
@@ -151,7 +151,7 @@ func goVNext(pCursor unsafe.Pointer) *C.char {
//export goVEof
func
goVEof
(
pCursor
unsafe
.
Pointer
)
C
.
int
{
vtc
:=
(
*
sqliteVTabCursor
)(
pCursor
)
return
btocint
(
vtc
.
vTabCursor
.
E
of
())
return
btocint
(
vtc
.
vTabCursor
.
E
OF
())
}
//export goVColumn
...
...
@@ -218,7 +218,7 @@ type VTabCursor interface {
Close
()
error
// See http://sqlite.org/vtab.html#xclose
Filter
(
/*idxNum int, idxStr string, int argc, sqlite3_value **argv*/
)
error
// See http://sqlite.org/vtab.html#xfilter
Next
()
error
// See http://sqlite.org/vtab.html#xnext
E
of
()
bool
// See http://sqlite.org/vtab.html#xeof
E
OF
()
bool
// See http://sqlite.org/vtab.html#xeof
// col is zero-based so the first column is numbered 0
Column
(
c
*
Context
,
col
int
)
error
// See http://sqlite.org/vtab.html#xcolumn
Rowid
()
(
int64
,
error
)
// See http://sqlite.org/vtab.html#xrowid
...
...
vtab_test.go
View file @
ebcb34c3
...
...
@@ -81,8 +81,8 @@ func (vc *testVTabCursor) Next() error {
vc
.
index
++
return
nil
}
func
(
vc
*
testVTabCursor
)
E
of
()
bool
{
//fmt.Printf("testVTabCursor.E
of
: %v\n", vc)
func
(
vc
*
testVTabCursor
)
E
OF
()
bool
{
//fmt.Printf("testVTabCursor.E
OF
: %v\n", vc)
return
vc
.
index
>=
len
(
vc
.
vTab
.
intarray
)
}
func
(
vc
*
testVTabCursor
)
Column
(
c
*
Context
,
col
int
)
error
{
...
...
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