Jeremy- 

Real quick, with your thoughts, I believe it IS a SQLite problem. Besides 
updating the project to the latest gems, the Mac was update to Mountain Lion. 
The primary keys are all auto increment. It maybe that SQLite installation is 
broken. I look into it when I get home. 


Thanks, 


-GregD 

----- Original Message -----

From: "Jeremy Evans" <[email protected]> 
To: [email protected] 
Sent: Wednesday, October 24, 2012 2:30:53 AM 
Subject: Re: one_to_one not working in an older project 

On Tuesday, October 23, 2012 10:35:54 PM UTC-7, Jeremy Evans wrote: 


On Tuesday, October 23, 2012 6:54:16 PM UTC-7, GregD wrote: 

<blockquote>



It looks like after the insert the key returned is not found in a followup 
select. It is trying to do a select on id 1. The table is still empty for some 
reason. 



et = Tournament.first 
TournamentConfiguration.create(:tournament => et) 





(0.031481s) SELECT * FROM `tournaments` LIMIT 1 
(0.000198s) SELECT sqlite_version() LIMIT 1 
(0.000074s) BEGIN 
(0.001818s) INSERT INTO `tournament_configurations` (`tournament_id`) VALUES 
(1) 
(0.000181s) SELECT * FROM `tournament_configurations` WHERE (`id` = 1) LIMIT 1 
(0.000409s) ROLLBACK 




See that ROLLBACK? For some reason, the transaction is rolling back and not 
committing. So naturally nothing is persisted in that case. You'll need to find 
out what is causing that ROLLBACK. Normal inserts don't cause that. Since it 
occurs after the SELECT * query, it isn't even occuring in an after_save or 
similar hook. The only thing I can think of that would cause what you are 
seeing without an exception being raised is if the transaction is being 
manually rolled back via a surrounding transaction(:rollback=>true), raising 
Sequel::Rollback after save returns, or manually swallowing the exception. 
</blockquote>



I wasn't thinking too clearly when I wrote that, I needed to get some fresh 
night air. Putting the SQL log together with the backtrace and your comments, 
the ROLLBACK is obviously caused by the the Sequel::Model code after the SELECT 
* query returns 0 rows. 


So the question becomes why SQLite or the Sequel adapter in use isn't returning 
the correct inserted id. First, which Sequel adapter are you using to access 
SQLite (sqlite, jdbc, swift, do, amalgalite, etc.?), and what is the schema for 
the tournament_configurations table (use ".dump tournament_configurations" from 
the sqlite3 command prompt and post the output)? If you call 
DB[:tournament_configurations].insert(:tournament_id=>1) a few times, does it 
return 1 every time, or does it increment? 


All Sequel adapters I test that can access SQLite return the correct 
autoincremented primary key upon insert, so I'm not sure what could be causing 
your error, but knowing the adapter in use and the schema for the table is the 
first step towards diagnosing the issue. 


If I had to guess at this point, tournament_configurations.id is not declared 
as an INTEGER PRIMARY KEY in SQLite, so insert is return the value of 
tournament_configuration.rowid (the hidden integer primary key). Since you are 
looking for tournament_configurations.id = 1, no row is found. SQLite is 
nonstandard in that if you declare a PRIMARY KEY field with a non-INTEGER type, 
that column can have NULL values (unless you explicitly set the column as NOT 
NULL). The table schema dump from SQLite should make it obvious whether that 
guess is accurate. 


Jeremy 
-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group. 
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/j6NQ1NWgmxwJ . 
To post to this group, send email to [email protected]. 
To unsubscribe from this group, send email to 
[email protected]. 
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en. 

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to