# ActiveRecord & Sqlite3 & serialize & "f"

**URL:** <https://www.ruby-forum.com/t/activerecord-sqlite3-serialize-f/109983>\
**Category:** Ruby\
**Created:** [July 20, 2007, 9:43pm UTC](https://www.ruby-forum.com/t/activerecord-sqlite3-serialize-f/109983 "2007-07-20T21:43:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![erikveen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/59ef9b/32.png) [@erikveen](https://www.ruby-forum.com/u/erikveen)\
**Post date:** [July 20, 2007, 9:43pm UTC](https://www.ruby-forum.com/t/activerecord-sqlite3-serialize-f/109983/1 "2007-07-20T21:43:08Z")

</div>

What’s wrong with the code below?

It returns this “f” instead of “”. Where does “f” come from?

Thanks.

gegroet,  
Erik V. - [http://www.erikveen.dds.nl/](http://www.erikveen.dds.nl/)

* * *

$ ruby test.rb  
:bar  
“f” \<\<\<\< Should be “”  
nil

$ echo “select \* from key\_values;” | sqlite3 test.db  
1|— :foo  
|— :bar

2|— :empty  
|f  
3|— :nil  
|

* * *

require “rubygems”  
require “active\_record”

class KeyValue \< ActiveRecord::Base  
serialize :key  
serialize :value

def self.create\_table  
unless connection.tables.include?(table\_name)  
connection.create\_table(table\_name) do |table|  
table.column :id , :primary\_key  
table.column :key , :text  
table.column :value , :text  
end  
end  
end

def self.  
find\_or\_create\_by\_key(key).value  
end

def self.[]=(key, value)  
config = find\_or\_create\_by\_key(key)  
config.value = value  
config.save  
end  
end

File.delete(“test.db”) if File.file?(“test.db”)

ActiveRecord::Base.establish\_connection(:adapter=\>“sqlite3”,  
:database=\>“test.db”)

KeyValue.create\_table

KeyValue[:foo] = :bar  
KeyValue[:empty] = “”  
KeyValue[:nil] = nil

p KeyValue[:foo]  
p KeyValue[:empty]  
p KeyValue[:nil]

---

<div class="post-metadata">

**Author:** ![erikveen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/59ef9b/32.png) [@erikveen](https://www.ruby-forum.com/u/erikveen)\
**Post date:** [July 20, 2007, 9:50pm UTC](https://www.ruby-forum.com/t/activerecord-sqlite3-serialize-f/109983/2 "2007-07-20T21:50:10Z")

</div>

On 7/20/07, Erik V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What’s wrong with the code below?
> 
> It returns this “f” instead of “”. Where does “f” come from?

sqlite3 returns #f for null columns. Google “sqlite3 null f” for some  
references. Somewhere in the confusion it seems your “” is becoming a  
null  
in the database.

Cheers,  
Peter C.

> **[Ruby Inside: The Ruby Blog](http://www.rubyinside.com/)**
>
> The biggest Ruby and Rails blog since 2006 - tutorials, news, and lots more
