mirror of
https://github.com/glebarez/go-sqlite.git
synced 2025-10-05 15:56:52 +08:00
minor syntax changes for better aligning with upstream
This commit is contained in:
31
sqlite.go
31
sqlite.go
@@ -47,6 +47,7 @@ var (
|
|||||||
_ error = (*Error)(nil)
|
_ error = (*Error)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// LogSqlStatements - if true when Open() is called, all SQL statements will be logged to standard output
|
||||||
var LogSqlStatements bool
|
var LogSqlStatements bool
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -165,17 +166,12 @@ func (r *result) RowsAffected() (int64, error) {
|
|||||||
type rows struct {
|
type rows struct {
|
||||||
allocs []uintptr // allocations made for this prepared statement (to be freed)
|
allocs []uintptr // allocations made for this prepared statement (to be freed)
|
||||||
c *conn // connection
|
c *conn // connection
|
||||||
|
columns []string // column names
|
||||||
pstmt uintptr // correspodning prepared statement
|
pstmt uintptr // correspodning prepared statement
|
||||||
columns []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRows(c *conn, pstmt uintptr, allocs []uintptr) (r *rows, err error) {
|
func newRows(c *conn, pstmt uintptr, allocs []uintptr) (r *rows, err error) {
|
||||||
// create rows
|
r = &rows{c: c, pstmt: pstmt, allocs: allocs}
|
||||||
r = &rows{
|
|
||||||
c: c,
|
|
||||||
pstmt: pstmt,
|
|
||||||
allocs: allocs,
|
|
||||||
}
|
|
||||||
|
|
||||||
// deferred close if anything goes wrong
|
// deferred close if anything goes wrong
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -186,13 +182,13 @@ func newRows(c *conn, pstmt uintptr, allocs []uintptr) (r *rows, err error) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
// get columns count
|
// get columns count
|
||||||
nCols, err := c.columnCount(pstmt)
|
n, err := c.columnCount(pstmt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// get column names
|
// get column names
|
||||||
r.columns = make([]string, nCols)
|
r.columns = make([]string, n)
|
||||||
for i := range r.columns {
|
for i := range r.columns {
|
||||||
if r.columns[i], err = r.c.columnName(pstmt, i); err != nil {
|
if r.columns[i], err = r.c.columnName(pstmt, i); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -233,7 +229,7 @@ func (r *rows) Next(dest []driver.Value) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// analyze error code
|
// analyze error code
|
||||||
switch rc & 0xff {
|
switch rc {
|
||||||
case sqlite3.SQLITE_ROW:
|
case sqlite3.SQLITE_ROW:
|
||||||
if g, e := len(dest), len(r.columns); g != e {
|
if g, e := len(dest), len(r.columns); g != e {
|
||||||
return fmt.Errorf("sqlite: Next: have %v destination values, expected %v", g, e)
|
return fmt.Errorf("sqlite: Next: have %v destination values, expected %v", g, e)
|
||||||
@@ -587,10 +583,8 @@ func (s *stmt) Query(args []driver.Value) (driver.Rows, error) { //TODO StmtQuer
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *stmt) query(ctx context.Context, args []driver.NamedValue) (r driver.Rows, err error) {
|
func (s *stmt) query(ctx context.Context, args []driver.NamedValue) (r driver.Rows, err error) {
|
||||||
var (
|
var pstmt uintptr // C-pointer to prepared statement
|
||||||
pstmt uintptr // C-pointer to prepared statement
|
var done int32 // done indicator (atomic usage)
|
||||||
done int32 // done indicator (atomic usage)
|
|
||||||
)
|
|
||||||
|
|
||||||
// context honoring
|
// context honoring
|
||||||
if ctx != nil && ctx.Done() != nil {
|
if ctx != nil && ctx.Done() != nil {
|
||||||
@@ -1521,10 +1515,6 @@ func newDriver() *Driver { return d }
|
|||||||
// available at
|
// available at
|
||||||
// https://www.sqlite.org/lang_transaction.html#deferred_immediate_and_exclusive_transactions
|
// https://www.sqlite.org/lang_transaction.html#deferred_immediate_and_exclusive_transactions
|
||||||
func (d *Driver) Open(name string) (driver.Conn, error) {
|
func (d *Driver) Open(name string) (driver.Conn, error) {
|
||||||
if LogSqlStatements {
|
|
||||||
log.Println("new connection")
|
|
||||||
}
|
|
||||||
|
|
||||||
c, err := newConn(name)
|
c, err := newConn(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1536,6 +1526,11 @@ func (d *Driver) Open(name string) (driver.Conn, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if LogSqlStatements {
|
||||||
|
log.Println("new connection")
|
||||||
|
}
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user