Как правильно перейти с помощью продолжения на Access 2007 - PullRequest
1 голос
/ 25 мая 2011

При переносе приложения в Access 2007 с помощью библиотеки сиквелов Ruby.Я получаю ошибки следующим образом.Кто-нибудь знает, как правильно мигрировать?Спасибо.

C:\ContractManagement>rackup
C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/adapters/ado.rb:63:
in `method_missing': WIN32OLERuntimeError: (in OLE method `Execute': ) (Sequel::
DatabaseError)
   OLE error code:80040E14 in Microsoft Office Access Database Engine
     Syntax error (missing operator) in query expression 'LIMIT 1 1'.
   HRESULT error code:0x80020009
     Exception occurred.
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/adapte
rs/ado.rb:63:in `block (2 levels) in execute'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/databa
se/logging.rb:28:in `log_yield'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/adapte
rs/ado.rb:63:in `block in execute'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/connec
tion_pool/threaded.rb:84:in `hold'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/databa
se/connecting.rb:226:in `synchronize'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/adapte
rs/ado.rb:61:in `execute'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/datase
t/actions.rb:541:in `execute'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/adapte
rs/ado.rb:97:in `fetch_rows'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/datase
t/actions.rb:123:in `each'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/datase
t/actions.rb:449:in `single_record'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/datase
t/actions.rb:457:in `single_value'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/datase
t/actions.rb:200:in `get'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/datase
t/actions.rb:133:in `empty?'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/extens
ions/migration.rb:499:in `schema_dataset'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/extens
ions/migration.rb:381:in `initialize'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/extens
ions/migration.rb:422:in `initialize'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/extens
ions/migration.rb:332:in `new'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/extens
ions/migration.rb:332:in `run'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sequel-3.23.0/lib/sequel/extens
ions/migration.rb:316:in `apply'
       from C:/ContractManagement/config.ru:12:in `block in <main>'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/lib/rack/builder.rb:
51:in `instance_eval'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/lib/rack/builder.rb:
51:in `initialize'
       from C:/ContractManagement/config.ru:1:in `new'
       from C:/ContractManagement/config.ru:1:in `<main>'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/lib/rack/builder.rb:
40:in `eval'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/lib/rack/builder.rb:
40:in `parse_file'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/lib/rack/server.rb:2
00:in `app'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/lib/rack/server.rb:3
01:in `wrapped_app'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/lib/rack/server.rb:2
52:in `start'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/lib/rack/server.rb:1
37:in `start'
       from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.3.0/bin/rackup:4:in `<to
p (required)>'
       from C:/Ruby192/bin/rackup:19:in `load'
       from C:/Ruby192/bin/rackup:19:in `<main>'

Вот конфигурация соединения.DB = Sequel.ado (: conn_string => 'Provider = Microsoft.ACE.OLEDB.12.0; Источник данных = C: \ ContractManagement1.accdb')

А вот и шаги миграции.Все они передаются на PostgreSQL 8.4.

Sequel.migration do
  up do
    create_table :people do
      primary_key :id
      String :name, :size => 20, :unique => true, :null => false
      String :password, :size => 30, :null => false
      String :role, :size => 20, :null => false
    end
  end

  down do
    drop_table :people
  end
end

Sequel.migration do
  up do
    create_table :currencies do
      primary_key :id
      String :name, :size => 10, :null => false
    end
  end

  down do
    drop_table :currencies
  end
end

Sequel.migration do
  up do
    create_table :statuses do
      primary_key :id
      String :name, :size => 10, :null => false
    end
  end

  down do
    drop_table :statuses
  end
end

# encoding: utf-8

Sequel.migration do
  up do
    create_table :contracts do
      primary_key :id
      String :contract_id, :size => 36, :unique => true, :null => false
      String :content, :size => 150
      String :supplier, :size => 30
      Date :created_on
      Date :expired_on
      BigDecimal :amount, :size => [10, 2], :null => false
      Fixnum :debt_days
      Fixnum :guarantee_period
      String :order_id, :size => 50 # 订单号
      String :supplier_contract_id, :size => 36
      String :operator, :size => 30
      foreign_key :currency_id, :currencies, :on_delete => :cascade, :on_update => :cascade, :null => false
      foreign_key :status_id, :statuses, :on_delete => :cascade, :on_update => :cascade, :null => false
      constraint(:min_amount) { amount >= 0.01 }
    end
  end

  down do
    drop_table :contracts
  end
end

# encoding: utf-8

Sequel.migration do
  up do
    self[:currencies].insert(:name => "人民币")
    self[:currencies].insert(:name => "欧元")
    self[:currencies].insert(:name => "美元")
  end

  down do
    self[:currencies].delete
  end
end

# encoding: utf-8

Sequel.migration do
  up do
    self[:statuses].insert(:name => "执行中")
    self[:statuses].insert(:name => "关闭")
    self[:statuses].insert(:name => "作废")
  end

  down do
    self[:statuses].delete
  end
end

# encoding: utf-8

Sequel.migration do
  up do
    create_table :payments do
      primary_key :id
      BigDecimal :prepayment, :size => [10, 2], :default => 0 # 预付金额(元)
      BigDecimal :offset_prepayment, :size => [10, 2], :default => 0 # 冲预付
      BigDecimal :guarantee_price, :size => [10, 2], :default => 0 # 质保金
      BigDecimal :request_amount, :size => [10, 2], :default => 0 # 申请付款额
      foreign_key :contract_id, :contracts, :on_delete => :cascade, :on_update => :cascade
      foreign_key :person_id, :people, :on_delete => :cascade, :on_update => :cascade
      constraint(:offset_prepayment_is_not_greater_than_prepayment) { prepayment >= offset_prepayment } # offset_prepayment不能大于prepayment
    end
  end

  down do
    drop_table :payments
  end
end

Sequel.migration do
  up do
    {"admin" => "Admin", "contract" => "ContractOperator", "payment" => "PaymentOperator", "report" => "ReportReviewer"}.each do |n, r|
      self[:people].insert(:name => n, :password => n, :role => r)
    end
    self[:people].insert(:name => "payment1", :password => "payment1", :role => "PaymentOperator")
  end

  down do
    self[:people].delete
  end
end

Ответы [ 2 ]

1 голос
/ 26 мая 2011

Это исправлено в основной ветке Sequel, в версии 3.24.0 (которая выйдет на следующей неделе) будет исправлено.

1 голос
/ 25 мая 2011

Я думаю, вы получите это сообщение об ошибке ...

OLE error code:80040E14 in Microsoft Office Access Database Engine
     Syntax error (missing operator) in query expression 'LIMIT 1 1'.

... потому что Access SQL не поддерживает LIMIT. См. этот ответ на связанный вопрос переполнения стека.

Проверьте, можете ли вы использовать Access SQL TOP N вместо LIMIT N.

SELECT TOP 1 m.id, m.paid_in_full, m.date_field
FROM MyTable AS m
ORDER BY m.date_field DESC;
...