cbaclig-ar-extensions 0.9.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +148 -0
- data/Manifest +111 -0
- data/README +167 -0
- data/Rakefile +65 -0
- data/ar-extensions.gemspec +19 -0
- data/benchmarks/README +32 -0
- data/benchmarks/benchmark.rb +61 -0
- data/benchmarks/boot.rb +21 -0
- data/benchmarks/lib/base.rb +121 -0
- data/benchmarks/lib/cli_parser.rb +103 -0
- data/benchmarks/lib/float.rb +15 -0
- data/benchmarks/lib/mysql_benchmark.rb +27 -0
- data/benchmarks/lib/output_to_csv.rb +18 -0
- data/benchmarks/lib/output_to_html.rb +69 -0
- data/cbaclig-ar-extensions.gemspec +30 -0
- data/config/database.yml +7 -0
- data/config/database.yml.template +7 -0
- data/config/mysql.schema +72 -0
- data/config/postgresql.schema +39 -0
- data/db/migrate/generic_schema.rb +97 -0
- data/db/migrate/mysql_schema.rb +32 -0
- data/db/migrate/oracle_schema.rb +5 -0
- data/db/migrate/version.rb +4 -0
- data/init.rb +31 -0
- data/lib/ar-extensions.rb +5 -0
- data/lib/ar-extensions/adapters/abstract_adapter.rb +139 -0
- data/lib/ar-extensions/adapters/mysql.rb +10 -0
- data/lib/ar-extensions/adapters/oracle.rb +14 -0
- data/lib/ar-extensions/adapters/postgresql.rb +9 -0
- data/lib/ar-extensions/adapters/sqlite.rb +7 -0
- data/lib/ar-extensions/create_and_update.rb +509 -0
- data/lib/ar-extensions/create_and_update/mysql.rb +7 -0
- data/lib/ar-extensions/csv.rb +309 -0
- data/lib/ar-extensions/delete.rb +143 -0
- data/lib/ar-extensions/delete/mysql.rb +3 -0
- data/lib/ar-extensions/extensions.rb +506 -0
- data/lib/ar-extensions/finder_options.rb +275 -0
- data/lib/ar-extensions/finder_options/mysql.rb +6 -0
- data/lib/ar-extensions/finders.rb +94 -0
- data/lib/ar-extensions/foreign_keys.rb +70 -0
- data/lib/ar-extensions/fulltext.rb +62 -0
- data/lib/ar-extensions/fulltext/mysql.rb +44 -0
- data/lib/ar-extensions/import.rb +362 -0
- data/lib/ar-extensions/import/mysql.rb +50 -0
- data/lib/ar-extensions/import/postgresql.rb +7 -0
- data/lib/ar-extensions/import/sqlite.rb +22 -0
- data/lib/ar-extensions/insert_select.rb +178 -0
- data/lib/ar-extensions/insert_select/mysql.rb +7 -0
- data/lib/ar-extensions/synchronize.rb +30 -0
- data/lib/ar-extensions/temporary_table.rb +131 -0
- data/lib/ar-extensions/temporary_table/mysql.rb +3 -0
- data/lib/ar-extensions/union.rb +204 -0
- data/lib/ar-extensions/union/mysql.rb +6 -0
- data/lib/ar-extensions/util/sql_generation.rb +27 -0
- data/lib/ar-extensions/util/support_methods.rb +32 -0
- data/lib/ar-extensions/version.rb +9 -0
- data/tests/README +68 -0
- data/tests/boot.rb +23 -0
- data/tests/database.yml +31 -0
- data/tests/database.yml.sample +28 -0
- data/tests/fixtures/addresses.yml +25 -0
- data/tests/fixtures/books.yml +46 -0
- data/tests/fixtures/developers.yml +20 -0
- data/tests/fixtures/unit/active_record_base_finders/addresses.yml +25 -0
- data/tests/fixtures/unit/active_record_base_finders/books.yml +64 -0
- data/tests/fixtures/unit/active_record_base_finders/developers.yml +20 -0
- data/tests/fixtures/unit/synchronize/books.yml +16 -0
- data/tests/fixtures/unit/to_csv_headers/addresses.yml +8 -0
- data/tests/fixtures/unit/to_csv_headers/developers.yml +6 -0
- data/tests/fixtures/unit/to_csv_with_common_options/addresses.yml +40 -0
- data/tests/fixtures/unit/to_csv_with_common_options/developers.yml +13 -0
- data/tests/fixtures/unit/to_csv_with_common_options/languages.yml +29 -0
- data/tests/fixtures/unit/to_csv_with_common_options/teams.yml +3 -0
- data/tests/fixtures/unit/to_csv_with_default_options/developers.yml +7 -0
- data/tests/models/address.rb +4 -0
- data/tests/models/animal.rb +2 -0
- data/tests/models/book.rb +3 -0
- data/tests/models/cart_item.rb +4 -0
- data/tests/models/developer.rb +8 -0
- data/tests/models/group.rb +3 -0
- data/tests/models/language.rb +5 -0
- data/tests/models/mysql/book.rb +3 -0
- data/tests/models/mysql/test_innodb.rb +3 -0
- data/tests/models/mysql/test_memory.rb +3 -0
- data/tests/models/mysql/test_myisam.rb +3 -0
- data/tests/models/project.rb +2 -0
- data/tests/models/shopping_cart.rb +4 -0
- data/tests/models/team.rb +4 -0
- data/tests/models/topic.rb +13 -0
- data/tests/mysql/test_create_and_update.rb +290 -0
- data/tests/mysql/test_delete.rb +142 -0
- data/tests/mysql/test_finder_options.rb +121 -0
- data/tests/mysql/test_finders.rb +29 -0
- data/tests/mysql/test_import.rb +354 -0
- data/tests/mysql/test_insert_select.rb +173 -0
- data/tests/mysql/test_mysql_adapter.rb +45 -0
- data/tests/mysql/test_union.rb +81 -0
- data/tests/oracle/test_adapter.rb +14 -0
- data/tests/postgresql/test_adapter.rb +14 -0
- data/tests/prepare.rb +9 -0
- data/tests/run.rb +13 -0
- data/tests/run_from_gem.rb +17 -0
- data/tests/test_activerecord_compatability.rb +71 -0
- data/tests/test_finders.rb +543 -0
- data/tests/test_helper.rb +70 -0
- data/tests/test_import.rb +339 -0
- data/tests/test_synchronize.rb +31 -0
- data/tests/test_temporary_tables.rb +93 -0
- data/tests/test_to_csv_headers.rb +204 -0
- data/tests/test_to_csv_with_common_options.rb +670 -0
- data/tests/test_to_csv_with_default_options.rb +34 -0
- metadata +211 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{cbaclig-ar-extensions}
|
5
|
+
s.version = "0.9.2.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = [""]
|
9
|
+
s.date = %q{2010-06-02}
|
10
|
+
s.description = %q{}
|
11
|
+
s.email = %q{}
|
12
|
+
s.extra_rdoc_files = ["README", "lib/ar-extensions.rb", "lib/ar-extensions/adapters/abstract_adapter.rb", "lib/ar-extensions/adapters/mysql.rb", "lib/ar-extensions/adapters/oracle.rb", "lib/ar-extensions/adapters/postgresql.rb", "lib/ar-extensions/adapters/sqlite.rb", "lib/ar-extensions/create_and_update.rb", "lib/ar-extensions/create_and_update/mysql.rb", "lib/ar-extensions/csv.rb", "lib/ar-extensions/delete.rb", "lib/ar-extensions/delete/mysql.rb", "lib/ar-extensions/extensions.rb", "lib/ar-extensions/finder_options.rb", "lib/ar-extensions/finder_options/mysql.rb", "lib/ar-extensions/finders.rb", "lib/ar-extensions/foreign_keys.rb", "lib/ar-extensions/fulltext.rb", "lib/ar-extensions/fulltext/mysql.rb", "lib/ar-extensions/import.rb", "lib/ar-extensions/import/mysql.rb", "lib/ar-extensions/import/postgresql.rb", "lib/ar-extensions/import/sqlite.rb", "lib/ar-extensions/insert_select.rb", "lib/ar-extensions/insert_select/mysql.rb", "lib/ar-extensions/synchronize.rb", "lib/ar-extensions/temporary_table.rb", "lib/ar-extensions/temporary_table/mysql.rb", "lib/ar-extensions/union.rb", "lib/ar-extensions/union/mysql.rb", "lib/ar-extensions/util/sql_generation.rb", "lib/ar-extensions/util/support_methods.rb", "lib/ar-extensions/version.rb"]
|
13
|
+
s.files = ["ChangeLog", "README", "Rakefile", "ar-extensions.gemspec", "benchmarks/README", "benchmarks/benchmark.rb", "benchmarks/boot.rb", "benchmarks/lib/base.rb", "benchmarks/lib/cli_parser.rb", "benchmarks/lib/float.rb", "benchmarks/lib/mysql_benchmark.rb", "benchmarks/lib/output_to_csv.rb", "benchmarks/lib/output_to_html.rb", "cbaclig-ar-extensions.gemspec", "config/database.yml", "config/database.yml.template", "config/mysql.schema", "config/postgresql.schema", "db/migrate/generic_schema.rb", "db/migrate/mysql_schema.rb", "db/migrate/oracle_schema.rb", "db/migrate/version.rb", "init.rb", "lib/ar-extensions.rb", "lib/ar-extensions/adapters/abstract_adapter.rb", "lib/ar-extensions/adapters/mysql.rb", "lib/ar-extensions/adapters/oracle.rb", "lib/ar-extensions/adapters/postgresql.rb", "lib/ar-extensions/adapters/sqlite.rb", "lib/ar-extensions/create_and_update.rb", "lib/ar-extensions/create_and_update/mysql.rb", "lib/ar-extensions/csv.rb", "lib/ar-extensions/delete.rb", "lib/ar-extensions/delete/mysql.rb", "lib/ar-extensions/extensions.rb", "lib/ar-extensions/finder_options.rb", "lib/ar-extensions/finder_options/mysql.rb", "lib/ar-extensions/finders.rb", "lib/ar-extensions/foreign_keys.rb", "lib/ar-extensions/fulltext.rb", "lib/ar-extensions/fulltext/mysql.rb", "lib/ar-extensions/import.rb", "lib/ar-extensions/import/mysql.rb", "lib/ar-extensions/import/postgresql.rb", "lib/ar-extensions/import/sqlite.rb", "lib/ar-extensions/insert_select.rb", "lib/ar-extensions/insert_select/mysql.rb", "lib/ar-extensions/synchronize.rb", "lib/ar-extensions/temporary_table.rb", "lib/ar-extensions/temporary_table/mysql.rb", "lib/ar-extensions/union.rb", "lib/ar-extensions/union/mysql.rb", "lib/ar-extensions/util/sql_generation.rb", "lib/ar-extensions/util/support_methods.rb", "lib/ar-extensions/version.rb", "tests/README", "tests/boot.rb", "tests/database.yml", "tests/database.yml.sample", "tests/fixtures/addresses.yml", "tests/fixtures/books.yml", "tests/fixtures/developers.yml", "tests/fixtures/unit/active_record_base_finders/addresses.yml", "tests/fixtures/unit/active_record_base_finders/books.yml", "tests/fixtures/unit/active_record_base_finders/developers.yml", "tests/fixtures/unit/synchronize/books.yml", "tests/fixtures/unit/to_csv_headers/addresses.yml", "tests/fixtures/unit/to_csv_headers/developers.yml", "tests/fixtures/unit/to_csv_with_common_options/addresses.yml", "tests/fixtures/unit/to_csv_with_common_options/developers.yml", "tests/fixtures/unit/to_csv_with_common_options/languages.yml", "tests/fixtures/unit/to_csv_with_common_options/teams.yml", "tests/fixtures/unit/to_csv_with_default_options/developers.yml", "tests/models/address.rb", "tests/models/animal.rb", "tests/models/book.rb", "tests/models/cart_item.rb", "tests/models/developer.rb", "tests/models/group.rb", "tests/models/language.rb", "tests/models/mysql/book.rb", "tests/models/mysql/test_innodb.rb", "tests/models/mysql/test_memory.rb", "tests/models/mysql/test_myisam.rb", "tests/models/project.rb", "tests/models/shopping_cart.rb", "tests/models/team.rb", "tests/models/topic.rb", "tests/mysql/test_create_and_update.rb", "tests/mysql/test_delete.rb", "tests/mysql/test_finder_options.rb", "tests/mysql/test_finders.rb", "tests/mysql/test_import.rb", "tests/mysql/test_insert_select.rb", "tests/mysql/test_mysql_adapter.rb", "tests/mysql/test_union.rb", "tests/oracle/test_adapter.rb", "tests/postgresql/test_adapter.rb", "tests/prepare.rb", "tests/run.rb", "tests/run_from_gem.rb", "tests/test_activerecord_compatability.rb", "tests/test_finders.rb", "tests/test_helper.rb", "tests/test_import.rb", "tests/test_synchronize.rb", "tests/test_temporary_tables.rb", "tests/test_to_csv_headers.rb", "tests/test_to_csv_with_common_options.rb", "tests/test_to_csv_with_default_options.rb", "Manifest"]
|
14
|
+
s.homepage = %q{}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Cbaclig-ar-extensions", "--main", "README"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{cbaclig-ar-extensions}
|
18
|
+
s.rubygems_version = %q{1.3.6}
|
19
|
+
s.summary = %q{}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
data/config/database.yml
ADDED
data/config/mysql.schema
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
|
2
|
+
create table test_myisam(
|
3
|
+
id int(11) unsigned not null auto_increment,
|
4
|
+
my_name varchar(20) not null,
|
5
|
+
description varchar(255) default '',
|
6
|
+
primary key (id)
|
7
|
+
)ENGINE=MyISAM;
|
8
|
+
|
9
|
+
|
10
|
+
create table test_innodb(
|
11
|
+
id int(11) unsigned not null auto_increment,
|
12
|
+
my_name varchar(20) not null,
|
13
|
+
description varchar(255) default '',
|
14
|
+
primary key (id)
|
15
|
+
)ENGINE=InnoDb;
|
16
|
+
|
17
|
+
|
18
|
+
create table test_memory(
|
19
|
+
id int(11) unsigned not null auto_increment,
|
20
|
+
my_name varchar(20) not null,
|
21
|
+
description varchar(255) default '',
|
22
|
+
primary key (id)
|
23
|
+
)ENGINE=memory;
|
24
|
+
|
25
|
+
|
26
|
+
create temporary table test_temp(
|
27
|
+
id int(11) unsigned not null auto_increment,
|
28
|
+
my_name varchar(20) not null,
|
29
|
+
description varchar(255) default '',
|
30
|
+
primary key (id)
|
31
|
+
);
|
32
|
+
|
33
|
+
CREATE TABLE `topics` (
|
34
|
+
`id` int(11) NOT NULL auto_increment,
|
35
|
+
`title` varchar(255) default NULL,
|
36
|
+
`author_name` varchar(255) default NULL,
|
37
|
+
`author_email_address` varchar(255) default NULL,
|
38
|
+
`written_on` datetime default NULL,
|
39
|
+
`bonus_time` time default NULL,
|
40
|
+
`last_read` date default NULL,
|
41
|
+
`content` text,
|
42
|
+
`approved` tinyint(1) default '1',
|
43
|
+
`replies_count` int(11) default '0',
|
44
|
+
`parent_id` int(11) default NULL,
|
45
|
+
`type` varchar(50) default NULL,
|
46
|
+
PRIMARY KEY (`id`)
|
47
|
+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
48
|
+
|
49
|
+
CREATE TABLE `projects` (
|
50
|
+
`id` int(11) NOT NULL auto_increment,
|
51
|
+
`name` varchar(100) default NULL,
|
52
|
+
`type` varchar(255) NOT NULL,
|
53
|
+
PRIMARY KEY (`id`)
|
54
|
+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
55
|
+
|
56
|
+
CREATE TABLE `developers` (
|
57
|
+
`id` int(11) NOT NULL auto_increment,
|
58
|
+
`name` varchar(100) default NULL,
|
59
|
+
`salary` int(11) default '70000',
|
60
|
+
`created_at` datetime default NULL,
|
61
|
+
`updated_at` datetime default NULL,
|
62
|
+
PRIMARY KEY (`id`)
|
63
|
+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
64
|
+
|
65
|
+
CREATE TABLE `books` (
|
66
|
+
`id` int(11) NOT NULL auto_increment,
|
67
|
+
`title` varchar(255) NOT NULL,
|
68
|
+
`publisher` varchar(255) NOT NULL,
|
69
|
+
`author_name` varchar(255) NOT NULL,
|
70
|
+
PRIMARY KEY (`id`),
|
71
|
+
FULLTEXT( `title`, `publisher`, `author_name` )
|
72
|
+
) ENGINE=MyISAM;
|
@@ -0,0 +1,39 @@
|
|
1
|
+
CREATE TABLE topics (
|
2
|
+
id serial NOT NULL,
|
3
|
+
title character varying(255) default NULL,
|
4
|
+
author_name character varying(255) default NULL,
|
5
|
+
author_email_address character varying(255) default NULL,
|
6
|
+
written_on timestamp default NULL,
|
7
|
+
bonus_time time default NULL,
|
8
|
+
last_read date default NULL,
|
9
|
+
content text,
|
10
|
+
approved bool default TRUE,
|
11
|
+
replies_count integer default 0,
|
12
|
+
parent_id serial default NULL,
|
13
|
+
type character varying(50) default NULL,
|
14
|
+
PRIMARY KEY (id)
|
15
|
+
);
|
16
|
+
|
17
|
+
CREATE TABLE projects (
|
18
|
+
id serial NOT NULL,
|
19
|
+
name character varying(100) default NULL,
|
20
|
+
type character varying(255) NOT NULL,
|
21
|
+
PRIMARY KEY (id)
|
22
|
+
);
|
23
|
+
|
24
|
+
CREATE TABLE developers (
|
25
|
+
id serial NOT NULL,
|
26
|
+
name character varying(100) default NULL,
|
27
|
+
salary integer default 70000,
|
28
|
+
created_at timestamp default NULL,
|
29
|
+
updated_at timestamp default NULL,
|
30
|
+
PRIMARY KEY (id)
|
31
|
+
);
|
32
|
+
|
33
|
+
CREATE TABLE books (
|
34
|
+
id serial NOT NULL,
|
35
|
+
title character varying(255) NOT NULL,
|
36
|
+
publisher character varying(255) NOT NULL,
|
37
|
+
author_name character varying(255) NOT NULL,
|
38
|
+
PRIMARY KEY (id)
|
39
|
+
);
|
@@ -0,0 +1,97 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
|
3
|
+
create_table :schema_info, :force=>true do |t|
|
4
|
+
t.column :version, :integer, :unique=>true
|
5
|
+
end
|
6
|
+
SchemaInfo.create :version=>SchemaInfo::VERSION
|
7
|
+
|
8
|
+
create_table :group, :force => true do |t|
|
9
|
+
t.column :order, :string
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
|
13
|
+
create_table :topics, :force=>true do |t|
|
14
|
+
t.column :title, :string, :null=>false
|
15
|
+
t.column :author_name, :string
|
16
|
+
t.column :author_email_address, :string
|
17
|
+
t.column :written_on, :datetime
|
18
|
+
t.column :bonus_time, :time
|
19
|
+
t.column :last_read, :datetime
|
20
|
+
t.column :content, :text
|
21
|
+
t.column :approved, :boolean, :default=>'1'
|
22
|
+
t.column :replies_count, :integer
|
23
|
+
t.column :parent_id, :integer
|
24
|
+
t.column :type, :string
|
25
|
+
t.column :created_at, :datetime
|
26
|
+
t.column :updated_at, :datetime
|
27
|
+
end
|
28
|
+
|
29
|
+
create_table :projects, :force=>true do |t|
|
30
|
+
t.column :name, :string
|
31
|
+
t.column :type, :string
|
32
|
+
end
|
33
|
+
|
34
|
+
create_table :developers, :force=>true do |t|
|
35
|
+
t.column :name, :string
|
36
|
+
t.column :salary, :integer, :default=>'70000'
|
37
|
+
t.column :created_at, :datetime
|
38
|
+
t.column :team_id, :integer
|
39
|
+
t.column :updated_at, :datetime
|
40
|
+
end
|
41
|
+
|
42
|
+
create_table :addresses, :force=>true do |t|
|
43
|
+
t.column :address, :string
|
44
|
+
t.column :city, :string
|
45
|
+
t.column :state, :string
|
46
|
+
t.column :zip, :string
|
47
|
+
t.column :developer_id, :integer
|
48
|
+
end
|
49
|
+
|
50
|
+
create_table :teams, :force=>true do |t|
|
51
|
+
t.column :name, :string
|
52
|
+
end
|
53
|
+
|
54
|
+
create_table :books, :force=>true do |t|
|
55
|
+
t.column :title, :string, :null=>false
|
56
|
+
t.column :publisher, :string, :null=>false, :default => 'Default Publisher'
|
57
|
+
t.column :author_name, :string, :null=>false
|
58
|
+
t.column :created_at, :datetime
|
59
|
+
t.column :created_on, :datetime
|
60
|
+
t.column :updated_at, :datetime
|
61
|
+
t.column :updated_on, :datetime
|
62
|
+
t.column :publish_date, :date
|
63
|
+
t.column :topic_id, :integer
|
64
|
+
t.column :for_sale, :boolean, :default => true
|
65
|
+
end
|
66
|
+
|
67
|
+
create_table :languages, :force=>true do |t|
|
68
|
+
t.column :name, :string
|
69
|
+
t.column :developer_id, :integer
|
70
|
+
end
|
71
|
+
|
72
|
+
create_table :shopping_carts, :force=>true do |t|
|
73
|
+
t.column :name, :string, :null => true
|
74
|
+
t.column :created_at, :datetime
|
75
|
+
t.column :updated_at, :datetime
|
76
|
+
end
|
77
|
+
|
78
|
+
create_table :cart_items, :force => true do |t|
|
79
|
+
t.column :shopping_cart_id, :string, :null => false
|
80
|
+
t.column :book_id, :string, :null => false
|
81
|
+
t.column :copies, :integer, :default => 1
|
82
|
+
t.column :created_at, :datetime
|
83
|
+
t.column :updated_at, :datetime
|
84
|
+
end
|
85
|
+
|
86
|
+
add_index :cart_items, [:shopping_cart_id, :book_id], :unique => true, :name => 'uk_shopping_cart_books'
|
87
|
+
|
88
|
+
create_table :animals, :force => true do |t|
|
89
|
+
t.column :name, :string, :null => false
|
90
|
+
t.column :size, :string, :default => nil
|
91
|
+
t.column :created_at, :datetime
|
92
|
+
t.column :updated_at, :datetime
|
93
|
+
end
|
94
|
+
|
95
|
+
add_index :animals, [:name], :unique => true, :name => 'uk_animals'
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
|
3
|
+
create_table :test_myisam, :options=>'ENGINE=MyISAM', :force=>true do |t|
|
4
|
+
t.column :my_name, :string, :null=>false
|
5
|
+
t.column :description, :string
|
6
|
+
end
|
7
|
+
|
8
|
+
create_table :test_innodb, :options=>'ENGINE=InnoDb', :force=>true do |t|
|
9
|
+
t.column :my_name, :string, :null=>false
|
10
|
+
t.column :description, :string
|
11
|
+
end
|
12
|
+
|
13
|
+
create_table :test_memory, :options=>'ENGINE=Memory', :force=>true do |t|
|
14
|
+
t.column :my_name, :string, :null=>false
|
15
|
+
t.column :description, :string
|
16
|
+
end
|
17
|
+
|
18
|
+
create_table :books, :options=>'ENGINE=MyISAM', :force=>true do |t|
|
19
|
+
t.column :title, :string, :null=>false
|
20
|
+
t.column :publisher, :string, :null=>false, :default => 'Default Publisher'
|
21
|
+
t.column :author_name, :string, :null=>false
|
22
|
+
t.column :created_at, :datetime
|
23
|
+
t.column :created_on, :datetime
|
24
|
+
t.column :updated_at, :datetime
|
25
|
+
t.column :updated_on, :datetime
|
26
|
+
t.column :publish_date, :date
|
27
|
+
t.column :topic_id, :integer
|
28
|
+
t.column :for_sale, :boolean, :default => true
|
29
|
+
end
|
30
|
+
execute "ALTER TABLE books ADD FULLTEXT( `title`, `publisher`, `author_name` )"
|
31
|
+
|
32
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
begin ; require 'active_record' ; rescue LoadError; require 'rubygems'; require 'active_record'; end
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
|
5
|
+
|
6
|
+
require 'ar-extensions/util/support_methods'
|
7
|
+
require 'ar-extensions/util/sql_generation'
|
8
|
+
require 'ar-extensions/version'
|
9
|
+
require 'ar-extensions/delete'
|
10
|
+
require 'ar-extensions/extensions'
|
11
|
+
require 'ar-extensions/create_and_update'
|
12
|
+
require 'ar-extensions/finder_options'
|
13
|
+
require 'ar-extensions/foreign_keys'
|
14
|
+
require 'ar-extensions/fulltext'
|
15
|
+
require 'ar-extensions/import'
|
16
|
+
require 'ar-extensions/insert_select'
|
17
|
+
require 'ar-extensions/finders'
|
18
|
+
require 'ar-extensions/synchronize'
|
19
|
+
require 'ar-extensions/temporary_table'
|
20
|
+
require 'ar-extensions/union'
|
21
|
+
require 'ar-extensions/adapters/abstract_adapter'
|
22
|
+
|
23
|
+
#load all available functionality for specified adapter
|
24
|
+
# Ex. ENV['LOAD_ADAPTER_EXTENSIONS'] = 'mysql'
|
25
|
+
if ENV['LOAD_ADAPTER_EXTENSIONS']
|
26
|
+
require "active_record/connection_adapters/#{ENV['LOAD_ADAPTER_EXTENSIONS']}_adapter.rb"
|
27
|
+
file_regexp = File.join(File.dirname(__FILE__), 'lib', 'ar-extensions','**',
|
28
|
+
"#{ENV['LOAD_ADAPTER_EXTENSIONS']}.rb")
|
29
|
+
|
30
|
+
Dir.glob(file_regexp){|file| require(file) }
|
31
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
module ActiveRecord # :nodoc:
|
2
|
+
module ConnectionAdapters # :nodoc:
|
3
|
+
class AbstractAdapter # :nodoc:
|
4
|
+
NO_MAX_PACKET = 0
|
5
|
+
QUERY_OVERHEAD = 8 #This was shown to be true for MySQL, but it's not clear where the overhead is from.
|
6
|
+
|
7
|
+
def next_value_for_sequence(sequence_name)
|
8
|
+
%{#{sequence_name}.nextval}
|
9
|
+
end
|
10
|
+
|
11
|
+
# +sql+ can be a single string or an array. If it is an array all
|
12
|
+
# elements that are in position >= 1 will be appended to the final SQL.
|
13
|
+
def insert_many( sql, values, *args ) # :nodoc:
|
14
|
+
# the number of inserts default
|
15
|
+
number_of_inserts = 0
|
16
|
+
|
17
|
+
base_sql,post_sql = if sql.is_a?( String )
|
18
|
+
[ sql, '' ]
|
19
|
+
elsif sql.is_a?( Array )
|
20
|
+
[ sql.shift, sql.join( ' ' ) ]
|
21
|
+
end
|
22
|
+
|
23
|
+
sql_size = QUERY_OVERHEAD + base_sql.size + post_sql.size
|
24
|
+
|
25
|
+
# the number of bytes the requested insert statement values will take up
|
26
|
+
values_in_bytes = self.class.sum_sizes( *values )
|
27
|
+
|
28
|
+
# the number of bytes (commas) it will take to comma separate our values
|
29
|
+
comma_separated_bytes = values.size-1
|
30
|
+
|
31
|
+
# the total number of bytes required if this statement is one statement
|
32
|
+
total_bytes = sql_size + values_in_bytes + comma_separated_bytes
|
33
|
+
|
34
|
+
max = max_allowed_packet
|
35
|
+
|
36
|
+
# if we can insert it all as one statement
|
37
|
+
if NO_MAX_PACKET == max or total_bytes < max
|
38
|
+
number_of_inserts += 1
|
39
|
+
sql2insert = base_sql + values.join( ',' ) + post_sql
|
40
|
+
insert( sql2insert, *args )
|
41
|
+
else
|
42
|
+
value_sets = self.class.get_insert_value_sets( values, sql_size, max )
|
43
|
+
value_sets.each do |values|
|
44
|
+
number_of_inserts += 1
|
45
|
+
sql2insert = base_sql + values.join( ',' ) + post_sql
|
46
|
+
insert( sql2insert, *args )
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
number_of_inserts
|
51
|
+
end
|
52
|
+
|
53
|
+
def pre_sql_statements(options)
|
54
|
+
sql = []
|
55
|
+
sql << options[:pre_sql] if options[:pre_sql]
|
56
|
+
sql << options[:command] if options[:command]
|
57
|
+
sql << "IGNORE" if options[:ignore]
|
58
|
+
|
59
|
+
#add keywords like IGNORE or DELAYED
|
60
|
+
if options[:keywords].is_a?(Array)
|
61
|
+
sql.concat(options[:keywords])
|
62
|
+
elsif options[:keywords]
|
63
|
+
sql << options[:keywords].to_s
|
64
|
+
end
|
65
|
+
|
66
|
+
sql
|
67
|
+
end
|
68
|
+
|
69
|
+
# Synchronizes the passed in ActiveRecord instances with the records in
|
70
|
+
# the database by calling +reload+ on each instance.
|
71
|
+
def after_import_synchronize( instances )
|
72
|
+
instances.each { |e| e.reload }
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns an array of post SQL statements given the passed in options.
|
76
|
+
def post_sql_statements( table_name, options ) # :nodoc:
|
77
|
+
post_sql_statements = []
|
78
|
+
if options[:on_duplicate_key_update]
|
79
|
+
post_sql_statements << sql_for_on_duplicate_key_update( table_name, options[:on_duplicate_key_update] )
|
80
|
+
end
|
81
|
+
|
82
|
+
#custom user post_sql
|
83
|
+
post_sql_statements << options[:post_sql] if options[:post_sql]
|
84
|
+
|
85
|
+
#with rollup
|
86
|
+
post_sql_statements << rollup_sql if options[:rollup]
|
87
|
+
|
88
|
+
post_sql_statements
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
# Generates the INSERT statement used in insert multiple value sets.
|
93
|
+
def multiple_value_sets_insert_sql(table_name, column_names, options) # :nodoc:
|
94
|
+
"INSERT #{options[:ignore] ? 'IGNORE ':''}INTO #{table_name} (#{column_names.join(',')}) VALUES "
|
95
|
+
end
|
96
|
+
|
97
|
+
# Returns SQL the VALUES for an INSERT statement given the passed in +columns+
|
98
|
+
# and +array_of_attributes+.
|
99
|
+
def values_sql_for_column_names_and_attributes( columns, array_of_attributes ) # :nodoc:
|
100
|
+
# Assume that all of the attributes are already quoted
|
101
|
+
array_of_attributes.map{ |arr| '(' + arr.join( ',' ) + ')' }
|
102
|
+
end
|
103
|
+
|
104
|
+
# Returns the sum of the sizes of the passed in objects. This should
|
105
|
+
# probably be moved outside this class, but to where?
|
106
|
+
def self.sum_sizes( *objects ) # :nodoc:
|
107
|
+
objects.inject( 0 ){|sum,o| sum += o.size }
|
108
|
+
end
|
109
|
+
|
110
|
+
# Returns the maximum number of bytes that the server will allow
|
111
|
+
# in a single packet
|
112
|
+
def max_allowed_packet
|
113
|
+
NO_MAX_PACKET
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.get_insert_value_sets( values, sql_size, max_bytes ) # :nodoc:
|
117
|
+
value_sets = []
|
118
|
+
arr, current_arr_values_size, current_size = [], 0, 0
|
119
|
+
values.each_with_index do |val,i|
|
120
|
+
comma_bytes = arr.size
|
121
|
+
sql_size_thus_far = sql_size + current_size + val.size + comma_bytes
|
122
|
+
if NO_MAX_PACKET == max_bytes or sql_size_thus_far <= max_bytes
|
123
|
+
current_size += val.size
|
124
|
+
arr << val
|
125
|
+
else
|
126
|
+
value_sets << arr
|
127
|
+
arr = [ val ]
|
128
|
+
current_size = val.size
|
129
|
+
end
|
130
|
+
|
131
|
+
# if we're on the last iteration push whatever we have in arr to value_sets
|
132
|
+
value_sets << arr if i == (values.size-1)
|
133
|
+
end
|
134
|
+
[ *value_sets ]
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|