Ruby Driver & ORM

2010-07-21
2013-06-05
  • Esen Sagynov
    Esen Sagynov
    2010-07-21

    Hello everyone,

    Let's develop a step-by-step plan that we'll follow to move Ruby Driver development forward.

    First thing first, I have already prepared a message to Ruby Community to assist us with Ruby Driver development. Do you think, they will help us?

    Second, if we find the contributors, should the development take place on sf.net SVN under the same /ruby directory?

    If you have any suggestions for further actions, post them here.

     
  • Esen Sagynov
    Esen Sagynov
    2010-07-22

    I receive the reply from two Ruby developers. The first one was telling that he could not find neither Ruby nor JDBC drivers on our website (a point to consider). I sent him the direct links to the files on sf.net. He replied he is downloading them and will try to use.

    Second guy seems very experienced in both database and Ruby development. See his answer here. He asked many detailed question about the difference between other databases, particularly MySQL, and CUBRID. Also, he is wondering on why we have this kind of database design, related to Data Types. So, I will answer him today.

     
  • Esen Sagynov
    Esen Sagynov
    2010-07-22

    There is one more thing which requires our attention. Here is what that guy also said: "One good place to start would be making the ActiveRecord adapter and the Ruby driver available on Gemcutter. I was eventually able to locate the adapter via Google, but the page is tricky to spot since it's 90+% in Korean…"

    So, we have to dig a bit around that Gemcutter.

     
  • I don't think there is something we need to study about Gemcutter. Matt was right: Gemcutter is the main and the most popular package repository for Ruby and it is a MUST to have ActiveRecord adapter and Ruby driver available there if we want Ruby developers to use CUBRID. I think that the Ruby driver\adapter available on source forge are ready to be uploaded on Gemcutter.

    I think first step we should make next is to have a good perspective about the already developed ActiveRecord adapter and Ruby driver (this was planned by the end of this week, but the guys from CUBRID dev are pretty busy this week). The second step would be to make the packages available on Gemcutter (and also on cubrid.org) and after these 2 steps, we should continue posting on the ruby on rails talk group.

    We will let you know when the analyze of the current ActiveRecord adapter the Ruby driver will be finished and also the conclusions.

     
  • Esen Sagynov
    Esen Sagynov
    2010-07-23

    I have already created an account for CUBRID. The Handle (username) is "cubrid". So, in case you need, let me know. I will send the password. Yesterday I tested with cubrid-0.6.gem. However, there was an error, so I could not submit to Gemcutter. I will look again today.

     
  • Esen Sagynov
    Esen Sagynov
    2010-10-12

    As we have already seen, Ruby Driver is online at http://www.cubrid.org/cubrid_ruby_programming. Previously I have tested it on CUBRID 2.2 x86 with Ruby 1.8.7.

    Today I have tested with the new CUBRID 3.0, works fine.

    Right now I will test on x64 machines for both 2.2 and 3.0.

    I also have tested the ActiveRecord Adapter that Catalin sent me last time. It didn't work. In fact, it was installed correctly. I could connect. I could do some very, very basic operations. However, when I tried to create table, insert data, and retrieve those new data, the adapter gives an error. I was using the general AR (ActiveRecord) syntax. I think I will need to wait Catalin's Manual on ActiveRecords, and see why my requests are not processed.

     
  • Esen Sagynov
    Esen Sagynov
    2010-10-14

    Dear Essen,

    Today we had a difficult time installing CUBRID gem for Ruby in order to write the Active Record tutorial.
    I'll try to keep short…

    On the Ruby support page (http://www.cubrid.org/cubrid_ruby_programming) there are listed the following libraries:


    0.64 - cubrid-0.64.gem:
    - Cross-platform: compatible with all platforms.
    - Compatible with CUBRID 2.2 x86 and CUBRID 3.0 x86 on Ruby 1.8.7.
    - Available through "gem install cubrid".

    This package does not work out of the box neither on Windows nor Ubuntu Linux 64-bit (that's what I use)

    a) On Windows, gem installer wants to compile the cubrid module so the user must have gcc/MingW installed. Otherwise the module installation fails with errors.

    b) On Linux the things are more gruesome because there are some issues with default ruby distro on Ubuntu 10.04 LTS x86_64.
    i18n package required in the process needs gem >= 1.3.7 and this is not available right now in Ubuntu repo (it will be in 10.10).
    I've installed by hand, but furthermore the package won't compile because an obsolete setting in gem build file requiring $CUBRID/lib64 folder that is no longer available. It worked with a symlink to lib/ directory.

    But, whenever I try to connect from Ruby it gives the following error:
    /usr/lib/ruby/gems/1.8/gems/activerecord-cubrid-adapter-0.6/lib/active_record/connection_adapters/cubrid_adapter.rb:341:in `cubrid_connection': CUBRID Libraries could not be loaded. (LoadError)
        from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `send'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `new_connection'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:238:in `checkout_new_connection'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:194:in `checkout'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in `loop'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in `checkout'
        from /usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:189:in `checkout'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in `connection'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:318:in `retrieve_connection'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:97:in `retrieve_connection'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:679:in `columns'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/persistence.rb:285:in `attributes_from_column_definition'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/locking/optimistic.rb:62:in `attributes_from_column_definition'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:1396:in `initialize'
        from test.rb:14:in `new'
        from test.rb:14


    0.61 - cubrid-0.61-x86-mingw32.gem:
    - Built under Windows 7 32 bit.
    - Compatible with Windows platforms.
    - Compatible with CUBRID 2.2 x86 on Ruby 1.8.7.
    - Available through "gem install cubrid -version 0.61".

    This one successfully installs on Windows, but unfortunately it's broken (when connecting to Cubrid 3.0 final). Whenever I try to connect to database application dies with error:

    select 1 from db_root
    select * from db_attribute where class_name = 'countries'
    C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:202:in `log': StandardError:
    ERROR: CCI, -8, Type conversion error: select * from db_attribute where class_name = 'countries' (ActiveRecord::StatementInvalid)
            from C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-cubrid-adapter-0.6/lib/active_record/connection_adapters/cubrid_adapter.rb:321:i
    n `select'
            from C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-cubrid-adapter-0.6/lib/active_record/connection_adapters/cubrid_adapter.rb:183:i
    n `columns'
            from C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:679:in `columns'
            from C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/persistence.rb:285:in `attributes_from_column_definition
    '
            from C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/locking/optimistic.rb:62:in `attributes_from_column_defi
    nition'
            from C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:1396:in `initialize'
            from C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:496:in `new'
            from C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-3.0.0/lib/active_record/base.rb:496:in `create'
            from tutorial.rb:20


    So, what I did to work was to ask another colleague to compile the module 0.64 for Windows with gcc/MingW,  install the 0.61 and override the cubrid.so module from "C:\Ruby187\lib\ruby\gems\1.8\gems\cubrid-0.61-x86-mingw32\lib" with that built from cubrid-0.64 source code.

    My question is … is it possible to provide a binary compiled for Windows in 0.64? This would eliminate the need to put MingW on Windows.
    Also, in Linux it doesn't work at all. I could test on another distro like FC13 if really needed as for Debian-based systems there are some problems with Ruby (dependencies) anyway. See http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=ubuntu+gem+1.3.7#sclient=psy&num=10&hl=en&newwindow=1&safe=off&q=ubuntu+10.04+gem+1.3.7&aq=f&aqi=&aql=&oq=&gs_rfai=&pbx=1&fp=9f2370386c77b788

    That wasn't so short after all … :D

    Regards,
    Cristian

     
  • Esen Sagynov
    Esen Sagynov
    2010-10-14

    Dear Cristian,

    I expected such a feedback starting from yesterday when I tested CUBRID gem with CUBRID 3.0. Here is the thing, I suppose RubyGems have altered the algorithm they use to determine which version of the gem should be downloaded and installed. They have simplified it.

    a) As you know, when you type "gem install cubrid" it requests the latest version. However, couple months ago when I pushed this gem to RubyGems the algorithm was different. To avoid this exact inconvenience for Windows users, I pushed the Windows version "cubrid-0.61-x86-mingw32.gem". Their old algorithm used to check what operating system is requesting this gem. If it is Win32, it would return the latest win32 compatible gem, if it exists. That's why before it used to work. Yesterday, I also had problems installing the cubrid gem out of the box. I needed to install the DevKit-3.4.5-20100819-1535-sfx.exe from http://rubyinstaller.org/downloads/.

    cubrid-0.64.gem requires the DevKit on Windows and ruby1.8-dev on Linux.

    b) To use cubrid gem, you should not install the default ruby as the latest one is 1.9.1, which is not supported by cubrid gem. See this tutorial for Linux http://wiki.cubrid.org/index.php/Ruby_Programming_with_CUBRID#On_Linux. You can notice that I have explicitly installed ruby 1.8. I didn't have problems with the gem. The default one will be 1.3.7. If 1.3.5, you can upgrade it by typing "gem update -system".

    c) $CUBRID/lib64 path is obsolete. That's why I have prepared the cubrid-0.65.gem for the release. However, I have bigger problems. The thing is, Ruby is 32 bit and cannot work with 64 bit libraries. On your x64 machine you, logically, install CUBRID x64, which as I understood will not work with Ruby at all. Check this Ruby forum thread I posted yesterday http://www.ruby-forum.com/topic/225138?reply_to=949882. I wonder HOW DID YOU COMPILE CUBRID GEM WITH CUBRID X64? Please tell me your solution.

    d) Like I told, Ruby changed its behavior since I used it last time. Now you cannot load any gem like "require 'cubrid'" without calling "require 'rubygems'" before it. So, try this. It should work fine.

    e) cubrid-0.61-x86-mingw32.gem on Windows 32 bit and CUBRID 3.0 stable works fine. Make sure your CUBRID Service and the database have been started. And don't forget to "require 'rubygems'" at the very beginning. Let me know if you still have problems.

    f) Maybe you already know this. You can install the local version of the gem. For example, you have your own cubrid-0.64.gem compiled by your colleague. Assuming you are in the same directory, type "gem install cubrid -version 0.64 -local. This will make sure you install this cubrid-0.64.gem even if you have other versions of the gem in the same directory.

    g) As with cubrid-0.61-x86-mingw32.gem it is possible to provide the compiled version of the gem for Windows users. I can do that.

    I understand that this step is very important for us. Therefore, please let me know if you have ANY difficulties with cubrid gem. If you have problems, I am more than sure other users have bigger problems.

    P.S. I need to know if you have succeeded with installing cubrid gem on x64 machines with CUBRID x64 installed.

     
  • The environment:

    * Ubuntu 10.04 LTS
    * Linux cristi 2.6.32-25-generic #44-Ubuntu SMP Fri Sep 17 20:05:27 UTC 2010 x86_64 GNU/Linux
    * ruby 1.8.7 (2010-01-10 patchlevel 249)
    * CUBRID 3.0 release

    Please note that I have installed Ruby 1.8:
    #>apt-get install ruby-full
    #>apt-get install ruby1.8-dev
    # gem -v
    1.3.7
    Gem was updated from 1.3.5. to 1.3.7 manually following this post: http://help.rubygems.org/discussions/problems/350-installing-rubygems-137-and-jekyll-on-ubuntu-1004

    #> gem list
    *** LOCAL GEMS ***
    activemodel (3.0.0)
    activerecord (3.0.0)
    activerecord-cubrid-adapter (0.6)
    activesupport (3.0.0)
    arel (1.0.1)
    builder (2.1.2)
    cubrid (0.64)
    i18n (0.4.1)
    tzinfo (0.3.23)

    A. Trying to install cubrid-0.64 gem gives the following error:

    root@cristi:/var/lib/gems/1.8/gems# gem install cubrid
    Building native extensions.  This could take a while…
    ERROR:  Error installing cubrid:
    ERROR: Failed to build gem native extension.

    /usr/bin/ruby1.8 extconf.rb
    checking for cci_init() in -lcascci… no
    *** extconf.rb failed ***
    Could not create Makefile due to some reason, probably lack of
    necessary libraries and/or headers.  Check the mkmf.log file for more
    details.  You may need configuration options.

    Provided configuration options:
    -with-opt-dir
    -without-opt-dir
    -with-opt-include
    -without-opt-include=${opt-dir}/include
    -with-opt-lib
    -without-opt-lib=${opt-dir}/lib
    -with-make-prog
    -without-make-prog
    -srcdir=.
    -curdir
    -ruby=/usr/bin/ruby1.8
    -with-casccilib
    -without-casccilib
    cascci could not be found. Possibly you have not installed CUBRID Database yet.

    Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/cubrid-0.64 for inspection.
    Results logged to /usr/lib/ruby/gems/1.8/gems/cubrid-0.64/ext/gem_make.out
    root@cristi:/var/lib/gems/1.8/gems#

    In order to fix this:

    1. Went to home directory and executed
    #>. .cubrid.sh
    2. I went to $CUBRID/ and done a symbolic link
    #>ln -s lib lib64
    3. Ran again
    #>gem install cubrid

    Running again yields:

    #> gem install cubrid
    Building native extensions.  This could take a while…
    Successfully installed cubrid-0.64
    1 gem installed
    Installing ri documentation for cubrid-0.64…

    No definition for cubrid_oid_method_missing
    Installing RDoc documentation for cubrid-0.64…

    No definition for cubrid_oid_method_missing

    The library was installed in /usr/lib/ruby/gems/1.8/gems/cubrid-0.64
    It seems after a cleanup/reinstall that the whole thing is actually working on Linux!!!!!!
    It seem that I had some leftovers in /var/lib/gems, after a clean and recompilation (gem install cubrid) it worked.

    Test script:

    require 'rubygems' 
    require 'active_record'
    require 'pp'

    ActiveRecord::Base.establish_connection( 
    :adapter => "cubrid", 
    :host => "localhost", 
    :database => "demodb" ,
    :user => "dba"
    )

    ActiveRecord::Schema.define do
    create_table :books do |table|
    table.column :title, :string, :null => false
    table.column :price, :float, :null => false
    table.column :author_id, :integer, :null => false
    end
    end

    class Book < ActiveRecord::Base
    end

    Book.create(:title => 'Test', :price => 22, :author_id => 1 )

    root@cristi:~# ruby test.rb
    - create_table(:books)
    select 1 from db_root
    CREATE TABLE books (id int primary key, title varchar(256) NOT NULL, price float NOT NULL, author_id int NOT NULL)
    alter table books DROP PRIMARY KEY
    alter table books DROP COLUMN id
    ALTER TABLE books ADD COLUMN id INT PRIMARY KEY NOT NULL AUTO_INCREMENT UNIQUE
       -> 0.3658s
       -> 0 rows
    select * from db_attribute where class_name = 'books'
    select a.name as name from "_db_index_key","db_serial" as a where index_of.is_primary_key = 1 and a.class_name = index_of.class_of.class_name and a.class_name='books'
    select books_ai_id.next_value id from db_root
    select class_name from db_class where is_system_class = 'NO'
    select * from db_attribute where class_name = 'books'
    select a.name as name from "_db_index_key","db_serial" as a where index_of.is_primary_key = 1 and a.class_name = index_of.class_of.class_name and a.class_name='books'
    INSERT INTO books (author_id, id, price, title) VALUES (1, 1, 22.0, 'Test')