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
7e0fdf5c
Commit
7e0fdf5c
authored
Jun 03, 2013
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Golint applied.
parent
703414bf
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
61 additions
and
62 deletions
+61
-62
blob.go
blob.go
+6
-6
driver.go
driver.go
+1
-1
example_test.go
example_test.go
+2
-2
meta.go
meta.go
+5
-5
pragma.go
pragma.go
+1
-1
sqlite.go
sqlite.go
+30
-30
sqlite_test.go
sqlite_test.go
+2
-2
stmt.go
stmt.go
+10
-11
stmt_test.go
stmt_test.go
+4
-4
No files found.
blob.go
View file @
7e0fdf5c
...
...
@@ -17,7 +17,7 @@ import (
"unsafe"
)
//
io.ReadCloser adapter to
BLOB
//
BlobReader is an io.ReadCloser adapter for
BLOB
// (See http://sqlite.org/c3ref/blob.html)
type
BlobReader
struct
{
c
*
Conn
...
...
@@ -26,7 +26,7 @@ type BlobReader struct {
offset
int
}
//
io.ReadWriteCloser adapter to
BLOB
//
BlobReadWriter is an io.ReadWriteCloser adapter for
BLOB
type
BlobReadWriter
struct
{
BlobReader
}
...
...
@@ -38,7 +38,7 @@ type ZeroBlobLength int
//
// (See http://sqlite.org/c3ref/blob_open.html)
func
(
c
*
Conn
)
NewBlobReader
(
db
,
table
,
column
string
,
row
int64
)
(
*
BlobReader
,
error
)
{
bl
,
err
:=
c
.
blob
_o
pen
(
db
,
table
,
column
,
row
,
false
)
bl
,
err
:=
c
.
blob
O
pen
(
db
,
table
,
column
,
row
,
false
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -48,14 +48,14 @@ func (c *Conn) NewBlobReader(db, table, column string, row int64) (*BlobReader,
// NewBlobReadWriter opens a BLOB for incremental I/O.
// (See http://sqlite.org/c3ref/blob_open.html)
func
(
c
*
Conn
)
NewBlobReadWriter
(
db
,
table
,
column
string
,
row
int64
)
(
*
BlobReadWriter
,
error
)
{
bl
,
err
:=
c
.
blob
_o
pen
(
db
,
table
,
column
,
row
,
true
)
bl
,
err
:=
c
.
blob
O
pen
(
db
,
table
,
column
,
row
,
true
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
BlobReadWriter
{
BlobReader
{
c
,
bl
,
-
1
,
0
}},
nil
}
func
(
c
*
Conn
)
blob
_o
pen
(
db
,
table
,
column
string
,
row
int64
,
write
bool
)
(
*
C
.
sqlite3_blob
,
error
)
{
func
(
c
*
Conn
)
blob
O
pen
(
db
,
table
,
column
string
,
row
int64
,
write
bool
)
(
*
C
.
sqlite3_blob
,
error
)
{
zDb
:=
C
.
CString
(
db
)
defer
C
.
free
(
unsafe
.
Pointer
(
zDb
))
zTable
:=
C
.
CString
(
table
)
...
...
@@ -68,7 +68,7 @@ func (c *Conn) blob_open(db, table, column string, row int64, write bool) (*C.sq
if
bl
!=
nil
{
C
.
sqlite3_blob_close
(
bl
)
}
return
nil
,
c
.
error
(
rv
,
fmt
.
Sprintf
(
"Conn.blob
_o
pen(db: %q, tbl: %q, col: %q, row: %d)"
,
db
,
table
,
column
,
row
))
return
nil
,
c
.
error
(
rv
,
fmt
.
Sprintf
(
"Conn.blob
O
pen(db: %q, tbl: %q, col: %q, row: %d)"
,
db
,
table
,
column
,
row
))
}
if
bl
==
nil
{
return
nil
,
errors
.
New
(
"sqlite succeeded without returning a blob"
)
...
...
driver.go
View file @
7e0fdf5c
...
...
@@ -26,7 +26,7 @@ func init() {
ConfigMemStatus
(
false
)
}
//
A
dapter to database/sql/driver
//
Driver is an a
dapter to database/sql/driver
type
Driver
struct
{
}
type
connImpl
struct
{
...
...
example_test.go
View file @
7e0fdf5c
...
...
@@ -91,9 +91,9 @@ func ExampleStmt_Insert() {
defer
s
.
Finalize
()
data
:=
[]
string
{
"Go"
,
"SQLite"
,
"Driver"
}
for
_
,
d
:=
range
data
{
rowI
d
,
err
:=
s
.
Insert
(
d
)
rowI
D
,
err
:=
s
.
Insert
(
d
)
check
(
err
)
fmt
.
Println
(
rowI
d
)
fmt
.
Println
(
rowI
D
)
}
// Output: 1
// 2
...
...
meta.go
View file @
7e0fdf5c
...
...
@@ -48,7 +48,7 @@ func (c *Conn) Databases() (map[string]string, error) {
return
nil
,
err
}
defer
s
.
finalize
()
var
databases
map
[
string
]
string
=
make
(
map
[
string
]
string
)
var
databases
=
make
(
map
[
string
]
string
)
var
name
,
file
string
err
=
s
.
Select
(
func
(
s
*
Stmt
)
(
err
error
)
{
if
err
=
s
.
Scan
(
nil
,
&
name
,
&
file
);
err
!=
nil
{
...
...
@@ -77,7 +77,7 @@ func (c *Conn) Tables(dbName string) ([]string, error) {
return
nil
,
err
}
defer
s
.
finalize
()
var
tables
[]
string
=
make
([]
string
,
0
,
20
)
var
tables
=
make
([]
string
,
0
,
20
)
err
=
s
.
Select
(
func
(
s
*
Stmt
)
(
err
error
)
{
name
,
_
:=
s
.
ScanText
(
0
)
tables
=
append
(
tables
,
name
)
...
...
@@ -116,7 +116,7 @@ func (c *Conn) Columns(dbName, table string) ([]Column, error) {
return
nil
,
err
}
defer
s
.
finalize
()
var
columns
[]
Column
=
make
([]
Column
,
0
,
20
)
var
columns
=
make
([]
Column
,
0
,
20
)
err
=
s
.
Select
(
func
(
s
*
Stmt
)
(
err
error
)
{
c
:=
Column
{}
if
err
=
s
.
Scan
(
&
c
.
Cid
,
&
c
.
Name
,
&
c
.
DataType
,
&
c
.
NotNull
,
&
c
.
DfltValue
,
&
c
.
Pk
);
err
!=
nil
{
...
...
@@ -251,7 +251,7 @@ func (c *Conn) Indexes(dbName, table string) ([]Index, error) {
return
nil
,
err
}
defer
s
.
finalize
()
var
indexes
[]
Index
=
make
([]
Index
,
0
,
5
)
var
indexes
=
make
([]
Index
,
0
,
5
)
err
=
s
.
Select
(
func
(
s
*
Stmt
)
(
err
error
)
{
i
:=
Index
{}
if
err
=
s
.
Scan
(
nil
,
&
i
.
Name
,
&
i
.
Unique
);
err
!=
nil
{
...
...
@@ -281,7 +281,7 @@ func (c *Conn) IndexColumns(dbName, index string) ([]Column, error) {
return
nil
,
err
}
defer
s
.
finalize
()
var
columns
[]
Column
=
make
([]
Column
,
0
,
5
)
var
columns
=
make
([]
Column
,
0
,
5
)
err
=
s
.
Select
(
func
(
s
*
Stmt
)
(
err
error
)
{
c
:=
Column
{}
if
err
=
s
.
Scan
(
nil
,
&
c
.
Cid
,
&
c
.
Name
);
err
!=
nil
{
...
...
pragma.go
View file @
7e0fdf5c
...
...
@@ -168,7 +168,7 @@ func (c *Conn) ForeignKeyCheck(dbName, table string) ([]FkViolation, error) {
}
defer
s
.
finalize
()
// table|rowid|parent|fkid
var
violations
[]
FkViolation
=
make
([]
FkViolation
,
0
,
20
)
var
violations
=
make
([]
FkViolation
,
0
,
20
)
err
=
s
.
Select
(
func
(
s
*
Stmt
)
(
err
error
)
{
v
:=
FkViolation
{}
if
err
=
s
.
Scan
(
&
v
.
Table
,
&
v
.
Rowid
,
&
v
.
Parent
,
&
v
.
Fkid
);
err
!=
nil
{
...
...
sqlite.go
View file @
7e0fdf5c
...
...
@@ -75,36 +75,36 @@ func (e Errno) Error() string {
return
s
}
var
(
ErrError
error
=
Errno
(
C
.
SQLITE_ERROR
)
/* SQL error or missing database */
ErrInternal
error
=
Errno
(
C
.
SQLITE_INTERNAL
)
/* Internal logic error in SQLite */
ErrPerm
error
=
Errno
(
C
.
SQLITE_PERM
)
/* Access permission denied */
ErrAbort
error
=
Errno
(
C
.
SQLITE_ABORT
)
/* Callback routine requested an abort */
ErrBusy
error
=
Errno
(
C
.
SQLITE_BUSY
)
/* The database file is locked */
ErrLocked
error
=
Errno
(
C
.
SQLITE_LOCKED
)
/* A table in the database is locked */
ErrNoMem
error
=
Errno
(
C
.
SQLITE_NOMEM
)
/* A malloc() failed */
ErrReadOnly
error
=
Errno
(
C
.
SQLITE_READONLY
)
/* Attempt to write a readonly database */
ErrInterrupt
error
=
Errno
(
C
.
SQLITE_INTERRUPT
)
/* Operation terminated by sqlite3_interrupt()*/
ErrIOErr
error
=
Errno
(
C
.
SQLITE_IOERR
)
/* Some kind of disk I/O error occurred */
ErrCorrupt
error
=
Errno
(
C
.
SQLITE_CORRUPT
)
/* The database disk image is malformed */
ErrNotFound
error
=
Errno
(
C
.
SQLITE_NOTFOUND
)
/* Unknown opcode in sqlite3_file_control() */
ErrFull
error
=
Errno
(
C
.
SQLITE_FULL
)
/* Insertion failed because database is full */
ErrCantOpen
error
=
Errno
(
C
.
SQLITE_CANTOPEN
)
/* Unable to open the database file */
ErrProtocol
error
=
Errno
(
C
.
SQLITE_PROTOCOL
)
/* Database lock protocol error */
ErrEmpty
error
=
Errno
(
C
.
SQLITE_EMPTY
)
/* Database is empty */
ErrSchema
error
=
Errno
(
C
.
SQLITE_SCHEMA
)
/* The database schema changed */
ErrTooBig
error
=
Errno
(
C
.
SQLITE_TOOBIG
)
/* String or BLOB exceeds size limit */
ErrConstraint
error
=
Errno
(
C
.
SQLITE_CONSTRAINT
)
/* Abort due to constraint violation */
ErrMismatch
error
=
Errno
(
C
.
SQLITE_MISMATCH
)
/* Data type mismatch */
ErrMisuse
error
=
Errno
(
C
.
SQLITE_MISUSE
)
/* Library used incorrectly */
ErrNolfs
error
=
Errno
(
C
.
SQLITE_NOLFS
)
/* Uses OS features not supported on host */
ErrAuth
error
=
Errno
(
C
.
SQLITE_AUTH
)
/* Authorization denied */
ErrFormat
error
=
Errno
(
C
.
SQLITE_FORMAT
)
/* Auxiliary database format error */
ErrRange
error
=
Errno
(
C
.
SQLITE_RANGE
)
/* 2nd parameter to sqlite3_bind out of range */
ErrNotDB
error
=
Errno
(
C
.
SQLITE_NOTADB
)
/* File opened that is not a database file */
Row
=
Errno
(
C
.
SQLITE_ROW
)
/* sqlite3_step() has another row ready */
Done
=
Errno
(
C
.
SQLITE_DONE
)
/* sqlite3_step() has finished executing */
ErrSpecific
=
Errno
(
-
1
)
/* Wrapper specific error */
const
(
ErrError
=
Errno
(
C
.
SQLITE_ERROR
)
/* SQL error or missing database */
ErrInternal
=
Errno
(
C
.
SQLITE_INTERNAL
)
/* Internal logic error in SQLite */
ErrPerm
=
Errno
(
C
.
SQLITE_PERM
)
/* Access permission denied */
ErrAbort
=
Errno
(
C
.
SQLITE_ABORT
)
/* Callback routine requested an abort */
ErrBusy
=
Errno
(
C
.
SQLITE_BUSY
)
/* The database file is locked */
ErrLocked
=
Errno
(
C
.
SQLITE_LOCKED
)
/* A table in the database is locked */
ErrNoMem
=
Errno
(
C
.
SQLITE_NOMEM
)
/* A malloc() failed */
ErrReadOnly
=
Errno
(
C
.
SQLITE_READONLY
)
/* Attempt to write a readonly database */
ErrInterrupt
=
Errno
(
C
.
SQLITE_INTERRUPT
)
/* Operation terminated by sqlite3_interrupt()*/
ErrIOErr
=
Errno
(
C
.
SQLITE_IOERR
)
/* Some kind of disk I/O error occurred */
ErrCorrupt
=
Errno
(
C
.
SQLITE_CORRUPT
)
/* The database disk image is malformed */
ErrNotFound
=
Errno
(
C
.
SQLITE_NOTFOUND
)
/* Unknown opcode in sqlite3_file_control() */
ErrFull
=
Errno
(
C
.
SQLITE_FULL
)
/* Insertion failed because database is full */
ErrCantOpen
=
Errno
(
C
.
SQLITE_CANTOPEN
)
/* Unable to open the database file */
ErrProtocol
=
Errno
(
C
.
SQLITE_PROTOCOL
)
/* Database lock protocol error */
ErrEmpty
=
Errno
(
C
.
SQLITE_EMPTY
)
/* Database is empty */
ErrSchema
=
Errno
(
C
.
SQLITE_SCHEMA
)
/* The database schema changed */
ErrTooBig
=
Errno
(
C
.
SQLITE_TOOBIG
)
/* String or BLOB exceeds size limit */
ErrConstraint
=
Errno
(
C
.
SQLITE_CONSTRAINT
)
/* Abort due to constraint violation */
ErrMismatch
=
Errno
(
C
.
SQLITE_MISMATCH
)
/* Data type mismatch */
ErrMisuse
=
Errno
(
C
.
SQLITE_MISUSE
)
/* Library used incorrectly */
ErrNolfs
=
Errno
(
C
.
SQLITE_NOLFS
)
/* Uses OS features not supported on host */
ErrAuth
=
Errno
(
C
.
SQLITE_AUTH
)
/* Authorization denied */
ErrFormat
=
Errno
(
C
.
SQLITE_FORMAT
)
/* Auxiliary database format error */
ErrRange
=
Errno
(
C
.
SQLITE_RANGE
)
/* 2nd parameter to sqlite3_bind out of range */
ErrNotDB
=
Errno
(
C
.
SQLITE_NOTADB
)
/* File opened that is not a database file */
Row
=
Errno
(
C
.
SQLITE_ROW
)
/* sqlite3_step() has another row ready */
Done
=
Errno
(
C
.
SQLITE_DONE
)
/* sqlite3_step() has finished executing */
ErrSpecific
=
Errno
(
-
1
)
/* Wrapper specific error */
)
func
(
c
*
Conn
)
error
(
rv
C
.
int
,
details
...
string
)
error
{
...
...
sqlite_test.go
View file @
7e0fdf5c
...
...
@@ -139,8 +139,8 @@ func TestInsert(t *testing.T) {
}
checkNoError
(
t
,
db
.
Commit
(),
"Error: %s"
)
lastI
d
:=
db
.
LastInsertRowid
()
assertEquals
(
t
,
"last insert row id error: expected %d but got %d"
,
int64
(
1000
),
lastI
d
)
lastI
D
:=
db
.
LastInsertRowid
()
assertEquals
(
t
,
"last insert row id error: expected %d but got %d"
,
int64
(
1000
),
lastI
D
)
cs
,
_
:=
db
.
Prepare
(
"SELECT COUNT(*) FROM test"
)
defer
checkFinalize
(
cs
,
t
)
...
...
stmt.go
View file @
7e0fdf5c
...
...
@@ -315,10 +315,10 @@ func (s *Stmt) Bind(args ...interface{}) error {
}
// NullIfEmpty transforms empty string to null when true (true by default)
var
NullIfEmptyString
bool
=
true
var
NullIfEmptyString
=
true
// NullIfZeroTime transforms zero time (time.Time.IsZero) to null when true (true by default)
var
NullIfZeroTime
bool
=
true
var
NullIfZeroTime
=
true
// BindByIndex binds value to the specified host parameter of the prepared statement.
// The leftmost SQL parameter has an index of 1.
...
...
@@ -485,12 +485,12 @@ func (t Type) String() string {
return
typeText
[
t
]
}
var
(
Integer
Type
=
Type
(
C
.
SQLITE_INTEGER
)
Float
Type
=
Type
(
C
.
SQLITE_FLOAT
)
Blob
Type
=
Type
(
C
.
SQLITE_BLOB
)
Null
Type
=
Type
(
C
.
SQLITE_NULL
)
Text
Type
=
Type
(
C
.
SQLITE3_TEXT
)
const
(
Integer
=
Type
(
C
.
SQLITE_INTEGER
)
Float
=
Type
(
C
.
SQLITE_FLOAT
)
Blob
=
Type
(
C
.
SQLITE_BLOB
)
Null
=
Type
(
C
.
SQLITE_NULL
)
Text
=
Type
(
C
.
SQLITE3_TEXT
)
)
var
typeText
=
map
[
Type
]
string
{
...
...
@@ -785,10 +785,9 @@ func (s *Stmt) ScanValue(index int, blob bool) (interface{}, bool) {
p
:=
C
.
sqlite3_column_blob
(
s
.
stmt
,
C
.
int
(
index
))
n
:=
C
.
sqlite3_column_bytes
(
s
.
stmt
,
C
.
int
(
index
))
return
C
.
GoBytes
(
p
,
n
),
false
}
else
{
p
:=
C
.
sqlite3_column_text
(
s
.
stmt
,
C
.
int
(
index
))
return
C
.
GoString
((
*
C
.
char
)(
unsafe
.
Pointer
(
p
))),
false
}
p
:=
C
.
sqlite3_column_text
(
s
.
stmt
,
C
.
int
(
index
))
return
C
.
GoString
((
*
C
.
char
)(
unsafe
.
Pointer
(
p
))),
false
case
Integer
:
return
int64
(
C
.
sqlite3_column_int64
(
s
.
stmt
,
C
.
int
(
index
))),
false
case
Float
:
...
...
stmt_test.go
View file @
7e0fdf5c
...
...
@@ -167,11 +167,11 @@ func TestScanNull(t *testing.T) {
if
!
Must
(
s
.
Next
())
{
t
.
Fatal
(
"no result"
)
}
var
pi
*
int
=
new
(
int
)
var
pi
=
new
(
int
)
null
:=
Must
(
s
.
ScanByIndex
(
0
,
&
pi
))
assert
(
t
,
"expected null value"
,
null
)
assertEquals
(
t
,
"expected nil (%p) but got %p"
,
(
*
int
)(
nil
),
pi
)
var
ps
*
string
=
new
(
string
)
var
ps
=
new
(
string
)
null
=
Must
(
s
.
ScanByIndex
(
0
,
&
ps
))
assert
(
t
,
"expected null value"
,
null
)
assertEquals
(
t
,
"expected nil (%p) but got %p"
,
(
*
string
)(
nil
),
ps
)
...
...
@@ -187,11 +187,11 @@ func TestScanNotNull(t *testing.T) {
if
!
Must
(
s
.
Next
())
{
t
.
Fatal
(
"no result"
)
}
var
pi
*
int
=
new
(
int
)
var
pi
=
new
(
int
)
null
:=
Must
(
s
.
ScanByIndex
(
0
,
&
pi
))
assert
(
t
,
"expected not null value"
,
!
null
)
assertEquals
(
t
,
"expected %d but got %d"
,
1
,
*
pi
)
var
ps
*
string
=
new
(
string
)
var
ps
=
new
(
string
)
null
=
Must
(
s
.
ScanByIndex
(
0
,
&
ps
))
assert
(
t
,
"expected not null value"
,
!
null
)
assertEquals
(
t
,
"expected %s but got %s"
,
"1"
,
*
ps
)
...
...
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