rails+drizzle demo创建

①activerecord gem包的修改:

经过测试可知在drizzle数据库中不支持如下两个SQL语句:

(SET NAMES='utf8';)和(SET SQL_AUTO_IS_NULL=0;)

因此为了成功的将rails和drizzle数据库连接起来,需要将activerecord gem包中的代码作如下的修正:

修改文件:

C:/Ruby187/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/mysql_adapter.rb

修改前:

    def configure_connection

       encoding = @config[:encoding]

       execute("SET NAMES '#{encoding}'") if encoding

 

       # By default, MySQL 'where id is null' selects the last inserted id.

       # Turn this off. http://dev.rubyonrails.org/ticket/6778

       execute("SET SQL_AUTO_IS_NULL=0")

    end

修改后(修改部分为红色被注释部分):

    def configure_connection

       encoding = @config[:encoding]

       #execute("SET NAMES '#{encoding}'") if encoding     

 

       # By default, MySQL 'where id is null' selects the last inserted id.

       # Turn this off. http://dev.rubyonrails.org/ticket/6778

       #execute("SET SQL_AUTO_IS_NULL=0")

    end

 

②rails+drizzle demo创建手顺

 

a)数据库配置为(database.yml):

development:

  adapter: mysql

  database: drizzledemo_development

  encoding: utf8

  username: root

  password: 123

  host: 133.25.78.144

  port: 8606

b)rails工程创建手顺

在D:\QP\workspace\下创建drizzledemo工程目录

cd D:\QP\workspace\

D:\QP\workspace>rails drizzledemo

D:\QP\workspace>cd drizzledemo

D:\QP\workspace\drizzledemo>ruby script/generate scaffold product title:string description:text image_url:string

D:\QP\workspace\drizzledemo>rake db:migrate --trace

启动drizzledemo服务器(本次端口配置为3009),然后输入URL(http://localhost:3009/products/)即可访问并且增删改查数据了。



你可能感兴趣的:(sql,mysql,Ruby,Rails,ActiveRecord)