Commit 0d695f4e authored by gwenn's avatar gwenn

Consider any value different from zero to be true.

parent caa35353
......@@ -287,7 +287,7 @@ func (c *ScalarContext) SetAuxData(n int, ad interface{}) {
// Bool obtains a SQL function parameter value.
// The leftmost value is number 0.
func (c *FunctionContext) Bool(i int) bool {
return c.Int(i) == 1
return c.Int(i) != 0
}
// Blob obtains a SQL function parameter value.
......
......@@ -38,8 +38,8 @@ func (c *Conn) Column(dbName, tableName, columnName string) (*Column, error) {
if rv != C.SQLITE_OK {
return nil, c.error(rv, fmt.Sprintf("Conn.Column(db: %q, tbl: %q, col: %q)", dbName, tableName, columnName))
}
return &Column{-1, columnName, C.GoString(zDataType), notNull == 1, "", int(primaryKey),
autoinc == 1, C.GoString(zCollSeq)}, nil
return &Column{-1, columnName, C.GoString(zDataType), notNull != 0, "", int(primaryKey),
autoinc != 0, C.GoString(zCollSeq)}, nil
}
// ColumnDatabaseName returns the database
......
......@@ -978,7 +978,7 @@ func (s *Stmt) ScanBool(index int) (value bool, isNull bool, err error) {
if CheckTypeMismatch {
err = s.checkTypeMismatch(ctype, Integer)
}
value = C.sqlite3_column_int(s.stmt, C.int(index)) == 1
value = C.sqlite3_column_int(s.stmt, C.int(index)) != 0
}
return
}
......@@ -1162,5 +1162,5 @@ func (s *Stmt) Conn() *Conn {
// ReadOnly returns true if the prepared statement is guaranteed to not modify the database.
// (See http://sqlite.org/c3ref/stmt_readonly.html)
func (s *Stmt) ReadOnly() bool {
return C.sqlite3_stmt_readonly(s.stmt) == 1
return C.sqlite3_stmt_readonly(s.stmt) != 0
}
......@@ -749,3 +749,28 @@ func TestCheckTypeMismatch(t *testing.T) {
assert.T(t, err != nil)
//println(err.Error())
}
func TestReadOnly(t *testing.T) {
db := open(t)
defer checkClose(db, t)
s, err := db.Prepare("DROP TABLE IF EXISTS test")
checkNoError(t, err, "prepare error: %s")
assert.T(t, s.ReadOnly())
//checkNoError(t, s.Exec(), "exe error: %s")
checkFinalize(s, t)
s, err = db.Prepare("CREATE TABLE test (data TEXT)")
checkNoError(t, err, "prepare error: %s")
assert.T(t, !s.ReadOnly())
checkNoError(t, s.Exec(), "exe error: %s")
checkFinalize(s, t)
s, err = db.Prepare("DROP TABLE IF EXISTS test")
//s, err = db.Prepare("DROP TABLE test")
checkNoError(t, err, "prepare error: %s")
assert.T(t, s.ReadOnly()) // FIXME
checkNoError(t, s.Exec(), "exe error: %s")
checkFinalize(s, t)
assert.T(t, !s.ReadOnly())
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment