Skip to content

Commit

Permalink
Add ColumnBool and GetBool methods
Browse files Browse the repository at this point in the history
Fixes #37
  • Loading branch information
zombiezen committed Jan 17, 2022
1 parent c6d6f6a commit bc594c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
that take in an `ExecOptions` struct.
([#5](https://github.com/zombiezen/go-sqlite/issues/5))
- New method `sqlite.ResultCode.ToError` to create error values.
- New methods `ColumnBool` and `GetBool` on `*sqlite.Stmt`
([#37](https://github.com/zombiezen/go-sqlite/issues/37)).

### Changed

Expand Down
14 changes: 14 additions & 0 deletions sqlite.go
Expand Up @@ -1026,6 +1026,15 @@ func (stmt *Stmt) ColumnInt64(col int) int64 {
return lib.Xsqlite3_column_int64(stmt.conn.tls, stmt.stmt, int32(col))
}

// ColumnBool reports whether a query result value is non-zero.
//
// Column indices start at 0.
//
// https://www.sqlite.org/c3ref/column_blob.html
func (stmt *Stmt) ColumnBool(col int) bool {
return stmt.ColumnInt64(col) != 0
}

// ColumnBytes reads a query result into buf.
// It reports the number of bytes read.
//
Expand Down Expand Up @@ -1165,6 +1174,11 @@ func (stmt *Stmt) GetInt64(colName string) int64 {
return stmt.ColumnInt64(col)
}

// GetBool reports whether the query result value for colName is non-zero.
func (stmt *Stmt) GetBool(colName string) bool {
return stmt.GetInt64(colName) != 0
}

// GetBytes reads a query result for colName into buf.
// It reports the number of bytes read.
func (stmt *Stmt) GetBytes(colName string, buf []byte) int {
Expand Down

0 comments on commit bc594c9

Please sign in to comment.