sequel 0.5.0.2 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/COPYING +18 -18
  2. data/Rakefile +17 -98
  3. data/lib/sequel.rb +2 -71
  4. metadata +10 -108
  5. data/CHANGELOG +0 -989
  6. data/bin/sequel +0 -41
  7. data/lib/sequel/adapters/adapter_skeleton.rb +0 -68
  8. data/lib/sequel/adapters/ado.rb +0 -100
  9. data/lib/sequel/adapters/db2.rb +0 -158
  10. data/lib/sequel/adapters/dbi.rb +0 -126
  11. data/lib/sequel/adapters/informix.rb +0 -87
  12. data/lib/sequel/adapters/jdbc.rb +0 -108
  13. data/lib/sequel/adapters/mysql.rb +0 -269
  14. data/lib/sequel/adapters/odbc.rb +0 -145
  15. data/lib/sequel/adapters/odbc_mssql.rb +0 -93
  16. data/lib/sequel/adapters/openbase.rb +0 -90
  17. data/lib/sequel/adapters/oracle.rb +0 -99
  18. data/lib/sequel/adapters/postgres.rb +0 -519
  19. data/lib/sequel/adapters/sqlite.rb +0 -192
  20. data/lib/sequel/ado.rb +0 -6
  21. data/lib/sequel/array_keys.rb +0 -296
  22. data/lib/sequel/connection_pool.rb +0 -152
  23. data/lib/sequel/core_ext.rb +0 -59
  24. data/lib/sequel/core_sql.rb +0 -191
  25. data/lib/sequel/database.rb +0 -433
  26. data/lib/sequel/dataset.rb +0 -409
  27. data/lib/sequel/dataset/convenience.rb +0 -321
  28. data/lib/sequel/dataset/sequelizer.rb +0 -354
  29. data/lib/sequel/dataset/sql.rb +0 -586
  30. data/lib/sequel/db2.rb +0 -6
  31. data/lib/sequel/dbi.rb +0 -6
  32. data/lib/sequel/exceptions.rb +0 -45
  33. data/lib/sequel/informix.rb +0 -6
  34. data/lib/sequel/migration.rb +0 -191
  35. data/lib/sequel/model.rb +0 -8
  36. data/lib/sequel/mysql.rb +0 -6
  37. data/lib/sequel/odbc.rb +0 -6
  38. data/lib/sequel/oracle.rb +0 -6
  39. data/lib/sequel/postgres.rb +0 -6
  40. data/lib/sequel/pretty_table.rb +0 -73
  41. data/lib/sequel/schema.rb +0 -8
  42. data/lib/sequel/schema/schema_generator.rb +0 -131
  43. data/lib/sequel/schema/schema_sql.rb +0 -131
  44. data/lib/sequel/sqlite.rb +0 -6
  45. data/lib/sequel/worker.rb +0 -58
  46. data/spec/adapters/informix_spec.rb +0 -139
  47. data/spec/adapters/mysql_spec.rb +0 -330
  48. data/spec/adapters/oracle_spec.rb +0 -130
  49. data/spec/adapters/postgres_spec.rb +0 -189
  50. data/spec/adapters/sqlite_spec.rb +0 -345
  51. data/spec/array_keys_spec.rb +0 -679
  52. data/spec/connection_pool_spec.rb +0 -356
  53. data/spec/core_ext_spec.rb +0 -67
  54. data/spec/core_sql_spec.rb +0 -301
  55. data/spec/database_spec.rb +0 -811
  56. data/spec/dataset_spec.rb +0 -2381
  57. data/spec/migration_spec.rb +0 -261
  58. data/spec/pretty_table_spec.rb +0 -66
  59. data/spec/rcov.opts +0 -4
  60. data/spec/schema_generator_spec.rb +0 -86
  61. data/spec/schema_spec.rb +0 -230
  62. data/spec/sequel_spec.rb +0 -10
  63. data/spec/sequelizer_spec.rb +0 -389
  64. data/spec/spec.opts +0 -5
  65. data/spec/spec_helper.rb +0 -44
  66. data/spec/worker_spec.rb +0 -96
@@ -1,87 +0,0 @@
1
- require 'informix'
2
-
3
- module Sequel
4
- module Informix
5
- class Database < Sequel::Database
6
- set_adapter_scheme :informix
7
-
8
- # AUTO_INCREMENT = 'IDENTITY(1,1)'.freeze
9
- #
10
- # def auto_increment_sql
11
- # AUTO_INCREMENT
12
- # end
13
-
14
- def connect
15
- ::Informix.connect(@opts[:database], @opts[:user], @opts[:password])
16
- end
17
-
18
- def disconnect
19
- @pool.disconnect {|c| c.close}
20
- end
21
-
22
- def dataset(opts = nil)
23
- Sequel::Informix::Dataset.new(self, opts)
24
- end
25
-
26
- # Returns number of rows affected
27
- def execute(sql)
28
- @logger.info(sql) if @logger
29
- @pool.hold {|c| c.do(sql)}
30
- end
31
- alias_method :do, :execute
32
-
33
- def query(sql, &block)
34
- @logger.info(sql) if @logger
35
- @pool.hold {|c| block[c.cursor(sql)]}
36
- end
37
- end
38
-
39
- class Dataset < Sequel::Dataset
40
- def literal(v)
41
- case v
42
- when Time
43
- literal(v.iso8601)
44
- else
45
- super
46
- end
47
- end
48
-
49
- def select_sql(opts = nil)
50
- limit = opts.delete(:limit)
51
- offset = opts.delete(:offset)
52
- sql = super
53
- if limit
54
- limit = "FIRST #{limit}"
55
- offset = offset ? "SKIP #{offset}" : ""
56
- sql.sub!(/^select /i,"SELECT #{offset} #{limit} ")
57
- end
58
- sql
59
- end
60
-
61
- def fetch_rows(sql, &block)
62
- @db.synchronize do
63
- @db.query(sql) do |cursor|
64
- begin
65
- cursor.open.each_hash {|r| block[r]}
66
- ensure
67
- cursor.drop
68
- end
69
- end
70
- end
71
- self
72
- end
73
-
74
- def insert(*values)
75
- @db.do insert_sql(*values)
76
- end
77
-
78
- def update(*args, &block)
79
- @db.do update_sql(*args, &block)
80
- end
81
-
82
- def delete(opts = nil)
83
- @db.do delete_sql(opts)
84
- end
85
- end
86
- end
87
- end
@@ -1,108 +0,0 @@
1
- require 'java'
2
-
3
- module Sequel
4
- module JDBC
5
- module JavaLang; include_package 'java.lang'; end
6
- module JavaSQL; include_package 'java.sql'; end
7
-
8
- def self.load_driver(driver)
9
- JavaLang::Class.forName(driver)
10
- # "com.mysql.jdbc.Driver"
11
- end
12
-
13
- class Database < Sequel::Database
14
- set_adapter_scheme :jdbc
15
-
16
- def connect
17
- unless conn_string = @opts[:uri] || @opts[:url] || @opts[:database]
18
- raise Error, "No connection string specified"
19
- end
20
- unless conn_string =~ /^jdbc:/
21
- conn_string = "jdbc:#{conn_string}"
22
- end
23
- JavaSQL::DriverManager.getConnection(
24
- conn_string,
25
- @opts[:user],
26
- @opts[:password]
27
- )
28
- # "jdbc:mysql://127.0.0.1:3306/ruby?user=root"
29
- # "mysql://127.0.0.1:3306/ruby?user=root"
30
- end
31
-
32
- def disconnect
33
- @pool.disconnect {|c| c.close}
34
- end
35
-
36
- def dataset(opts = nil)
37
- JDBC::Dataset.new(self, opts)
38
- end
39
-
40
- def execute_and_forget(sql)
41
- @logger.info(sql) if @logger
42
- @pool.hold do |conn|
43
- stmt = conn.createStatement
44
- begin
45
- stmt.executeQuery(sql)
46
- ensure
47
- stmt.close
48
- end
49
- end
50
- end
51
-
52
- def execute(sql)
53
- @logger.info(sql) if @logger
54
- @pool.hold do |conn|
55
- stmt = conn.createStatement
56
- begin
57
- yield stmt.executeQuery(sql)
58
- ensure
59
- stmt.close
60
- end
61
- end
62
- end
63
- end
64
-
65
- class Dataset < Sequel::Dataset
66
- def literal(v)
67
- case v
68
- when Time
69
- literal(v.iso8601)
70
- else
71
- super
72
- end
73
- end
74
-
75
- def fetch_rows(sql, &block)
76
- @db.synchronize do
77
- @db.execute(sql) do |result|
78
- # get column names
79
- meta = result.getMetaData
80
- column_count = meta.getColumnCount
81
- @columns = []
82
- column_count.times {|i| @columns << meta.getColumnName(i).to_sym}
83
-
84
- # get rows
85
- while result.next
86
- row = {}
87
- @columns.each_with_index {|v, i| row[v] = result.getObject(i)}
88
- yield row
89
- end
90
- end
91
- end
92
- self
93
- end
94
-
95
- def insert(*values)
96
- @db.execute_and_forget insert_sql(*values)
97
- end
98
-
99
- def update(*args, &block)
100
- @db.execute_and_forget update_sql(*args, &block)
101
- end
102
-
103
- def delete(opts = nil)
104
- @db.execute_and_forget delete_sql(opts)
105
- end
106
- end
107
- end
108
- end
@@ -1,269 +0,0 @@
1
- require 'mysql'
2
-
3
- # Monkey patch Mysql::Result to yield hashes with symbol keys
4
- class Mysql::Result
5
- MYSQL_TYPES = {
6
- 0 => :to_d, # MYSQL_TYPE_DECIMAL
7
- 1 => :to_i, # MYSQL_TYPE_TINY
8
- 2 => :to_i, # MYSQL_TYPE_SHORT
9
- 3 => :to_i, # MYSQL_TYPE_LONG
10
- 4 => :to_f, # MYSQL_TYPE_FLOAT
11
- 5 => :to_f, # MYSQL_TYPE_DOUBLE
12
- # 6 => ??, # MYSQL_TYPE_NULL
13
- 7 => :to_time, # MYSQL_TYPE_TIMESTAMP
14
- 8 => :to_i, # MYSQL_TYPE_LONGLONG
15
- 9 => :to_i, # MYSQL_TYPE_INT24
16
- 10 => :to_time, # MYSQL_TYPE_DATE
17
- 11 => :to_time, # MYSQL_TYPE_TIME
18
- 12 => :to_time, # MYSQL_TYPE_DATETIME
19
- 13 => :to_i, # MYSQL_TYPE_YEAR
20
- 14 => :to_time, # MYSQL_TYPE_NEWDATE
21
- # 15 => :to_s # MYSQL_TYPE_VARCHAR
22
- # 16 => :to_s, # MYSQL_TYPE_BIT
23
- 246 => :to_d, # MYSQL_TYPE_NEWDECIMAL
24
- 247 => :to_i, # MYSQL_TYPE_ENUM
25
- 248 => :to_i # MYSQL_TYPE_SET
26
- # 249 => :to_s, # MYSQL_TYPE_TINY_BLOB
27
- # 250 => :to_s, # MYSQL_TYPE_MEDIUM_BLOB
28
- # 251 => :to_s, # MYSQL_TYPE_LONG_BLOB
29
- # 252 => :to_s, # MYSQL_TYPE_BLOB
30
- # 253 => :to_s, # MYSQL_TYPE_VAR_STRING
31
- # 254 => :to_s, # MYSQL_TYPE_STRING
32
- # 255 => :to_s # MYSQL_TYPE_GEOMETRY
33
- }
34
-
35
- def convert_type(v, type)
36
- v ? ((t = MYSQL_TYPES[type]) ? v.send(t) : v) : nil
37
- end
38
-
39
- def columns(with_table = nil)
40
- unless @columns
41
- @column_types = []
42
- @columns = fetch_fields.map do |f|
43
- @column_types << f.type
44
- (with_table ? (f.table + "." + f.name) : f.name).to_sym
45
- end
46
- end
47
- @columns
48
- end
49
-
50
- def each_array(with_table = nil)
51
- c = columns
52
- while row = fetch_row
53
- c.each_with_index do |f, i|
54
- if (t = MYSQL_TYPES[@column_types[i]]) && (v = row[i])
55
- row[i] = v.send(t)
56
- end
57
- end
58
- row.keys = c
59
- yield row
60
- end
61
- end
62
-
63
- def each_hash(with_table = nil)
64
- c = columns
65
- while row = fetch_row
66
- h = {}
67
- c.each_with_index {|f, i| h[f] = convert_type(row[i], @column_types[i])}
68
- yield h
69
- end
70
- end
71
- end
72
-
73
- module Sequel
74
- module MySQL
75
- class Database < Sequel::Database
76
- set_adapter_scheme :mysql
77
-
78
- def serial_primary_key_options
79
- {:primary_key => true, :type => :integer, :auto_increment => true}
80
- end
81
-
82
- AUTO_INCREMENT = 'AUTO_INCREMENT'.freeze
83
-
84
- def auto_increment_sql
85
- AUTO_INCREMENT
86
- end
87
-
88
- def connect
89
- conn = Mysql.real_connect(@opts[:host], @opts[:user], @opts[:password],
90
- @opts[:database], @opts[:port], nil, Mysql::CLIENT_MULTI_RESULTS)
91
- conn.query_with_result = false
92
- if encoding = @opts[:encoding] || @opts[:charset]
93
- conn.query("set character_set_connection = '#{encoding}'")
94
- conn.query("set character_set_client = '#{encoding}'")
95
- conn.query("set character_set_results = '#{encoding}'")
96
- end
97
- conn.reconnect = true
98
- conn
99
- end
100
-
101
- def disconnect
102
- @pool.disconnect {|c| c.close}
103
- end
104
-
105
- def tables
106
- @pool.hold do |conn|
107
- conn.list_tables.map {|t| t.to_sym}
108
- end
109
- end
110
-
111
- def dataset(opts = nil)
112
- MySQL::Dataset.new(self, opts)
113
- end
114
-
115
- def execute(sql)
116
- @logger.info(sql) if @logger
117
- @pool.hold do |conn|
118
- conn.query(sql)
119
- end
120
- end
121
-
122
- def execute_select(sql)
123
- @logger.info(sql) if @logger
124
- @pool.hold do |conn|
125
- conn.query(sql)
126
- conn.use_result
127
- end
128
- end
129
-
130
- def execute_insert(sql)
131
- @logger.info(sql) if @logger
132
- @pool.hold do |conn|
133
- conn.query(sql)
134
- conn.insert_id
135
- end
136
- end
137
-
138
- def execute_affected(sql)
139
- @logger.info(sql) if @logger
140
- @pool.hold do |conn|
141
- conn.query(sql)
142
- conn.affected_rows
143
- end
144
- end
145
-
146
- def alter_table_sql(table, op)
147
- case op[:op]
148
- when :rename_column
149
- "ALTER TABLE #{table} CHANGE COLUMN #{literal(op[:name])} #{literal(op[:new_name])} #{op[:type]}"
150
- when :set_column_type
151
- "ALTER TABLE #{table} CHANGE COLUMN #{literal(op[:name])} #{literal(op[:name])} #{op[:type]}"
152
- when :drop_index
153
- "DROP INDEX #{default_index_name(table, op[:columns])} ON #{table}"
154
- else
155
- super(table, op)
156
- end
157
- end
158
-
159
- def transaction
160
- @pool.hold do |conn|
161
- @transactions ||= []
162
- if @transactions.include? Thread.current
163
- return yield(conn)
164
- end
165
- conn.query(SQL_BEGIN)
166
- begin
167
- @transactions << Thread.current
168
- result = yield(conn)
169
- conn.query(SQL_COMMIT)
170
- result
171
- rescue => e
172
- conn.query(SQL_ROLLBACK)
173
- raise e unless Error::Rollback === e
174
- ensure
175
- @transactions.delete(Thread.current)
176
- end
177
- end
178
- end
179
- end
180
-
181
- class Dataset < Sequel::Dataset
182
- def quote_column_ref(c); "`#{c}`"; end
183
-
184
- TRUE = '1'
185
- FALSE = '0'
186
-
187
- def literal(v)
188
- case v
189
- when LiteralString
190
- v
191
- when String
192
- "'#{v.gsub(/'|\\/, '\&\&')}'"
193
- when true
194
- TRUE
195
- when false
196
- FALSE
197
- else
198
- super
199
- end
200
- end
201
-
202
- def match_expr(l, r)
203
- case r
204
- when Regexp
205
- r.casefold? ? \
206
- "(#{literal(l)} REGEXP #{literal(r.source)})" :
207
- "(#{literal(l)} REGEXP BINARY #{literal(r.source)})"
208
- else
209
- super
210
- end
211
- end
212
-
213
- # MySQL supports ORDER and LIMIT clauses in UPDATE statements.
214
- def update_sql(values, opts = nil)
215
- sql = super
216
-
217
- opts = opts ? @opts.merge(opts) : @opts
218
-
219
- if order = opts[:order]
220
- sql << " ORDER BY #{column_list(order)}"
221
- end
222
-
223
- if limit = opts[:limit]
224
- sql << " LIMIT #{limit}"
225
- end
226
-
227
- sql
228
- end
229
-
230
- def insert(*values)
231
- @db.execute_insert(insert_sql(*values))
232
- end
233
-
234
- def update(*args, &block)
235
- @db.execute_affected(update_sql(*args, &block))
236
- end
237
-
238
- def delete(opts = nil)
239
- @db.execute_affected(delete_sql(opts))
240
- end
241
-
242
- def fetch_rows(sql)
243
- @db.synchronize do
244
- r = @db.execute_select(sql)
245
- begin
246
- @columns = r.columns
247
- r.each_hash {|row| yield row}
248
- ensure
249
- r.free
250
- end
251
- end
252
- self
253
- end
254
-
255
- def array_tuples_fetch_rows(sql, &block)
256
- @db.synchronize do
257
- r = @db.execute_select(sql)
258
- begin
259
- @columns = r.columns
260
- r.each_array(&block)
261
- ensure
262
- r.free
263
- end
264
- end
265
- self
266
- end
267
- end
268
- end
269
- end