Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bvinc committed Aug 12, 2018
1 parent 737f70a commit 29f6e0e
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 42 deletions.
4 changes: 2 additions & 2 deletions LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2013 The Go-SQLite Authors. All rights reserved.
Copyright (c) 2018 The go-sqlite-lite Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
Expand All @@ -12,7 +12,7 @@ met:
documentation and/or other materials provided with the
distribution.

* Neither the name of the go-sqlite project nor the names of its
* Neither the name of the go-sqlite-lite project nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

Expand Down
2 changes: 1 addition & 1 deletion sqlite3/backup.go
@@ -1,4 +1,4 @@
// Copyright 2013 The Go-SQLite Authors. All rights reserved.
// Copyright 2018 The go-sqlite-lite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Expand Down
2 changes: 1 addition & 1 deletion sqlite3/const.go
@@ -1,4 +1,4 @@
// Copyright 2013 The Go-SQLite Authors. All rights reserved.
// Copyright 2018 The go-sqlite-lite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Expand Down
2 changes: 1 addition & 1 deletion sqlite3/io.go
@@ -1,4 +1,4 @@
// Copyright 2013 The Go-SQLite Authors. All rights reserved.
// Copyright 2018 The go-sqlite-lite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Expand Down
2 changes: 1 addition & 1 deletion sqlite3/sqlite3.c
@@ -1,4 +1,4 @@
// Copyright 2013 The Go-SQLite Authors. All rights reserved.
// Copyright 2018 The go-sqlite-lite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Expand Down
40 changes: 20 additions & 20 deletions sqlite3/sqlite3.go
@@ -1,4 +1,4 @@
// Copyright 2013 The Go-SQLite Authors. All rights reserved.
// Copyright 2018 The go-sqlite-lite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Expand All @@ -20,12 +20,15 @@ package sqlite3
#cgo CFLAGS: -DSQLITE_ENABLE_STAT3=1
#cgo CFLAGS: -DSQLITE_OMIT_AUTHORIZATION=1
#cgo CFLAGS: -DSQLITE_OMIT_AUTOINIT=1
#cgo CFLAGS: -DSQLITE_OMIT_DEPRECATED=1
#cgo CFLAGS: -DSQLITE_OMIT_PROGRESS_CALLBACK=1
#cgo CFLAGS: -DSQLITE_OMIT_LOAD_EXTENSION=1
#cgo CFLAGS: -DSQLITE_OMIT_TRACE=1
#cgo CFLAGS: -DSQLITE_OMIT_UTF16=1
#cgo CFLAGS: -DSQLITE_SOUNDEX=1
#cgo CFLAGS: -DSQLITE_TEMP_STORE=2
#cgo CFLAGS: -DSQLITE_THREADSAFE=2
#cgo CFLAGS: -DSQLITE_USE_ALLOCA=1
#cgo CFLAGS: -DSQLITE_USE_URI=1
// Fix for BusyTimeout on *nix systems.
Expand Down Expand Up @@ -114,7 +117,7 @@ type Conn struct {
// [https://www.sqlite.org/c3ref/open.html]
func Open(name string, flagArgs ...int) (*Conn, error) {
if len(flagArgs) > 1 {
pkgErr(MISUSE, "too many arguments provided to Open")
return nil, pkgErr(MISUSE, "too many arguments provided to Open")
}

if initErr != nil {
Expand Down Expand Up @@ -433,10 +436,6 @@ func (s *Stmt) ColumnCount() int {
return int(C.sqlite3_column_count(s.stmt))
}

// unnamedVars is assigned to Stmt.varNames if the prepared statement does not
// use named parameters. It just causes s.varNames == nil to evaluate to false.
var unnamedVars = make([]string, 0, 1)

// // Params returns the names of bound parameters in the prepared statement. Nil
// // is returned if the statement does not use named parameters.
// // [https://www.sqlite.org/c3ref/bind_parameter_name.html]
Expand Down Expand Up @@ -469,7 +468,8 @@ func (s *Stmt) ColumnName(i int) string {
return C.GoString(C.sqlite3_column_name(s.stmt, C.int(i)))
}

// Columns returns the names of columns produced by the prepared statement.
// ColumnsNames returns the names of columns produced by the prepared
// statement.
// [https://www.sqlite.org/c3ref/column_name.html]
func (s *Stmt) ColumnNames() []string {
nCols := s.ColumnCount()
Expand Down Expand Up @@ -558,9 +558,9 @@ func (s *Stmt) Bind(args ...interface{}) error {
if i != 0 || len(args) != 1 {
return pkgErr(MISUSE, "RowArgs must be used as the only argument to Bind()")
}
return s.bindNamed(NamedArgs(v))
return s.bindNamed(v)
default:
return pkgErr(MISUSE, "unsupported type at index %d (%T)", int(i), v)
return pkgErr(MISUSE, "unsupported type at index %d (%T)", i, v)
}
if rc != OK {
return errStr(rc)
Expand Down Expand Up @@ -632,33 +632,33 @@ func (s *Stmt) bindNamed(args NamedArgs) error {

var rc C.int
if v == nil {
rc = C.sqlite3_bind_null(s.stmt, C.int(i))
rc = C.sqlite3_bind_null(s.stmt, i)
if rc != OK {
return errStr(rc)
}
continue
}
switch v := v.(type) {
case int:
rc = C.sqlite3_bind_int64(s.stmt, C.int(i), C.sqlite3_int64(v))
rc = C.sqlite3_bind_int64(s.stmt, i, C.sqlite3_int64(v))
case int64:
rc = C.sqlite3_bind_int64(s.stmt, C.int(i), C.sqlite3_int64(v))
rc = C.sqlite3_bind_int64(s.stmt, i, C.sqlite3_int64(v))
case float64:
rc = C.sqlite3_bind_double(s.stmt, C.int(i), C.double(v))
rc = C.sqlite3_bind_double(s.stmt, i, C.double(v))
case bool:
rc = C.sqlite3_bind_int64(s.stmt, C.int(i), C.sqlite3_int64(cBool(v)))
rc = C.sqlite3_bind_int64(s.stmt, i, C.sqlite3_int64(cBool(v)))
case string:
rc = C.bind_text(s.stmt, C.int(i), cStr(v), C.int(len(v)), 1)
rc = C.bind_text(s.stmt, i, cStr(v), C.int(len(v)), 1)
case []byte:
rc = C.bind_blob(s.stmt, C.int(i), cBytes(v), C.int(len(v)), 1)
rc = C.bind_blob(s.stmt, i, cBytes(v), C.int(len(v)), 1)
case time.Time:
rc = C.sqlite3_bind_int64(s.stmt, C.int(i), C.sqlite3_int64(v.Unix()))
rc = C.sqlite3_bind_int64(s.stmt, i, C.sqlite3_int64(v.Unix()))
case RawString:
rc = C.bind_text(s.stmt, C.int(i), cStr(string(v)), C.int(len(v)), 0)
rc = C.bind_text(s.stmt, i, cStr(string(v)), C.int(len(v)), 0)
case RawBytes:
rc = C.bind_blob(s.stmt, C.int(i), cBytes(v), C.int(len(v)), 0)
rc = C.bind_blob(s.stmt, i, cBytes(v), C.int(len(v)), 0)
case ZeroBlob:
rc = C.sqlite3_bind_zeroblob(s.stmt, C.int(i), C.int(v))
rc = C.sqlite3_bind_zeroblob(s.stmt, i, C.int(v))
default:
return pkgErr(MISUSE, "unsupported type for %s (%T)", name, v)
}
Expand Down
2 changes: 1 addition & 1 deletion sqlite3/sqlite3.h
@@ -1,4 +1,4 @@
// Copyright 2013 The Go-SQLite Authors. All rights reserved.
// Copyright 2018 The go-sqlite-lite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Expand Down
2 changes: 1 addition & 1 deletion sqlite3/sqlite3_test.go
@@ -1,4 +1,4 @@
// Copyright 2013 The Go-SQLite Authors. All rights reserved.
// Copyright 2018 The go-sqlite-lite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Expand Down
40 changes: 26 additions & 14 deletions sqlite3/util.go
@@ -1,4 +1,4 @@
// Copyright 2013 The Go-SQLite Authors. All rights reserved.
// Copyright 2018 The go-sqlite-lite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -26,21 +26,33 @@ import (
// [http://www.sqlite.org/lang_expr.html#varparam]
type NamedArgs map[string]interface{}

// RawString and RawBytes are special string and []byte types that may be used
// for database input and output without the cost of an extra copy operation.
//
// When used as an argument to a statement, the contents are bound using
// SQLITE_STATIC instead of SQLITE_TRANSIENT flag. This requires the contents to
// remain valid and unmodified until the end of statement execution. In
// particular, the caller must keep a reference to the value to prevent it from
// being garbage collected.
//
// When used for retrieving query output, the internal string/[]byte pointer is
// set to reference memory belonging to SQLite. The memory remains valid until
// another method is called on the Stmt object and should not be modified.
type (
// RawString is a special string type that may be used for database input and
// output without the cost of an extra copy operation.
//
// When used as an argument to a statement, the contents are bound using
// SQLITE_STATIC instead of SQLITE_TRANSIENT flag. This requires the contents to
// remain valid and unmodified until the end of statement execution. In
// particular, the caller must keep a reference to the value to prevent it from
// being garbage collected.
//
// When used for retrieving query output, the internal string pointer is set
// to reference memory belonging to SQLite. The memory remains valid until
// another method is called on the Stmt object and should not be modified.
RawString string
RawBytes []byte
// RawBytes is a special string type that may be used for database input and
// output without the cost of an extra copy operation.
//
// When used as an argument to a statement, the contents are bound using
// SQLITE_STATIC instead of SQLITE_TRANSIENT flag. This requires the contents to
// remain valid and unmodified until the end of statement execution. In
// particular, the caller must keep a reference to the value to prevent it from
// being garbage collected.
//
// When used for retrieving query output, the internal []byte pointer is set
// to reference memory belonging to SQLite. The memory remains valid until
// another method is called on the Stmt object and should not be modified.
RawBytes []byte
)

// Copy returns a Go-managed copy of s.
Expand Down

0 comments on commit 29f6e0e

Please sign in to comment.