activesalesforce 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,18 +45,18 @@ module ActiveRecord
45
45
  def self.salesforce_connection(config) # :nodoc:
46
46
  puts "Using Salesforce connection!"
47
47
 
48
- config = config.symbolize_keys
49
-
50
- url = config[:url].to_s
51
- username = config[:username].to_s
52
- password = config[:password].to_s
48
+ url = config[:url]
49
+ username = config[:username]
50
+ password = config[:password]
53
51
 
54
52
  connection = @@cache["#{url}.#{username}.#{password}"]
55
-
56
- if not connection
53
+ unless connection
54
+ puts "Establishing new connection for ['#{url}', '#{username}']"
55
+
57
56
  connection = SalesforceLogin.new(url, username, password).proxy
58
57
  @@cache["#{url}.#{username}.#{password}"] = connection
59
- puts "Created new connection for [#{url}, #{username}]"
58
+
59
+ puts "Created new connection for ['#{url}', '#{username}']"
60
60
  end
61
61
 
62
62
  ConnectionAdapters::SalesforceAdapter.new(connection, logger, [url, username, password], config)
@@ -166,22 +166,28 @@ module ActiveRecord
166
166
  def select_all(sql, name = nil) #:nodoc:
167
167
  log(sql, name)
168
168
 
169
- raw_table_name = sql.match(/FROM (\w+) /)[1]
169
+ # Check for SELECT COUNT(*) FROM query
170
+ matchCount = sql.match(/SELECT COUNT\(\*\) FROM/i)
171
+ if matchCount
172
+ sql = "SELECT id FROM#{matchCount.post_match}"
173
+ end
174
+
175
+ raw_table_name = sql.match(/FROM (\w+)/i)[1]
170
176
  table_name = raw_table_name.singularize
171
177
  entity_name = entity_name_from_table(table_name)
172
178
  entity_def = get_entity_def(entity_name)
173
179
 
174
180
  column_names = api_column_names(table_name)
175
181
 
176
- soql = sql.sub(/SELECT \* FROM /, "SELECT #{column_names.join(', ')} FROM ")
182
+ soql = sql.sub(/SELECT \* FROM/i, "SELECT #{column_names.join(', ')} FROM")
177
183
 
178
- soql.sub!(/ FROM \w+ /, " FROM #{entity_def.api_name} ")
184
+ soql.sub!(/ FROM \w+/i, " FROM #{entity_def.api_name}")
179
185
 
180
186
  # Look for a LIMIT clause
181
- soql.sub!(/LIMIT 1/, "")
187
+ soql.sub!(/LIMIT 1/i, "")
182
188
 
183
189
  # Look for an OFFSET clause
184
- soql.sub!(/\d+ OFFSET \d+/, "")
190
+ soql.sub!(/\d+ OFFSET \d+/i, "")
185
191
 
186
192
  # Fixup column references to use api names
187
193
  columns = columns_map(table_name)
@@ -191,7 +197,7 @@ module ActiveRecord
191
197
  end
192
198
 
193
199
  # Update table name references
194
- soql.sub!(/#{raw_table_name}\./, "#{entity_def.api_name}.")
200
+ soql.sub!(/#{raw_table_name}\./i, "#{entity_def.api_name}.")
195
201
 
196
202
  # Remove column value prefix
197
203
  soql.gsub!(/@V_/, "")
@@ -215,9 +221,6 @@ module ActiveRecord
215
221
  record.each do |name, value|
216
222
  name = column_nameize(name.to_s)
217
223
  if name != "type"
218
- # Replace nil element with nil
219
- value = nil if value.respond_to?(:xmlattr_nil) and value.xmlattr_nil
220
-
221
224
  # Ids are returned in an array with 2 duplicate entries...
222
225
  value = value[0] if name == "id"
223
226
 
@@ -228,28 +231,22 @@ module ActiveRecord
228
231
  result << row
229
232
  end
230
233
 
231
- result
234
+ if matchCount
235
+ [{ :count => result.actual_size }]
236
+ else
237
+ result
238
+ end
232
239
  end
233
240
 
234
241
 
235
242
  def select_one(sql, name = nil) #:nodoc:
236
243
  self.batch_size = 1
237
244
 
238
- # Check for SELECT COUNT(*) FROM query
239
- matchCount = sql.match(/SELECT COUNT\(\*\) FROM /)
240
- if matchCount
241
- sql = "SELECT id FROM #{matchCount.post_match}"
242
- end
243
-
244
245
  log(sql, name)
245
246
 
246
247
  result = select_all(sql, name)
247
248
 
248
- if matchCount
249
- { :count => result.actual_size }
250
- else
251
- result.nil? ? nil : result.first
252
- end
249
+ result.nil? ? nil : result.first
253
250
  end
254
251
 
255
252
 
@@ -257,7 +254,7 @@ module ActiveRecord
257
254
  log(sql, name)
258
255
 
259
256
  # Convert sql to sobject
260
- table_name = sql.match(/INSERT INTO (\w+) /)[1].singularize
257
+ table_name = sql.match(/INSERT INTO (\w+) /i)[1].singularize
261
258
  entity_name = entity_name_from_table(table_name)
262
259
  columns = columns_map(table_name)
263
260
 
@@ -285,7 +282,7 @@ module ActiveRecord
285
282
  log(sql, name)
286
283
 
287
284
  # Convert sql to sobject
288
- table_name = sql.match(/UPDATE (\w+) /)[1].singularize
285
+ table_name = sql.match(/UPDATE (\w+) /i)[1].singularize
289
286
  entity_name = entity_name_from_table(table_name)
290
287
  columns = columns_map(table_name)
291
288
 
@@ -299,7 +296,7 @@ module ActiveRecord
299
296
  fields[column.api_name] = value if not column.readonly and value != "NULL"
300
297
  end
301
298
 
302
- id = sql.match(/WHERE id = @V_'(\w+)'/)[1]
299
+ id = sql.match(/WHERE id = @V_'(\w+)'/i)[1]
303
300
 
304
301
  sobject = create_sobject(entity_name, id, fields)
305
302
 
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.1.8
7
- date: 2006-02-04 00:00:00 -05:00
6
+ version: 0.1.9
7
+ date: 2006-02-05 00:00:00 -05:00
8
8
  summary: ActiveSalesforce is an extension to the Rails Framework that allows for the dynamic creation and management of ActiveRecord objects through the use of Salesforce meta-data and uses a Salesforce.com organization as the backing store.
9
9
  require_paths:
10
10
  - lib