Git Product home page Git Product logo

ar-extensions's People

Contributors

blythedunham avatar crafterm avatar gtd avatar jherdman avatar pickavet avatar thibaudgg avatar zdennis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ar-extensions's Issues

Can't do bulk insert

I'm using rails 2.3.2 with ar-extensions 0.9.2 (MySQL version: 5.0.75-0ubuntu10.3 (Ubuntu))

I'm trying to use the import() method on my AR models, and it works but it still run a single insert query for each record. It's very wired my models call supports_import? always return false.

When I faked that method, it raises an error undefined method 'sql_for_on_duplicate_key_update'.
Can you explain how to insert bulk records?

Thanks

sanitize_sql_from_hash doesn't append nil to values array

The following call to sanitize_sql_from_hash yields invalid conditions:

sanitize_sql_from_hash({'state_id' => 3, 'county_id' => nil})

And ends up throwing:

wrong number of bind variables (1 for 2)

There seems to be a specific check to make sure nil is not appended to the values array, which doesn't seem right, but I don't pretend to fully understand this method so it's likely I'm missing something. Seems like the following diff would take care of it:

diff --git a/ar-extensions/lib/ar-extensions/finders.rb b/ar-extensions/lib/ar-extensions/finders.rb
index 874ba3c..374ac2a 100644
--- a/ar-extensions/lib/ar-extensions/finders.rb
+++ b/ar-extensions/lib/ar-extensions/finders.rb
@@ -63,7 +63,7 @@ class ActiveRecord::Base
           result = ActiveRecord::Extensions.process( key, val, self )
           if result
             conditions << result.sql
-            values.push( result.value ) unless result.value.nil?
+            values.push( result.value )
           else
             # Extract table name from qualified attribute names.
             attr = key.to_s
@@ -91,4 +91,4 @@ class ActiveRecord::Base
   end
   
 end
-end
\ No newline at end of file
+end

Rails 3.1 compatibility

In my Gemfile I have:
gem 'rails', '3.1.0' gem 'ar-extensions', :git => "git://github.com/zdennis/ar-extensions.git"
When I do bundle install I get:
Bundler could not find compatible versions for gem "activerecord": In Gemfile: ar-extensions (>= 0) ruby depends on activerecord (~> 2.1) ruby rails (= 3.1.0) ruby depends on activerecord (3.1.0)
Am I missing something or is the gem really not compatible with activerecord 3.1.0? Has anyone had success using rails 3.1.0/ruby 1.9.3 with this gem? I was using it with rails 3.0.9/ruby 1.8.7 and everything was fine.

issue can't convert Time into String

I have this issue when trying to create a new record. I'm using rails 2.3.4

columns = [:libelle]
=> [:libelle]
values = ["russe"]
=> ["russe"]
Langue.import columns, values
TypeError: can't convert Time into String
from /home/thomas/.rvm/gems/ruby-1.8.7-p352/gems/ar-extensions-0.9.5/lib/ar-extensions/import.rb:319:in <<' from /home/thomas/.rvm/gems/ruby-1.8.7-p352/gems/ar-extensions-0.9.5/lib/ar-extensions/import.rb:319:inadd_special_rails_stamps'
from /home/thomas/.rvm/gems/ruby-1.8.7-p352/gems/ar-extensions-0.9.5/lib/ar-extensions/import.rb:319:in each' from /home/thomas/.rvm/gems/ruby-1.8.7-p352/gems/ar-extensions-0.9.5/lib/ar-extensions/import.rb:319:inadd_special_rails_stamps'
from /home/thomas/.rvm/gems/ruby-1.8.7-p352/gems/ar-extensions-0.9.5/lib/ar-extensions/import.rb:311:in each_pair' from /home/thomas/.rvm/gems/ruby-1.8.7-p352/gems/ar-extensions-0.9.5/lib/ar-extensions/import.rb:311:inadd_special_rails_stamps'
from /home/thomas/.rvm/gems/ruby-1.8.7-p352/gems/ar-extensions-0.9.5/lib/ar-extensions/import.rb:205:in `import'
from (irb):7

any ideas ?

Postgresql Non Existant

You could mention in your README that PostgreSQL isn't supported for your import function.

Rails 2.3.3 sanitize_sql

In rails 2.3.3 they added a second parameter to sanitize_sql(). You can now pass the table_name as an option.

Error with CompositePrimaryKeys

Hello,

I am using the compositeprimarykeys gem and I am getting a error when I try to save a record with the LOW_PRIORTY keyword:

s = SurveyInfo.find_by_Client "Test Client"
=> #<SurveyInfo Client_Survey_Information_ID: 148, Client: "Test Client", Client_Division: "Test", Client_Survey: "Test 01", Client_Survey_Name: "Test 01", Old_Production_Client_Name: "test", Old_Production_Division_Name: "test", Dialing_Form: "Not tested in new system.", Alert_Brand: "test", Alert_Org_Name: "test", Alert_Logically: 0, Alert_Subject: "There shouldn't be alerts for this account!", Alert_To: "test", Alert_CC: "test", Alert_Instructions: "No alerts.", SQL_Alert_Criteria: "0=1", Mailmerge_Template: nil, SQL_Mailmerge_Criteria: nil, Rep_Survey_Note: nil, Alert_Contact_Name: nil, Alert_Contact_Phone: nil, Alert_Contact_EMail: nil, Sunday: 0, Monday: -1, Tuesday: -1, Wednesday: -1, Thursday: -1, Friday: -1, Saturday: 0, Added_At: "2006-03-28 14:56:42", Added_By: "test", Last_Modified_At: "2009-07-03 22:21:40", Last_Modified_By: "test", Caller_Id: "test", Record_Calls: 1>
s.Record_Calls = 0
=> 0
s.save(:keywords => 'LOW_PRIORITY')
ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'Client,Client_Division,Client_Survey' in 'where clause': UPDATE LOW_PRIORITY Client_Survey_Information SET Alert_Contact_Phone = NULL, Last_Modified_At = '2009-07-03 22:21:40', Rep_Survey_Note = NULL, Alert_Subject = 'There shouldn't be alerts for this account!', Alert_Contact_Name = NULL, Wednesday = -1, Client_Survey_Information_ID = 148, Alert_Org_Name = 'test', Added_At = '2006-03-28 14:56:42', Client_Survey_Name = 'EAP Bench Test 01', Alert_To = 'test', Old_Production_Division_Name = 'test', SQL_Alert_Criteria = '0=1', Alert_Instructions = 'No alerts.', Record_Calls = 0, Friday = -1, Alert_Logically = 0, Dialing_Form = 'Not tested in new system.', Old_Production_Client_Name = 'test', Last_Modified_By = 'test', Monday = -1, Sunday = 0, Thursday = -1, Caller_Id = 'test', Alert_Brand = 'test', Tuesday = -1, Mailmerge_Template = NULL, SQL_Mailmerge_Criteria = NULL, Saturday = 0, Alert_CC = 'test', Alert_Contact_EMail = NULL, Added_By = 'test' WHERE Client,Client_Division,Client_Survey = '--- !seq:CompositePrimaryKeys::CompositeIds \n- Test Client\n- Test\n- Test 01\n'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract_adapter.rb:219:in log' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/mysql_adapter.rb:323:inexecute'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:265:in update_sql' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/mysql_adapter.rb:338:inupdate_sql'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:49:in update_without_query_dirty' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/query_cache.rb:18:inupdate'
from /usr/local/lib/ruby/gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/create_and_update.rb:268:in update' from /usr/local/lib/ruby/gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/create_and_update.rb:229:increate_or_update'
from /usr/local/lib/ruby/gems/1.8/gems/ar-extensions-0.9.2/lib/ar-extensions/create_and_update.rb:206:in `save'

:on_duplicate_key_update results in "PRIMARY KEY must be unique"

Hi
I have imported data using ar_extensions 0.9.3 into sqlite 1.3.2 with impressive results. Now I want to process that data updating some fields in same table. The table has :id as primary key

  options = {:validate => false, :on_duplicate_key_update => [:x]}
  columns = [ :id,:x]
  igcfs = Igcfile.find(:all)  # get files
  igcfs.each do |igcf|    # for each file
    ps=[]
    igcps = igcf.igcpoint(:all, :order => 'seq_secs')   # get points
    igcps.each do |igcp|          # for each point

process data

      ps<<[igcp.id,igcp.x]         # push data to array
    end
    Igcpoint.import columns, ps, options   # update DB
  end

development.log sais - WARNING: Can't mass-assign these protected attributes: id

I see that this issue turned up a year ago. Not fixed yet?
http://zdennis.lighthouseapp.com/projects/14379/tickets/26-cant-import-protected-attributes

If there is no fix then it looks like a workaroundmight be to create a 2nd unique key and use that instead of :id

Peter

gem install of 0.9.2 (erroneously) installs activerecord 3.0.0 when activerecord 2.3.8 is already installed

The list of dependencies for ar-extensions doesn't appear to be absolutely correct. I have a Ruby (non-rails) project that uses ar-extensions for bulk insertion of data into the mysql db, and requires activerecord and activesupport from the 2.3.8 rails branch. On a fresh machine, in order to install ar-extensions with these versions in place I have to do a

gem install --ignore-dependencies ar-extensions

to prevent it from updating these (and adding in a number of other gems as a consequence).

Have I missed something, since I'm sure that I had ar-extensions working with 2.3.8 originally?

Paul

ar-extensions disrupts activerecord scope conditions

Without ar-extensions:

>> User.scoped(:conditions => {"users.name" => "bob"})
User Load (1.0ms)  SELECT * FROM `users` WHERE (`users`.`name` = 'bob')

With ar-extensions:

>> User.scoped(:conditions => {"users.name" => "bob"})
User Load (0.0ms)  Mysql::Error: Unknown column 'users.users.login' in 'where clause': SELECT * FROM `users` WHERE (`users`.`users.login` = 'bob')

Speed inversely propotional to import size

ar_extensions is great. But does it bog down with large imports. Look at this data for various file sizes

file.................................num_recs........recs/sec
public/data/095LCQJ1.igc 3117 164
public/data/656C3X61.IGC 1224 348
public/data/657C3X61.IGC 809 420
public/data/65EC3X62.IGC 2150 234
public/data/65RC3X62.IGC 4140 117

I suspect there is a sweet spot for import size probably order 100 recs

Peter

PS does activerecord_import work on rails 2.3.9 ruby 1.8.7. I couldnt get it to work so used ar_extensions instead

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.