[Rails] Re: ActiveRecord::StatementInvalid (OCIError: ORA-00001: unique constraint (xxxxxxxx) violated:
If I write the error message instead of xx, it is: OCIError: ORA-1: unique constraint (ABCSIGN_DBA.PK_ATTEND_IP) violated: INSERT INTO attend_ip (xxx, xxx, xxx, .) The PK prefix looks like a violation of the primary key. Maybe, inserting same row again or some kind of replay happens. If so, why this is not happening in production with same code??? How do I check if that case happens? Daniel On Thursday, September 18, 2014 3:35:50 AM UTC-5, kimda wrote: Hello, I have developed a small RoR app(ruby 1.8.7, rails 2.1.0, rubygem 0.9.4) a few years ago and now I moved the app on Windows 2008 server. I have a weird issue that insert doesn't work all the time. This is the error message and there is no duplicated PK insertion when I check DB table. ActiveRecord::StatementInvalid (OCIError: ORA-1: unique constraint () violated: INSERT INTO xx (, , , , ..) ... ... ... I am the only one who is testing and there are no opened sessions. I am sure production DB schema and test DB schema are identical. I tested with all three environments with test DB schema, but didn't help. One thing to note is that after I get the RoR error message, if I just hit F5 key a few times, the insertion works and I get the next successful page. This same app is working fine on Windows 2003 server though. (I just copied the app dir and all the RoR setup.) Any clues? thanks in advance. Daniel -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3daf3e0a-c703-41ac-b3e5-9fbec634462b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: ActiveRecord::StatementInvalid
but in terms of getting your application running can you not just truncate the string to a valid length before saving the record? Yes that is possible any way not the best. Relating to this two questions. 1) Is there any other gem than mysql. I found ruby-mysql but could not try since it requires ruby = 1.8.7 . Mine is 1.8.6 2) In mysql what is the next option than a text field that handles very large data Thanks -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Re: [Rails] Re: ActiveRecord::StatementInvalid
Quoting Tom Mac li...@ruby-forum.com: but in terms of getting your application running can you not just truncate the string to a valid length before saving the record? Yes that is possible any way not the best. Relating to this two questions. 1) Is there any other gem than mysql. I found ruby-mysql but could not try since it requires ruby = 1.8.7 . Mine is 1.8.6 2) In mysql what is the next option than a text field that handles very large data t.text description, :limit = 16777215 This in MySQL creates a MEDIUMTEXT field with a 24-bit length. There is also a LONGTEXT type with 32-bit lengths. The default is 16-bit lengths. HTH, Jeffrey -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: ActiveRecord::StatementInvalid
Thanks for your reply. Meanwhile I have done it. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: ActiveRecord::StatementInvalid: Mysql Errorr public_indices
On 28 Mar, 16:17, Graham Farrell li...@ruby-forum.com wrote: Hi all, I'm new to ROR so sorry if this is simple. I'm using NetBeans 6.8 as my IDE and I'm trying to run tests on my shared project but I'm hitting the error beow and I can't figure out what it means. ActiveRecord::StatementInvalid: Mysql::Error: Table 'mydatabase_test.publiic_indices' doesn't exist: DELETE FROM `publiic_indices` I know that none of my tables have an index setup could this be the problem?? It's looking for a table called publiic_indices, which sounds like a typo to me - public_indices would be a more normal spelling. If your database does contain a public_indices table then see if there are any references to that table name or a publiic_indices.yml fixture file and try correcting the spelling. Fred Any help greatly appricated. Graham -- Posted viahttp://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: ActiveRecord::StatementInvalid: Mysql Errorr public_indices
Frederick Cheung wrote: On 28 Mar, 16:17, Graham Farrell li...@ruby-forum.com wrote: `publiic_indices` I know that none of my tables have an index setup could this be the problem?? It's looking for a table called publiic_indices, which sounds like a typo to me - public_indices would be a more normal spelling. If your database does contain a public_indices table then see if there are any references to that table name or a publiic_indices.yml fixture file and try correcting the spelling. Fred Hi Fred, I noticed that it was looking for the table but I knew that I didn't have a table of this name in my project. I found the offending yml file in the fixtures, it was from a MVC that one of the other guys had created then deleted but for some reason the this file wasn't deleted also. Thanks for your help, Graham -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: ActiveRecord::StatementInvalid: Mysql::Error: Lock wait timeout exceeded
On Mar 17, 6:12 am, Ram yourstruly.vi...@gmail.com wrote: Hi all, Ive been getting this error on one particular query repeatedly for the past few days. ActiveRecord::StatementInvalid: Mysql::Error: Lock wait timeout exceeded; try restarting transaction: UPDATE `posts` SET `updated_at` = '2010-03-17 05:35:00', `view_count` = 54 WHERE `id` = 158 Googling around, I found that this is basically because the transaction times out after waiting for the time period thats defined in the InnoDB settings. I also found that acts_as_ferret could cause this while it locks down the row in question for indexing purposes. However, I dont have any such background processes running that might lock down rows in mass like this. Is there some technique for pinpointing a process thats locking down the rows in question? I found a plugin called deadlock-retry (http:// github.com/rails/deadlock_retry/) by Jamis Buck. But im not sure if this will solve the problem at all. Besides, since this error is happening only in production, im reluctant to deploy the plugin to production and waiting to see if it does anything at all. Mike Perham's http://github.com/mperham/deadlock_retry/commits/master fork of this logs the current innodb status when this happens (i think the database user rails runs as needs certain permissions to be able to run that statement). Another thing worth looking for is whether there were any actions that took a long time to run at round about the same time that that error occurred - if that action was slow because of a large database query it could be the cause Fred Anyone got any pointers on this? Thanks! -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: ActiveRecord::StatementInvalid: Mysql::Error: Lock wait timeout exceeded
Thanks Fred! I have a staging server where I could deploy this. But I need to reproduce the lockdown. Any hacks that I can use for that? The tables are all quite small and there are no large db queries that could be causing this that I know of. Will crawl through the rails logs and see if I can find anything. However, given that Im not logging the db connection times, I doubt I'll be able to point a finger at any one such query. This seems to be happening even when the server is under relatively low load. On Mar 17, 1:07 pm, Frederick Cheung frederick.che...@gmail.com wrote: On Mar 17, 6:12 am, Ram yourstruly.vi...@gmail.com wrote: Hi all, Ive been getting this error on one particular query repeatedly for the past few days. ActiveRecord::StatementInvalid: Mysql::Error: Lock wait timeout exceeded; try restarting transaction: UPDATE `posts` SET `updated_at` = '2010-03-17 05:35:00', `view_count` = 54 WHERE `id` = 158 Googling around, I found that this is basically because the transaction times out after waiting for the time period thats defined in the InnoDB settings. I also found that acts_as_ferret could cause this while it locks down the row in question for indexing purposes. However, I dont have any such background processes running that might lock down rows in mass like this. Is there some technique for pinpointing a process thats locking down the rows in question? I found a plugin called deadlock-retry (http:// github.com/rails/deadlock_retry/) by Jamis Buck. But im not sure if this will solve the problem at all. Besides, since this error is happening only in production, im reluctant to deploy the plugin to production and waiting to see if it does anything at all. Mike Perham'shttp://github.com/mperham/deadlock_retry/commits/master fork of this logs the current innodb status when this happens (i think the database user rails runs as needs certain permissions to be able to run that statement). Another thing worth looking for is whether there were any actions that took a long time to run at round about the same time that that error occurred - if that action was slow because of a large database query it could be the cause Fred Anyone got any pointers on this? Thanks! -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: ActiveRecord::StatementInvalid: Mysql::Error: Lock wait timeout exceeded
On Mar 17, 8:39 am, Ram yourstruly.vi...@gmail.com wrote: Thanks Fred! I have a staging server where I could deploy this. But I need to reproduce the lockdown. Any hacks that I can use for that? The tables are all quite small and there are no large db queries that could be causing this that I know of. Will crawl through the rails logs and see if I can find anything. However, given that Im not logging the db connection times, I doubt I'll be able to point a finger at any one such query. This seems to be happening even when the server is under relatively low load. I'd turn on that logging. If you're effectively blind as far as your application's performance goes then this will be a needle in a haystack affair. given that the query mentions only the posts table it's worth looking at all queries that read or write to that table. Also check whether you have any long lived transactions - any locks held during a transaction last for the duration of the transaction Fred On Mar 17, 1:07 pm, Frederick Cheung frederick.che...@gmail.com wrote: On Mar 17, 6:12 am, Ram yourstruly.vi...@gmail.com wrote: Hi all, Ive been getting this error on one particular query repeatedly for the past few days. ActiveRecord::StatementInvalid: Mysql::Error: Lock wait timeout exceeded; try restarting transaction: UPDATE `posts` SET `updated_at` = '2010-03-17 05:35:00', `view_count` = 54 WHERE `id` = 158 Googling around, I found that this is basically because the transaction times out after waiting for the time period thats defined in the InnoDB settings. I also found that acts_as_ferret could cause this while it locks down the row in question for indexing purposes. However, I dont have any such background processes running that might lock down rows in mass like this. Is there some technique for pinpointing a process thats locking down the rows in question? I found a plugin called deadlock-retry (http:// github.com/rails/deadlock_retry/) by Jamis Buck. But im not sure if this will solve the problem at all. Besides, since this error is happening only in production, im reluctant to deploy the plugin to production and waiting to see if it does anything at all. Mike Perham'shttp://github.com/mperham/deadlock_retry/commits/master fork of this logs the current innodb status when this happens (i think the database user rails runs as needs certain permissions to be able to run that statement). Another thing worth looking for is whether there were any actions that took a long time to run at round about the same time that that error occurred - if that action was slow because of a large database query it could be the cause Fred Anyone got any pointers on this? Thanks! -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[Rails] Re: ActiveRecord::StatementInvalid (invalid date) with Oracle
Thanks for the tip, pepe... I was optimistic and implemented this in my class: def creation_datetime if (self[:creation_datetime].nil? || self[:creation_datetime].year == 0) '01-01-1999'.to_date else self[:creation_datetime] end end and it would work perfectly, but it does not help for the problem I encountered, as the values are retrieved from the database *before* this overridden method is called. I still need my fix in the Oracle Enhanced adapter, I'm afraid :| I am now looking into the issue with the developer of the adapter, via the Oracle Enhanced mailing list, as it is a very, very strange error... When I have a final conclusion as to how to prevent this error or propertly fix it in code, I will get back to this list. Meanwhile, here is what I posted on the Oracle Enhanced mailing list about the 'guilty' date value in my Oracle database that triggers the error: When a date field is NULL in Oracle, it *is* retrieved as 'nil' by ruby-oci8. So that is working perfectly, also in the Oracle Enhanced code. The problem occurs, when the date field value is not 'nil' nor filled with a valid date value: it is empty. An 'empty' date is returned as a datetime with only '0' values by OCI8. And this is where the problem occured. I created the following SQL to get a better look at the data of a record that does work, and a record that causes the error: select fllid, creation_datetime , nvl(creation_datetime, Sysdate), length(creation_datetime), to_ char(creation_datetime) from filelist where fllid=959 or fllid=198 It outputs: FLLID creation_datetime nvl() length() to_char() - - -- - 198 24-9-2009 13:49:38 959 9 00-000-00 The date with fllid '198' works perfectly and is treated as a 'nil' value by OCI and hence by the Oracle Adapter. The date with fllid '959' is the one that will cause problems: As you can see, it IS 9 characters long (???) but it is not 'null' (indicated by the empty nvl(..) column) and it is displayed as an 'empty' date just like the date above! Only when converting it to 'char', the '0' values are shown... I tried to create an insert statement that can reproduce a date like this, but have not succeeded so far. I already tried insert statements like this: insert into datatest (id) values (1) -- just inserts as 'NULL' insert into datatest (id, dt) values (2, '') -- just inserts as 'NULL' insert into datatest (id, dt) values (5, to_date('00/00/','MM/DD/')) -- is not valid insert into datatest (id, dt) values (5, to_date('01/01/4712 bc','DD/MM/ bc')) -- inserts as normal date insert into datatest (id, dt) VALUES (6, to_date( '00/00/ 00:00:00 00', 'MM/DD/ HH:MI:SS AM')) -- is not valid So I'm really a bit at a loss here, how this data was inserted at all into the database, as you can imagine. I do know this Oracle 10 database was created by importing (with Oracle's imp.exe) an export (using Oracle's exp.exe) from a Oracle 8i database... On Wed, Sep 23, 2009 at 5:10 PM, pepe p...@betterrpg.com wrote: I don't know if this could help but I had kind of a similar problem at one point. After much research I ended up coming across a solution by which you can modify in your model the value returned from the DB. You have to override the reader method (code below). This worked for me only when reading values from the table as I had no problem inserting values in it and never inserted a null or empty value but I guess the same could be done with the writer method (dob= in this case): class MyOracleTable ActiveRecord::Base def dob self[:dob] or '0001-01-01'.to_date end end Every time that a row is retrieved from the table and the value of DOB is used the model will return the DOB if there is one or an initialized date value. I chose to implement '0001-01-01' but it could be anything you want (i.e.: Date.new). I hope this helps. On Sep 14, 11:03 am, rheenen rhee...@gmail.com wrote: Hello all. I am a novice Ruby on Rails programmer, starting my first project using a legacy Oracle 10 database. Using 'reverse_scaffold' I have created the models/controllers/views for my existing Oracle tables. All seems to work well, using /model/index, /model/show for most of my tables, *except* when one of the tables contains a Oracle 'date' column, for example when going to ~/filelists/show/959: ActiveRecord::StatementInvalid in FilelistsController#show ArgumentError: invalid date: SELECT * FROM filelist WHERE (filelist.fllid = 959) I already tried updating the record with NULL values for the date columns, or with actual valid date values, but ActiveRecord *or* OracleEnhancedAdapter seems to refuse to load my date values. Is this a known issue or is there something else I should do in my model file to make date support work? Thanks!
[Rails] Re: ActiveRecord::StatementInvalid (invalid date) with Oracle
As far as I can see now, the problem is in the oracle_enhanced adapter or in ActiveRecord. I created this small Ruby script to test each component: require 'rubygems' gem 'ruby-oci8' require 'oci8' gem 'activerecord' gem 'activerecord-oracle_enhanced-adapter' require 'activerecord' puts(Testing Oracle OCI gem by selecting record:) OCI8.new('ccems', 'ccems', 'XE').exec('SELECT * FROM filelist WHERE (filelist.fllid = 959)') do |r| puts r.join(\n) end puts(Testing oracle_enhanced installation:) ActiveRecord::Base.establish_connection( :adapter = oracle_enhanced, :database = XE, :username = ccems, :password = ccems) puts(oracle_enhanced connected succesfully) puts(Testing selection of one record) class Filelist ActiveRecord::Base set_table_name 'filelist' set_primary_key 'fllid' #set_date_columns 'creation_datetime', 'modification_datetime', 'firstrecord_datetime' #ignore_table_columns 'creation_datetime', 'modification_datetime', 'firstrecord_datetime' end filelist = Filelist.find(959); and, as expected, the very last line returns this error: D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract_adapter.rb:219:in `log': ArgumentError: invalid date: SELECT * FROM filelist WHERE (filelist.fllid = 959) (ActiveRecord::StatementInvalid) from D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.2.1/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:958:in `select' from D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache' from D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all' from D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:661:in `find_by_sql' from D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1548:in `find_every' from D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1583:in `find_one' from D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1569:in `find_from_ids' from D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:616:in `find' from test.rb:27 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: ActiveRecord::StatementInvalid (invalid date) with Oracle
Finally, I found the error with 'invalid date' on Oracle 8. Seems that oracle not only allows 'null' dates, but also 'empty' dates. On 'empty' dates, the error would come up! Below is what I changed in oracle_enhanced_oci_connection.rb in lib\ruby\gems\activerecord-oracle_enhanced-adapter-1.2.1\lib\connection_adapters\. The changed lines are marked with #MVR as comment above it. Starts around line 128: # ruby-oci8 1.0 returns OraDate when OraDate # MVR: treat 'empty' date/time strings as null too! if !(v.hour == 0 v.minute == 0 v.second == 0 v.year == 0 v.month == 0 v.day == 0) # RSI: added emulate_dates_by_column_name functionality if OracleEnhancedAdapter.emulate_dates (v.hour == 0 v.minute == 0 v.second == 0) v.to_date else # code from Time.time_with_datetime_fallback begin Time.send(Base.default_timezone, v.year, v.month, v.day, v.hour, v.minute, v.second) rescue offset = Base.default_timezone.to_sym == :local ? ::DateTime.local_offset : 0 ::DateTime.civil(v.year, v.month, v.day, v.hour, v.minute, v.second, offset) end end end # ruby-oci8 2.0 returns Time or DateTime when Time, DateTime # MVR: treat 'empty' date/time strings as null too! if !(v.hour == 0 v.minute == 0 v.second == 0 v.year == 0 v.month == 0 v.day == 0) if OracleEnhancedAdapter.emulate_dates (v.hour == 0 v.min == 0 v.sec == 0) v.to_date else # recreate Time or DateTime using Base.default_timezone begin Time.send(Base.default_timezone, v.year, v.month, v.day, v.hour, v.min, v.sec) rescue offset = Base.default_timezone.to_sym == :local ? ::DateTime.local_offset : 0 ::DateTime.civil(v.year, v.month, v.day, v.hour, v.min, v.sec, offset) end end end else v end Hope this is of any help to those fighting with Oracle ;) Cheers On Wed, Sep 23, 2009 at 12:45 PM, Martijn van Rheenen rhee...@gmail.comwrote: As far as I can see now, the problem is in the oracle_enhanced adapter or in ActiveRecord. I created this small Ruby script to test each component: require 'rubygems' gem 'ruby-oci8' require 'oci8' gem 'activerecord' gem 'activerecord-oracle_enhanced-adapter' require 'activerecord' puts(Testing Oracle OCI gem by selecting record:) OCI8.new('ccems', 'ccems', 'XE').exec('SELECT * FROM filelist WHERE (filelist.fllid = 959)') do |r| puts r.join(\n) end puts(Testing oracle_enhanced installation:) ActiveRecord::Base.establish_connection( :adapter = oracle_enhanced, :database = XE, :username = ccems, :password = ccems) puts(oracle_enhanced connected succesfully) puts(Testing selection of one record) class Filelist ActiveRecord::Base set_table_name 'filelist' set_primary_key 'fllid' #set_date_columns 'creation_datetime', 'modification_datetime', 'firstrecord_datetime' #ignore_table_columns 'creation_datetime', 'modification_datetime', 'firstrecord_datetime' end filelist = Filelist.find(959); and, as expected, the very last line returns this error: D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract_adapter.rb:219:in `log': ArgumentError: invalid date: SELECT * FROM filelist WHERE (filelist.fllid = 959) (ActiveRecord::StatementInvalid) from D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.2.1/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:958:in `select' from D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache' from D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all' from D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:661:in `find_by_sql' from D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1548:in `find_every' from D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1583:in `find_one' from D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1569:in `find_from_ids' from D:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:616:in `find' from test.rb:27 --~--~-~--~~~---~--~~ You received this message because
[Rails] Re: ActiveRecord::StatementInvalid (invalid date) with Oracle
I don't know if this could help but I had kind of a similar problem at one point. After much research I ended up coming across a solution by which you can modify in your model the value returned from the DB. You have to override the reader method (code below). This worked for me only when reading values from the table as I had no problem inserting values in it and never inserted a null or empty value but I guess the same could be done with the writer method (dob= in this case): class MyOracleTable ActiveRecord::Base def dob self[:dob] or '0001-01-01'.to_date end end Every time that a row is retrieved from the table and the value of DOB is used the model will return the DOB if there is one or an initialized date value. I chose to implement '0001-01-01' but it could be anything you want (i.e.: Date.new). I hope this helps. On Sep 14, 11:03 am, rheenen rhee...@gmail.com wrote: Hello all. I am a novice Ruby on Rails programmer, starting my first project using a legacy Oracle 10 database. Using 'reverse_scaffold' I have created the models/controllers/views for my existing Oracle tables. All seems to work well, using /model/index, /model/show for most of my tables, *except* when one of the tables contains a Oracle 'date' column, for example when going to ~/filelists/show/959: ActiveRecord::StatementInvalid in FilelistsController#show ArgumentError: invalid date: SELECT * FROM filelist WHERE (filelist.fllid = 959) I already tried updating the record with NULL values for the date columns, or with actual valid date values, but ActiveRecord *or* OracleEnhancedAdapter seems to refuse to load my date values. Is this a known issue or is there something else I should do in my model file to make date support work? Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: ActiveRecord::StatementInvalid (invalid date) with Oracle
My horrible but working solution: class UploadController ApplicationController require 'dbi' ... def method db=DBI.connect('dbi:ODBC:giomai_db_dsn', sa, .43tco376) begin ... db.execute(INSERT INTO valutazionescorta values ('#{data}', '#{code}', #{scorta})) if prodotto and scorta and scorta 0 rescue DBI::DatabaseError = e puts Errore: #{e.err} puts #{e.errstr} ensure # disconnect from server db.disconnect if db end end end -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: ActiveRecord::StatementInvalid (invalid date) with Oracle
Wow, that *is* an ugly solution, with all respects ;) I still have not found a solution for the original issue with Oracle, somehow retrieval of 'date' / 'datetime' values is not working still. I have already tried to set the NLG_LANG environment variable to American, but this did not solve the problem. I will get back to you all with a full stack trace of the error. (meanwhile I reverted back to Symfony / PHP / Doctrine to at least be able to finish my prototype application, but would rather have seen RoR for this project ofcourse) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: ActiveRecord::StatementInvalid (invalid date) with Oracle
Martijn van Rheenen wrote: As an extra hint: Can this be caused by a wrongly configured NLS_LANG setting on my Windows client, causing ActiveRecord to get an 'unexpected' date format back? Hi Martijn, I've the same problem storing in the Date column. I'm using this code( with a mix of italian and english words :D ) in the controller writing = ValutazioneScorta.create(:Codice = code, :Scorta = scorta,:Data = data ) if code != and data so it's really embarrassing to read: DBI::DatabaseError: 23000 (515) [Microsoft][ODBC SQL Server Driver][SQL Server]Impossibile inserire il valore Null nella colonna 'Data, tabella 'giomai_db.dbo.ValutazioneScorta'. La colonna non supporta valori Null. INSERT avrà esito negativo.: INSERT INTO [ValutazioneScorta] ([Scorta], [Data], [CodiceMaietta]) VALUES (5, NULL, 'CNC-1320B008AA') showing Null for Data( date ) columns ( Null nella colonna 'Data, ... ) I'm sure that is a framework problem but I can't say where the value is lost. Error Stack is in attachment! Attachments: http://www.ruby-forum.com/attachment/4042/Full_Trace.txt -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: ActiveRecord::StatementInvalid (invalid date) with Oracle
Of course, overriding the create method( how explained here http://railsruby.blogspot.com/2006/01/activerecordstatementinvalid-in.html ) is not a solution. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: ActiveRecord::StatementInvalid (invalid date) with Oracle
As an extra hint: Can this be caused by a wrongly configured NLS_LANG setting on my Windows client, causing ActiveRecord to get an 'unexpected' date format back? On Mon, Sep 14, 2009 at 5:03 PM, rheenen rhee...@gmail.com wrote: Hello all. I am a novice Ruby on Rails programmer, starting my first project using a legacy Oracle 10 database. Using 'reverse_scaffold' I have created the models/controllers/views for my existing Oracle tables. All seems to work well, using /model/index, /model/show for most of my tables, *except* when one of the tables contains a Oracle 'date' column, for example when going to ~/filelists/show/959: ActiveRecord::StatementInvalid in FilelistsController#show ArgumentError: invalid date: SELECT * FROM filelist WHERE (filelist.fllid = 959) I already tried updating the record with NULL values for the date columns, or with actual valid date values, but ActiveRecord *or* OracleEnhancedAdapter seems to refuse to load my date values. Is this a known issue or is there something else I should do in my model file to make date support work? Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---
[Rails] Re: ActiveRecord::StatementInvalid in new action on scaffolding
Hi, I had the same problem! Try removing the quote_table_name call in the file C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active_record/connection_adapters/sqlite3_adapter.rb line 29 that did it for me. In short replace the line : returning structure = @connection.table_info(quote_table_name (table_name)) do with : returning structure = @connection.table_info(table_name) do Math On Mar 31, 2:34 am, Darren VanBuren onekop...@gmail.com wrote: I am trying to learnRailsby experimenting with it. Currently, I'm trying on my laptop runningWindows7 (build 7000), with Ruby 1.8.6, RubyGems 1.3.1, andRails2.3.2(.1). I of course had to get sqlite3-ruby installed, which I did. I just created some scaffolding with script/generate (which I had to do as ruby .\script\generate, as I was inWindowsPowerShell) then attempted to run the DB migrations. PS C:\Users\Darren VanBuren\rails\blog rake db:migrate (in C:/Users/Darren VanBuren/rails/blog) == CreatePosts: migrating -- create_table(:posts) - 0.0050s == CreatePosts: migrated (0.0150s) === rake aborted!Could not find table'posts' Running with --trace presents: PS C:\Users\Darren VanBuren\rails\blog rake db:migrate --trace (in C:/Users/Darren VanBuren/rails/blog) ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:migrate ** Invoke db:schema:dump (first_time) ** Invoke environment ** Execute db:schema:dump rake aborted!Could not find table'posts' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:29:in `table structure' C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/object/misc.rb:39:in `returning' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:28:in `table structure' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite_adapter.rb:213:in `colum s' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/schema_dumper.rb:77:in `table' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/schema_dumper.rb:72:in `tables' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/schema_dumper.rb:63:in `each' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/schema_dumper.rb:63:in `tables' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/schema_dumper.rb:25:in `dump' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/schema_dumper.rb:19:in `dump' C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/tasks/databases.rake:251 C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/tasks/databases.rake:250:in `open' C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/tasks/databases.rake:250 C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in `call' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in `execute' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in `each' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in `execute' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:578:in `invoke_with_call_chain' C:/Ruby/lib/ruby/1.8/monitor.rb:242:in `synchronize' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:571:in `invoke_with_call_chain' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:564:in `invoke' C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/tasks/databases.rake:117 C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in `call' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:617:in `execute' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in `each' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:612:in `execute' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:578:in `invoke_with_call_chain' C:/Ruby/lib/ruby/1.8/monitor.rb:242:in `synchronize' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:571:in `invoke_with_call_chain' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:564:in `invoke' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2027:in `invoke_task' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in `top_level' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in `each' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2005:in `top_level' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in `standard_exception_handling' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1999:in `top_level' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1977:in `run' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:2044:in `standard_exception_handling' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/lib/rake.rb:1974:in `run' C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/bin/rake:31 C:/Ruby/bin/rake:19:in `load'
[Rails] Re: ActiveRecord::StatementInvalid could not find table
I'm not sure how it's possible to have a different database adapter called up in the script/console from the one you get through script/ server since both paths use the same database.yml file. One way to confirm what you are running in each case is: Both methods start with you in your project directory. Do not change any files between runs. 1) For console case type: script/about You should see something like: About your application's environment Ruby version 1.9.1 (powerpc-darwin9.6.0) RubyGems version 1.3.1 Rack version 1.0 bundled Rails version 2.3.2 Active Record version 2.3.2 Action Pack version 2.3.2 Active Resource version 2.3.2 Action Mailer version 2.3.2 Active Support version2.3.2 Application root /Users/rick/test Environment development Database adapter mysql Database schema version 20090401180059 1) For browser case type: script/server 2) Then, in browser window display site: localhost:3000/rails/info/ properties You should see: Ruby version1.9.1 (powerpc-darwin9.6.0) RubyGems version1.3.1 Rack version1.0 bundled Rails version 2.3.2 Active Record version 2.3.2 Action Pack version 2.3.2 Active Resource version 2.3.2 Action Mailer version 2.3.2 Active Support version 2.3.2 Application root/Users/rick/test Environment development Database adaptermysql Database schema version 20090401180059 What you see in both tests should be identical. Obviously, for you the important fields are Database adapter and Database schema version. Rick On Apr 1, 3:14 am, willem will.mas...@gmail.com wrote: Hi, Have searched and searched the group and the net with no joy on this... I have set up users table and am trying to insert newly registered users with the following code from: class UserController ApplicationController def index end def register @title = Register if request.post? #raise params[:user].inspect @user = User.new(params[:user]) if @user.save render :text = User created! end end end end I receive the following error: ActiveRecord::StatementInvalid in UserController#register Could not find table 'users' RAILS_ROOT: /Users/Will/Development/rails_space Application Trace | Framework Trace | Full Trace /Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/ connection_adapters/sqlite3_adapter.rb:29:in `table_structure' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/ core_ext/object/misc.rb:39:in `returning' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/ connection_adapters/sqlite3_adapter.rb:28:in `table_structure' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/ connection_adapters/sqlite_adapter.rb:213:in `columns' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/ base.rb:1276:in `columns' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/ base.rb:3008:in `attributes_from_column_definition_without_lock' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/ locking/optimistic.rb:66:in `attributes_from_column_definition' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/ base.rb:2435:in `initialize' /Users/Will/Development/rails_space/app/controllers/user_controller.rb: 10:in `new' /Users/Will/Development/rails_space/app/controllers/user_controller.rb: 10:in `register' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ base.rb:1322:in `send' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ base.rb:1322:in `perform_action_without_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ filters.rb:617:in `call_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ filters.rb:610:in `perform_action_without_benchmark' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ benchmarking.rb:68:in `perform_action_without_rescue' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/ core_ext/benchmark.rb:17:in `ms' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/ core_ext/benchmark.rb:10:in `realtime' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/ core_ext/benchmark.rb:17:in `ms' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ benchmarking.rb:68:in `perform_action_without_rescue' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ rescue.rb:160:in `perform_action_without_flash' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ flash.rb:141:in `perform_action' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ base.rb:523:in `send' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/ base.rb:523:in `process_without_filters'
[Rails] Re: ActiveRecord::StatementInvalid NO_GENERATED_KEYS
On Nov 28, 7:07 am, Valentino Lun [EMAIL PROTECTED] wrote: Dear all I type the following command in script/console and got the error ActiveRecord::StatementInvalid: ActiveRecord::ActiveRecordError: JZ0NK: ..Statement.NO_GENERATED_KEYS It is quit strange that the title is nil when I saved the recordThis problem only happened in the rails console. It is no problem in my irb. Please help me. Thank you. Your attr_accessor :title is messing things up. You do not need that for attributes defined in the database. Furthermore attributes are not stored in instance variables so doing @title = 'foo' is a waste of time Fred --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~--~~~~--~~--~--~---