I need to gain access to field that is in an AS400 file. There is an existing connection to the 400 and now I just need to use a different file than the one that is being used.
我需要访问AS400文件中的字段。现有与400的连接,现在我只需要使用与正在使用的文件不同的文件。
class Distributor < ActiveRecord::Base
establish_connection "as400_#{RAILS_ENV}"
set_table_name "DISTJ01"
# TODO: what to return if no distributor?
# Create array of hashed distributor info.
def self.get_distributors_by_state state, preferred_distributor
d = []
# see validate_distributor_number below
# If they have a preferred distributor, pull that one and make it first so it will default to that.
if !preferred_distributor.blank?
s = Distributor.find_by_sql ["SELECT CNAM05 cnam05, CUSNP1 cusnp1 FROM DISTJ01 WHERE CUSNP1 = ?", preferred_distributor]
d << { :name => s[0].cnam05, :id => s[0].cusnp1 } unless s.blank?
end
# If they have an account number, they can choose to purchase direct in addition to choosing a distributor.
# Per Ron 4/20/11, removed this.
#d << { :name => "DIRECT PURCHASE", :id => account_number } unless account_number.blank?
# Get all other available distributors for this state.
s = Distributor.find_by_sql ["SELECT CNAM05 cnam05, CUSNP1 cusnp1 FROM DISTJ01 WHERE STATEP2 = ? AND CUSNP1 <> ? ORDER BY CNAM05", state.upcase, preferred_distributor]
unless s.blank?
s.each do |t|
d << { :name => t.cnam05, :id => t.cusnp1 }
end
end
d
end
def self.validate_distributor_number distributor_number, user
# We need to make sure that the distributor number we are assigning
# is valid. Since it comes from a form post, somebody could pick
# another number if they wanted. We can't have that. Granted they
# already had to logon so they are a legit user, but, they still
# could try to trick us.
if distributor_number.strip == user.as400_fields[:account_number].strip
distributor_number
else
# If a DSD account chooses to purchase from their preferred distributor, we use the customer number from
# the sign-on table, not from the distributor.
if user.as400_fields[:preferred_distributor] == distributor_number and user.as400_fields[:account_type].strip == "DSD"
user.as400_fields[:account_number]
else
d = Distributor.find_by_sql ["SELECT CUSNP1 cusnp1 FROM DISTJ01, SIGNONS " +
"WHERE DISTJ01.STATEP2 = SIGNONS.BSSTCDW1 AND SIGNONS.USERW1 = ? AND DISTJ01.CUSNP1 = ?", user.login.upcase, distributor_number]
d[0].cusnp1 unless d.blank?
end
end
end
end
I need to replace the "DISTJ01" with ""C@OEF23L03" and I need to access field EMAL23 but I still need the existing connection and query. I tried simply swapping out the existing file but I must be overcomplicating it because it does not work. any ideas?
我需要用“”C @ OEF23L03“替换”DISTJ01“,我需要访问字段EMAL23,但我仍然需要现有的连接和查询。我尝试简单地交换现有文件,但我必须过度复杂,因为它不工作。任何想法?
this is from the error log:
这是来自错误日志:
[Wed Apr 10 11:52:20 2013] [notice] Apache/2.2.14 (Ubuntu) Phusion_Passenger/3.0.1 configured -- resuming normal operations
[ pid=14922 thr=77098160 file=utils.rb:176 time=2013-04-10 11:52:58.610 ]: *** Exception SyntaxError in PhusionPassenger::ClassicRails::ApplicationSpawner (/var/www /onlineordering.coastalpet.com/app/models/distributor.rb:59: syntax error, unexpected keyword_end, expecting $end) (process 14922, thread #<Thread:0x930d960>):
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-2.3.10/lib/active_support/dependencies.rb:184:in `require'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-2.3.10/lib/active_support/dependencies.rb:291:in `require_or_load'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-2.3.10/lib/active_support/dependencies.rb:250:in `depend_on'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-2.3.10/lib/active_support/dependencies.rb:162:in `require_dependency'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rails-2.3.10/lib/initializer.rb:414:in `block (2 levels) in load_application_classes'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rails-2.3.10/lib/initializer.rb:413:in `each'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rails-2.3.10/lib/initializer.rb:413:in `block in load_application_classes'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rails-2.3.10/lib/initializer.rb:411:in `each'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rails-2.3.10/lib/initializer.rb:411:in `load_application_classes'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rails-2.3.10/lib/initializer.rb:197:in `process'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rails-2.3.10/lib/initializer.rb:113:in `run'
from /var/www/onlineordering.coastalpet.com/config/environment.rb:6:in `<top (required)>'
from <internal:lib/rubygems/custom_require>:29:in `require'
from <internal:lib/rubygems/custom_require>:29:in `require'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/classic_rails/application_spawner.rb:222:in `preload_application'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/classic_rails/application_spawner.rb:181:in `block in initialize_server'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/utils.rb:564:in `report_app_init_status'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/classic_rails/application_spawner.rb:174:in `initialize_server'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/abstract_server.rb:204:in `start_synchronously'
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/abstract_server.rb:180:in `start'
from /usr/local/ruby
1 个解决方案
#1
0
Isn't line 2 of your error log saying that there was a syntax error in line 59? I only see 53 lines in the source you included, but perhaps you took out a few. Looking at the syntax error message closer, it looks like it found the keyword end
when it was expecting something it labels $end, which I will take to mean it was expecting end-of-source. I'm not a Ruby programmer (or at least not hardly yet) but looking back at your source, there does seem to be an extra end
that doesn't seem to match up with anything. Or is that to end the class?
错误日志的第2行是不是说第59行有语法错误?我只在你包含的源代码中看到53行,但也许你拿了几行。仔细查看语法错误消息,看起来它找到了关键字end,当它期待它标记为$ end时,我会认为它意味着期待源代码结束。我不是一个Ruby程序员(或者至少还不是很难),但回顾你的来源,似乎确实有一个似乎与任何东西都不匹配的额外结局。或者是结束课程?
#1
0
Isn't line 2 of your error log saying that there was a syntax error in line 59? I only see 53 lines in the source you included, but perhaps you took out a few. Looking at the syntax error message closer, it looks like it found the keyword end
when it was expecting something it labels $end, which I will take to mean it was expecting end-of-source. I'm not a Ruby programmer (or at least not hardly yet) but looking back at your source, there does seem to be an extra end
that doesn't seem to match up with anything. Or is that to end the class?
错误日志的第2行是不是说第59行有语法错误?我只在你包含的源代码中看到53行,但也许你拿了几行。仔细查看语法错误消息,看起来它找到了关键字end,当它期待它标记为$ end时,我会认为它意味着期待源代码结束。我不是一个Ruby程序员(或者至少还不是很难),但回顾你的来源,似乎确实有一个似乎与任何东西都不匹配的额外结局。或者是结束课程?