# SQLite/Rails/Human bug? "SQL logic error"

**URL:** <https://www.ruby-forum.com/t/sqlite-rails-human-bug-sql-logic-error/110188>\
**Category:** Rails\
**Created:** [July 24, 2007, 1:02am UTC](https://www.ruby-forum.com/t/sqlite-rails-human-bug-sql-logic-error/110188 "2007-07-24T01:02:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![darth\_ivan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@darth\_ivan](https://www.ruby-forum.com/u/darth_ivan)\
**Post date:** [July 24, 2007, 1:02am UTC](https://www.ruby-forum.com/t/sqlite-rails-human-bug-sql-logic-error/110188/1 "2007-07-24T01:02:39Z")

</div>

Hi,

I’ve searched with no end for any clue as to why I get the following  
error:

SQLite3::SQLException: SQL logic error or missing database: INSERT INTO  
estudio\_stages (“updated\_at”, “estudio\_id”, “created\_at”, “stage\_id”)  
VALUES(‘2007-07-23 16:32:42’, 2, ‘2007-07-23 16:32:42’, 4)

…when accesing a certain action in a controller… but if I execute  
that SQL code directly in sqlite, or call the appropiate method in my  
model from the console, it works!

So what gives?

Thanks for any help!

- Ivan V.

---

<div class="post-metadata">

**Author:** ![darth\_ivan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@darth\_ivan](https://www.ruby-forum.com/u/darth_ivan)\
**Post date:** [July 24, 2007, 1:08am UTC](https://www.ruby-forum.com/t/sqlite-rails-human-bug-sql-logic-error/110188/2 "2007-07-24T01:08:43Z")

</div>

Ivan V. wrote:

> Hi,
> 
> I’ve searched with no end for any clue as to why I get the following  
> error:
> 
> SQLite3::SQLException: SQL logic error or missing database: INSERT INTO  
> estudio\_stages (“updated\_at”, “estudio\_id”, “created\_at”, “stage\_id”)  
> VALUES(‘2007-07-23 16:32:42’, 2, ‘2007-07-23 16:32:42’, 4)
> 
> …when accesing a certain action in a controller… but if I execute  
> that SQL code directly in sqlite, or call the appropiate method in my  
> model from the console, it works!
> 
> So what gives?
> 
> Thanks for any help!
> 
> - Ivan V.

For a second there I thought I had a clue… Here’s part of the trace:

vendor/rails/activerecord/lib/active\_record/connection\_adapters/abstract\_adapter.rb:135:in  
`log' vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:132:in`execute’  
vendor/rails/activerecord/lib/active\_record/connection\_adapters/sqlite\_adapter.rb:341:in  
`catch_schema_changes' vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:132:in`execute’  
vendor/rails/activerecord/lib/active\_record/connection\_adapters/sqlite\_adapter.rb:147:in  
`insert’

So there’s a method named ‘catch\_schema\_changes’ in the sqlite adapter,  
and I read somewhere that SQLite doesn’t support renaming columns, so I  
thought if I deleted and then re-created the schema.rb file then it  
might just work (don’t ask me the logic behind such reasoning), but it  
doesn’t…

---

<div class="post-metadata">

**Author:** ![darth\_ivan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@darth\_ivan](https://www.ruby-forum.com/u/darth_ivan)\
**Post date:** [July 24, 2007, 1:52am UTC](https://www.ruby-forum.com/t/sqlite-rails-human-bug-sql-logic-error/110188/3 "2007-07-24T01:52:04Z")

</div>

Ivan V. wrote:

> Hi,
> 
> I’ve searched with no end for any clue as to why I get the following  
> error:
> 
> SQLite3::SQLException: SQL logic error or missing database: INSERT INTO  
> estudio\_stages (“updated\_at”, “estudio\_id”, “created\_at”, “stage\_id”)  
> VALUES(‘2007-07-23 16:32:42’, 2, ‘2007-07-23 16:32:42’, 4)
> 
> …when accesing a certain action in a controller… but if I execute  
> that SQL code directly in sqlite, or call the appropiate method in my  
> model from the console, it works!
> 
> So what gives?
> 
> Thanks for any help!
> 
> - Ivan V.

This just gets weirder… If I debug the application with NetBeans and  
set a breakpoint on the AR object’s save method to try and see where the  
problem might be, I step into a few statements, then NetBeans seem to  
not want to step any further, so I press “Continue” to finish the  
remaining calls… and then it works…, with no error thrown…

Just now I also tried executing directly with  
AR::Base.connection.execute… no luck ☹

---

<div class="post-metadata">

**Author:** ![darth\_ivan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/22d042/32.png) [@darth\_ivan](https://www.ruby-forum.com/u/darth_ivan)\
**Post date:** [July 24, 2007, 2:20am UTC](https://www.ruby-forum.com/t/sqlite-rails-human-bug-sql-logic-error/110188/4 "2007-07-24T02:20:28Z")

</div>

Ivan V. wrote:

> Ivan V. wrote:
> 
> > Hi,
> > 
> > I’ve searched with no end for any clue as to why I get the following  
> > error:
> > 
> > SQLite3::SQLException: SQL logic error or missing database: INSERT INTO  
> > estudio\_stages (“updated\_at”, “estudio\_id”, “created\_at”, “stage\_id”)  
> > VALUES(‘2007-07-23 16:32:42’, 2, ‘2007-07-23 16:32:42’, 4)
> > 
> > …when accesing a certain action in a controller… but if I execute  
> > that SQL code directly in sqlite, or call the appropiate method in my  
> > model from the console, it works!
> > 
> > So what gives?
> > 
> > Thanks for any help!
> > 
> > - Ivan V.
> 
> This just gets weirder… If I debug the application with NetBeans and  
> set a breakpoint on the AR object’s save method to try and see where the  
> problem might be, I step into a few statements, then NetBeans seem to  
> not want to step any further, so I press “Continue” to finish the  
> remaining calls… and then it works…, with no error thrown…
> 
> Just now I also tried executing directly with  
> AR::Base.connection.execute… no luck ☹

I dare you to find another hack that can be called the fugliest hack  
ever:

```
if ENV["RAILS_ENV"] == "development"
  created = Time.now.strftime('%Y-%m-%d %H:%M:%S')
  sql = "INSERT INTO estudio_stages ('updated_at', 'estudio_id', 

```

‘created\_at’, ‘stage\_id’) VALUES(’#{created}’, #{self.id}, ‘#{created}’,  
#{s.id})"  
a = %x[sqlite3 #{RAILS\_ROOT}/db/development.db “#{sql}”]  
self.save!  
self.reload  
else  
self.stages.build :stage\_id =\> s.id  
self.save  
end

Sigh…
