# Can't Save Integer Zero to SQLite3 DB

**URL:** <https://www.ruby-forum.com/t/cant-save-integer-zero-to-sqlite3-db/173818>\
**Category:** Rails\
**Created:** [August 15, 2009, 9:15pm UTC](https://www.ruby-forum.com/t/cant-save-integer-zero-to-sqlite3-db/173818 "2009-08-15T21:15:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![djames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@djames](https://www.ruby-forum.com/u/djames)\
**Post date:** [August 15, 2009, 9:15pm UTC](https://www.ruby-forum.com/t/cant-save-integer-zero-to-sqlite3-db/173818/1 "2009-08-15T21:15:47Z")

</div>

FWIW, I’m using the SQLite3 DB.

I have a table column declared to be of type integer. When I update a  
record (using ActiveRecord, of course) any changes to any other  
columns are made perfectly. Changes to this particular column are  
also made perfectly as long as the new value is not zero. However,  
if the new value for this column is zero, it is not updated and the  
old value is retained.

I’m sorry. I seem to be encountering more than my share of bizarre  
situations lately. Does anyone have any thoughts? Thanks.

```
     ... doug
```

---

<div class="post-metadata">

**Author:** ![djames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@djames](https://www.ruby-forum.com/u/djames)\
**Post date:** [August 15, 2009, 11:50pm UTC](https://www.ruby-forum.com/t/cant-save-integer-zero-to-sqlite3-db/173818/2 "2009-08-15T23:50:18Z")

</div>

On Aug 15, 8:14 pm, doug [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> FWIW, I’m using the SQLite3 DB.
> 
> I have a table column declared to be of type integer. When I update a  
> record (using ActiveRecord, of course) any changes to any other  
> columns are made perfectly. Changes to this particular column are  
> also made perfectly as long as the new value is not zero. However,  
> if the new value for this column is zero, it is not updated and the  
> old value is retained.

What version of rails ? I do recall some bugs with change tracking and  
setting integer columns to zero.

Fred

---

<div class="post-metadata">

**Author:** ![djames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@djames](https://www.ruby-forum.com/u/djames)\
**Post date:** [August 16, 2009, 12:51am UTC](https://www.ruby-forum.com/t/cant-save-integer-zero-to-sqlite3-db/173818/3 "2009-08-16T00:51:10Z")

</div>

> What version of rails ?

2.3.2 and it’s going to be really difficult for me to alter that. If  
it’s a Rails bug it could be a major problem for me unless I can find  
a work-around. Thanks for the input.

```
   ... doug
```

---

<div class="post-metadata">

**Author:** ![djames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@djames](https://www.ruby-forum.com/u/djames)\
**Post date:** [August 16, 2009, 1:22am UTC](https://www.ruby-forum.com/t/cant-save-integer-zero-to-sqlite3-db/173818/4 "2009-08-16T01:22:47Z")

</div>

On Sat, Aug 15, 2009 at 3:50 PM, djolley[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 2.3.2 and it’s going to be really difficult for me to alter that. If  
> it’s a Rails bug it could be a major problem for me unless I can find  
> a work-around. Thanks for the input.

I just genned a test app with 2.3.2 + SQLite3 having a model with an  
integer field.

Setting that field to 0 was successful both via rspec test and console .

I would either try to create a minimal test case app that demonstrates  
the problem you’re seeing, or write more tests. Which couldn’t hurt,  
in any case 🙂

## FWIW,

Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![djames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@djames](https://www.ruby-forum.com/u/djames)\
**Post date:** [August 16, 2009, 10:08pm UTC](https://www.ruby-forum.com/t/cant-save-integer-zero-to-sqlite3-db/173818/5 "2009-08-16T22:08:52Z")

</div>

> I just genned a test app with 2.3.2 + SQLite3 having a model with an  
> integer field.

My gosh!! I didn’t intend for you to have to go to that extreme. I  
do sincerely appreciate your investing the time on my behalf.

I swear that what I reported yesterday was the results I was seeing at  
that time. Today things seem to be a bit different. I have to  
conclude that maybe I didn’t investigate this thoroughly enough  
yesterday before posting. I really thought that I had.

Today, the problem seems to be totally different. What’s happening is  
that values set in select elements are properly included in the record  
TO BE saved. However, those values and only those values are not  
transferred to the new saved record. The new saved record properly  
reflects any changes to fields which are not associated with select  
elements. However, new values associated with select elements which  
are properly set in the record TO BE saved are not saved. Instead the  
old values are retained.

At this point, I can only conclude that I must have totally mis-read  
this problem yesterday and somehow interpreted it to be what I  
reported. I really apologize for that especially since you went to  
the trouble of genning a test app under my version of Rails in an  
attempt to reproduce the problem. I am truly embarrassed.

I may have to re-post this “new” problem. Thanks ever so much for  
your help.

```
      ... doug
```

---

<div class="post-metadata">

**Author:** ![djames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@djames](https://www.ruby-forum.com/u/djames)\
**Post date:** [August 16, 2009, 10:17pm UTC](https://www.ruby-forum.com/t/cant-save-integer-zero-to-sqlite3-db/173818/6 "2009-08-16T22:17:38Z")

</div>

On Sun, Aug 16, 2009 at 1:07 PM, djolley[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > I just genned a test app with 2.3.2 + SQLite3 having a model with an  
> > integer field.
> 
> My gosh!! I didn’t intend for you to have to go to that extreme. I  
> do sincerely appreciate your investing the time on my behalf.

NP, 5 minutes max to create it, write a couple of tests and open up  
a console to play with. A short break from other stuff. Besides, I’m  
kinda ADD and – oh, look, a cat! 🙂

> that values set in select elements are properly included in the record  
> TO BE saved. However, those values and only those values are not  
> transferred to the new saved record. The new saved record properly  
> reflects any changes to fields which are not associated with select  
> elements. However, new values associated with select elements which  
> are properly set in the record TO BE saved are not saved.

Yeah, that sounds very odd. See if you can come up with a simple  
(reproducible) test case.

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![djames](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7ab992/32.png) [@djames](https://www.ruby-forum.com/u/djames)\
**Post date:** [August 16, 2009, 1:25am UTC](https://www.ruby-forum.com/t/cant-save-integer-zero-to-sqlite3-db/173818/7 "2009-08-16T01:25:42Z")

</div>

On Aug 15, 11:50 pm, djolley [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > What version of rails ?
> 
> 2.3.2 and it’s going to be really difficult for me to alter that. If  
> it’s a Rails bug it could be a major problem for me unless I can find  
> a work-around. Thanks for the input.

the stuff I remember was fixed before then. Is it the assignment that  
does nothing or the save itself ? Anything peculiar about the code ?

Fred
