6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQLをSqliteに変換する。

Posted at
mysql2sqlite.rb
#!/usr/bin/env ruby
require 'rubygems'


if ARGV.size < 1 or not ARGV.all?{|e|  File.exist? e} then
   puts "usage: #{__FILE__} mysql_create_table.sql
          MySQL の show create table などで出力したファイルを引数に指定する"
           exit 2
end

open(ARGV[0],"r"){|f|
  f.each_line{|line|
    line = line.gsub /engine[^\s]+/, ""
    line = line.gsub /character\s+set\s+'utf8'/, ""
    line = line.gsub /drop\s+table\s+if\s+.+$/, ""
    line = line.gsub /use.+$/, ""
    line = line.gsub /lock.+$/, ""
    line = line.gsub /unlock.+$/, ""
    line = line.gsub /key\s+.+$/, ""
    line = line.gsub /auto_increment\s/, ""
    line = line.gsub /bigint\s/, "int "
    line = line.gsub /unsigned\s/, ""
    line = line.gsub /tinyint\s/, "boolean "       #tinyint は booleanへ
    line = line.gsub /default\s+.+,/, ","          #tinyint にdefault 1 が設定されてるとまずいので消す
    line = line.gsub /#.*$/, ""                   # コメントは消す
    puts line

  }


}

Mysqlのcreate tableをsqliteのcreate tableにざっくり変換する。

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?