Skip to content

Commit b8d537f

Browse files
authored
Merge pull request #461 from mattn/solaris
support Solaris
2 parents d40d490 + 8d81c2f commit b8d537f

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

sqlite3.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ type SQLiteTx struct {
182182

183183
// SQLiteStmt implement sql.Stmt.
184184
type SQLiteStmt struct {
185+
mu sync.Mutex
185186
c *SQLiteConn
186187
s *C.sqlite3_stmt
187188
t string
@@ -803,6 +804,8 @@ func (c *SQLiteConn) prepare(ctx context.Context, query string) (driver.Stmt, er
803804

804805
// Close the statement.
805806
func (s *SQLiteStmt) Close() error {
807+
s.mu.Lock()
808+
defer s.mu.Unlock()
806809
if s.closed {
807810
return nil
808811
}
@@ -980,26 +983,33 @@ func (s *SQLiteStmt) exec(ctx context.Context, args []namedValue) (driver.Result
980983

981984
// Close the rows.
982985
func (rc *SQLiteRows) Close() error {
986+
rc.s.mu.Lock()
983987
if rc.s.closed || rc.closed {
988+
rc.s.mu.Unlock()
984989
return nil
985990
}
986991
rc.closed = true
987992
if rc.done != nil {
988993
close(rc.done)
989994
}
990995
if rc.cls {
996+
rc.s.mu.Unlock()
991997
return rc.s.Close()
992998
}
993999
rv := C.sqlite3_reset(rc.s.s)
9941000
if rv != C.SQLITE_OK {
1001+
rc.s.mu.Unlock()
9951002
return rc.s.c.lastError()
9961003
}
1004+
rc.s.mu.Unlock()
9971005
return nil
9981006
}
9991007

10001008
// Columns return column names.
10011009
func (rc *SQLiteRows) Columns() []string {
1002-
if rc.nc != len(rc.cols) {
1010+
rc.s.mu.Lock()
1011+
defer rc.s.mu.Unlock()
1012+
if rc.s.s != nil && rc.nc != len(rc.cols) {
10031013
rc.cols = make([]string, rc.nc)
10041014
for i := 0; i < rc.nc; i++ {
10051015
rc.cols[i] = C.GoString(C.sqlite3_column_name(rc.s.s, C.int(i)))
@@ -1008,9 +1018,8 @@ func (rc *SQLiteRows) Columns() []string {
10081018
return rc.cols
10091019
}
10101020

1011-
// DeclTypes return column types.
1012-
func (rc *SQLiteRows) DeclTypes() []string {
1013-
if rc.decltype == nil {
1021+
func (rc *SQLiteRows) declTypes() []string {
1022+
if rc.s.s != nil && rc.decltype == nil {
10141023
rc.decltype = make([]string, rc.nc)
10151024
for i := 0; i < rc.nc; i++ {
10161025
rc.decltype[i] = strings.ToLower(C.GoString(C.sqlite3_column_decltype(rc.s.s, C.int(i))))
@@ -1019,8 +1028,20 @@ func (rc *SQLiteRows) DeclTypes() []string {
10191028
return rc.decltype
10201029
}
10211030

1031+
// DeclTypes return column types.
1032+
func (rc *SQLiteRows) DeclTypes() []string {
1033+
rc.s.mu.Lock()
1034+
defer rc.s.mu.Unlock()
1035+
return rc.declTypes()
1036+
}
1037+
10221038
// Next move cursor to next.
10231039
func (rc *SQLiteRows) Next(dest []driver.Value) error {
1040+
if rc.s.closed {
1041+
return io.EOF
1042+
}
1043+
rc.s.mu.Lock()
1044+
defer rc.s.mu.Unlock()
10241045
rv := C.sqlite3_step(rc.s.s)
10251046
if rv == C.SQLITE_DONE {
10261047
return io.EOF
@@ -1033,7 +1054,7 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
10331054
return nil
10341055
}
10351056

1036-
rc.DeclTypes()
1057+
rc.declTypes()
10371058

10381059
for i := range dest {
10391060
switch C.sqlite3_column_type(rc.s.s, C.int(i)) {

sqlite3_libsqlite3.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ package sqlite3
1010
#cgo CFLAGS: -DUSE_LIBSQLITE3
1111
#cgo linux LDFLAGS: -lsqlite3
1212
#cgo darwin LDFLAGS: -L/usr/local/opt/sqlite/lib -lsqlite3
13+
#cgo solaris LDFLAGS: -lsqlite3
1314
*/
1415
import "C"

sqlite3_other.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ package sqlite3
99
/*
1010
#cgo CFLAGS: -I.
1111
#cgo linux LDFLAGS: -ldl
12+
#cgo solaris LDFLAGS: -lc
1213
*/
1314
import "C"

0 commit comments

Comments
 (0)