Skip to content

Commit bc594c9

Browse files
committed
Add ColumnBool and GetBool methods
Fixes zombiezen#37
1 parent c6d6f6a commit bc594c9

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
that take in an `ExecOptions` struct.
1919
([#5](https://github.com/zombiezen/go-sqlite/issues/5))
2020
- New method `sqlite.ResultCode.ToError` to create error values.
21+
- New methods `ColumnBool` and `GetBool` on `*sqlite.Stmt`
22+
([#37](https://github.com/zombiezen/go-sqlite/issues/37)).
2123

2224
### Changed
2325

sqlite.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,15 @@ func (stmt *Stmt) ColumnInt64(col int) int64 {
10261026
return lib.Xsqlite3_column_int64(stmt.conn.tls, stmt.stmt, int32(col))
10271027
}
10281028

1029+
// ColumnBool reports whether a query result value is non-zero.
1030+
//
1031+
// Column indices start at 0.
1032+
//
1033+
// https://www.sqlite.org/c3ref/column_blob.html
1034+
func (stmt *Stmt) ColumnBool(col int) bool {
1035+
return stmt.ColumnInt64(col) != 0
1036+
}
1037+
10291038
// ColumnBytes reads a query result into buf.
10301039
// It reports the number of bytes read.
10311040
//
@@ -1165,6 +1174,11 @@ func (stmt *Stmt) GetInt64(colName string) int64 {
11651174
return stmt.ColumnInt64(col)
11661175
}
11671176

1177+
// GetBool reports whether the query result value for colName is non-zero.
1178+
func (stmt *Stmt) GetBool(colName string) bool {
1179+
return stmt.GetInt64(colName) != 0
1180+
}
1181+
11681182
// GetBytes reads a query result for colName into buf.
11691183
// It reports the number of bytes read.
11701184
func (stmt *Stmt) GetBytes(colName string, buf []byte) int {

0 commit comments

Comments
 (0)