activesalesforce 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/asf_adapter.rb +21 -17
- metadata +2 -2
data/lib/asf_adapter.rb
CHANGED
@@ -41,6 +41,10 @@ module ActiveRecord
|
|
41
41
|
def self.debug(msg)
|
42
42
|
logger.debug(msg) if logger
|
43
43
|
end
|
44
|
+
|
45
|
+
def self.flush_connections()
|
46
|
+
@@cache = {}
|
47
|
+
end
|
44
48
|
|
45
49
|
# Establishes a connection to the database that's used by all Active Record objects.
|
46
50
|
def self.activesalesforce_connection(config) # :nodoc:
|
@@ -79,7 +83,7 @@ module ActiveRecord
|
|
79
83
|
ConnectionAdapters::SalesforceAdapter.new(binding, logger, [url, sid], config)
|
80
84
|
else
|
81
85
|
# Check to insure that the second to last path component is a 'u' for Partner API
|
82
|
-
raise ActiveSalesforce::ASFError.new(logger, "Invalid salesforce server url '#{url}', must be a valid Parter API URL") unless url.match(/\/u\//
|
86
|
+
raise ActiveSalesforce::ASFError.new(logger, "Invalid salesforce server url '#{url}', must be a valid Parter API URL") unless url.match(/\/u\//mi)
|
83
87
|
|
84
88
|
binding = @@cache["#{url}.#{username}.#{password}"] unless binding
|
85
89
|
|
@@ -252,7 +256,7 @@ module ActiveRecord
|
|
252
256
|
|
253
257
|
def select_all(sql, name = nil) #:nodoc:
|
254
258
|
log(sql, name) {
|
255
|
-
raw_table_name = sql.match(/FROM (\w+)/
|
259
|
+
raw_table_name = sql.match(/FROM (\w+)/mi)[1]
|
256
260
|
table_name, columns, entity_def = lookup(raw_table_name)
|
257
261
|
|
258
262
|
column_names = columns.map { |column| column.api_name }
|
@@ -260,23 +264,23 @@ module ActiveRecord
|
|
260
264
|
# Check for SELECT COUNT(*) FROM query
|
261
265
|
|
262
266
|
# Rails 1.1
|
263
|
-
selectCountMatch = sql.match(/SELECT\s+COUNT\(\*\)\s+AS\s+count_all\s+FROM/
|
267
|
+
selectCountMatch = sql.match(/SELECT\s+COUNT\(\*\)\s+AS\s+count_all\s+FROM/mi)
|
264
268
|
|
265
269
|
# Rails 1.0
|
266
|
-
selectCountMatch = sql.match(/SELECT\s+COUNT\(\*\)\s+FROM/
|
270
|
+
selectCountMatch = sql.match(/SELECT\s+COUNT\(\*\)\s+FROM/mi) unless selectCountMatch
|
267
271
|
|
268
272
|
if selectCountMatch
|
269
273
|
soql = "SELECT id FROM#{selectCountMatch.post_match}"
|
270
274
|
else
|
271
|
-
if sql.match(/SELECT\s+\*\s+FROM/
|
275
|
+
if sql.match(/SELECT\s+\*\s+FROM/mi)
|
272
276
|
# Always convert SELECT * to select all columns (required for the AR attributes mechanism to work correctly)
|
273
|
-
soql = sql.sub(/SELECT .+ FROM/
|
277
|
+
soql = sql.sub(/SELECT .+ FROM/mi, "SELECT #{column_names.join(', ')} FROM")
|
274
278
|
else
|
275
279
|
soql = sql
|
276
280
|
end
|
277
281
|
end
|
278
282
|
|
279
|
-
soql.sub!(/\s+FROM\s+\w+/
|
283
|
+
soql.sub!(/\s+FROM\s+\w+/mi, " FROM #{entity_def.api_name}")
|
280
284
|
|
281
285
|
# Look for a LIMIT clause
|
282
286
|
limit = extract_sql_modifier(soql, "LIMIT")
|
@@ -298,7 +302,7 @@ module ActiveRecord
|
|
298
302
|
end
|
299
303
|
|
300
304
|
# Update table name references
|
301
|
-
soql.sub!(/#{raw_table_name}\./
|
305
|
+
soql.sub!(/#{raw_table_name}\./mi, "#{entity_def.api_name}.")
|
302
306
|
|
303
307
|
@connection.batch_size = @batch_size if @batch_size
|
304
308
|
@batch_size = nil
|
@@ -366,14 +370,14 @@ module ActiveRecord
|
|
366
370
|
def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
|
367
371
|
log(sql, name) {
|
368
372
|
# Convert sql to sobject
|
369
|
-
table_name, columns, entity_def = lookup(sql.match(/INSERT\s+INTO\s+(\w+)\s+/
|
373
|
+
table_name, columns, entity_def = lookup(sql.match(/INSERT\s+INTO\s+(\w+)\s+/mi)[1])
|
370
374
|
columns = entity_def.column_name_to_column
|
371
375
|
|
372
376
|
# Extract array of column names
|
373
|
-
names = sql.match(/\((.+)\)\s+VALUES/
|
377
|
+
names = sql.match(/\((.+)\)\s+VALUES/mi)[1].scan(/\w+/mi)
|
374
378
|
|
375
379
|
# Extract arrays of values
|
376
|
-
values = sql.match(/VALUES\s*\((.+)\)/
|
380
|
+
values = sql.match(/VALUES\s*\((.+)\)/mi)[1]
|
377
381
|
values = values.scan(/(NULL|TRUE|FALSE|'(?:(?:[^']|'')*)'),*/mi).flatten
|
378
382
|
values.map! { |v| v.first == "'" ? v.slice(1, v.length - 2) : v == "NULL" ? nil : v }
|
379
383
|
|
@@ -393,18 +397,18 @@ module ActiveRecord
|
|
393
397
|
def update(sql, name = nil) #:nodoc:
|
394
398
|
log(sql, name) {
|
395
399
|
# Convert sql to sobject
|
396
|
-
table_name, columns, entity_def = lookup(sql.match(/UPDATE\s+(\w+)\s+/
|
400
|
+
table_name, columns, entity_def = lookup(sql.match(/UPDATE\s+(\w+)\s+/mi)[1])
|
397
401
|
columns = entity_def.column_name_to_column
|
398
402
|
|
399
403
|
match = sql.match(/SET\s+(.+)\s+WHERE/mi)[1]
|
400
|
-
names = match.scan(/(\w+)\s*=\s*(?:'|NULL|TRUE|FALSE)/
|
404
|
+
names = match.scan(/(\w+)\s*=\s*(?:'|NULL|TRUE|FALSE)/mi).flatten
|
401
405
|
|
402
406
|
values = match.scan(/=\s*(NULL|TRUE|FALSE|'(?:(?:[^']|'')*)'),*/mi).flatten
|
403
407
|
values.map! { |v| v.first == "'" ? v.slice(1, v.length - 2) : v == "NULL" ? nil : v }
|
404
408
|
|
405
409
|
fields = get_fields(columns, names, values, :updateable)
|
406
410
|
|
407
|
-
id = sql.match(/WHERE\s+id\s*=\s*'(\w+)'/
|
411
|
+
id = sql.match(/WHERE\s+id\s*=\s*'(\w+)'/mi)[1]
|
408
412
|
|
409
413
|
sobject = create_sobject(entity_def.api_name, id, fields)
|
410
414
|
|
@@ -483,10 +487,10 @@ module ActiveRecord
|
|
483
487
|
|
484
488
|
|
485
489
|
def extract_sql_modifier(soql, modifier)
|
486
|
-
value = soql.match(/\s+#{modifier}\s+(\d+)/
|
490
|
+
value = soql.match(/\s+#{modifier}\s+(\d+)/mi)
|
487
491
|
if value
|
488
492
|
value = value[1].to_i
|
489
|
-
soql.sub!(/\s+#{modifier}\s+\d+/
|
493
|
+
soql.sub!(/\s+#{modifier}\s+\d+/mi, "")
|
490
494
|
end
|
491
495
|
|
492
496
|
value
|
@@ -545,7 +549,7 @@ module ActiveRecord
|
|
545
549
|
column = SalesforceColumn.new(field)
|
546
550
|
cached_columns << column
|
547
551
|
|
548
|
-
cached_relationships << SalesforceRelationship.new(field, column) if field[:type] =~ /reference/
|
552
|
+
cached_relationships << SalesforceRelationship.new(field, column) if field[:type] =~ /reference/mi
|
549
553
|
end
|
550
554
|
|
551
555
|
relationships = metadata[:childRelationships]
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: activesalesforce
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.5.
|
7
|
-
date: 2006-05-
|
6
|
+
version: 0.5.7
|
7
|
+
date: 2006-05-15 00:00:00 -04:00
|
8
8
|
summary: ActiveSalesforce (ASF) is a Rails connection adapter that provides direct access to Salesforce.com hosted data and metadata via the ActiveRecord model layer. Objects, fields, and relationships are all auto surfaced as active record attributes and rels.
|
9
9
|
require_paths:
|
10
10
|
- lib
|