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
e8891f64
Commit
e8891f64
authored
Nov 02, 2011
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix error type.
parent
ecae65ef
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
108 additions
and
114 deletions
+108
-114
backup.go
backup.go
+5
-5
blob.go
blob.go
+10
-10
meta.go
meta.go
+7
-10
sqlite.go
sqlite.go
+83
-83
trace.go
trace.go
+3
-6
No files found.
backup.go
View file @
e8891f64
...
...
@@ -19,7 +19,7 @@ import (
)
// Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupinit
func
NewBackup
(
dst
*
Conn
,
dstTable
string
,
src
*
Conn
,
srcTable
string
)
(
*
Backup
,
os
.
E
rror
)
{
func
NewBackup
(
dst
*
Conn
,
dstTable
string
,
src
*
Conn
,
srcTable
string
)
(
*
Backup
,
e
rror
)
{
dname
:=
C
.
CString
(
dstTable
)
sname
:=
C
.
CString
(
srcTable
)
defer
C
.
free
(
unsafe
.
Pointer
(
dname
))
...
...
@@ -38,7 +38,7 @@ type Backup struct {
}
// Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep
func
(
b
*
Backup
)
Step
(
npage
int
)
os
.
E
rror
{
func
(
b
*
Backup
)
Step
(
npage
int
)
e
rror
{
rv
:=
C
.
sqlite3_backup_step
(
b
.
sb
,
C
.
int
(
npage
))
if
rv
==
C
.
SQLITE_OK
||
Errno
(
rv
)
==
ErrBusy
||
Errno
(
rv
)
==
ErrLocked
{
return
nil
...
...
@@ -57,8 +57,8 @@ func (b *Backup) Status() BackupStatus {
}
// Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupstep, sqlite3_backup_remaining and sqlite3_backup_pagecount
func
(
b
*
Backup
)
Run
(
npage
int
,
sleepNs
int64
,
c
chan
<-
BackupStatus
)
os
.
E
rror
{
var
err
os
.
E
rror
func
(
b
*
Backup
)
Run
(
npage
int
,
sleepNs
int64
,
c
chan
<-
BackupStatus
)
e
rror
{
var
err
e
rror
for
{
err
=
b
.
Step
(
npage
)
if
err
!=
nil
{
...
...
@@ -73,7 +73,7 @@ func (b *Backup) Run(npage int, sleepNs int64, c chan<- BackupStatus) os.Error {
}
// Calls http://sqlite.org/c3ref/backup_finish.html#sqlite3backupfinish
func
(
b
*
Backup
)
Close
()
os
.
E
rror
{
func
(
b
*
Backup
)
Close
()
e
rror
{
if
b
.
sb
==
nil
{
return
os
.
EINVAL
}
...
...
blob.go
View file @
e8891f64
...
...
@@ -13,7 +13,7 @@ package sqlite
import
"C"
import
(
"
o
s"
"
error
s"
"unsafe"
)
...
...
@@ -29,7 +29,7 @@ type BlobReadWriter struct {
type
ZeroBlobLength
int
// Calls http://sqlite.org/c3ref/blob_open.html
func
(
c
*
Conn
)
NewBlobReader
(
db
,
table
,
column
string
,
row
int64
)
(
*
BlobReader
,
os
.
E
rror
)
{
func
(
c
*
Conn
)
NewBlobReader
(
db
,
table
,
column
string
,
row
int64
)
(
*
BlobReader
,
e
rror
)
{
bl
,
err
:=
c
.
blob_open
(
db
,
table
,
column
,
row
,
false
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -38,7 +38,7 @@ func (c *Conn) NewBlobReader(db, table, column string, row int64) (*BlobReader,
}
// Calls http://sqlite.org/c3ref/blob_open.html
func
(
c
*
Conn
)
NewBlobReadWriter
(
db
,
table
,
column
string
,
row
int64
)
(
*
BlobReadWriter
,
os
.
E
rror
)
{
func
(
c
*
Conn
)
NewBlobReadWriter
(
db
,
table
,
column
string
,
row
int64
)
(
*
BlobReadWriter
,
e
rror
)
{
bl
,
err
:=
c
.
blob_open
(
db
,
table
,
column
,
row
,
true
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -46,7 +46,7 @@ func (c *Conn) NewBlobReadWriter(db, table, column string, row int64) (*BlobRead
return
&
BlobReadWriter
{
BlobReader
{
c
,
bl
}},
nil
}
func
(
c
*
Conn
)
blob_open
(
db
,
table
,
column
string
,
row
int64
,
write
bool
)
(
*
C
.
sqlite3_blob
,
os
.
E
rror
)
{
func
(
c
*
Conn
)
blob_open
(
db
,
table
,
column
string
,
row
int64
,
write
bool
)
(
*
C
.
sqlite3_blob
,
e
rror
)
{
zDb
:=
C
.
CString
(
db
)
defer
C
.
free
(
unsafe
.
Pointer
(
zDb
))
zTable
:=
C
.
CString
(
table
)
...
...
@@ -62,13 +62,13 @@ func (c *Conn) blob_open(db, table, column string, row int64, write bool) (*C.sq
return
nil
,
c
.
error
(
rv
)
}
if
bl
==
nil
{
return
nil
,
os
.
NewError
(
"sqlite succeeded without returning a blob"
)
return
nil
,
errors
.
New
(
"sqlite succeeded without returning a blob"
)
}
return
bl
,
nil
}
// Calls http://sqlite.org/c3ref/blob_close.html
func
(
r
*
BlobReader
)
Close
()
os
.
E
rror
{
func
(
r
*
BlobReader
)
Close
()
e
rror
{
rv
:=
C
.
sqlite3_blob_close
(
r
.
bl
)
if
rv
!=
C
.
SQLITE_OK
{
return
r
.
c
.
error
(
rv
)
...
...
@@ -78,7 +78,7 @@ func (r *BlobReader) Close() os.Error {
}
// Calls http://sqlite.org/c3ref/blob_read.html
func
(
r
*
BlobReader
)
Read
(
v
[]
byte
)
(
int
,
os
.
E
rror
)
{
func
(
r
*
BlobReader
)
Read
(
v
[]
byte
)
(
int
,
e
rror
)
{
var
p
*
byte
if
len
(
v
)
>
0
{
p
=
&
v
[
0
]
...
...
@@ -91,13 +91,13 @@ func (r *BlobReader) Read(v []byte) (int, os.Error) {
}
// Calls http://sqlite.org/c3ref/blob_bytes.html
func
(
r
*
BlobReader
)
Size
()
(
int
,
os
.
E
rror
)
{
func
(
r
*
BlobReader
)
Size
()
(
int
,
e
rror
)
{
s
:=
C
.
sqlite3_blob_bytes
(
r
.
bl
)
return
int
(
s
),
nil
}
// Calls http://sqlite.org/c3ref/blob_write.html
func
(
w
*
BlobReadWriter
)
Write
(
v
[]
byte
)
(
int
,
os
.
E
rror
)
{
func
(
w
*
BlobReadWriter
)
Write
(
v
[]
byte
)
(
int
,
e
rror
)
{
var
p
*
byte
if
len
(
v
)
>
0
{
p
=
&
v
[
0
]
...
...
@@ -110,7 +110,7 @@ func (w *BlobReadWriter) Write(v []byte) (int, os.Error) {
}
// Calls http://sqlite.org/c3ref/blob_reopen.html
func
(
r
*
BlobReader
)
Reopen
(
rowid
int64
)
os
.
E
rror
{
func
(
r
*
BlobReader
)
Reopen
(
rowid
int64
)
e
rror
{
rv
:=
C
.
sqlite3_blob_reopen
(
r
.
bl
,
C
.
sqlite3_int64
(
rowid
))
if
rv
!=
C
.
SQLITE_OK
{
return
r
.
c
.
error
(
rv
)
...
...
meta.go
View file @
e8891f64
...
...
@@ -17,13 +17,10 @@ static char *my_mprintf(char *zFormat, char *arg) {
*/
import
"C"
import
(
"os"
"unsafe"
)
import
"unsafe"
// Executes pragma 'database_list'
func
(
c
*
Conn
)
Databases
()
(
map
[
string
]
string
,
os
.
E
rror
)
{
func
(
c
*
Conn
)
Databases
()
(
map
[
string
]
string
,
e
rror
)
{
s
,
err
:=
c
.
Prepare
(
"PRAGMA database_list"
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -46,7 +43,7 @@ func (c *Conn) Databases() (map[string]string, os.Error) {
}
// Selects tables (no view) from 'sqlite_master' and filters system tables out.
func
(
c
*
Conn
)
Tables
()
([]
string
,
os
.
E
rror
)
{
func
(
c
*
Conn
)
Tables
()
([]
string
,
e
rror
)
{
s
,
err
:=
c
.
Prepare
(
"SELECT name FROM sqlite_master WHERE type IN ('table') AND name NOT LIKE 'sqlite_%'"
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -77,7 +74,7 @@ type Column struct {
// Executes pragma 'table_info'
// TODO How to specify a database-name?
// TODO sqlite3_table_column_metadata?
func
(
c
*
Conn
)
Columns
(
table
string
)
([]
Column
,
os
.
E
rror
)
{
func
(
c
*
Conn
)
Columns
(
table
string
)
([]
Column
,
e
rror
)
{
s
,
err
:=
c
.
Prepare
(
Mprintf
(
"PRAGMA table_info(%Q)"
,
table
))
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -107,7 +104,7 @@ type ForeignKey struct {
// Executes pragma 'foreign_key_list'
// TODO How to specify a database-name?
func
(
c
*
Conn
)
ForeignKeys
(
table
string
)
(
map
[
int
]
*
ForeignKey
,
os
.
E
rror
)
{
func
(
c
*
Conn
)
ForeignKeys
(
table
string
)
(
map
[
int
]
*
ForeignKey
,
e
rror
)
{
s
,
err
:=
c
.
Prepare
(
Mprintf
(
"PRAGMA foreign_key_list(%Q)"
,
table
))
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -144,7 +141,7 @@ type Index struct {
// Executes pragma 'index_list'
// TODO How to specify a database-name?
func
(
c
*
Conn
)
Indexes
(
table
string
)
([]
Index
,
os
.
E
rror
)
{
func
(
c
*
Conn
)
Indexes
(
table
string
)
([]
Index
,
e
rror
)
{
s
,
err
:=
c
.
Prepare
(
Mprintf
(
"PRAGMA index_list(%Q)"
,
table
))
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -168,7 +165,7 @@ func (c *Conn) Indexes(table string) ([]Index, os.Error) {
// Executes pragma 'index_info'
// Only Column.Cid and Column.Name are specified. All other fields are unspecifed.
func
(
c
*
Conn
)
IndexColumns
(
index
string
)
([]
Column
,
os
.
E
rror
)
{
func
(
c
*
Conn
)
IndexColumns
(
index
string
)
([]
Column
,
e
rror
)
{
s
,
err
:=
c
.
Prepare
(
Mprintf
(
"PRAGMA index_info(%Q)"
,
index
))
if
err
!=
nil
{
return
nil
,
err
...
...
sqlite.go
View file @
e8891f64
This diff is collapsed.
Click to expand it.
trace.go
View file @
e8891f64
...
...
@@ -46,10 +46,7 @@ static void my_log(int iErrCode, char *msg) {
*/
import
"C"
import
(
"os"
"unsafe"
)
import
"unsafe"
type
Tracer
func
(
udp
interface
{},
sql
string
)
...
...
@@ -162,7 +159,7 @@ func goXAuth(udp unsafe.Pointer, action C.int, arg1, arg2, dbName, triggerName *
}
// Calls http://sqlite.org/c3ref/set_authorizer.html
func
(
c
*
Conn
)
SetAuthorizer
(
f
Authorizer
,
udp
interface
{})
os
.
E
rror
{
func
(
c
*
Conn
)
SetAuthorizer
(
f
Authorizer
,
udp
interface
{})
e
rror
{
if
f
==
nil
{
c
.
authorizer
=
nil
return
c
.
error
(
C
.
sqlite3_set_authorizer
(
c
.
db
,
nil
,
nil
))
...
...
@@ -188,7 +185,7 @@ func goXBusy(udp unsafe.Pointer, count C.int) C.int {
// TODO NOT TESTED
// Calls http://sqlite.org/c3ref/busy_handler.html
func
(
c
*
Conn
)
BusyHandler
(
f
BusyHandler
,
udp
interface
{})
os
.
E
rror
{
func
(
c
*
Conn
)
BusyHandler
(
f
BusyHandler
,
udp
interface
{})
e
rror
{
if
f
==
nil
{
c
.
busyHandler
=
nil
return
c
.
error
(
C
.
sqlite3_busy_handler
(
c
.
db
,
nil
,
nil
))
...
...
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