mysql-2.9.1/0000755000004100000410000000000012414313001012705 5ustar www-datawww-datamysql-2.9.1/Rakefile0000644000004100000410000000060612414313001014354 0ustar www-datawww-data#-- # Copyright (c) 2008 Luis Lavena # # This source code is released under the MIT License. # See LICENSE file for details #++ # # NOTE: Keep this file clean. # Add your customizations inside tasks directory. # Thank You. # begin require 'rake' rescue LoadError require 'rubygems' require 'rake' end # load rakefile extensions (tasks) Dir['tasks/*.rake'].sort.each { |f| load f } mysql-2.9.1/.gemtest0000644000004100000410000000000012414313001014344 0ustar www-datawww-datamysql-2.9.1/Manifest.txt0000644000004100000410000000042412414313001015214 0ustar www-datawww-dataCOPYING COPYING.ja History.txt Manifest.txt README.txt Rakefile ext/mysql_api/extconf.rb ext/mysql_api/mysql.c extra/README.html extra/README_ja.html extra/tommy.css lib/mysql.rb lib/mysql/version.rb tasks/gem.rake tasks/native.rake tasks/vendor_mysql.rake test/test_mysql.rb mysql-2.9.1/README.txt0000644000004100000410000000161012414313001014401 0ustar www-datawww-data= MySQL/Ruby Interface * http://github.com/luislavena/mysql-gem == DESCRIPTION This is the MySQL API module for Ruby. It provides the same functions for Ruby programs that the MySQL C API provides for C programs. This package is offered as gem for easy installation using RubyGems. It wraps unmodified tmtm's mysql-ruby extension into a proper gem. Please note that tmtm (Tomita Mashahiro) has deprecated development of this extension and only update it for bug fixes. === Warning about incompatible MySQL versions under Windows Mixing MySQL versions will generate segmentation faults. Running the binary version of this gem against a different version of MySQL shared library libMySQL.dll will generate segmentation faults and terminate your application. Please use the exact same MAJOR.MINOR version of MySQL, see History.txt for specific version of MySQL used to build the binaries. mysql-2.9.1/History.txt0000644000004100000410000000205712414313001015113 0ustar www-datawww-data=== 2.9.1 / 2013-02-16 / Vacation time! * Bugfixes: * Use C89 comment style in source code. #13 [knu] * Use ULL2NUM to return `affected_rows`. #11, #12 [cbandy] === 2.9.0 / 2012-11-17 DEPRECATION: Ruby 1.8.6 is no longer supported. Do not update your production application blindly without testing first any dependency change! * Incompatibility: * Requires Ruby 1.8.7 or newer. * Enhancements: * Detect MySQL version at load time and fail on mismatch [ghazel] * Use MySQL Connector/C for Windows binary bindings instead * Bug fixes: * Use RbConfig since Config is deprecated in Ruby 2.0 [tenderlove] === 2.8.2 / 2012-11-06 / *yanked* * Yanked: * Changes in requirements render this gem incompatible for some users. === 2.8.1 / 2009-08-21 * New features: * Early support for Ruby 1.9 * Enhancements: * Improved gem release process using Hoe as development dependency * Implemented support for cross compilation * Binary version built against MySQL 5.0.83 * Bug fixes: * Improved detection of mysql and it's configuration (mysql_config) mysql-2.9.1/lib/0000755000004100000410000000000012414313001013453 5ustar www-datawww-datamysql-2.9.1/lib/mysql.rb0000644000004100000410000000031512414313001015144 0ustar www-datawww-data# support multiple ruby version (fat binaries under windows) begin RUBY_VERSION =~ /(\d+.\d+)/ require "mysql/#{$1}/mysql_api" rescue LoadError require 'mysql/mysql_api' end require 'mysql/version' mysql-2.9.1/lib/mysql/0000755000004100000410000000000012414313001014620 5ustar www-datawww-datamysql-2.9.1/lib/mysql/version.rb0000644000004100000410000000020212414313001016624 0ustar www-datawww-data# define version string to be used internally for the Gem by Hoe. class Mysql module GemVersion VERSION = '2.9.1' end end mysql-2.9.1/metadata.yml0000644000004100000410000000560512414313001015216 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: mysql version: !ruby/object:Gem::Version hash: 41 prerelease: segments: - 2 - 9 - 1 version: 2.9.1 platform: ruby authors: - TOMITA Masahiro autorequire: bindir: bin cert_chain: [] date: 2013-02-16 00:00:00 Z dependencies: - !ruby/object:Gem::Dependency name: rdoc prerelease: false requirement: &id001 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version hash: 19 segments: - 3 - 10 version: "3.10" type: :development version_requirements: *id001 - !ruby/object:Gem::Dependency name: rake-compiler prerelease: false requirement: &id002 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version hash: 61 segments: - 0 - 8 - 1 version: 0.8.1 type: :development version_requirements: *id002 - !ruby/object:Gem::Dependency name: hoe prerelease: false requirement: &id003 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version hash: 13 segments: - 3 - 5 version: "3.5" type: :development version_requirements: *id003 description: |- This is the MySQL API module for Ruby. It provides the same functions for Ruby programs that the MySQL C API provides for C programs. This package is offered as gem for easy installation using RubyGems. It wraps unmodified tmtm's mysql-ruby extension into a proper gem. Please note that tmtm (Tomita Mashahiro) has deprecated development of this extension and only update it for bug fixes. email: - tommy@tmtm.org executables: [] extensions: - ext/mysql_api/extconf.rb extra_rdoc_files: - History.txt - Manifest.txt - README.txt files: - COPYING - COPYING.ja - History.txt - Manifest.txt - README.txt - Rakefile - ext/mysql_api/extconf.rb - ext/mysql_api/mysql.c - extra/README.html - extra/README_ja.html - extra/tommy.css - lib/mysql.rb - lib/mysql/version.rb - tasks/gem.rake - tasks/native.rake - tasks/vendor_mysql.rake - test/test_mysql.rb - .gemtest homepage: http://github.com/luislavena/mysql-gem licenses: [] post_install_message: rdoc_options: - --main - README.txt require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 57 segments: - 1 - 8 - 7 version: 1.8.7 required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" requirements: [] rubyforge_project: mysql-win rubygems_version: 1.8.24 signing_key: specification_version: 3 summary: This is the MySQL API module for Ruby test_files: - test/test_mysql.rb mysql-2.9.1/test/0000755000004100000410000000000012414313001013664 5ustar www-datawww-datamysql-2.9.1/test/test_mysql.rb0000644000004100000410000013266212414313001016427 0ustar www-datawww-data#!/usr/local/bin/ruby # $Id: test.rb 244 2009-02-01 08:43:39Z tommy $ require "test/unit" require 'ostruct' require 'mysql' CONFIG = OpenStruct.new CONFIG.host = ENV['MYSQL_HOST'] || 'localhost' CONFIG.port = ENV['MYSQL_PORT'] || '3306' CONFIG.user = ENV['MYSQL_USER'] || 'root' CONFIG.pass = ENV['MYSQL_PASS'] || '' CONFIG.sock = ENV['MYSQL_SOCK'] CONFIG.flag = ENV['MYSQL_FLAG'] CONFIG.database = ENV['MYSQL_DATABASE'] || 'test' class TC_Mysql < Test::Unit::TestCase def setup() @host = CONFIG.host @user = CONFIG.user @pass = CONFIG.pass @db = CONFIG.database @port = CONFIG.port.to_i @sock = CONFIG.sock @flag = CONFIG.flag.to_i end def teardown() end def test_version() assert_equal(20802, Mysql::VERSION) end def test_init() assert_nothing_raised{@m = Mysql.init} assert_nothing_raised{@m.close} end def test_real_connect() assert_nothing_raised{@m = Mysql.real_connect(@host, @user, @pass, @db, @port, @sock, @flag)} assert_nothing_raised{@m.close} end def test_connect() assert_nothing_raised{@m = Mysql.connect(@host, @user, @pass, @db, @port, @sock, @flag)} assert_nothing_raised{@m.close} end def test_new() assert_nothing_raised{@m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag)} assert_nothing_raised{@m.close} end def test_escape_string() assert_equal("abc\\'def\\\"ghi\\0jkl%mno", Mysql.escape_string("abc'def\"ghi\0jkl%mno")) end def test_quote() assert_equal("abc\\'def\\\"ghi\\0jkl%mno", Mysql.quote("abc'def\"ghi\0jkl%mno")) end def test_get_client_info() assert_match(/^\d.\d+.\d+[a-z]?(-.*)?$/, Mysql.get_client_info()) end def test_client_info() assert_match(/^\d.\d+.\d+[a-z]?(-.*)?$/, Mysql.client_info()) end def test_options() @m = Mysql.init assert_equal(@m, @m.options(Mysql::INIT_COMMAND, "SET AUTOCOMMIT=0")) assert_equal(@m, @m.options(Mysql::OPT_COMPRESS)) assert_equal(@m, @m.options(Mysql::OPT_CONNECT_TIMEOUT, 10)) assert_equal(@m, @m.options(Mysql::GUESS_CONNECTION)) if defined? Mysql::GUESS_CONNECTION assert_equal(@m, @m.options(Mysql::OPT_LOCAL_INFILE, true)) # assert_equal(@m, @m.options(Mysql::OPT_NAMED_PIPE)) # assert_equal(@m, @m.options(Mysql::OPT_PROTOCOL, 1)) assert_equal(@m, @m.options(Mysql::OPT_READ_TIMEOUT, 10)) if defined? Mysql::OPT_READ_TIMEOUT assert_equal(@m, @m.options(Mysql::OPT_USE_EMBEDDED_CONNECTION)) if defined? Mysql::OPT_USE_EMBEDDED_CONNECTION assert_equal(@m, @m.options(Mysql::OPT_USE_REMOTE_CONNECTION)) if defined? Mysql::OPT_USE_REMOTE_CONNECTION assert_equal(@m, @m.options(Mysql::OPT_WRITE_TIMEOUT, 10)) if defined? Mysql::OPT_WRITE_TIMEOUT # assert_equal(@m, @m.options(Mysql::READ_DEFAULT_FILE, "/tmp/hoge")) assert_equal(@m, @m.options(Mysql::READ_DEFAULT_GROUP, "test")) assert_equal(@m, @m.options(Mysql::SECURE_AUTH, true)) if defined? Mysql::SECURE_AUTH # assert_equal(@m, @m.options(Mysql::SET_CHARSET_DIR, "??")) assert_equal(@m, @m.options(Mysql::SET_CHARSET_NAME, "latin1")) assert_equal(@m, @m.options(Mysql::SET_CLIENT_IP, "127.0.0.1")) if defined? Mysql::SET_CLIENT_IP # assert_equal(@m, @m.options(Mysql::SHARED_MEMORY_BASE_NAME, "xxx")) assert_equal(@m, @m.connect(@host, @user, @pass, @db, @port, @sock, @flag)) @m.close end def test_real_connect2() @m = Mysql.init assert_equal(@m, @m.real_connect(@host, @user, @pass, @db, @port, @sock, @flag)) @m.close end def test_connect2() @m = Mysql.init assert_equal(@m, @m.connect(@host, @user, @pass, @db, @port, @sock, @flag)) @m.close end end class TC_Mysql2 < Test::Unit::TestCase def setup() @host = CONFIG.host @user = CONFIG.user @pass = CONFIG.pass @db = CONFIG.database @port = CONFIG.port.to_i @sock = CONFIG.sock @flag = CONFIG.flag.to_i @m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag) end def teardown() @m.close if @m end def test_affected_rows() @m.query("create temporary table t (id int)") @m.query("insert into t values (1)") assert_equal(1, @m.affected_rows) end def test_autocommit() if @m.methods.include? "autocommit" then assert_equal(@m, @m.autocommit(true)) assert_equal(@m, @m.autocommit(false)) end end # def test_ssl_set() # end def test_more_results_next_result() if @m.server_version >= 40100 then @m.query_with_result = false @m.set_server_option(Mysql::OPTION_MULTI_STATEMENTS_ON) if defined? Mysql::OPTION_MULTI_STATEMENTS_ON @m.query("select 1,2,3; select 4,5,6") res = @m.store_result assert_equal(["1","2","3"], res.fetch_row) assert_equal(nil, res.fetch_row) assert_equal(true, @m.more_results) assert_equal(true, @m.more_results?) assert_equal(true, @m.next_result) res = @m.store_result assert_equal(["4","5","6"], res.fetch_row) assert_equal(nil, res.fetch_row) assert_equal(false, @m.more_results) assert_equal(false, @m.more_results?) assert_equal(false, @m.next_result) end end if Mysql.client_version >= 40100 def test_query_with_block() if @m.server_version >= 40100 then @m.set_server_option(Mysql::OPTION_MULTI_STATEMENTS_ON) expect = [["1","2","3"], ["4","5","6"]] @m.query("select 1,2,3; select 4,5,6") {|res| assert_equal(1, res.num_rows) assert_equal(expect.shift, res.fetch_row) } assert(expect.empty?) expect = [["1","2","3"], ["4","5","6"]] assert_raises(Mysql::Error) { @m.query("select 1,2,3; hoge; select 4,5,6") {|res| assert_equal(1, res.num_rows) assert_equal(expect.shift, res.fetch_row) } } assert_equal(1, expect.size) expect = [["1","2","3"], ["4","5","6"]] assert_raises(Mysql::Error) { @m.query("select 1,2,3; select 4,5,6; hoge") {|res| assert_equal(1, res.num_rows) assert_equal(expect.shift, res.fetch_row) } } assert(expect.empty?) end end def test_query_with_block_single() @m.query("select 1,2,3") {|res| assert_equal(1, res.num_rows) assert_equal(["1","2","3"], res.fetch_row) } end def test_set_server_option() if @m.server_version >= 40101 then assert_equal(@m, @m.set_server_option(Mysql::OPTION_MULTI_STATEMENTS_ON)) assert_equal(@m, @m.set_server_option(Mysql::OPTION_MULTI_STATEMENTS_OFF)) end end if Mysql.client_version >= 40101 def test_sqlstate() if @m.server_version >= 40100 then if RUBY_PLATFORM !~ /mingw|mswin/ then assert_equal("00000", @m.sqlstate) else assert_equal("HY000", @m.sqlstate) end assert_raises(Mysql::Error){@m.query("hogehoge")} assert_equal("42000", @m.sqlstate) end end def test_query_with_result() assert_equal(true, @m.query_with_result) assert_equal(false, @m.query_with_result = false) assert_equal(false, @m.query_with_result) assert_equal(true, @m.query_with_result = true) assert_equal(true, @m.query_with_result) end def test_reconnect() assert_equal(false, @m.reconnect) assert_equal(true, @m.reconnect = true) assert_equal(true, @m.reconnect) assert_equal(false, @m.reconnect = false) assert_equal(false, @m.reconnect) end end class TC_MysqlRes < Test::Unit::TestCase def setup() @host = CONFIG.host @user = CONFIG.user @pass = CONFIG.pass @db = CONFIG.database @port = CONFIG.port.to_i @sock = CONFIG.sock @flag = CONFIG.flag.to_i @m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag) @m.query("create temporary table t (id int, str char(10), primary key (id))") @m.query("insert into t values (1, 'abc'), (2, 'defg'), (3, 'hi'), (4, null)") @res = @m.query("select * from t") end def teardown() @res.free @m.close end def test_num_fields() assert_equal(2, @res.num_fields) end def test_num_rows() assert_equal(4, @res.num_rows) end def test_fetch_row() assert_equal(["1","abc"], @res.fetch_row) assert_equal(["2","defg"], @res.fetch_row) assert_equal(["3","hi"], @res.fetch_row) assert_equal(["4",nil], @res.fetch_row) assert_equal(nil, @res.fetch_row) end def test_fetch_hash() assert_equal({"id"=>"1", "str"=>"abc"}, @res.fetch_hash) assert_equal({"id"=>"2", "str"=>"defg"}, @res.fetch_hash) assert_equal({"id"=>"3", "str"=>"hi"}, @res.fetch_hash) assert_equal({"id"=>"4", "str"=>nil}, @res.fetch_hash) assert_equal(nil, @res.fetch_hash) end def test_fetch_hash2() assert_equal({"t.id"=>"1", "t.str"=>"abc"}, @res.fetch_hash(true)) assert_equal({"t.id"=>"2", "t.str"=>"defg"}, @res.fetch_hash(true)) assert_equal({"t.id"=>"3", "t.str"=>"hi"}, @res.fetch_hash(true)) assert_equal({"t.id"=>"4", "t.str"=>nil}, @res.fetch_hash(true)) assert_equal(nil, @res.fetch_hash) end def test_each() ary = [["1","abc"], ["2","defg"], ["3","hi"], ["4",nil]] @res.each do |a| assert_equal(ary.shift, a) end end def test_each_hash() hash = [{"id"=>"1","str"=>"abc"}, {"id"=>"2","str"=>"defg"}, {"id"=>"3","str"=>"hi"}, {"id"=>"4","str"=>nil}] @res.each_hash do |h| assert_equal(hash.shift, h) end end def test_data_seek() assert_equal(["1","abc"], @res.fetch_row) assert_equal(["2","defg"], @res.fetch_row) assert_equal(["3","hi"], @res.fetch_row) @res.data_seek(1) assert_equal(["2","defg"], @res.fetch_row) end def test_row_seek() assert_equal(["1","abc"], @res.fetch_row) pos = @res.row_tell assert_equal(["2","defg"], @res.fetch_row) assert_equal(["3","hi"], @res.fetch_row) @res.row_seek(pos) assert_equal(["2","defg"], @res.fetch_row) end def test_field_seek() assert_equal(0, @res.field_tell) @res.fetch_field assert_equal(1, @res.field_tell) @res.fetch_field assert_equal(2, @res.field_tell) @res.field_seek(1) assert_equal(1, @res.field_tell) end def test_fetch_field() f = @res.fetch_field assert_equal("id", f.name) assert_equal("t", f.table) assert_equal(nil, f.def) assert_equal(Mysql::Field::TYPE_LONG, f.type) assert_equal(11, f.length) assert_equal(1, f.max_length) assert_equal(Mysql::Field::NUM_FLAG|Mysql::Field::PRI_KEY_FLAG|Mysql::Field::PART_KEY_FLAG|Mysql::Field::NOT_NULL_FLAG, f.flags) assert_equal(0, f.decimals) f = @res.fetch_field assert_equal("str", f.name) assert_equal("t", f.table) assert_equal(nil, f.def) assert_equal(Mysql::Field::TYPE_STRING, f.type) assert_equal(30, f.length) assert_equal(4, f.max_length) assert_equal(0, f.flags) assert_equal(0, f.decimals) f = @res.fetch_field assert_equal(nil, f) end def test_fetch_fields() a = @res.fetch_fields assert_equal(2, a.size) assert_equal("id", a[0].name) assert_equal("str", a[1].name) end def test_fetch_field_direct() f = @res.fetch_field_direct(0) assert_equal("id", f.name) f = @res.fetch_field_direct(1) assert_equal("str", f.name) assert_raises(Mysql::Error){@res.fetch_field_direct(-1)} assert_raises(Mysql::Error){@res.fetch_field_direct(2)} end def test_fetch_lengths() assert_equal(nil, @res.fetch_lengths()) @res.fetch_row assert_equal([1, 3], @res.fetch_lengths()) @res.fetch_row assert_equal([1, 4], @res.fetch_lengths()) @res.fetch_row assert_equal([1, 2], @res.fetch_lengths()) @res.fetch_row assert_equal([1, 0], @res.fetch_lengths()) @res.fetch_row assert_equal(nil, @res.fetch_lengths()) end def test_field_hash() f = @res.fetch_field h = { "name" => "id", "table" => "t", "def" => nil, "type" => Mysql::Field::TYPE_LONG, "length" => 11, "max_length" => 1, "flags" => Mysql::Field::NUM_FLAG|Mysql::Field::PRI_KEY_FLAG|Mysql::Field::PART_KEY_FLAG|Mysql::Field::NOT_NULL_FLAG, "decimals" => 0, } assert_equal(h, f.hash) f = @res.fetch_field h = { "name" => "str", "table" => "t", "def" => nil, "type" => Mysql::Field::TYPE_STRING, "length" => 30, "max_length" => 4, "flags" => 0, "decimals" => 0, } assert_equal(h, f.hash) end def test_field_inspect() f = @res.fetch_field assert_equal("#", f.inspect) f = @res.fetch_field assert_equal("#", f.inspect) end def test_is_num() f = @res.fetch_field assert_equal(true, f.is_num?) f = @res.fetch_field assert_equal(false, f.is_num?) end def test_is_not_null() f = @res.fetch_field assert_equal(true, f.is_not_null?) f = @res.fetch_field assert_equal(false, f.is_not_null?) end def test_is_pri_key() f = @res.fetch_field assert_equal(true, f.is_pri_key?) f = @res.fetch_field assert_equal(false, f.is_pri_key?) end end class TC_MysqlStmt < Test::Unit::TestCase def setup() @host = CONFIG.host @user = CONFIG.user @pass = CONFIG.pass @db = CONFIG.database @port = CONFIG.port.to_i @sock = CONFIG.sock @flag = CONFIG.flag.to_i @m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag) end def teardown() end def test_init() if @m.server_version >= 40100 then s = @m.stmt_init() assert_equal(Mysql::Stmt, s.class) s.close end end def test_prepare() if @m.server_version >= 40100 then s = @m.prepare("select 1") assert_equal(Mysql::Stmt, s.class) s.close end end end if Mysql.client_version >= 40100 class TC_MysqlStmt2 < Test::Unit::TestCase def setup() @host = CONFIG.host @user = CONFIG.user @pass = CONFIG.pass @db = CONFIG.database @port = CONFIG.port.to_i @sock = CONFIG.sock @flag = CONFIG.flag.to_i @m = Mysql.new(@host, @user, @pass, @db, @port, @sock, @flag) @s = @m.stmt_init() end def teardown() @s.close @m.close end def test_affected_rows() if @m.server_version >= 40100 then @m.query("create temporary table t (i int, c char(10))") @s.prepare("insert into t values (?,?)") @s.execute(1, "hoge") assert_equal(1, @s.affected_rows()) @s.execute(2, "hoge") @s.execute(3, "hoge") @s.prepare("update t set c=?") @s.execute("fuga") assert_equal(3, @s.affected_rows()) end end =begin def test_attr_get() assert_equal(false, @s.attr_get(Mysql::Stmt::ATTR_UPDATE_MAX_LENGTH)) assert_raises(Mysql::Error){@s.attr_get(999)} end def test_attr_set() @s.attr_set(Mysql::Stmt::ATTR_UPDATE_MAX_LENGTH, true) assert_equal(true, @s.attr_get(Mysql::Stmt::ATTR_UPDATE_MAX_LENGTH)) @s.attr_set(Mysql::Stmt::ATTR_UPDATE_MAX_LENGTH, false) assert_equal(false, @s.attr_get(Mysql::Stmt::ATTR_UPDATE_MAX_LENGTH)) assert_raises(Mysql::Error){@s.attr_set(999, true)} end def test_bind_param() @s.prepare("insert into t values (?,?)") @s.bind_param(123, "abc") @s.bind_param(Time.now, nil) assert_raises(Mysql::Error){@s.bind_param(1, 2, 3)} b = @s.bind_param(Bind.new(Mysql::TYPE_TINY, 99, false)) @s.bind_param(98.765, b) end =end def test_bind_result_nil() if @m.server_version >= 40100 then @m.query("create temporary table t (i int, c char(10), d double, t datetime)") @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") @s.prepare("select * from t") @s.bind_result(nil,nil,nil,nil) @s.execute a = @s.fetch assert_equal([123, "9abcdefg", 1.2345, Mysql::Time.new(2005,8,2,23,50,11)], a) end end def test_bind_result_numeric() if @m.server_version >= 40100 then @m.query("create temporary table t (i int, c char(10), d double, t datetime)") @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") @s.prepare("select * from t") @s.bind_result(Numeric, Numeric, Numeric, Numeric) @s.execute a = @s.fetch if Mysql.client_version < 50000 then assert_equal([123, 9, 1, 2005], a) else assert_equal([123, 9, 1, 20050802235011], a) end end end def test_bind_result_integer() if @m.server_version >= 40100 then @m.query("create temporary table t (i int, c char(10), d double, t datetime)") @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") @s.prepare("select * from t") @s.bind_result(Integer, Integer, Integer, Integer) @s.execute a = @s.fetch if Mysql.client_version < 50000 then assert_equal([123, 9, 1, 2005], a) else assert_equal([123, 9, 1, 20050802235011], a) end end end def test_bind_result_fixnum() if @m.server_version >= 40100 then @m.query("create temporary table t (i int, c char(10), d double, t datetime)") @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") @s.prepare("select * from t") @s.bind_result(Fixnum, Fixnum, Fixnum, Fixnum) @s.execute a = @s.fetch if Mysql.client_version < 50000 then assert_equal([123, 9, 1, 2005], a) else assert_equal([123, 9, 1, 20050802235011.0], a) end end end def test_bind_result_string() if @m.server_version >= 40100 then @m.query("create temporary table t (i int, c char(10), d double, t datetime)") @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") @s.prepare("select * from t") @s.bind_result(String, String, String, String) @s.execute a = @s.fetch assert_equal(["123", "9abcdefg", "1.2345", "2005-08-02 23:50:11"], a) end end def test_bind_result_float() if @m.server_version >= 40100 then @m.query("create temporary table t (i int, c char(10), d double, t datetime)") @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") @s.prepare("select * from t") @s.bind_result(Float, Float, Float, Float) @s.execute a = @s.fetch if Mysql.client_version < 50000 then assert_equal([123.0, 9.0, 1.2345, 2005.0], a) else assert_equal([123.0, 9.0, 1.2345, 20050802235011.0], a) end end end def test_bind_result_mysqltime() if @m.server_version >= 40100 then @m.query("create temporary table t (i int, c char(10), d double, t datetime)") @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") @s.prepare("select * from t") @s.bind_result(Mysql::Time, Mysql::Time, Mysql::Time, Mysql::Time) @s.execute a = @s.fetch if Mysql.client_version < 50000 then assert_equal([Mysql::Time.new, Mysql::Time.new, Mysql::Time.new, Mysql::Time.new(2005,8,2,23,50,11)], a) else assert_equal([Mysql::Time.new(2000,1,23), Mysql::Time.new, Mysql::Time.new, Mysql::Time.new(2005,8,2,23,50,11)], a) end end end def test_bind_result_unknown() if @m.server_version >= 40100 then @m.query("create temporary table t (i int, c char(10), d double, t datetime)") @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") @s.prepare("select * from t") assert_raises(TypeError){@s.bind_result(Time, nil, nil, nil)} end end def test_bind_result_unmatch_count() if @m.server_version >= 40100 then @m.query("create temporary table t (i int, c char(10), d double, t datetime)") @m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)") @s.prepare("select * from t") assert_raises(Mysql::Error){@s.bind_result(nil, nil)} end end def test_data_seek() if @m.server_version >= 40100 then @m.query("create temporary table t (i int)") @m.query("insert into t values (0),(1),(2),(3),(4),(5)") @s.prepare("select i from t") @s.execute assert_equal([0], @s.fetch) assert_equal([1], @s.fetch) assert_equal([2], @s.fetch) @s.data_seek(5) assert_equal([5], @s.fetch) @s.data_seek(1) assert_equal([1], @s.fetch) end end =begin def test_errno() @s.errno() end def test_error() @s.error() end =end def test_execute() if @m.server_version >= 40100 then @m.query("create temporary table t (i int)") @s.prepare("insert into t values (123)") @s.execute() assert_equal(1, @s.affected_rows) @s.execute() assert_equal(1, @s.affected_rows) assert_equal(2, @m.query("select count(*) from t").fetch_row[0].to_i) end end def test_execute2() if @m.server_version >= 40100 then @m.query("create temporary table t (i int)") @s.prepare("insert into t values (?)") @s.execute(123) @s.execute("456") @s.prepare("select * from t") @s.execute assert_equal([123], @s.fetch) assert_equal([456], @s.fetch) end end def test_execute3() if @m.server_version >= 40100 then @m.query("create temporary table t (i int, c char(255), t timestamp)") @s.prepare("insert into t values (?,?,?)") @s.execute(123, "hoge", Time.local(2005,7,19,23,53,0)); assert_raises(Mysql::Error){@s.execute(123, "hoge")} assert_raises(Mysql::Error){@s.execute(123, "hoge", 0, "fuga")} @s.prepare("select * from t") @s.execute assert_equal([123, "hoge", Mysql::Time.new(2005,7,19,23,53,0)], @s.fetch) end end def test_execute4() if @m.server_version >= 40100 then @m.query("create temporary table t (i int, c char(255), t timestamp)") @s.prepare("insert into t values (?,?,?)") @s.execute(nil, "hoge", Mysql::Time.new(2005,7,19,23,53,0)); @s.prepare("select * from t") @s.execute assert_equal([nil, "hoge", Mysql::Time.new(2005,7,19,23,53,0)], @s.fetch) end end def test_execute5() if @m.server_version >= 40100 then [30, 31, 32, 62, 63].each do |i| v, = @m.prepare("select cast(? as signed)").execute(2**i-1).fetch assert_equal(2**i-1, v) v, = @m.prepare("select cast(? as signed)").execute(-(2**i)).fetch assert_equal(-(2**i), v) end end end def test_fetch() if @m.server_version >= 40100 then @s.prepare("select 123, 'abc', null") @s.execute() assert_equal([123, "abc", nil], @s.fetch()) end end def test_fetch_bit() if @m.client_version >= 50003 and @m.server_version >= 50003 then @m.query("create temporary table t (i bit(8))") @m.query("insert into t values (0),(-1),(127),(-128),(255),(-255),(256)") @s.prepare("select i from t") @s.execute assert_equal(["\x00"], @s.fetch) assert_equal(["\xff"], @s.fetch) assert_equal(["\x7f"], @s.fetch) assert_equal(["\xff"], @s.fetch) assert_equal(["\xff"], @s.fetch) assert_equal(["\xff"], @s.fetch) assert_equal(["\xff"], @s.fetch) @m.query("create temporary table t2 (i bit(64))") @m.query("insert into t2 values (0),(-1),(4294967296),(18446744073709551615),(18446744073709551616)") @s.prepare("select i from t2") @s.execute assert_equal(["\x00\x00\x00\x00\x00\x00\x00\x00"], @s.fetch) assert_equal(["\xff\xff\xff\xff\xff\xff\xff\xff"], @s.fetch) assert_equal(["\x00\x00\x00\x01\x00\x00\x00\x00"], @s.fetch) assert_equal(["\xff\xff\xff\xff\xff\xff\xff\xff"], @s.fetch) assert_equal(["\xff\xff\xff\xff\xff\xff\xff\xff"], @s.fetch) end end def test_fetch_tinyint() if @m.server_version >= 40100 then @m.query("create temporary table t (i tinyint)") @m.query("insert into t values (0),(-1),(127),(-128),(255),(-255)") @s.prepare("select i from t") @s.execute assert_equal([0], @s.fetch) assert_equal([-1], @s.fetch) assert_equal([127], @s.fetch) assert_equal([-128], @s.fetch) assert_equal([127], @s.fetch) assert_equal([-128], @s.fetch) end end def test_fetch_tinyint_unsigned() if @m.server_version >= 40100 then @m.query("create temporary table t (i tinyint unsigned)") @m.query("insert into t values (0),(-1),(127),(-128),(255),(-255),(256)") @s.prepare("select i from t") @s.execute assert_equal([0], @s.fetch) assert_equal([0], @s.fetch) assert_equal([127], @s.fetch) assert_equal([0], @s.fetch) assert_equal([255], @s.fetch) assert_equal([0], @s.fetch) assert_equal([255], @s.fetch) end end def test_fetch_smallint() if @m.server_version >= 40100 then @m.query("create temporary table t (i smallint)") @m.query("insert into t values (0),(-1),(32767),(-32768),(65535),(-65535),(65536)") @s.prepare("select i from t") @s.execute assert_equal([0], @s.fetch) assert_equal([-1], @s.fetch) assert_equal([32767], @s.fetch) assert_equal([-32768], @s.fetch) assert_equal([32767], @s.fetch) assert_equal([-32768], @s.fetch) end end def test_fetch_smallint_unsigned() if @m.server_version >= 40100 then @m.query("create temporary table t (i smallint unsigned)") @m.query("insert into t values (0),(-1),(32767),(-32768),(65535),(-65535),(65536)") @s.prepare("select i from t") @s.execute assert_equal([0], @s.fetch) assert_equal([0], @s.fetch) assert_equal([32767], @s.fetch) assert_equal([0], @s.fetch) assert_equal([65535], @s.fetch) assert_equal([0], @s.fetch) assert_equal([65535], @s.fetch) end end def test_fetch_mediumint() if @m.server_version >= 40100 then @m.query("create temporary table t (i mediumint)") @m.query("insert into t values (0),(-1),(8388607),(-8388608),(16777215),(-16777215),(16777216)") @s.prepare("select i from t") @s.execute assert_equal([0], @s.fetch) assert_equal([-1], @s.fetch) assert_equal([8388607], @s.fetch) assert_equal([-8388608], @s.fetch) assert_equal([8388607], @s.fetch) assert_equal([-8388608], @s.fetch) end end def test_fetch_mediumint_unsigned() if @m.server_version >= 40100 then @m.query("create temporary table t (i mediumint unsigned)") @m.query("insert into t values (0),(-1),(8388607),(-8388608),(16777215),(-16777215),(16777216)") @s.prepare("select i from t") @s.execute assert_equal([0], @s.fetch) assert_equal([0], @s.fetch) assert_equal([8388607], @s.fetch) assert_equal([0], @s.fetch) assert_equal([16777215], @s.fetch) assert_equal([0], @s.fetch) assert_equal([16777215], @s.fetch) end end def test_fetch_int() if @m.server_version >= 40100 then @m.query("create temporary table t (i int)") @m.query("insert into t values (0),(-1),(2147483647),(-2147483648),(4294967295),(-4294967295),(4294967296)") @s.prepare("select i from t") @s.execute assert_equal([0], @s.fetch) assert_equal([-1], @s.fetch) assert_equal([2147483647], @s.fetch) assert_equal([-2147483648], @s.fetch) assert_equal([2147483647], @s.fetch) assert_equal([-2147483648], @s.fetch) end end def test_fetch_int_unsigned() if @m.server_version >= 40100 then @m.query("create temporary table t (i int unsigned)") @m.query("insert into t values (0),(-1),(2147483647),(-2147483648),(4294967295),(-4294967295),(4294967296)") @s.prepare("select i from t") @s.execute assert_equal([0], @s.fetch) assert_equal([0], @s.fetch) assert_equal([2147483647], @s.fetch) assert_equal([0], @s.fetch) assert_equal([4294967295], @s.fetch) assert_equal([0], @s.fetch) assert_equal([4294967295], @s.fetch) end end def test_fetch_bigint() if @m.server_version >= 40100 then @m.query("create temporary table t (i bigint)") @m.query("insert into t values (0),(-1),(9223372036854775807),(-9223372036854775808),(18446744073709551615),(-18446744073709551615),(18446744073709551616)") @s.prepare("select i from t") @s.execute assert_equal([0], @s.fetch) assert_equal([-1], @s.fetch) assert_equal([9223372036854775807], @s.fetch) assert_equal([-9223372036854775808], @s.fetch) if @m.server_version >= 50000 then assert_equal([9223372036854775807], @s.fetch) else assert_equal([-1], @s.fetch) # MySQL problem end assert_equal([-9223372036854775808], @s.fetch) assert_equal([9223372036854775807], @s.fetch) end end def test_fetch_bigint_unsigned() if @m.server_version >= 40100 then @m.query("create temporary table t (i bigint unsigned)") @m.query("insert into t values (0),(-1),(9223372036854775807),(-9223372036854775808),(18446744073709551615),(-18446744073709551615),(18446744073709551616)") @s.prepare("select i from t") @s.execute assert_equal([0], @s.fetch) if @m.server_version >= 50000 then assert_equal([0], @s.fetch) else assert_equal([18446744073709551615], @s.fetch) # MySQL problem end assert_equal([9223372036854775807], @s.fetch) if @m.server_version >= 50000 then assert_equal([0], @s.fetch) else assert_equal([9223372036854775808], @s.fetch) # MySQL problem end assert_equal([18446744073709551615], @s.fetch) assert_equal([0], @s.fetch) assert_equal([18446744073709551615], @s.fetch) end end def test_fetch_float() if @m.server_version >= 40100 then @m.query("create temporary table t (i float)") @m.query("insert into t values (0),(-3.402823466E+38),(-1.175494351E-38),(1.175494351E-38),(3.402823466E+38)") @s.prepare("select i from t") @s.execute assert_equal([0], @s.fetch) assert_in_delta(-3.402823466E+38, @s.fetch[0], 0.000000001E+38) assert_in_delta(-1.175494351E-38, @s.fetch[0], 0.000000001E-38) assert_in_delta(1.175494351E-38, @s.fetch[0], 0.000000001E-38) assert_in_delta(3.402823466E+38, @s.fetch[0], 0.000000001E+38) end end def test_fetch_float_unsigned() if @m.server_version >= 40100 then @m.query("create temporary table t (i float unsigned)") @m.query("insert into t values (0),(-3.402823466E+38),(-1.175494351E-38),(1.175494351E-38),(3.402823466E+38)") @s.prepare("select i from t") @s.execute assert_equal([0], @s.fetch) assert_equal([0], @s.fetch) assert_equal([0], @s.fetch) assert_in_delta(1.175494351E-38, @s.fetch[0], 0.000000001E-38) assert_in_delta(3.402823466E+38, @s.fetch[0], 0.000000001E+38) end end def test_fetch_double() if @m.server_version >= 40100 then @m.query("create temporary table t (i double)") @m.query("insert into t values (0),(-1.7976931348623157E+308),(-2.2250738585072014E-308),(2.2250738585072014E-308),(1.7976931348623157E+308)") @s.prepare("select i from t") @s.execute assert_equal([0], @s.fetch) assert_in_delta(-Float::MAX, @s.fetch[0], Float::EPSILON) assert_in_delta(-Float::MIN, @s.fetch[0], Float::EPSILON) assert_in_delta(Float::MIN, @s.fetch[0], Float::EPSILON) assert_in_delta(Float::MAX, @s.fetch[0], Float::EPSILON) end end def test_fetch_double_unsigned() if @m.server_version >= 40100 then @m.query("create temporary table t (i double unsigned)") @m.query("insert into t values (0),(-1.7976931348623157E+308),(-2.2250738585072014E-308),(2.2250738585072014E-308),(1.7976931348623157E+308)") @s.prepare("select i from t") @s.execute assert_equal([0], @s.fetch) assert_equal([0], @s.fetch) assert_equal([0], @s.fetch) assert_in_delta(Float::MIN, @s.fetch[0], Float::EPSILON) assert_in_delta(Float::MAX, @s.fetch[0], Float::EPSILON) end end def test_fetch_decimal() if (@m.server_version >= 50000 and Mysql.client_version >= 50000) or (@m.server_version >= 40100 and @m.server_version < 50000) then @m.query("create temporary table t (i decimal)") @m.query("insert into t values (0),(9999999999),(-9999999999),(10000000000),(-10000000000)") @s.prepare("select i from t") @s.execute assert_equal(["0"], @s.fetch) assert_equal(["9999999999"], @s.fetch) assert_equal(["-9999999999"], @s.fetch) if @m.server_version < 50000 then assert_equal(["10000000000"], @s.fetch) # MySQL problem else assert_equal(["9999999999"], @s.fetch) end assert_equal(["-9999999999"], @s.fetch) end end def test_fetch_decimal_unsigned() if (@m.server_version >= 50000 and Mysql.client_version >= 50000) or (@m.server_version >= 40100 and @m.server_version < 50000) then @m.query("create temporary table t (i decimal unsigned)") @m.query("insert into t values (0),(9999999998),(9999999999),(-9999999998),(-9999999999),(10000000000),(-10000000000)") @s.prepare("select i from t") @s.execute assert_equal(["0"], @s.fetch) assert_equal(["9999999998"], @s.fetch) assert_equal(["9999999999"], @s.fetch) assert_equal(["0"], @s.fetch) assert_equal(["0"], @s.fetch) assert_equal(["9999999999"], @s.fetch) assert_equal(["0"], @s.fetch) end end def test_fetch_date() if @m.server_version >= 40100 then @m.query("create temporary table t (i date)") @m.query("insert into t values ('0000-00-00'),('1000-01-01'),('9999-12-31')") @s.prepare("select i from t") @s.execute assert_equal([Mysql::Time.new(0,0,0)], @s.fetch) assert_equal([Mysql::Time.new(1000,1,1)], @s.fetch) assert_equal([Mysql::Time.new(9999,12,31)], @s.fetch) end end def test_fetch_datetime() if @m.server_version >= 40100 then @m.query("create temporary table t (i datetime)") @m.query("insert into t values ('0000-00-00 00:00:00'),('1000-01-01 00:00:00'),('9999-12-31 23:59:59')") @s.prepare("select i from t") @s.execute assert_equal([Mysql::Time.new(0,0,0,0,0,0)], @s.fetch) assert_equal([Mysql::Time.new(1000,1,1,0,0,0)], @s.fetch) assert_equal([Mysql::Time.new(9999,12,31,23,59,59)], @s.fetch) end end def test_fetch_timestamp() if @m.server_version >= 40100 then @m.query("create temporary table t (i timestamp)") @m.query("insert into t values ('1970-01-02 00:00:00'),('2037-12-30 23:59:59')") @s.prepare("select i from t") @s.execute assert_equal([Mysql::Time.new(1970,1,2,0,0,0)], @s.fetch) assert_equal([Mysql::Time.new(2037,12,30,23,59,59)], @s.fetch) end end def test_fetch_time() if @m.server_version >= 40100 then @m.query("create temporary table t (i time)") @m.query("insert into t values ('-838:59:59'),(0),('838:59:59')") @s.prepare("select i from t") @s.execute assert_equal([Mysql::Time.new(0,0,0,838,59,59,true)], @s.fetch) assert_equal([Mysql::Time.new(0,0,0,0,0,0,false)], @s.fetch) assert_equal([Mysql::Time.new(0,0,0,838,59,59,false)], @s.fetch) end end def test_fetch_year() if @m.server_version >= 40100 then @m.query("create temporary table t (i year)") @m.query("insert into t values (0),(70),(69),(1901),(2155)") @s.prepare("select i from t") @s.execute assert_equal([0], @s.fetch) assert_equal([1970], @s.fetch) assert_equal([2069], @s.fetch) assert_equal([1901], @s.fetch) assert_equal([2155], @s.fetch) end end def test_fetch_char() if @m.server_version >= 40100 then @m.query("create temporary table t (i char(10))") @m.query("insert into t values (null),('abc')") @s.prepare("select i from t") @s.execute assert_equal([nil], @s.fetch) assert_equal(["abc"], @s.fetch) end end def test_fetch_varchar() if @m.server_version >= 40100 then @m.query("create temporary table t (i varchar(10))") @m.query("insert into t values (null),('abc')") @s.prepare("select i from t") @s.execute assert_equal([nil], @s.fetch) assert_equal(["abc"], @s.fetch) end end def test_fetch_binary() if @m.server_version >= 40100 then @m.query("create temporary table t (i binary(10))") @m.query("insert into t values (null),('abc')") @s.prepare("select i from t") @s.execute assert_equal([nil], @s.fetch) if @m.server_version >= 50000 then assert_equal(["abc\0\0\0\0\0\0\0"], @s.fetch) else assert_equal(["abc"], @s.fetch) end end end def test_fetch_varbinary() if @m.server_version >= 40100 then @m.query("create temporary table t (i varbinary(10))") @m.query("insert into t values (null),('abc')") @s.prepare("select i from t") @s.execute assert_equal([nil], @s.fetch) assert_equal(["abc"], @s.fetch) end end def test_fetch_tinyblob() if @m.server_version >= 40100 then @m.query("create temporary table t (i tinyblob)") @m.query("insert into t values (null),('abc')") @s.prepare("select i from t") @s.execute assert_equal([nil], @s.fetch) assert_equal(["abc"], @s.fetch) end end def test_fetch_tinytext() if @m.server_version >= 40100 then @m.query("create temporary table t (i tinytext)") @m.query("insert into t values (null),('abc')") @s.prepare("select i from t") @s.execute assert_equal([nil], @s.fetch) assert_equal(["abc"], @s.fetch) end end def test_fetch_blob() if @m.server_version >= 40100 then @m.query("create temporary table t (i blob)") @m.query("insert into t values (null),('abc')") @s.prepare("select i from t") @s.execute assert_equal([nil], @s.fetch) assert_equal(["abc"], @s.fetch) end end def test_fetch_text() if @m.server_version >= 40100 then @m.query("create temporary table t (i text)") @m.query("insert into t values (null),('abc')") @s.prepare("select i from t") @s.execute assert_equal([nil], @s.fetch) assert_equal(["abc"], @s.fetch) end end def test_fetch_mediumblob() if @m.server_version >= 40100 then @m.query("create temporary table t (i mediumblob)") @m.query("insert into t values (null),('abc')") @s.prepare("select i from t") @s.execute assert_equal([nil], @s.fetch) assert_equal(["abc"], @s.fetch) end end def test_fetch_mediumtext() if @m.server_version >= 40100 then @m.query("create temporary table t (i mediumtext)") @m.query("insert into t values (null),('abc')") @s.prepare("select i from t") @s.execute assert_equal([nil], @s.fetch) assert_equal(["abc"], @s.fetch) end end def test_fetch_longblob() if @m.server_version >= 40100 then @m.query("create temporary table t (i longblob)") @m.query("insert into t values (null),('abc')") @s.prepare("select i from t") @s.execute assert_equal([nil], @s.fetch) assert_equal(["abc"], @s.fetch) end end def test_fetch_longtext() if @m.server_version >= 40100 then @m.query("create temporary table t (i longtext)") @m.query("insert into t values (null),('abc')") @s.prepare("select i from t") @s.execute assert_equal([nil], @s.fetch) assert_equal(["abc"], @s.fetch) end end def test_fetch_enum() if @m.server_version >= 40100 then @m.query("create temporary table t (i enum('abc','def'))") @m.query("insert into t values (null),(0),(1),(2),('abc'),('def'),('ghi')") @s.prepare("select i from t") @s.execute assert_equal([nil], @s.fetch) assert_equal([""], @s.fetch) assert_equal(["abc"], @s.fetch) assert_equal(["def"], @s.fetch) assert_equal(["abc"], @s.fetch) assert_equal(["def"], @s.fetch) assert_equal([""], @s.fetch) end end def test_fetch_set() if @m.server_version >= 40100 then @m.query("create temporary table t (i set('abc','def'))") @m.query("insert into t values (null),(0),(1),(2),(3),('abc'),('def'),('abc,def'),('ghi')") @s.prepare("select i from t") @s.execute assert_equal([nil], @s.fetch) assert_equal([""], @s.fetch) assert_equal(["abc"], @s.fetch) assert_equal(["def"], @s.fetch) assert_equal(["abc,def"], @s.fetch) assert_equal(["abc"], @s.fetch) assert_equal(["def"], @s.fetch) assert_equal(["abc,def"], @s.fetch) assert_equal([""], @s.fetch) end end def test_each() if @m.server_version >= 40100 then @m.query("create temporary table t (i int, c char(255), d datetime)") @m.query("insert into t values (1,'abc','19701224235905'),(2,'def','21120903123456'),(3,'123',null)") @s.prepare("select * from t") @s.execute c = 0 @s.each do |a| case c when 0 assert_equal([1,"abc",Mysql::Time.new(1970,12,24,23,59,05)], a) when 1 assert_equal([2,"def",Mysql::Time.new(2112,9,3,12,34,56)], a) when 2 assert_equal([3,"123",nil], a) else raise end c += 1 end end end def test_field_count() if @m.server_version >= 40100 then @s.prepare("select 1,2,3") @s.execute() assert_equal(3, @s.field_count()) @s.prepare("set @a=1") @s.execute() assert_equal(0, @s.field_count()) end end def test_free_result() if @m.server_version >= 40100 then @s.free_result() @s.prepare("select 1,2,3") @s.execute() @s.free_result() end end def test_insert_id() if @m.server_version >= 40100 then @m.query("create temporary table t (i bigint auto_increment, unique(i))") @s.prepare("insert into t values (?)") @s.execute(0) assert_equal(1, @s.insert_id()) @s.execute(0) assert_equal(2, @s.insert_id()) @s.execute(2**32) assert_equal(2**32, @s.insert_id()) @s.execute(0) assert_equal(2**32+1, @s.insert_id()) end end def test_num_rows() if @m.server_version >= 40100 then @m.query("create temporary table t (i int)") @m.query("insert into t values (1),(2),(3),(4)") @s.prepare("select * from t") @s.execute assert_equal(4, @s.num_rows()) end end def test_param_count() if @m.server_version >= 40100 then @m.query("create temporary table t (a int, b int, c int)") @s.prepare("select * from t") assert_equal(0, @s.param_count()) @s.prepare("insert into t values (?,?,?)") assert_equal(3, @s.param_count()) end end =begin def test_param_metadata() @s.param_metadata() end =end def test_prepare() if @m.server_version >= 40100 then @s.prepare("select 1") assert_raises(Mysql::Error){@s.prepare("invalid syntax")} end end =begin def test_reset() @s.reset() end =end def test_result_metadata() if @m.server_version >= 40100 then @s.prepare("select 1 foo, 2 bar") res = @s.result_metadata() f = res.fetch_fields assert_equal("foo", f[0].name) assert_equal("bar", f[1].name) end end def test_result_metadata_nodata() if @m.server_version >= 40100 then @m.query("create temporary table t (i int)") @s.prepare("insert into t values (1)") assert_equal(nil, @s.result_metadata()) end end def test_row_seek_tell() if @m.server_version >= 40100 then @m.query("create temporary table t (i int)") @m.query("insert into t values (0),(1),(2),(3),(4)") @s.prepare("select * from t") @s.execute row0 = @s.row_tell assert_equal([0], @s.fetch) assert_equal([1], @s.fetch) row2 = @s.row_seek(row0) assert_equal([0], @s.fetch) @s.row_seek(row2) assert_equal([2], @s.fetch) end end =begin def test_send_long_data() @m.query("create temporary table t (i int, t text)") @s.prepare("insert into t values (?,?)") @s.send_long_data(1, "long long data ") @s.send_long_data(1, "long long data2") assert_raises(Mysql::Error){@s.send_long_data(9, "invalid param number")} @s.execute(99, "hoge") assert_equal("long long data long long data2", @m.query("select t from t").fetch_row[0]) end =end def test_sqlstate() if @m.server_version >= 40100 then @s.prepare("select 1") if @m.client_version >= 50000 then assert_equal("00000", @s.sqlstate) else assert_equal("", @s.sqlstate) end assert_raises(Mysql::Error){@s.prepare("hogehoge")} assert_equal("42000", @s.sqlstate) end end =begin def test_store_result() @s.store_result() end =end end if Mysql.client_version >= 40100 class TC_MysqlTime < Test::Unit::TestCase def setup() end def teardown() end def test_init() t = Mysql::Time.new assert_equal(0, t.year); assert_equal(0, t.month); assert_equal(0, t.day); assert_equal(0, t.hour); assert_equal(0, t.minute); assert_equal(0, t.second); assert_equal(false, t.neg); assert_equal(0, t.second_part); end def test_year() t = Mysql::Time.new assert_equal(2005, t.year = 2005) assert_equal(2005, t.year) end def test_month() t = Mysql::Time.new assert_equal(11, t.month = 11) assert_equal(11, t.month) end def test_day() t = Mysql::Time.new assert_equal(23, t.day = 23) assert_equal(23, t.day) end def test_hour() t = Mysql::Time.new assert_equal(15, t.hour = 15) assert_equal(15, t.hour) end def test_minute() t = Mysql::Time.new assert_equal(58, t.month = 58) assert_equal(58, t.month) end def test_second() t = Mysql::Time.new assert_equal(34, t.second = 34) assert_equal(34, t.second) end def test_tos() t = Mysql::Time.new(2005, 7, 19, 10, 15, 49) assert_equal("2005-07-19 10:15:49", t.to_s) end def test_eql() t1 = Mysql::Time.new(2005,7,19,23,56,13) t2 = Mysql::Time.new(2005,7,19,23,56,13) assert_equal(t1, t2) end end if Mysql.client_version >= 40100 mysql-2.9.1/COPYING.ja0000644000004100000410000000405512414313001014335 0ustar www-datawww-data$BK\%W%m%0%i%`$O%U%j!<%=%U%H%&%'%"$G$9!%(BGPL(the GNU General Public License)$B$^$?$O0J2<$K<($9>r7o$GK\%W%m%0%i%`$r:FG[I[$G(B $B$-$^$9!%(BGPL$B$K$D$$$F$O(BGPL$B%U%!%$%k$r;2>H$7$F2<$5$$!%(B 1. $BJ#@=$O@)8B$J$/<+M3$G$9!%(B 2. $B0J2<$N>r7o$N$$$:$l$+$rK~$?$9;~$KK\%W%m%0%i%`$N%=!<%9$r(B $B<+M3$KJQ99$G$-$^$9!%(B (a) $B%M%C%H%K%e!<%:$K%]%9%H$7$?$j!$:nA0$rJQ99$9$k!%(B $B$=$N%=%U%H%&%'%"$rG[I[$9$k;~$K$OJQ99A0$NK\%W%m%0%i(B $B%`$bF1;~$KG[I[$9$k!%$^$?$OJQ99A0$NK\%W%m%0%i%`$N%=!<(B $B%9$NF~$NJQ99>r7o$r:nr7o$N$$$:$l$+$rK~$?$9;~$KK\%W%m%0%i%`$r%3%s%Q%$(B $B%k$7$?%*%V%8%'%/%H%3!<%I$dA0$rJQ99$7$?$&$(!$%*%j%8%J(B $B%k$N%=!<%9%3!<%I$NF~$NG[I[>r7o$r:n$N%W%m%0%i%`$X$N0zMQ$O$$$+$J$kL\E*$G$"$l<+M3$G$9!%$?(B $B$@$7!$K\%W%m%0%i%`$K4^$^$l$kB>$N:n$l$N:nl9g$,$"$j$^$9!%(B $B$=$l$i%U%!%$%k$N0lMw$H$=$l$>$l$NG[I[>r7o$J$I$KIU$$$F$O(B LEGAL$B%U%!%$%k$r;2>H$7$F$/$@$5$$!%(B 5. $BK\%W%m%0%i%`$X$NF~NO$H$J$k%9%/%j%W%H$*$h$S!$K\%W%m%0%i(B $B%`$+$i$N=PNO$N8"Mx$OK\%W%m%0%i%`$N:n(B $B$l$NF~=PNO$r@8@.$7$??M$KB0$7$^$9!%$^$?!$K\%W%m%0%i%`$K(B $BAH$_9~$^$l$k$?$a$N3HD%%i%$%V%i%j$K$D$$$F$bF1MM$G$9!%(B 6. $BK\%W%m%0%i%`$OL5J]>Z$G$9!%:n MySQL/Ruby

MySQL/Ruby

[Japanese]


This is the MySQL API module for Ruby. It provides the same functions for Ruby programs that the MySQL C API provides for C programs.

Download

Requirement

  • MySQL 5.0.67
  • Ruby 1.8.7, 1.9.1

The module may work for other versions, but that has not been verified.

License

This program is under Ruby's license.

Install

1st:

% ruby extconf.rb

or

% ruby extconf.rb --with-mysql-dir=/usr/local/mysql

or

% ruby extconf.rb --with-mysql-config

then

% make

extconf.rb has following options:

--with-mysql-include=dir
MySQL header file directory. Default is /usr/local/include.
--with-mysql-lib=dir
MySQL library directory. Default is /usr/local/lib.
--with-mysql-dir=dir
Same as --with-mysql-include=dir/include, --with-mysql-lib=dir/lib.
--with-mysql-config[=/path/to/mysql_config]
Get compile-parameter from mysql_config command.

2nd:

% ruby ./test.rb -- [hostname [user [passwd [dbname [port [socket [flag]]]]]]]

3rd:

# make install

Note

If you get error like 'libmysqlclient not found' when testing, you need to specify the directory in which the library is located so that make can find it.

% env LD_RUN_PATH=libmysqlclient.so directory make

test.rb is tested on Linux only.

Usage

The names of methods provided by this module basically are the same as the names of the functions in the C API, except that the Ruby method names do not begin with a 'mysql_' prefix. For example, the Ruby query() method corresponds to the C API mysql_query() function. For details on the use of each Ruby method, see the descriptions of the corresponding C functions in the MySQL Reference Manual.

Some Ruby methods may be invoked under other names that serve as equivalent aliases, as noted below.

If an error occurs when a method executes, it raises a Mysql::Error exception.

Mysql class

CLASS METHODS

init()

It return Mysql object. It not connect to mysqld.

real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil)
connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil)
new(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil)

connect to mysqld and return Mysql object.

escape_string(str)
quote(str)

quote string for insert/update.

get_client_info()
client_info()

return client version information.

get_client_version()
client_version()

return client version as number.

debug(str)

same as C API mysql_debug().

OBJECT METHODS

options(opt, val=nil)

same as C API mysql_options().

real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil)
connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil)

same as Mysql.real_connect().

affected_rows()

return affected rows.

autocommit(mode)

set autocommit mode.

change_user(user=nil, passwd=nil, db=nil)

change user.

character_set_name()

return character set.

close()

close connection.

commit()

commit transaction.

create_db(db)

create database.

drop_db(db)

drop database.

dump_debug_info()

same as C API mysql_dump_debug_info().

errno()

return error number.

error()

return error message.

escape_string(str)
quote(str)

quote strings for insert/update. same as C API mysql_real_escape_string().

field_count()

return number of columns of last query.

get_client_info()
client_info()

return client version information.

get_client_version()
client_version()

return client version number.

get_host_info()
host_info()

return connection information.

get_proto_info()
proto_info()

return connection protocol version.

get_server_info()
server_info()

return server version information.

get_server_version()
server_version()

return server version number.

info()

return information of last query.

insert_id()

return last AUTO_INCREMENT value.

kill(id)

kill thread.

list_dbs(db=nil)

return database list.

list_fields(table, field=nil)

return Mysql::Result object.

list_processes()

return Mysql::Result object.

list_tables(table=nil)

return table list Array.

more_results?()

returns true if more results exist from the currently executed query.

next_result()

returns true if more results exist from the currently executed query. after this, you do store_result() to get result table of query.

ping()

check server.

prepare(q)

query(q)
real_query(q)

do query and store_result(). return Mysql::Result object. If query_with_result is false, it does not store_result().

query(q) {|res| ...}
real_query(q) {|res| ...}

do query and execute block with Mysql::Result object. Mysql::Result object is freed when exiting block. If multiple statement mode, it does repeat block each query.

Since MySQL/Ruby 2.8, it no longer turn on multiple statement mode automatically. If you want to turn on multiple statement mode, set Mysql::CLIENT_MULTI_STATEMENTS for Mysql.connect or execute Mysql#set_server_option(Mysql::OPTION_MULTI_STATEMENTS_ON).

refresh(r)

flush server log or cache.

reload()

reload access privilege table.

rollback()

rollback transaction.

select_db(db)

select database.

set_server_option(opt)

set option to server. options is one of Mysql::OPTION_MULTI_STATEMENTS_ON, Mysql::OPTION_MULTI_STATEMENTS_OFF.

shutdown()

shutdown server.

ssl_set(key=nil, cert=nil, ca=nil, capath=nil, cipher=nil)

use SSL.

stat()

return server status.

stmt_init()

return Mysql::Stmt class object.

store_result()

return Mysql::Result object.

thread_id()

retrun thread id.

use_result()

return Mysql::Result object.

warning_count()

return warning count last query.

OBJECT VARIABLES

query_with_result

If true, query() also invokes store_result() and returns a Mysql::Result object. Default is true.

reconnect

If true, reconnect to server automatically when disconect to server. Default is false.

Mysql::Result class

OBJECT METHODS

free()

free memory of result table.

data_seek(offset)

seek row.

fetch_field()

return next Mysql::Field object.

fetch_fields()

return Array of Mysql::Field object.

fetch_field_direct(fieldnr)

return Mysql::Field object.

fetch_lengths()

return Array of field length.

fetch_row()

return row as Array.

fetch_hash(with_table=false)

return row as Hash. If with_table is true, hash key format is "tablename.fieldname".

field_seek(offset)

seek field.

field_tell()

return field position.

num_fields()

return number of fields.

num_rows()

return number of rows.

row_seek(offset)

seek row.

row_tell()

return row position.

ITERATOR

each() {|x| ...}

'x' is array of column values.

each_hash(with_table=false) {|x| ...}

'x' is hash of column values, and the keys are the column names.

Mysql::Field class

OBJECT VARIABLES(read only)

name
field name
table
table name
def
default value
type
field type
length
field length
max_length
max field length
flags
field flag
decimals
number of decimals

OBJECT METHODS

hash()

return field as Hash.

ex.) obj.name == obj.hash['name']

is_not_null?()

True if this field is defined as NOT NULL.

is_num?()

True if this field type is numeric.

is_pri_key?()

True if this field is a primary key.

inspect()

return "#<Mysql::Field:fieldname>"

Mysql::Stmt class

Example:

my = Mysql.new(hostname, username, password, databasename)
st = my.prepare("insert into tblname (col1,col2,col3) values (?,?,?)")
st.execute("abc",123,Time.now)
st.prepare("select col1,col2,col3 from tblname")
st.execute
st.fetch  # => ["abc", 123, #<Mysql::Time:2005-07-24 23:52:55>]
st.close

OBJECT METHODS

affected_rows()

bind_result(class, ...)

close()

data_seek(offset)

execute(arg, ...)

fetch()

Type mapping:

MySQL typeRuby class
TINYINT, SMALLINT, MEDIUMINT, YEARFixnum
INT, BIGINTFixnum or Bignum
FLOAT, DOUBLEFloat
DECIMALString
DATE, DATETIME, TIMESTAMP, TIMEMysql::Time
CHAR, VARCHAR, BINARY, VARBINARY, TINYBLOB, TINYTEXT, TINYBLOB, TINYTEXT, MEDIUMBLOB, MEDIUMTEXT, LONGBLOB, LONGTEXT, ENUM, SET, BITString
NULLNilClass
field_count()

free_result()

insert_id()

num_rows()

param_count()

prepare(q)

result_metadata()

row_seek(offset)

row_tell()

sqlstate()

ITERATOR

each() {|x| ...}

Mysql::Time class

CLASS METHODS

new(year=0,month=0,day=0,hour=0,minute=0,second=0,neg=false,second_part=0)

OBJECT VARIABLES

year
month
day
hour
minute
second
neg
second_part

Mysql::Error class

OBJECT VARIABLES(read only)

error
eror message
errno
error number

History

2010-02-11
version 2.8.2
  • Fix: Mysql#insert_id returns invalid value when larger than 2**32.
2009-02-01
version 2.8.1
  • correspond to Ruby 1.9.1
2008-09-29
version 2.8
version 2.7.7
  • When connecting to MySQL, EINTR is occurred sometimes ([ruby-dev:31842])
  • MySQL/Ruby 2.7.* can not be compiled on Ruby 1.8.5.
2008-06-20
version 2.8pre4
  • [ruby-dev:35152]
2008-06-17
version 2.8pre3
version 2.7.6
  • On 64bit machine, Mysql::Stmt#execute raise error on large numeric value(>= 2**30).
2008-03-08
version 2.8pre2
version 2.7.5
  • On 64bit machine, Mysql::Stmt#fetch return invalid numeric value.
2007-12-26
version 2.8pre1
  • for Ruby 1.9.0
  • Incompat: Mysql::Result#each_hash don't create column name string each row. it's shared.
  • Incompat: Mysql#query with block no longer turn on multi-statements mode automatically.
2007-08-22
version 2.7.4
  • BUG: Mysql::Stmt#execute memory leak.
2006-12-20
version 2.7.3
  • BUG: Mysql#query with block is stopped when last query failed.
2006-10-28
version 2.7.2
  • BUG: Mysql::Stmt#result_metadata don't return nil. (Thanks to Hidetoshi)
  • BUG: Mysql#close check mysql_errno.
  • BUG: multistatement Mysql#query with block ignore error.
  • extconf.rb for Visual C++. (Thanks to Shugo Maeda)
  • support MySQL BIT type.
  • add Mysql::Field::TYPE_BIT, TYPE_NEWDECIMAL.
2006-06-04
version 2.7.1
  • change free() to xfree(). To avoid crash on Windows. (Thanks Tobias Grimm)
2005-08-22
version 2.7
  • add constants for Mysql#options: Mysql::OPT_GUESS_CONNECTION, Mysql::OPT_USE_EMBEDDED_CONNECTION, Mysql::OPT_USE_REMOTE_CONNECTION, Mysql::SET_CLIENT_IP
  • test.rb: for 4.0.x, 5.0.x
2005-08-16
version 2.7-beta3
  • add Mysql::Stmt#bind_result
2005-08-02
version 2.7-beta2
  • BUG: mysql.c.in: fetch_hash: nil value doesn't exist in hash. (Thanks Stefan Kaes)
  • add constant Mysql::VERSION.
  • add Mysql#prepare
2005-07-24
version 2.7-beta
  • add Mysql#stmt_init method
  • add Mysql::Stmt, Mysql::Time, Mysql::RowOffset class
  • add Mysql::Error#sqlstate method
  • change offset value to Mysql::RowOffset object that is used by Mysql::Result#row_seek,row_tell
2005-07-31
version 2.6.3
  • add constant Mysql::VERSION.
2005-07-26
version 2.6.2
  • BUG: mysql.c.in: fetch_hash: nil value doesn't exist in hash. (Thanks Stefan Kaes)
2005-06-28
version 2.6.1
  • mysql.c.in: fix to compile error on MacOSX.
2005-04-25
version 2.6
  • add constants for Mysql#option(): Mysql::OPT_PROTOCOL, Mysql::OPT_READ_TIMEOUT, Mysql::OPT_WRITE_TIMEOUT, Mysql::SET_CHARSET_DIR, Mysql::SET_CHARSET_NAME, Mysql::SHARED_MEMORY_BASE_NAME, Mysql::SECURE_AUTH
  • add methods: Mysql#more_results?(), Mysql#next_result(), Mysql#set_server_option(), Mysql#sqlstate()
  • add constants for Mysql#connect(): Mysql::CLIENT_MULTI_STATEMENTS, Mysql::CLIENT_MULTI_RESULTS
  • add constants for Mysql#set_server_option(): Mysql::OPTION_MULTI_STATEMENTS_ON, Mysql::OPTION_MULTI_STATEMENTS_OFF
  • add Mysql#query() with block
  • add Mysql#reconnect(), Mysql#reconnect=()
  • When connection was closed, it don't try to reconnect by default.
2005-02-12
version 2.5.2
  • BUG: Mysql#connect make object to not close. (Thanks Andres Salomon)
2004-09-20
version 2.5.1
  • add Mysql#set_ssl().
2004-08-31
version 2.5
  • correspond to MySQL 4.1.x.
  • change MysqlRes, MysqlField, MysqlError to Mysql::Result, Mysql::Field, Mysql::Error.
  • add Mysql.client_version(), Mysql.get_client_version(), Mysql#client_version(), Mysql#get_client_version(), Mysql#server_version(), Mysql#get_server_version(), Mysql#warning_count(), Mysql#commit(), Mysql#rollback(), Mysql#autocommit().
  • add Mysql::Field#is_not_null?(), Mysql::Field#is_pri_key?(), Mysql::Field#is_num?().
  • add MysqlField::TYPE_VAR_STRING.
2003-08-10
version 2.4.5
  • extconf.rb: correspond to MySQL 4.1.
  • mysql.c.in: correspond to Ruby 1.8.
2003-02-23
version 2.4.4a
  • make extconf.rb to correspond to Ruby 1.8.0
2003-01-29
version 2.4.4
  • add Mysql::OPT_LOCAL_INFILE.
  • add --with-mysql-config option to extconf.rb.
  • extconf.rb automatically detect typical library.
2003-01-05
version 2.4.3c
  • modified English README. Thanks to Paul DuBois.
2002-12-24
version 2.4.3b
  • make extconf.rb to correspond to Ruby 1.6.8.
2002-11-07
version 2.4.3a
  • fix bug duplicating constant.
2002-09-10
version 2.4.3
  • for error number with prefix ER_ .
  • get error constant from errmsg.h and mysqld_error.h automatically.
2002-01-07
version 2.4.2
  • for MySQL 4.0.
  • change `uint' to `unsigned int' (for mswin).
2001-12-02
version 2.4.1
  • remove `extern' (for Cygiwn).
  • change option of extconf.rb.
2001-10-12
version 2.4.0
  • for Ruby 1.7.
  • add Mysql::debug(), Mysql#change_user(), Mysql#character_set_name(), Mysql#dump_debug_info().

Author

e-mail: TOMITA Masahiro tommy@tmtm.org http://tmtm.org


TOMITA Masahiro
Last modified: Sun Feb 1 17:48:41 JST 2009 mysql-2.9.1/extra/tommy.css0000644000004100000410000000245712414313001015717 0ustar www-datawww-databody { color: black; background: white; margin-left: 10%; margin-right: 10%; } h1 { color: white; background: #08d; width: 100%; } h1 a { color: white; } h1 a:link { } h1 a:visited { color: white; } h1 a:hover { } h2 { width: 100%; border: thin #0cc; border-style: solid none; background: #cff; } h3 { width: 100%; border: thin #0cc; border-style: none none solid; background: #eff; } h4 { border: thin #0cc; border-style: none none solid; } dt { font-weight: bold; } dd { margin-bottom: 3ex; } table { border-collapse: collapse; border: thin solid; } tr,th,td { border: thin solid; padding: 3px; } th { background-color: #00ffff; } td { background-color: #eeeeee; } div.intro { margin-right: 10%; margin-left: 10%; font-size: 90%; } div.code { margin-left: 10%; color: white; background: black; border: thin inset; padding: 4px; } div.code2 { margin-left: 10%; color: white; background: darkgreen; border: thin inset; padding: 4px; } pre { margin: 20px; padding: 4px; border: #363 inset; color: #fff; background: #232; width: 80%; } /* a { background: #eee; } */ a:link { color: #008; } a:visited { color: black; } a:hover { background: #fcc; } .red { color: red; } .notice { font-weight: bold; background: #f88; } .input { font-weight:bold; }mysql-2.9.1/extra/README_ja.html0000644000004100000410000007104112414313001016330 0ustar www-datawww-data MySQL/Ruby

MySQL/Ruby

[English]


¤³¤ì¤Ï MySQL ¤Î Ruby API ¤Ç¤¹¡£MySQL ¤Î C API ¤È¤Û¤ÜƱÅù¤Îµ¡Ç½¤¬¤¢¤ê¤Þ¤¹¡£

¥À¥¦¥ó¥í¡¼¥É

ɬÍפʤâ¤Î

  • MySQL 5.0.67
  • Ruby 1.8.7, 1.9.1

¤³¤ì¤é°Ê³°¤Ç¤â make ¤Ç¤­¤ë¤«¤â¤·¤ì¤Þ¤»¤ó¤¬¡¢³Îǧ¤·¤Æ¤Þ¤»¤ó¡£

¥é¥¤¥»¥ó¥¹

¤³¤Î¥×¥í¥°¥é¥à¤Ï Ruby ¥é¥¤¥»¥ó¥¹ ¤Ë½¾¤¤¤Þ¤¹¡£

¥¤¥ó¥¹¥È¡¼¥ë

¼¡¤ò¼Â¹Ô¤·¤Æ¤¯¤À¤µ¤¤¡£

% ruby extconf.rb

¤Þ¤¿¤Ï

% ruby extconf.rb --with-mysql-dir=/usr/local/mysql

¤Þ¤¿¤Ï

% ruby extconf.rb --with-mysql-config

¤½¤ì¤«¤é

% make

extconf.rb ¤Ë¤Ï¼¡¤Î¥ª¥×¥·¥ç¥ó¤ò»ØÄê¤Ç¤­¤Þ¤¹¡£

--with-mysql-include=dir
MySQL ¤Î¤Ø¥Ã¥À¥Õ¥¡¥¤¥ë¤Î¾ì½ê¤È¤·¤Æ /usr/local/include ¤ÎÂå¤ï¤ê¤Î¥Ç¥£¥ì¥¯¥È¥ê¤ò»ØÄꤷ¤Þ¤¹¡£
--with-mysql-lib=dir
MySQL ¤Î¥é¥¤¥Ö¥é¥ê¤Î¾ì½ê¤È¤·¤Æ /usr/local/lib ¤ÎÂå¤ï¤ê¤Î¥Ç¥£¥ì¥¯¥È¥ê¤ò»ØÄꤷ¤Þ¤¹¡£
--with-mysql-dir=dir
--with-mysql-include=dir/include, --with-mysql-lib=dir/lib ¤ÈƱ¤¸¤Ç¤¹¡£
--with-mysql-config[=/path/to/mysql_config]
mysql_config ¥³¥Þ¥ó¥É¤Î·ë²Ì¤«¤é¥³¥ó¥Ñ¥¤¥ë¥Ñ¥é¥á¡¼¥¿¤òÆÀ¤Þ¤¹¡£

¼¡¤Ç´Êñ¤Ê¥Æ¥¹¥È¤¬¤Ç¤­¤Þ¤¹¡£

% ruby ./test.rb -- [hostname [user [passwd [dbname [port [socket [flag]]]]]]]

test.rb ¤ËÍ¿¤¨¤ë°ú¿ô¤Ï Mysql.real_connect() ¤Î°ú¿ô¤ÈƱ¤¸¤Ç¤¹¡£

ÌäÂê¤Ê¤±¤ì¤Ð¡¢¥¹¡¼¥Ñ¡¼¥æ¡¼¥¶¤Ç¥¤¥ó¥¹¥È¡¼¥ë¤·¤Æ¤¯¤À¤µ¤¤¡£

# make install

Ãí°Õ

¥Æ¥¹¥È»þ¤Ë¥é¥¤¥Ö¥é¥ê libmysqlclient ¤¬¸«¤Ä¤«¤é¤Ê¤¤¤È¤¤¤¦¥¨¥é¡¼¤¬½Ð¤ë¾ì¹ç¤Ï¡¢make »þ¤Ë¥é¥¤¥Ö¥é¥ê¤Î¾ì½ê¤ò»ØÄꤹ¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£¼¡¤Î¤è¤¦¤Ë¤·¤Æ make ¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£

% env LD_RUN_PATH=libmysqlclient.so¤Î¾ì½ê make

test.rb ¤Ï Linux ¾å¤Ç¤Îưºî¤·¤«³Îǧ¤·¤Æ¤¤¤Þ¤»¤ó¡£ ¾¤Î¥×¥é¥Ã¥È¥Õ¥©¡¼¥à¤Ç¤Ï¥¨¥é¡¼¤¬½Ð¤ë¤«¤â¤·¤ì¤Þ¤»¤ó¡£

»È¤¤Êý

¥á¥½¥Ã¥É̾¤Ï C API ¤Î´Ø¿ô¤«¤é mysql_ ÀÜÆ¬¼­¤ò½ü¤¤¤¿¤â¤Î¤ÈƱ¤¸¤Ç¤¹¡£¥á¥½¥Ã¥É¤Î»ÈÍÑÊýË¡¤â´ðËÜŪ¤ËÂбþ¤¹¤ë C API ´Ø¿ô¤ÈƱÍͤǤ¹¤Î¤Ç¡¢¾ÜºÙ¤Ï MySQL ¤Î¥Þ¥Ë¥å¥¢¥ë¤ò¸«¤Æ¤¯¤À¤µ¤¤¡£

¥á¥½¥Ã¥ÉÃæ¤Ç¥¨¥é¡¼¤¬È¯À¸¤·¤¿¾ì¹ç¤Ï Mysql::Error Îã³°¤¬È¯À¸¤·¤Þ¤¹¡£

ÆÃ¤Ë°ÕÌ£¤Î¤¢¤ëÃͤòÊÖ¤µ¤Ê¤¤´Ø¿ô¤Ï self ¤òÊÖ¤·¤Þ¤¹¡£

Mysql ¥¯¥é¥¹

MySQL ¤òÁàºî¤¹¤ë¤¿¤á¤Î¥¯¥é¥¹¤Ç¤¹¡£

¥¯¥é¥¹¥á¥½¥Ã¥É

init()

Mysql ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤·¤Þ¤¹¡£mysqld ¤ËÀܳ¤Ï¤·¤Þ¤»¤ó¡£ Mysql#options() ¤¬É¬Íפʾì¹ç¤Ï¡¢¤³¤ì¤ò¸Æ¤ó¤À¸å¤Ë¹Ô¤Ê¤¤¤Þ¤¹¡£

real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil)
connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil)
new(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil)

mysqld ¤ËÀܳ¤·¡¢Mysql ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤·¤Þ¤¹¡£ flag ¤ÎÄê¿ô¤Ï C API ¤Î¤â¤Î¤ÈƱ¤¸¤Ç¤¹¡£

Îã) Mysql::CLIENT_FOUND_ROWS

escape_string(str)
quote(str)

insert, update ÍѤËʸ»úÎó¤ò¥¯¥ª¡¼¥È¤·¤Þ¤¹¡£

get_client_info()
client_info()

¥¯¥é¥¤¥¢¥ó¥È¥Ð¡¼¥¸¥ç¥ó¾ðÊó¤Îʸ»úÎó¤òÊÖ¤·¤Þ¤¹¡£

get_client_version()
client_version()

¥¯¥é¥¤¥¢¥ó¥È¥Ð¡¼¥¸¥ç¥ó¾ðÊó¤ò¿ôÃͤÇÊÖ¤·¤Þ¤¹¡£

debug(str)

C API mysql_debug() ¤ÈƱ¤¸¡£

¥ª¥Ö¥¸¥§¥¯¥È¥á¥½¥Ã¥É

options(opt, val=nil)

C API ¤Î mysql_options() ¤ÈƱ¤¸¤Ç¤¹¡£ opt ¤Ë»ØÄꤹ¤ëÄê¿ô¤Ï C API ¤«¤é MYSQL_ ÀÜÆ¬¼­¤ò¼è¤ê½ü¤¤¤¿¤â¤Î¤Ç¤¹¡£

Îã) Mysql::OPT_CONNECT_TIMEOUT

real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil)
connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil)

Mysql.real_connect() ¤ÈƱ¤¸¤Ç¤¹¡£Mysql.init() ¤ÇÀ¸À®¤·¤¿¥ª¥Ö¥¸¥§¥¯¥È¤ò¥µ¡¼¥Ð¤ËÀܳ¤¹¤ë¤¿¤á¤Ë»ÈÍѤ·¤Þ¤¹¡£

affected_rows()

±Æ¶Á¤µ¤ì¤¿¹Ô¿ô¤òÊÖ¤·¤Þ¤¹¡£

autocommit(mode)

autocommit ¥â¡¼¥É¤ò mode ¤ËÀßÄꤷ¤Þ¤¹¡£mode ¤¬ nil, false, 0 ¤Î»þ¤Ï¥ª¥Õ¡¢¤½¤ì°Ê³°¤Î¾ì¹ç¤Ï¥ª¥ó¤Ç¤¹¡£

change_user(user=nil, passwd=nil, db=nil)

Àܳ¥æ¡¼¥¶¤òÊѹ¹¤·¤Þ¤¹¡£

character_set_name()

¸½ºß¤Îʸ»ú¥»¥Ã¥È¤òÊÖ¤·¤Þ¤¹¡£

close()

Àܳ¤òÀÚÃǤ·¤Þ¤¹¡£

commit()

¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤ò¥³¥ß¥Ã¥È¤·¤Þ¤¹¡£

create_db(db)

¥Ç¡¼¥¿¥Ù¡¼¥¹¤òºîÀ®¤·¤Þ¤¹¡£

drop_db(db)

¥Ç¡¼¥¿¥Ù¡¼¥¹¤òÇË´þ¤·¤Þ¤¹¡£

dump_debug_info()

C API mysql_dump_debug_info() ¤ÈƱ¤¸¡£

errno()

¥¨¥é¡¼ÈÖ¹æ¤òÊÖ¤·¤Þ¤¹¡£

error()

¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤òÊÖ¤·¤Þ¤¹¡£

escape_string(str)
quote(str)

insert, update ÍѤËʸ»úÎó¤ò¥¯¥ª¡¼¥È¤·¤Þ¤¹¡£ C API ¤Î mysql_real_escape_string() ¤ÈƱ¤¸¡£

field_count()

ºÇ¸å¤Ë¼Â¹Ô¤µ¤ì¤¿¥¯¥¨¥ê¤Î¹àÌÜ¿ô¤òÊÖ¤·¤Þ¤¹¡£

get_client_info()
client_info()

¥¯¥é¥¤¥¢¥ó¥È¥Ð¡¼¥¸¥ç¥ó¾ðÊó¤Îʸ»úÎó¤òÊÖ¤·¤Þ¤¹¡£

get_client_version()
client_version()

¥¯¥é¥¤¥¢¥ó¥È¥Ð¡¼¥¸¥ç¥ó¾ðÊó¤ò¿ôÃͤÇÊÖ¤·¤Þ¤¹¡£

get_host_info()
host_info()

Àܳ¾ðÊó¤òʸ»úÎó¤ÇÊÖ¤·¤Þ¤¹¡£

get_proto_info()
proto_info()

Àܳ¥×¥í¥È¥³¥ë¥Ð¡¼¥¸¥ç¥ó¤ò¿ôÃͤÇÊÖ¤·¤Þ¤¹¡£

get_server_info()
server_info()

¥µ¡¼¥Ð¤Î¥Ð¡¼¥¸¥ç¥ó¾ðÊó¤òʸ»úÎó¤ÇÊÖ¤·¤Þ¤¹¡£

get_server_version()
server_version()

¥µ¡¼¥Ð¤Î¥Ð¡¼¥¸¥ç¥ó¾ðÊó¤ò¿ôÃͤÇÊÖ¤·¤Þ¤¹¡£

info()

ľÁ°¤Î¥¯¥¨¥ê¤Î¾ðÊó¤òʸ»úÎó¤ÇÊÖ¤·¤Þ¤¹¡£ÆÃ¤Ë¾ðÊ󤬤ʤ±¤ì¤Ð nil ¤¬ÊÖ¤ê¤Þ¤¹¡£

insert_id()

ºÇ¸å¤ËÀ¸À®¤µ¤ì¤¿ AUTO_INCREMENT ¹àÌܤÎÃͤòÊÖ¤·¤Þ¤¹¡£

kill(id)

id ¤Ç»ØÄꤷ¤¿¥¹¥ì¥Ã¥É¤ò»¦¤·¤Þ¤¹¡£

list_dbs(db=nil)

¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î°ìÍ÷¤òÇÛÎó¤ÇÊÖ¤·¤Þ¤¹¡£

list_fields(table, field=nil)

¥Æ¡¼¥Ö¥ëÆâ¤Î¹àÌܾðÊó¤Î°ìÍ÷¤ò¼¨¤¹ Mysql::Result ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤·¤Þ¤¹¡£

list_processes()

¥µ¡¼¥Ð¾å¤Î¸½ºß¤Î¥¹¥ì¥Ã¥É¤Î°ìÍ÷¤ò¼¨¤¹ Mysql::Result ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤·¤Þ¤¹¡£

list_tables(table=nil)

¥Æ¡¼¥Ö¥ë¤Î°ìÍ÷¤òÇÛÎó¤ÇÊÖ¤·¤Þ¤¹¡£

more_results?()

¼èÆÀ¤·¤Æ¤¤¤Ê¤¤¥¯¥¨¥ê·ë²Ì¤¬¤¢¤ë¾ì¹ç¤Ï¿¿¤òÊÖ¤·¤Þ¤¹¡£

next_result()

¼èÆÀ¤·¤Æ¤¤¤Ê¤¤¥¯¥¨¥ê·ë²Ì¤¬¤¢¤ë¾ì¹ç¤Ï¿¿¤òÊÖ¤·¤Þ¤¹¡£ ¤³¤Î¸å¤Ë store_result() ¤ò¼Â¹Ô¤¹¤ë¤È¥¯¥¨¥ê·ë²Ì¤ò¼èÆÀ¤Ç¤­¤Þ¤¹¡£

ping()

¥µ¡¼¥Ð¤¬À¸¤­¤Æ¤¤¤ë¤«¤É¤¦¤«¤ò¥Á¥§¥Ã¥¯¤·¤Þ¤¹¡£

prepare(q)

¥¯¥¨¥ê¤ò¥µ¡¼¥Ð¤ËÁ÷¤ê¤Þ¤¹¡£¤³¤Î»þÅÀ¤Ç¤Ï¤Þ¤À¼Â¹Ô¤µ¤ì¤Þ¤»¤ó¡£ Mysql::Stmt ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤·¤Þ¤¹¡£

Mysql#stmt_init.prepare(q) ¤ÈƱ¤¸¤Ç¤¹¡£

query(q)
real_query(q)

¥¯¥¨¥ê¤ò¼Â¹Ô¤·¤Þ¤¹¡£ ¥¯¥¨¥ê¤¬·ë²Ì¤òÊÖ¤¹¾ì¹ç¡¢¼«Æ°Åª¤Ë store_result() ¤â¼Â¹Ô¤·¤Æ¡¢Mysql::Result ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤·¤Þ¤¹¡£ query_with_result ¤Ë false ¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ì¤Ð¡¢store_result() ¤Ï¼Â¹Ô¤·¤Þ¤»¤ó¡£

query(q) {|res| ...}
real_query(q) {|res| ...}

¥¯¥¨¥ê¤ò¼Â¹Ô¤·¤Þ¤¹¡£ ¥¯¥¨¥ê¤¬·ë²Ì¤òÊÖ¤¹¾ì¹ç¡¢Mysql::Result ¥ª¥Ö¥¸¥§¥¯¥È¤ò°ú¿ô¤È¤·¤Æ¥Ö¥í¥Ã¥¯¤ò¼Â¹Ô¤·¤Þ¤¹¡£ ¥Ö¥í¥Ã¥¯½ªÎ»»þ¤Ë Mysql::Result ¥ª¥Ö¥¸¥§¥¯¥È¤Ï²òÊü¤µ¤ì¤Þ¤¹¡£ ¥Þ¥ë¥Á¥¹¥Æ¡¼¥È¥á¥ó¥È¥â¡¼¥É¤Ç¡¢°ú¿ô¤Ë¡Ö;¡×¤Ç¶èÀÚ¤é¤ì¤¿Ê£¿ô¤Î¥¯¥¨¥ê¤ò»ØÄꤷ¤¿¾ì¹ç¤Ï¡¢¥¯¥¨¥ê¤Î¿ô¤À¤±¥Ö¥í¥Ã¥¯¤ò·«¤êÊÖ¤·¤Þ¤¹¡£

MySQL/Ruby 2.8 ¤«¤é¤Ï¡¢¼«Æ°Åª¤Ë¥Þ¥ë¥Á¥¹¥Æ¡¼¥È¥á¥ó¥È¥â¡¼¥É¤Ë¤Ï¤Ê¤é¤Ê¤¯¤Ê¤ê¤Þ¤·¤¿¡£ Mysql.connect ¤Î flag ¤Ë Mysql::CLIENT_MULTI_STATEMENTS ¤ò»ØÄꤹ¤ë¤«¡¢Mysql#set_server_option(Mysql::OPTION_MULTI_STATEMENTS_ON) ¤ò¼Â¹Ô¤·¤Æ¤¯¤À¤µ¤¤¡£

refresh(r)

¥µ¡¼¥Ð¤Î¥í¥°¤ä¥­¥ã¥Ã¥·¥åÅù¤ò¥Õ¥é¥Ã¥·¥å¤·¤Þ¤¹¡£

reload()

¥¢¥¯¥»¥¹¸¢¥Æ¡¼¥Ö¥ë¤òºÆÆÉ¤ß¹þ¤ß¤·¤Þ¤¹¡£

rollback()

¥È¥é¥ó¥¶¥¯¥·¥ç¥ó¤ò¥í¡¼¥ë¥Ð¥Ã¥¯¤·¤Þ¤¹¡£

select_db(db)

¥Ç¡¼¥¿¥Ù¡¼¥¹¤òÁªÂò¤·¤Þ¤¹¡£

set_server_option(opt)

°ú¿ô¤Ç»ØÄꤷ¤¿¥ª¥×¥·¥ç¥ó¤ò¥µ¡¼¥Ð¤ËÀßÄꤷ¤Þ¤¹¡£ °ú¿ô¤Ë¤Ï¡¢Mysql::OPTION_MULTI_STATEMENTS_ON, Mysql::OPTION_MULTI_STATEMENTS_OFF ¤¬»ØÄê¤Ç¤­¤Þ¤¹¡£

shutdown()

¥µ¡¼¥Ð¤òÄä»ß¤·¤Þ¤¹¡£

ssl_set(key=nil, cert=nil, ca=nil, capath=nil, cipher=nil)

SSLÀܳ¤ò»ÈÍѤ·¤Þ¤¹¡£Mysql.init() ¸å¡¢Mysql#connect() Á°¤Ë¹Ô¤Ê¤¦É¬Íפ¬¤¢¤ê¤Þ¤¹¡£

stat()

¥µ¡¼¥Ð¤Î¾õÂÖ¤òʸ»úÎó¤ÇÊÖ¤·¤Þ¤¹¡£

stmt_init()

Mysql::Stmt ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤·¤Þ¤¹¡£

store_result()

¥¯¥¨¥ê¤Î·ë²Ì¤Î Mysql::Result ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤·¤Þ¤¹¡£

thread_id()

¸½ºß¤ÎÀܳ¤Î¥¹¥ì¥Ã¥ÉID¤òÊÖ¤·¤Þ¤¹¡£

use_result()

¥¯¥¨¥ê¤Î·ë²Ì¤Î Mysql::Result ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤·¤Þ¤¹¡£

warning_count()

ľÁ°¤Î¥¯¥¨¥ê¤Î·Ù¹ð¿ô¤òÊÖ¤·¤Þ¤¹¡£

¥ª¥Ö¥¸¥§¥¯¥ÈÊÑ¿ô

query_with_result

true ¤ËÀßÄꤹ¤ë¤È query() »þ¤Ë store_result() ¤â¼Â¹Ô¤·¤Æ¡¢Mysql::Result ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤·¤Þ¤¹¡£ false ¤ËÀßÄꤹ¤ë¤È¤½¤Îưºî¤Ï¹Ô¤ï¤ì¤Þ¤»¤ó¡£¥Ç¥Õ¥©¥ë¥È¤Ï true ¤Ç¤¹¡£

reconnect

true ¤ËÀßÄꤹ¤ë¤È MySQL ¥µ¡¼¥Ð¤È¤ÎÀܳ¤¬Àڤ줿¤È¤­¤Ë¼«Æ°Åª¤ËºÆÀܳ¤·¤Þ¤¹¡£ ¥Ç¥Õ¥©¥ë¥È¤Ï false ¤Ç¤¹¡£

Mysql::Result ¥¯¥é¥¹

¥¯¥¨¥ê·ë²Ì¤Î¥¯¥é¥¹¤Ç¤¹¡£

¥ª¥Ö¥¸¥§¥¯¥È¥á¥½¥Ã¥É

free()

·ë²Ì¥Æ¡¼¥Ö¥ëÍÑ¥á¥â¥ê¤ò²òÊü¤·¤Þ¤¹¡£

data_seek(offset)

¸½ºß¤Î¹Ô¤Î°ÌÃÖ¤ò offset ÈÖÌܤιԤˤ·¤Þ¤¹¡£

fetch_field()

¸½ºß¤Î¹àÌܤΠMysql::Field ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤·¤Þ¤¹¡£ ¼¡¤Ë¸Æ¤Ð¤ì¤¿»þ¤Ï¼¡¤Î¹àÌܤòÊÖ¤·¤Þ¤¹¡£

fetch_fields()

¹àÌÜÁ´ÂΤòɽ¤¹ Mysql::Field ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤ÎÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£

fetch_field_direct(fieldnr)

fieldnr ÈÖÌܤιàÌܤΠMysql::Field ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤òÊÖ¤·¤Þ¤¹¡£

fetch_lengths()

¸½ºß¤Î¹Ô¤Î³Æ¹àÌÜÃͤÎŤµ¤ÎÇÛÎó¤òÊÖ¤·¤Þ¤¹¡£

fetch_row()

¸¡º÷·ë²Ì¤Î£±¹Ô¤òÊÖ¤·¤Þ¤¹¡£¼¡¤Ë¸Æ¤Ð¤ì¤¿»þ¤Ï¼¡¤Î¹Ô¤òÊÖ¤·¤Þ¤¹¡£ Ìá¤êÃͤϹàÌÜÃͤÎÇÛÎó¤Ç¤¹¡£

fetch_hash(with_table=false)

¸¡º÷·ë²Ì¤Î£±¹Ô¤òÊÖ¤·¤Þ¤¹¡£¼¡¤Ë¸Æ¤Ð¤ì¤¿»þ¤Ï¼¡¤Î¹Ô¤òÊÖ¤·¤Þ¤¹¡£ Ìá¤êÃͤϹàÌÜ̾¤ò¥­¡¼¤È¤·¤¿¹àÌÜÃͤΥϥå·¥å¤Ç¤¹¡£ with_table ¤¬ true ¤Î¾ì¹ç¤Ï¥­¡¼¤Ë¥Æ¡¼¥Ö¥ë̾¤âÉղ䵤졢"¥Æ¡¼¥Ö¥ë̾.¹àÌÜ̾" ¤È¤¤¤¦·Á¼°¤Î¥­¡¼¤Ë¤Ê¤ê¤Þ¤¹¡£

field_seek(offset)

¸½ºß¤Î¹àÌܰÌÃÖ¤ò offset ÈÖÌܤιàÌܤˤ·¤Þ¤¹¡£

field_tell()

¸½ºß¤Î¹àÌܤΰÌÃÖ¤òÊÖ¤·¤Þ¤¹¡£

num_fields()

¹àÌÜ¿ô¤òÊÖ¤·¤Þ¤¹¡£

num_rows()

¸¡º÷·ï¿ô¤òÊÖ¤·¤Þ¤¹¡£

row_seek(offset)

¸½ºß¤Î¹Ô¤Î°ÌÃÖ¤òÀßÄꤷ¤Þ¤¹¡£ offset ¤ÏÆâÉôɽ¸½¤Ç row_tell() ¤¬ÊÖ¤·¤¿ Mysql::RowOffset ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¹¡£

row_tell()

¸½ºß¤Î¹Ô¤Î°ÌÃÖ¤ò Mysql::RowOffset ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤ÇÊÖ¤·¤Þ¤¹¡£

¥¤¥Æ¥ì¡¼¥¿

each() {|x| ¡Á}

¸¡º÷·ë²Ì¤Î³Æ¹Ô¤´¤È¤Ë {¡Á} ¤ò·«¤êÊÖ¤·¤Þ¤¹¡£x ¤Ï¹àÌÜÃͤÎÇÛÎó¤Ç¤¹¡£

each_hash(with_table=false) {|x| ¡Á}

¸¡º÷·ë²Ì¤Î³Æ¹Ô¤´¤È¤Ë {¡Á} ¤ò·«¤êÊÖ¤·¤Þ¤¹¡£ x ¤Ï¹àÌÜ̾¤ò¥­¡¼¤È¤·¤¿¹àÌÜÃͤΥϥå·¥å¤Ç¤¹¡£ with_table ¤¬ true ¤Î¾ì¹ç¤Ï¥­¡¼¤Ë¥Æ¡¼¥Ö¥ë̾¤âÉղ䵤졢"¥Æ¡¼¥Ö¥ë̾.¹àÌÜ̾" ¤È¤¤¤¦·Á¼°¤Î¥­¡¼¤Ë¤Ê¤ê¤Þ¤¹¡£

Mysql::Field ¥¯¥é¥¹

¹àÌܤξܺ٤òɽ¤¹¥¯¥é¥¹¤Ç¤¹¡£C API ¤È°Û¤Ê¤ê¡¢¥ª¥Ö¥¸¥§¥¯¥È¤Ï Mysql::Result ¤È¤ÏÆÈΩ¤·¤ÆÂ¸ºß¤¹¤ë¤Î¤Ç¡¢Mysql::Result ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤¬²òÊü¤µ¤ì¤¿¸å¤Ç¤âÍøÍѤǤ­¤Þ¤¹¡£¤¬¡¢¤½¤Î¤¿¤á C API ¤è¤ê¤â¥á¥â¥ê¤ò»ÈÍѤ·¤Þ¤¹¡£

¥ª¥Ö¥¸¥§¥¯¥ÈÊÑ¿ô(ÆÉ¤ß½Ð¤·¤Î¤ß)

name
¹àÌÜ̾
table
¥Æ¡¼¥Ö¥ë̾
def
¥Ç¥Õ¥©¥ë¥ÈÃÍ
type
¹àÌܤη¿
length
¹àÌܤÎŤµ
max_length
¸¡º÷·ë²ÌÃæ¤Î¹àÌÜÃͤκÇÂçĹ
flags
¥Õ¥é¥°
decimals
¾®¿ôÉô·å¿ô

type ¤ËÂбþ¤¹¤ëÄê¿ô¤Ï C API ¤Î¤â¤Î¤«¤é FIELD_ ÀÜÆ¬¼­¤ò½ü¤¤¤¿¤â¤Î¤Ç¤¹¡£

Îã) Mysql::Field::TYPE_STRING

flag ¤ËÂбþ¤¹¤ëÄê¿ô¤Ï C API ¤Î¤â¤Î¤ÈƱ¤¸¤Ç¤¹¡£

Îã) Mysql::Field::BLOB_FLAG

¥ª¥Ö¥¸¥§¥¯¥È¥á¥½¥Ã¥É

hash()

¾åµ­¤ÎÊÑ¿ô̾¤ò¥­¡¼¤È¤¹¤ë¥Ï¥Ã¥·¥å¤òÊÖ¤·¤Þ¤¹¡£

Îã) obj.name == obj.hash['name']

is_not_null?()

¥Õ¥£¡¼¥ë¥É¤¬ "NOT NULL" ¤ÈÄêµÁ¤µ¤ì¤Æ¤¤¤ì¤Ð¿¿¤òÊÖ¤·¤Þ¤¹¡£

is_num?()

¥Õ¥£¡¼¥ë¥É¤¬¿ôÃͤξì¹ç¤Ï¿¿¤òÊÖ¤·¤Þ¤¹¡£

is_pri_key?()

¥Õ¥£¡¼¥ë¥É¤¬¥×¥é¥¤¥Þ¥ê¥­¡¼¤Î¾ì¹ç¤Ï¿¿¤òÊÖ¤·¤Þ¤¹¡£

inspect()

ʸ»úÎó "#<Mysql::Field:¹àÌÜ̾>" ¤òÊÖ¤·¤Þ¤¹¡£

Mysql::Stmt ¥¯¥é¥¹

MySQL ¤Ç¥×¥ê¥Ú¥¢¥É¥¹¥Æ¡¼¥È¥á¥ó¥È¤ò°·¤¦¤¿¤á¤Î¥¯¥é¥¹¤Ç¤¹¡£

»ÈÍÑÎã:

my = Mysql.new(hostname, username, password, databasename)
st = my.prepare("insert into tblname (col1,col2,col3) values (?,?,?)")
st.execute("abc",123,Time.now)
st.prepare("select col1,col2,col3 from tblname")
st.execute
st.fetch  # => ["abc", 123, #<Mysql::Time:2005-07-24 23:52:55>]
st.close

¥ª¥Ö¥¸¥§¥¯¥È¥á¥½¥Ã¥É

affected_rows()

±Æ¶Á¤µ¤ì¤¿¹Ô¿ô¤òÊÖ¤·¤Þ¤¹¡£

bind_result(class, ...)

·ë²Ì¤òÊÖ¤¹¥¯¥¨¥ê¤Î¾ì¹ç¤Ë¡¢¼è¤ê½Ð¤µ¤ì¤ëÃͤΥ¯¥é¥¹¤ò»ØÄꤷ¤Þ¤¹¡£ »ØÄê¤Ç¤­¤ë¥¯¥é¥¹¤Ï¡¢Numeric, Integer, Fixnum, Float, Mysql::Time ¤Ç¤¹¡£ nil ¤ò»ØÄꤹ¤ë¤È¡¢¼«Æ°È½Ê̤·¤Þ¤¹¡£ bind_result ¤ò¼Â¹Ô¤·¤Ê¤¤¾ì¹ç¤Ï¼«Æ°È½Ê̤·¤Þ¤¹¡£

close()

Mysql::Stmt ¥ª¥Ö¥¸¥§¥¯¥È¤ò²òÊü¤·¤Þ¤¹¡£

data_seek(offset)

¼¡¤Ë fetch() ¤Ç¼è¤ê½Ð¤µ¤ì¤ë¹Ô¤ò offset ÈÖÌܤιԤˤ·¤Þ¤¹¡£ offset ¤Ï 0 ¤«¤é»Ï¤Þ¤ê¤Þ¤¹¡£

execute(arg, ...)

prepare() ¤·¤¿¥¯¥¨¥ê¤Ë¥Ñ¥é¥á¡¼¥¿¤òÍ¿¤¨¤Æ¼Â¹Ô¤·¤Þ¤¹¡£

fetch()

execute() ¤Ç¼Â¹Ô¤·¤¿¥¯¥¨¥ê¤Î·ë²Ì¤ÎÃͤòÇÛÎó¤Ç¼è¤ê½Ð¤·¤Þ¤¹¡£ ÃͤòÊÖ¤µ¤Ê¤¤¥¯¥¨¥ê¤Î¾ì¹ç¤ä¡¢ºÇ¸å¤Þ¤Ç¼è¤ê½Ð¤·¤¿¾ì¹ç¤Ï nil ¤òÊÖ¤·¤Þ¤¹¡£

ÇÛÎó¤Î³ÆÍ×ÁÇ¤Ï MySQL ¤Î·¿¤Ë±þ¤¸¤Æ¼¡¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£

MySQL¤Î·¿Ruby¤Î¥¯¥é¥¹
TINYINT, SMALLINT, MEDIUMINT, YEARFixnum
INT, BIGINTFixnum¤Þ¤¿¤ÏBignum
FLOAT, DOUBLEFloat
DECIMALString
DATE, DATETIME, TIMESTAMP, TIMEMysql::Time
CHAR, VARCHAR, BINARY, VARBINARY, TINYBLOB, TINYTEXT, TINYBLOB, TINYTEXT, MEDIUMBLOB, MEDIUMTEXT, LONGBLOB, LONGTEXT, ENUM, SET, BITString
NULLNilClass
field_count()

prepare ¤·¤¿¥¯¥¨¥ê¤¬ÊÖ¤¹·ë²Ì¤Î¥Õ¥£¡¼¥ë¥É¿ô¤òÊÖ¤·¤Þ¤¹¡£

free_result()

¸¡º÷·ë²Ì¤ò²òÊü¤·¤Þ¤¹¡£

insert_id()

À¸À®¤µ¤ì¤¿ AUTO_INCREMENT ¹àÌܤÎÃͤòÊÖ¤·¤Þ¤¹¡£

num_rows()

¸¡º÷·ë²Ì¤Î¹Ô¿ô¤òÊÖ¤·¤Þ¤¹¡£

param_count()

prepare() ¤·¤¿¥¯¥¨¥ê¤Î¥Ñ¥é¥á¡¼¥¿¡Ö?¡×¤Î¿ô¤òÊÖ¤·¤Þ¤¹¡£

prepare(q)

¥¯¥¨¥ê¤ò¥µ¡¼¥Ð¤ËÁ÷¤ê¤Þ¤¹¡£¤³¤Î»þÅÀ¤Ç¤Ï¤Þ¤À¼Â¹Ô¤µ¤ì¤Þ¤»¤ó¡£ execute() ¤Ç¼Â¹Ô¤µ¤ì¤Þ¤¹¡£

result_metadata()

prepare() ¤·¤¿¥¯¥¨¥ê¤ÎÊÖ¤µ¤ì¤ë·ë²Ì¤Î¥Õ¥£¡¼¥ë¥É¤ò Mysql::Result ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤ÇÊÖ¤·¤Þ¤¹¡£

row_seek(offset)

¼¡¤Ë fetch() ¤Ç¼è¤ê½Ð¤µ¤ì¤ë¹Ô¤ò offset ¤Î°ÌÃ֤ˤ·¤Þ¤¹¡£ data_seek ¤È°Û¤Ê¤ê offset ¤Ï row_tell() ¤ÇÊÖ¤µ¤ì¤ë Mysql::RowOffset ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤Ç¤¹¡£

row_tell()

¸½ºß¤Î¹Ô¤Î°ÌÃÖ¤ò Mysql::RowOffset ¥¯¥é¥¹¥ª¥Ö¥¸¥§¥¯¥È¤ÇÊÖ¤·¤Þ¤¹¡£

sqlstate()

¥¨¥é¡¼¥³¡¼¥É¤ò SQLSTATE ʸ»úÎó¤ÇÊÖ¤·¤Þ¤¹¡£

¥¤¥Æ¥ì¡¼¥¿

each() {|x| ¡Á}

¸¡º÷·ë²Ì¤Î³Æ¹Ô¤´¤È¤Ë {¡Á} ¤ò·«¤êÊÖ¤·¤Þ¤¹¡£ x ¤Ï fetch() ¤ÇÊÖ¤µ¤ì¤ë¤â¤Î¤ÈƱ¤¸ÇÛÎó¤Ç¤¹¡£

Mysql::Time ¥¯¥é¥¹

Mysql::Stmt ¤Ç»È¤ï¤ì¤ëÆü»þ¤òɽ¤¹¤¿¤á¤Î¥¯¥é¥¹¤Ç¤¹¡£

¥¯¥é¥¹¥á¥½¥Ã¥É

new(year=0,month=0,day=0,hour=0,minute=0,second=0,neg=false,second_part=0)

Mysql::Time¥¯¥é¥¹¤òºîÀ®¤·¤Þ¤¹¡£

¥ª¥Ö¥¸¥§¥¯¥ÈÊÑ¿ô

year
ǯ
month
·î
day
Æü
hour
»þ
minute
ʬ
second
ÉÃ
neg
»þ¹ï¤¬Àµ¤Î¾ì¹ç¤Ï false, Éé¤Î¾ì¹ç¤Ï true
second_part
Éäξ®¿ôÅÀ°Ê²¼¡£Ì¤»ÈÍÑ

Mysql::Error ¥¯¥é¥¹

MySQL ¤Î¥¨¥é¡¼¤òɽ¤ï¤¹¥¯¥é¥¹¤Ç¤¹¡£ MySQL ¤Î¥¨¥é¡¼¤¬È¯À¸¤·¤¿¾ì¹ç¤ËÎã³°¤È¤·¤ÆÀ¸À®¤µ¤ì¤Þ¤¹¡£

¥ª¥Ö¥¸¥§¥¯¥ÈÊÑ¿ô(ÆÉ¤ß½Ð¤·¤Î¤ß)

error
¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸
errno
¥¨¥é¡¼ÈÖ¹æ

errno ¤ËÂбþ¤¹¤ëÄê¿ô¤Ï C API ¤Î¤â¤Î¤ÈƱ¤¸¤Ç¤¹¡£

Îã) Mysql::Error::CR_UNKNOWN_HOST

ÍúÎò

2010-02-11
version 2.8.2
  • Fix: Mysql#insert_id ¤¬ 2**32 °Ê¾å¤Î»þ¤ËÉÔÀµ¤ÊÃͤòÊÖ¤¹¡£
2009-02-01
version 2.8.1
  • Ruby 1.9.1 ¤ËÂбþ¡£
2008-09-29
version 2.8
version 2.7.7
  • MySQL¤Ø¤ÎÀܳ»þ¤Ë SIGVTALRM ¤Ç EINTR ¤Ë¤Ê¤ë¤³¤È¤¬¤¢¤ëÌäÂê¤ò½¤Àµ ([ruby-dev:31842])
  • MySQL/Ruby 2.7.* ¤¬ Ruby 1.8.5 ¤Ç¥³¥ó¥Ñ¥¤¥ë¤Ç¤­¤Ê¤«¤Ã¤¿¡£
2008-06-20
version 2.8pre4
  • ¥¨¥é¡¼ÄêµÁ¥Õ¥¡¥¤¥ë¤ò³°¤À¤·¡£¤½¤Î¾¡£[ruby-dev:35152]
2008-06-17
version 2.8pre3
version 2.7.6
  • 64bit ´Ä¶­¤Ç Mysql::Stmt#execute ¤ÇÂ礭¤Ê¿ôÃÍ(2**30 °Ê¾å)¤Ç¥¨¥é¡¼¤Ë¤Ê¤ëÌäÂê¤ò½¤Àµ¡£
2008-03-08
version 2.8pre2
version 2.7.5
  • 64bit ´Ä¶­¤Ç Mysql::Stmt#fetch ¤Ç¿ôÃͤ¬²õ¤ì¤ëÌäÂê¤ò½¤Àµ¡£
2007-12-26
version 2.8pre1
  • Ruby 1.9.0 Âбþ
  • Incompat: Mysql::Result#each_hash ¤¬¹ÔËè¤Ë¥«¥é¥à̾ʸ»úÎó¤òÀ¸À®¤¹¤ë¤Î¤Ç¤Ï¤Ê¤¯¡¢¶¦Í­¤¹¤ë¤è¤¦¤Ë¤·¤¿¡£
  • Incompat: ¥Ö¥í¥Ã¥¯¤Ä¤­ Mysql#query ¤Ç¼«Æ°Åª¤Ë¥Þ¥ë¥Á¥¹¥Æ¡¼¥È¥á¥ó¥È¥â¡¼¥É¤Ë¤Ê¤é¤Ê¤¤¤è¤¦¤Ë¤·¤¿¡£
2007-08-22
version 2.7.4
  • BUG: Mysql::Stmt#execute ¤¬¥á¥â¥ê¥ê¡¼¥¯¤·¤Æ¤¤¤¿¡£
2006-12-20
version 2.7.3
  • BUG: ¥Ö¥í¥Ã¥¯¤Ä¤­ Mysql#query ¤¬¡¢ºÇ¸å¤Î¥¯¥¨¥ê¤¬¥¨¥é¡¼¤Î¾ì¹ç¤ËÄä»ß¤·¤Æ¤·¤Þ¤¦¡£
2006-10-28
version 2.7.2
  • BUG: ·ë²Ì¤òÊÖ¤µ¤Ê¤¤¥¯¥¨¥ê¤Ç Mysql::Stmt#result_metadata ¤¬ nil ¤òÊѤ¨¤¹¤è¤¦¤Ë¤·¤¿ (Thanks to Hidetoshi)
  • BUG: Mysql#close ¤Ç mysql_errno ¤ò¸«¤Ê¤¤¤è¤¦¤ËÊѹ¹
  • BUG: ¥Ö¥í¥Ã¥¯¤Ä¤­ Mysql#query ¤ÇÊ£¿ô¥¹¥Æ¡¼¥È¥á¥ó¥È»þ¤Ë¥¨¥é¡¼¤ò̵»ë¤·¤Æ¤¤¤¿¡£
  • extconf.rb ¤Î Visual C++ Âбþ (Thanks to Shugo Maeda)
  • BIT·¿¤ËÂбþ
  • Mysql::Field ¤Ë TYPE_BIT, TYPE_NEWDECIMAL ÄɲÃ
2006-06-04
version 2.7.1
  • free() ¤ò xfree() ¤ËÊѹ¹¡£Windows ¤Ç¤Î¥¯¥é¥Ã¥·¥å¤Î²óÈò¤Î¤¿¤á¡£(Tobias Grimm ¤Ë´¶¼Õ)
2005-08-22
version 2.7
  • Mysql#optionsÍÑÄê¿ôÄɲá£Mysql::OPT_GUESS_CONNECTION, Mysql::OPT_USE_EMBEDDED_CONNECTION, Mysql::OPT_USE_REMOTE_CONNECTION, Mysql::SET_CLIENT_IP
  • test.rb: 4.0.x, 5.0.x Âбþ
2005-08-16
version 2.7-beta3
  • Mysql::Stmt#bind_result ÄɲÃ
2005-08-02
version 2.7-beta2
  • BUG: mysql.c.in: fetch_hash: Ãͤ¬ nil ¤ÎÍ×ÁǤ¬¥Ï¥Ã¥·¥å¤Ë´Þ¤Þ¤ì¤Ê¤¤¡£(Stefan Kaes ¤Ë´¶¼Õ)
  • Äê¿ô Mysql::VERSION ÄɲÃ
  • Mysql#prepare ÄɲÃ
2005-07-24
version 2.7-beta
  • Mysql#stmt_init ÄɲÃ
  • Mysql::Stmt, Mysql::Time, Mysql::RowOffset ¥¯¥é¥¹ÄɲÃ
  • Mysql::Error#sqlstate ÄɲÃ
  • Mysql::Result#row_seek,row_tell ¤¬°·¤¦ offset Ãͤò Mysql::RowOffset ¥ª¥Ö¥¸¥§¥¯¥È¤ËÊѹ¹
2005-07-31
version 2.6.3
  • Äê¿ô Mysql::VERSION ÄɲÃ
2005-07-26
version 2.6.2
  • BUG: mysql.c.in: fetch_hash: Ãͤ¬ nil ¤ÎÍ×ÁǤ¬¥Ï¥Ã¥·¥å¤Ë´Þ¤Þ¤ì¤Ê¤¤¡£(Stefan Kaes ¤Ë´¶¼Õ)
2005-06-28
version 2.6.1
  • mysql.c.in: MacOSX ¤Ç¤Î¥³¥ó¥Ñ¥¤¥ë¥¨¥é¡¼¤ò½¤Àµ¡£
2005-04-25
version 2.6
  • Mysql#option() ÍѤÎÄê¿ôÄɲà Mysql::OPT_PROTOCOL, Mysql::OPT_READ_TIMEOUT, Mysql::OPT_WRITE_TIMEOUT, Mysql::SET_CHARSET_DIR, Mysql::SET_CHARSET_NAME, Mysql::SHARED_MEMORY_BASE_NAME, Mysql::SECURE_AUTH
  • Mysql#more_results?(), Mysql#next_result(), Mysql#set_server_option(), Mysql#sqlstate() ÄɲÃ
  • Mysql#connect() ¤Î¥Õ¥é¥°ÍÑÄê¿ôÄɲà Mysql::CLIENT_MULTI_STATEMENTS, Mysql::CLIENT_MULTI_RESULTS
  • Mysql#set_server_option() ÍѤÎÄê¿ôÄɲà Mysql::OPTION_MULTI_STATEMENTS_ON, Mysql::OPTION_MULTI_STATEMENTS_OFF
  • ¥Ö¥í¥Ã¥¯ÉÕ¤­ Mysql#query()
  • Mysql#reconnect(), Mysql#reconnect=() ÄɲÃ
  • MySQL ¤È¤ÎÀܳ¤¬Àڤ줿¤È¤­¤Ë¡¢¥Ç¥Õ¥©¥ë¥È¤Ç¤ÏºÆÀܳ¤·¤Ê¤¤¤è¤¦¤Ë¤·¤¿¡£
2005-02-12
version 2.5.2
  • BUG: Mysql#connect ¤ÇÀܳ¤¹¤ë¤ÈÀܳ¤¬ÀÚÃǤµ¤ì¤Ê¤¤¡£(Andres Salomon ¤Ë´¶¼Õ)
2004-09-20
version 2.5.1
  • Mysql#set_ssl() Äɲá£
2004-08-31
version 2.5
  • MySQL 4.1.x Âбþ
  • MysqlRes, MysqlField, MysqlError ¤ò Mysql::Result, Mysql::Field, Mysql::Error ¤ËÊѹ¹¡£
  • Mysql.client_version(), Mysql.get_client_version(), Mysql#client_version(), Mysql#get_client_version(), Mysql#server_version(), Mysql#get_server_version(), Mysql#warning_count(), Mysql#commit(), Mysql#rollback(), Mysql#autocommit() Äɲá£
  • Mysql::Field#is_not_null?(), Mysql::Field#is_pri_key?(), Mysql::Field#is_num?() Äɲá£
  • MysqlField::TYPE_VAR_STRING Äɲá£
2003-08-10
version 2.4.5
  • extconf.rb: MySQL 4.1 Âбþ¡£
  • mysql.c.in: Ruby 1.8 Âбþ¡£
2003-02-23
version 2.4.4a
  • extconf.rb ¤Î Ruby 1.8.0 Âбþ¡£
2003-01-29
version 2.4.4
  • Mysql::OPT_LOCAL_INFILE ¤òÄɲá£
  • extconf.rb ¤Ë --with-mysql-config ¥ª¥×¥·¥ç¥ó¤òÄɲÃ
  • extconf.rb »þ¤Ë¼ç¤Ê¥é¥¤¥Ö¥é¥ê¤ò¼«Æ°¸¡½Ð¤¹¤ë¤è¤¦¤Ë¤·¤¿¡£
2003-01-05
version 2.4.3c
  • ±Ñ¸ì¤Î README ¤Î²þÈÇ¡£Paul DuBois ¤Ë´¶¼Õ¡£
2002-12-24
version 2.4.3b
  • extconf.rb ¤Î Ruby 1.6.8 Âбþ¡£
2002-11-07
version 2.4.3a
  • ¥¨¥é¡¼Äê¿ô¤¬½ÅÊ£ÄêµÁ¤µ¤ì¤ë¤³¤È¤¬¤¢¤ë¥Ð¥°¤ò½¤Àµ¡£
2002-09-10
version 2.4.3
  • ER_ ¤Ç»Ï¤Þ¤ë¥¨¥é¡¼Äê¿ô¤Ë¤âÂбþ¤·¤¿¡£
  • errmsg.h ¤È mysqld_error.h ¤«¤é¼«Æ°Åª¤Ë¥¨¥é¡¼Äê¿ô¤ò¼èÆÀ¤¹¤ë¤è¤¦¤Ë¤·¤¿¡£
2002-01-07
version 2.4.2
  • MySQL 4.0 Âбþ¡£
  • uint ¤ò unsigned int ¤ËÊѹ¹¡ÊmswinÂбþ¡Ë¡£
2001-12-02
version 2.4.1
  • ÉÔÍ×¤Ê extern ¤òºï½ü¡ÊCygiwnÂбþ¡Ë¡£
  • extconf.rb ¤Î¥ª¥×¥·¥ç¥ó¤òÊѹ¹¡£
2001-10-12
version 2.4.0
  • Ruby 1.7 ¤ËÂбþ¡£
  • Mysql::debug(), Mysql#change_user(), Mysql#character_set_name(), Mysql#dump_debug_info() ¤òÄɲá£
2001-03-25
version 2.3.2a
  • t/50update.rb ¤ÎȽÄêÊýË¡¤òÊѹ¹
2001-03-19
version 2.3.2
  • °ìÄê¿ô(20²ó) MysqlRes ¥ª¥Ö¥¸¥§¥¯¥È¤òÀ¸À®¤·¤¿¤é¡¢¶¯À©Åª¤Ë GC ¤¹¤ë¤è¤¦¤Ë¤·¤¿¡£
  • Mysql#escape_string(), Mysql#quote() ¤Ï mysql_real_escape_string() ¤ò»ÈÍѤ¹¤ë¤è¤¦¤Ë¤·¤¿¡£
2000-09-02
version 2.3.1
  • Mysql#initialize() ¤òÄɲÃ(Ruby 1.6 Âбþ)¡£
2000-07-22
version 2.3.0
  • MysqlRes#free() ¤òÄɲá£
  • Mysql#initialize(), MysqlRes#initialize() ¤òÍ­¸ú¤Ë¤·¤¿¡£
  • true ¤òÊÖ¤·¤Æ¤¤¤¿¥á¥½¥Ã¥É¤ò¡¢self ¤òÊÖ¤¹¤è¤¦¤Ë¤·¤¿¡£
2000-05-27
version 2.2.1a
  • test.rb ¤ò°ú¿ô¤Ç¥Ñ¥é¥á¡¼¥¿¤ò»ØÄê¤Ç¤­¤ë¤è¤¦¤Ë¤·¤¿¡£
2000-05-10
version 2.2.1
  • ¥Ç¡¼¥¿¥Ù¡¼¥¹¤«¤é¤Î¥Ç¡¼¥¿¤ò¡Ö±øÀ÷¤µ¤ì¤¿¡×ʸ»úÎó¤ËÊѹ¹¡£
  • ¥Æ¥¹¥È¥¹¥¯¥ê¥×¥ÈÄɲá£
1999-09-28
version 2.2.0
  • Mysql::init(), Mysql#options(), Mysql#real_connect() ¤òÄɲá£
  • Mysql#field_count ¤òÄɲá£
1999-09-24
version 2.1.7
  • MySQL 3.22.26 ¤ËÂбþ¡£
  • MysqlField#inspect() ¤òÄɲá£
1999-06-17
version 2.1.6
  • fetch_field ¤ÇÍî¤Á¤ë¤³¤È¤¬¤¢¤Ã¤¿¡£
1999-06-12
version 2.1.5
  • Ruby 1.3.x Âбþ¤¬ÃæÅÓȾü¤À¤Ã¤¿¡£
1999-05-30
version 2.1.4
  • Ruby 1.3.x ¤ËÂбþ¡£
1999-04-13
version 2.1.3
  • fetch_hash/each_hash ¤Î°ú¿ô¤Î¿ô¤ÎÄêµÁ¤¬´Ö°ã¤Ã¤Æ¤¤¤¿¡£
  • fetch_hash/each_hash ¤Ë true ¤ò»ØÄꤷ¤¿»þ¤Î¹àÌÜ̾¤¬·ç¤±¤Æ¤¤¤¿¡£
  • NULLÃͤιàÌܤ¬¤¢¤ë¤È fetch_hash/each_hash ¤Îư¤­¤¬¤ª¤«¤·¤«¤Ã¤¿¡£
1999-02-01
version 2.1.2
  • Mysql#refresh() ¤È Mysql::REFRESH_* ¤òÄɲá£
  • MySQL 3.21.xx ¤Ë¤âÂбþ(¤µ¤»¤¿¤Ä¤â¤ê¡Ä)¡£
1999-01-24
version 2.1.1
  • MysqlError#error(), MysqlError#errno() ¤òÄɲá£
  • MysqlError::CR_* ¤òÄɲá£
1999-01-17
version 2.1
  • fetch_hash, each_hash ¤ò C ¥½¡¼¥¹¤Ë°Üư¡£
  • MysqlField#hash() ¤òÄɲá£
  • escape_string, get_client_info ¤ò¥ª¥Ö¥¸¥§¥¯¥È¥á¥½¥Ã¥É¤È¤·¤Æ¤â»È¤¨¤ë¤è¤¦¤Ë¤·¤¿¡£
1998-11-29
version 2.0.1
  • fetch_hash, each_hash ¤Ë with_table °ú¿ô¤òÄɲá£
  • ¤ä¤Ã¤Ñ¤ê get_* ¥á¥½¥Ã¥É̾¤â C API ¤ÈƱ¤¸¤Ë¤·¤¿¡£
  • mysql-compat.rb ¤ò alias ¤Ç½ñ¤­Ä¾¤·¤¿¡£
  • Mysql ¤ÎÄê¿ô CLIENT_* ¤¬ MysqlField ¤ÎÄê¿ô¤Ë¤Ê¤Ã¤Æ¤¤¤¿¡£
1998-11-15
version 2.0
  • ¥á¥½¥Ã¥É̾¤ò C API ¤ÈƱ¤¸¤Ë¤·¤¿¡£
  • C++ ¤Ç¤âÄ̤ë¤è¤¦¤Ë½ñ¤­Ä¾¤·¤¿¡£
1998-08-13
version 1.0
  • ½é´ü¥Ð¡¼¥¸¥ç¥ó¡£

ºî¼Ô

e-mail: ¤È¤ß¤¿¤Þ¤µ¤Ò¤í tommy@tmtm.org http://tmtm.org


TOMITA Masahiro
Last modified: Sun Feb 1 17:48:26 JST 2009 mysql-2.9.1/tasks/0000755000004100000410000000000012414313001014032 5ustar www-datawww-datamysql-2.9.1/tasks/gem.rake0000644000004100000410000000132612414313001015450 0ustar www-datawww-datarequire 'rubygems/package_task' require 'hoe' HOE = Hoe.spec 'mysql' do self.rubyforge_name = 'mysql-win' self.author = ['TOMITA Masahiro'] self.email = %w[tommy@tmtm.org] self.need_tar = false self.need_zip = false spec_extras[:required_ruby_version] = Gem::Requirement.new('>= 1.8.7') spec_extras[:extensions] = ["ext/mysql_api/extconf.rb"] extra_dev_deps << ['rake-compiler', "~> 0.8.1"] end file "#{HOE.spec.name}.gemspec" => ['Rakefile', 'tasks/gem.rake'] do |t| puts "Generating #{t.name}" File.open(t.name, 'w') { |f| f.puts HOE.spec.to_yaml } end desc "Generate or update the standalone gemspec file for the project" task :gemspec => ["#{HOE.spec.name}.gemspec"] mysql-2.9.1/tasks/native.rake0000644000004100000410000000372712414313001016175 0ustar www-datawww-data# use rake-compiler for building the extension require 'rake/extensiontask' CONNECTOR_VERSION = "6.0.2" CONNECTOR_MIRROR = ENV['CONNECTOR_MIRROR'] || "http://mysql.localhost.net.ar" Rake::ExtensionTask.new('mysql_api', HOE.spec) do |ext| # reference where the vendored MySQL got extracted mysql_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', "mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32")) # where native extension will be copied (matches makefile) ext.lib_dir = "lib/mysql" # define target for extension (supporting fat binaries) if RUBY_PLATFORM =~ /mswin|mingw/ then ruby_ver = RUBY_VERSION.match(/(\d+\.\d+)/)[1] ext.lib_dir = "lib/mysql/#{ruby_ver}" end # automatically add build options to avoid need of manual input if RUBY_PLATFORM =~ /mswin|mingw/ then ext.config_options << "--with-mysql-dir=#{mysql_lib}" else ext.cross_compile = true ext.cross_platform = ['i386-mingw32', 'i386-mswin32-60'] ext.cross_config_options << "--with-mysql-dir=#{mysql_lib}" ext.cross_compiling do |gemspec| gemspec.post_install_message = <<-POST_INSTALL_MESSAGE ====================================================================================================== You've installed the binary version of #{gemspec.name}. It was built using MySQL Connector/C version #{CONNECTOR_VERSION}. It's recommended to use the exact same version to avoid potential issues. At the time of building this gem, the necessary DLL files where available in the following URL: http://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32.zip/from/pick You can put the lib\\libmysql.dll available in this package to your Ruby bin directory. E.g. C:\\Ruby\\bin ====================================================================================================== POST_INSTALL_MESSAGE end end end # ensure things are compiled prior testing task :test => [:compile] mysql-2.9.1/tasks/vendor_mysql.rake0000644000004100000410000000253512414313001017425 0ustar www-datawww-datarequire 'rake/clean' require 'rake/extensioncompiler' # download mysql library and headers directory "vendor" CONNECTOR_DIR = "mysql-connector-c-noinstall-#{CONNECTOR_VERSION}-win32" CONNECTOR_ZIP = "#{CONNECTOR_DIR}.zip" file "vendor/#{CONNECTOR_ZIP}" => ['vendor'] do |t| url = "http://dev.mysql.com/get/Downloads/Connector-C/#{File.basename(t.name)}/from/#{CONNECTOR_MIRROR}/" when_writing "downloading #{t.name}" do sh "curl -L #{url} -o #{t.name}" end end file "vendor/#{CONNECTOR_DIR}/include/mysql.h" => ["vendor/#{CONNECTOR_ZIP}"] do |t| full_file = File.expand_path(t.prerequisites.last) when_writing "creating #{t.name}" do cd "vendor" do sh "unzip #{full_file} #{CONNECTOR_DIR}/bin/** #{CONNECTOR_DIR}/include/** #{CONNECTOR_DIR}/lib/**" end # update file timestamp to avoid Rake perform this extraction again. touch t.name end end # clobber expanded packages CLOBBER.include("vendor/#{CONNECTOR_ZIP}") CLOBBER.include("vendor/#{CONNECTOR_DIR}") # vendor:mysql task 'vendor:mysql' => ["vendor/#{CONNECTOR_DIR}/include/mysql.h"] # hook into cross compilation vendored mysql dependency if RUBY_PLATFORM =~ /mingw|mswin/ then Rake::Task['compile'].prerequisites.unshift 'vendor:mysql' else if Rake::Task.tasks.map {|t| t.name }.include? 'cross' Rake::Task['cross'].prerequisites.unshift 'vendor:mysql' end end mysql-2.9.1/ext/0000755000004100000410000000000012414313001013505 5ustar www-datawww-datamysql-2.9.1/ext/mysql_api/0000755000004100000410000000000012414313001015503 5ustar www-datawww-datamysql-2.9.1/ext/mysql_api/extconf.rb0000644000004100000410000000460612414313001017504 0ustar www-datawww-data# Darwin (OSX) special cases for universal binaries # This is to avoid the lack of UB binaries for MySQL ENV["RC_ARCHS"] = "" if RUBY_PLATFORM =~ /darwin/ require 'mkmf' # Improved detection of mysql_config # Code from DataObjects do_mysql adapter # All instances of mysql_config on PATH ... def mysql_config_paths ENV['PATH'].split(File::PATH_SEPARATOR).collect do |path| [ "#{path}/mysql_config", "#{path}/mysql_config5" ]. detect { |bin| File.exist?(bin) } end end # The first mysql_config binary on PATH ... def default_mysql_config_path mysql_config_paths.compact.first end # Allow overriding path to mysql_config on command line using: # ruby extconf.rb --with-mysql-config=/path/to/mysql_config if RUBY_PLATFORM =~ /mswin|mingw/ inc, lib = dir_config('mysql') exit 1 unless have_library("libmysql") elsif mc = with_config('mysql-config', default_mysql_config_path) then mc = 'mysql_config' if mc == true cflags = `#{mc} --cflags`.chomp exit 1 if $? != 0 libs = `#{mc} --libs`.chomp exit 1 if $? != 0 $CPPFLAGS += ' ' + cflags $libs = libs + " " + $libs else inc, lib = dir_config('mysql', '/usr/local') libs = ['m', 'z', 'socket', 'nsl', 'mygcc'] while not find_library('mysqlclient', 'mysql_query', lib, "#{lib}/mysql") do exit 1 if libs.empty? have_library(libs.shift) end end have_func('mysql_ssl_set') have_func('rb_str_set_len') have_func('rb_thread_start_timer') if have_header('mysql.h') then src = "#include \n#include \n" elsif have_header('mysql/mysql.h') then src = "#include \n#include \n" else exit 1 end # make mysql constant File.open("conftest.c", "w") do |f| f.puts src end if defined? cpp_command then cpp = RbConfig.expand(cpp_command('')) else cpp = RbConfig.expand sprintf(CPP, $CPPFLAGS, $CFLAGS, '') end if RUBY_PLATFORM =~ /mswin/ && !/-E/.match(cpp) cpp << " -E" end unless system "#{cpp} > confout" then exit 1 end File.unlink "conftest.c" error_syms = [] IO.foreach('confout') do |l| next unless l =~ /errmsg\.h|mysqld_error\.h/ fn = l.split(/\"/)[1] IO.foreach(fn) do |m| if m =~ /^#define\s+([CE]R_[0-9A-Z_]+)/ then error_syms << $1 end end end File.unlink 'confout' error_syms.uniq! File.open('error_const.h', 'w') do |f| error_syms.each do |s| f.puts " rb_define_mysql_const(#{s});" end end create_makefile("mysql/mysql_api") mysql-2.9.1/ext/mysql_api/mysql.c0000644000004100000410000020751612414313001017027 0ustar www-datawww-data/* ruby mysql module * $Id: mysql.c 250 2010-02-11 10:42:54Z tommy $ */ #include #ifndef RSTRING_PTR #define RSTRING_PTR(str) RSTRING(str)->ptr #endif #ifndef RSTRING_LEN #define RSTRING_LEN(str) RSTRING(str)->len #endif #ifndef RARRAY_PTR #define RARRAY_PTR(ary) RARRAY(ary)->ptr #endif #ifndef HAVE_RB_STR_SET_LEN #define rb_str_set_len(str, length) (RSTRING_LEN(str) = (length)) #endif #ifdef HAVE_MYSQL_H #include #include #include #else #include #include #include #endif #define MYSQL_RUBY_VERSION 20802 #define GC_STORE_RESULT_LIMIT 20 #if MYSQL_VERSION_ID < 32224 #define mysql_field_count mysql_num_fields #endif #define NILorSTRING(obj) (NIL_P(obj)? NULL: StringValuePtr(obj)) #define NILorINT(obj) (NIL_P(obj)? 0: NUM2INT(obj)) #define GetMysqlStruct(obj) (Check_Type(obj, T_DATA), (struct mysql*)DATA_PTR(obj)) #define GetHandler(obj) (Check_Type(obj, T_DATA), &(((struct mysql*)DATA_PTR(obj))->handler)) #define GetMysqlRes(obj) (Check_Type(obj, T_DATA), ((struct mysql_res*)DATA_PTR(obj))->res) #define GetMysqlStmt(obj) (Check_Type(obj, T_DATA), ((struct mysql_stmt*)DATA_PTR(obj))->stmt) VALUE cMysql; VALUE cMysqlRes; VALUE cMysqlField; VALUE cMysqlStmt; VALUE cMysqlRowOffset; VALUE cMysqlTime; VALUE eMysql; static int store_result_count = 0; struct mysql { MYSQL handler; char connection; char query_with_result; }; struct mysql_res { MYSQL_RES* res; char freed; }; #if MYSQL_VERSION_ID >= 40101 struct mysql_stmt { MYSQL_STMT *stmt; char closed; struct { int n; MYSQL_BIND *bind; unsigned long *length; MYSQL_TIME *buffer; } param; struct { int n; MYSQL_BIND *bind; my_bool *is_null; unsigned long *length; } result; MYSQL_RES *res; }; #endif /* free Mysql class object */ static void free_mysql(struct mysql* my) { if (my->connection == Qtrue) mysql_close(&my->handler); xfree(my); } static void free_mysqlres(struct mysql_res* resp) { if (resp->freed == Qfalse) { mysql_free_result(resp->res); store_result_count--; } xfree(resp); } #if MYSQL_VERSION_ID >= 40101 static void free_mysqlstmt_memory(struct mysql_stmt *s) { if (s->param.bind) { xfree(s->param.bind); s->param.bind = NULL; } if (s->param.length) { xfree(s->param.length); s->param.length = NULL; } if (s->param.buffer) { xfree(s->param.buffer); s->param.buffer = NULL; } s->param.n = 0; if (s->res) { mysql_free_result(s->res); s->res = NULL; } if (s->result.bind) { int i; for (i = 0; i < s->result.n; i++) { if (s->result.bind[i].buffer) xfree(s->result.bind[i].buffer); s->result.bind[i].buffer = NULL; } xfree(s->result.bind); s->result.bind = NULL; } if (s->result.is_null) { xfree(s->result.is_null); s->result.is_null = NULL; } if (s->result.length) { xfree(s->result.length); s->result.length = NULL; } s->result.n = 0; } static void free_execute_memory(struct mysql_stmt *s) { if (s->res && s->result.bind) { int i; for (i = 0; i < s->result.n; i++) { if (s->result.bind[i].buffer) xfree(s->result.bind[i].buffer); s->result.bind[i].buffer = NULL; } } mysql_stmt_free_result(s->stmt); } static void free_mysqlstmt(struct mysql_stmt* s) { free_mysqlstmt_memory(s); if (s->closed == Qfalse) mysql_stmt_close(s->stmt); if (s->res) mysql_free_result(s->res); xfree(s); } #endif static void mysql_raise(MYSQL* m) { VALUE e = rb_exc_new2(eMysql, mysql_error(m)); rb_iv_set(e, "errno", INT2FIX(mysql_errno(m))); #if MYSQL_VERSION_ID >= 40101 rb_iv_set(e, "sqlstate", rb_tainted_str_new2(mysql_sqlstate(m))); #endif rb_exc_raise(e); } static VALUE mysqlres2obj(MYSQL_RES* res) { VALUE obj; struct mysql_res* resp; obj = Data_Make_Struct(cMysqlRes, struct mysql_res, 0, free_mysqlres, resp); rb_iv_set(obj, "colname", Qnil); rb_iv_set(obj, "tblcolname", Qnil); resp->res = res; resp->freed = Qfalse; rb_obj_call_init(obj, 0, NULL); if (++store_result_count > GC_STORE_RESULT_LIMIT) rb_gc(); return obj; } /* make Mysql::Field object */ static VALUE make_field_obj(MYSQL_FIELD* f) { VALUE obj; if (f == NULL) return Qnil; obj = rb_obj_alloc(cMysqlField); rb_iv_set(obj, "name", f->name? rb_str_freeze(rb_tainted_str_new2(f->name)): Qnil); rb_iv_set(obj, "table", f->table? rb_str_freeze(rb_tainted_str_new2(f->table)): Qnil); rb_iv_set(obj, "def", f->def? rb_str_freeze(rb_tainted_str_new2(f->def)): Qnil); rb_iv_set(obj, "type", INT2NUM(f->type)); rb_iv_set(obj, "length", INT2NUM(f->length)); rb_iv_set(obj, "max_length", INT2NUM(f->max_length)); rb_iv_set(obj, "flags", INT2NUM(f->flags)); rb_iv_set(obj, "decimals", INT2NUM(f->decimals)); return obj; } /*------------------------------- * Mysql class method */ /* init() */ static VALUE init(VALUE klass) { struct mysql* myp; VALUE obj; obj = Data_Make_Struct(klass, struct mysql, 0, free_mysql, myp); mysql_init(&myp->handler); myp->connection = Qfalse; myp->query_with_result = Qtrue; rb_obj_call_init(obj, 0, NULL); return obj; } /* real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil) */ static VALUE real_connect(int argc, VALUE* argv, VALUE klass) { VALUE host, user, passwd, db, port, sock, flag; char *h, *u, *p, *d, *s; unsigned int pp, f; struct mysql* myp; VALUE obj; #if MYSQL_VERSION_ID >= 32200 rb_scan_args(argc, argv, "07", &host, &user, &passwd, &db, &port, &sock, &flag); d = NILorSTRING(db); f = NILorINT(flag); #elif MYSQL_VERSION_ID >= 32115 rb_scan_args(argc, argv, "06", &host, &user, &passwd, &port, &sock, &flag); f = NILorINT(flag); #else rb_scan_args(argc, argv, "05", &host, &user, &passwd, &port, &sock); #endif h = NILorSTRING(host); u = NILorSTRING(user); p = NILorSTRING(passwd); pp = NILorINT(port); s = NILorSTRING(sock); #ifdef HAVE_RB_THREAD_START_TIMER rb_thread_stop_timer(); #endif obj = Data_Make_Struct(klass, struct mysql, 0, free_mysql, myp); #if MYSQL_VERSION_ID >= 32200 mysql_init(&myp->handler); if (mysql_real_connect(&myp->handler, h, u, p, d, pp, s, f) == NULL) #elif MYSQL_VERSION_ID >= 32115 if (mysql_real_connect(&myp->handler, h, u, p, pp, s, f) == NULL) #else if (mysql_real_connect(&myp->handler, h, u, p, pp, s) == NULL) #endif { #ifdef HAVE_RB_THREAD_START_TIMER rb_thread_start_timer(); #endif mysql_raise(&myp->handler); } #ifdef HAVE_RB_THREAD_START_TIMER rb_thread_start_timer(); #endif myp->handler.reconnect = 0; myp->connection = Qtrue; myp->query_with_result = Qtrue; rb_obj_call_init(obj, argc, argv); return obj; } /* escape_string(string) */ static VALUE escape_string(VALUE klass, VALUE str) { VALUE ret; Check_Type(str, T_STRING); ret = rb_str_new(0, (RSTRING_LEN(str))*2+1); rb_str_set_len(ret, mysql_escape_string(RSTRING_PTR(ret), RSTRING_PTR(str), RSTRING_LEN(str))); return ret; } /* client_info() */ static VALUE client_info(VALUE klass) { return rb_tainted_str_new2(mysql_get_client_info()); } #if MYSQL_VERSION_ID >= 32332 /* my_debug(string) */ static VALUE my_debug(VALUE obj, VALUE str) { mysql_debug(StringValuePtr(str)); return obj; } #endif #if MYSQL_VERSION_ID >= 40000 /* client_version() */ static VALUE client_version(VALUE obj) { return INT2NUM(mysql_get_client_version()); } #endif /*------------------------------- * Mysql object method */ #if MYSQL_VERSION_ID >= 32200 /* real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, sock=nil, flag=nil) */ static VALUE real_connect2(int argc, VALUE* argv, VALUE obj) { VALUE host, user, passwd, db, port, sock, flag; char *h, *u, *p, *d, *s; unsigned int pp, f; MYSQL* m = GetHandler(obj); rb_scan_args(argc, argv, "07", &host, &user, &passwd, &db, &port, &sock, &flag); d = NILorSTRING(db); f = NILorINT(flag); h = NILorSTRING(host); u = NILorSTRING(user); p = NILorSTRING(passwd); pp = NILorINT(port); s = NILorSTRING(sock); #ifdef HAVE_RB_THREAD_START_TIMER rb_thread_stop_timer(); #endif if (mysql_real_connect(m, h, u, p, d, pp, s, f) == NULL) { #ifdef HAVE_RB_THREAD_START_TIMER rb_thread_start_timer(); #endif mysql_raise(m); } #ifdef HAVE_RB_THREAD_START_TIMER rb_thread_start_timer(); #endif m->reconnect = 0; GetMysqlStruct(obj)->connection = Qtrue; return obj; } /* options(opt, value=nil) */ static VALUE options(int argc, VALUE* argv, VALUE obj) { VALUE opt, val; int n; my_bool b; char* v; MYSQL* m = GetHandler(obj); rb_scan_args(argc, argv, "11", &opt, &val); switch(NUM2INT(opt)) { case MYSQL_OPT_CONNECT_TIMEOUT: #if MYSQL_VERSION_ID >= 40100 case MYSQL_OPT_PROTOCOL: #endif #if MYSQL_VERSION_ID >= 40101 case MYSQL_OPT_READ_TIMEOUT: case MYSQL_OPT_WRITE_TIMEOUT: #endif if (val == Qnil) rb_raise(rb_eArgError, "wrong # of arguments(1 for 2)"); n = NUM2INT(val); v = (char*)&n; break; case MYSQL_INIT_COMMAND: case MYSQL_READ_DEFAULT_FILE: case MYSQL_READ_DEFAULT_GROUP: #if MYSQL_VERSION_ID >= 32349 case MYSQL_SET_CHARSET_DIR: case MYSQL_SET_CHARSET_NAME: #endif #if MYSQL_VERSION_ID >= 40100 case MYSQL_SHARED_MEMORY_BASE_NAME: #endif #if MYSQL_VERSION_ID >= 40101 case MYSQL_SET_CLIENT_IP: #endif if (val == Qnil) rb_raise(rb_eArgError, "wrong # of arguments(1 for 2)"); v = StringValuePtr(val); break; #if MYSQL_VERSION_ID >= 40101 case MYSQL_SECURE_AUTH: if (val == Qnil || val == Qfalse) b = 1; else b = 0; v = (char*)&b; break; #endif #if MYSQL_VERSION_ID >= 32349 case MYSQL_OPT_LOCAL_INFILE: if (val == Qnil || val == Qfalse) v = NULL; else { n = 1; v = (char*)&n; } break; #endif default: v = NULL; } if (mysql_options(m, NUM2INT(opt), v) != 0) rb_raise(eMysql, "unknown option: %d", NUM2INT(opt)); return obj; } #endif #if MYSQL_VERSION_ID >= 32332 /* real_escape_string(string) */ static VALUE real_escape_string(VALUE obj, VALUE str) { MYSQL* m = GetHandler(obj); VALUE ret; Check_Type(str, T_STRING); ret = rb_str_new(0, (RSTRING_LEN(str))*2+1); rb_str_set_len(ret, mysql_real_escape_string(m, RSTRING_PTR(ret), RSTRING_PTR(str), RSTRING_LEN(str))); return ret; } #endif /* initialize() */ static VALUE initialize(int argc, VALUE* argv, VALUE obj) { return obj; } /* affected_rows() */ static VALUE affected_rows(VALUE obj) { return ULL2NUM(mysql_affected_rows(GetHandler(obj))); } #if MYSQL_VERSION_ID >= 32303 /* change_user(user=nil, passwd=nil, db=nil) */ static VALUE change_user(int argc, VALUE* argv, VALUE obj) { VALUE user, passwd, db; char *u, *p, *d; MYSQL* m = GetHandler(obj); rb_scan_args(argc, argv, "03", &user, &passwd, &db); u = NILorSTRING(user); p = NILorSTRING(passwd); d = NILorSTRING(db); if (mysql_change_user(m, u, p, d) != 0) mysql_raise(m); return obj; } #endif #if MYSQL_VERSION_ID >= 32321 /* character_set_name() */ static VALUE character_set_name(VALUE obj) { return rb_tainted_str_new2(mysql_character_set_name(GetHandler(obj))); } #endif /* close() */ static VALUE my_close(VALUE obj) { MYSQL* m = GetHandler(obj); mysql_close(m); GetMysqlStruct(obj)->connection = Qfalse; return obj; } #if MYSQL_VERSION_ID < 40000 /* create_db(db) */ static VALUE create_db(VALUE obj, VALUE db) { MYSQL* m = GetHandler(obj); if (mysql_create_db(m, StringValuePtr(db)) != 0) mysql_raise(m); return obj; } /* drop_db(db) */ static VALUE drop_db(VALUE obj, VALUE db) { MYSQL* m = GetHandler(obj); if (mysql_drop_db(m, StringValuePtr(db)) != 0) mysql_raise(m); return obj; } #endif #if MYSQL_VERSION_ID >= 32332 /* dump_debug_info() */ static VALUE dump_debug_info(VALUE obj) { MYSQL* m = GetHandler(obj); if (mysql_dump_debug_info(m) != 0) mysql_raise(m); return obj; } #endif /* errno() */ static VALUE my_errno(VALUE obj) { return INT2NUM(mysql_errno(GetHandler(obj))); } /* error() */ static VALUE my_error(VALUE obj) { return rb_str_new2(mysql_error(GetHandler(obj))); } /* field_count() */ static VALUE field_count(VALUE obj) { return INT2NUM(mysql_field_count(GetHandler(obj))); } /* host_info() */ static VALUE host_info(VALUE obj) { return rb_tainted_str_new2(mysql_get_host_info(GetHandler(obj))); } /* proto_info() */ static VALUE proto_info(VALUE obj) { return INT2NUM(mysql_get_proto_info(GetHandler(obj))); } /* server_info() */ static VALUE server_info(VALUE obj) { return rb_tainted_str_new2(mysql_get_server_info(GetHandler(obj))); } /* info() */ static VALUE info(VALUE obj) { const char* p = mysql_info(GetHandler(obj)); return p? rb_tainted_str_new2(p): Qnil; } /* insert_id() */ static VALUE insert_id(VALUE obj) { return ULL2NUM(mysql_insert_id(GetHandler(obj))); } /* kill(pid) */ static VALUE my_kill(VALUE obj, VALUE pid) { int p = NUM2INT(pid); MYSQL* m = GetHandler(obj); if (mysql_kill(m, p) != 0) mysql_raise(m); return obj; } /* list_dbs(db=nil) */ static VALUE list_dbs(int argc, VALUE* argv, VALUE obj) { unsigned int i, n; VALUE db, ret; MYSQL* m = GetHandler(obj); MYSQL_RES* res; rb_scan_args(argc, argv, "01", &db); res = mysql_list_dbs(m, NILorSTRING(db)); if (res == NULL) mysql_raise(m); n = mysql_num_rows(res); ret = rb_ary_new2(n); for (i=0; i= 40103 if (mysql_shutdown(m, NIL_P(level) ? SHUTDOWN_DEFAULT : NUM2INT(level)) != 0) #else if (mysql_shutdown(m) != 0) #endif mysql_raise(m); return obj; } /* stat() */ static VALUE my_stat(VALUE obj) { MYSQL* m = GetHandler(obj); const char* s = mysql_stat(m); if (s == NULL) mysql_raise(m); return rb_tainted_str_new2(s); } /* store_result() */ static VALUE store_result(VALUE obj) { MYSQL* m = GetHandler(obj); MYSQL_RES* res = mysql_store_result(m); if (res == NULL) mysql_raise(m); return mysqlres2obj(res); } /* thread_id() */ static VALUE thread_id(VALUE obj) { return INT2NUM(mysql_thread_id(GetHandler(obj))); } /* use_result() */ static VALUE use_result(VALUE obj) { MYSQL* m = GetHandler(obj); MYSQL_RES* res = mysql_use_result(m); if (res == NULL) mysql_raise(m); return mysqlres2obj(res); } static VALUE res_free(VALUE); /* query(sql) */ static VALUE query(VALUE obj, VALUE sql) { int loop = 0; MYSQL* m = GetHandler(obj); Check_Type(sql, T_STRING); if (GetMysqlStruct(obj)->connection == Qfalse) { rb_raise(eMysql, "query: not connected"); } if (rb_block_given_p()) { if (mysql_real_query(m, RSTRING_PTR(sql), RSTRING_LEN(sql)) != 0) mysql_raise(m); do { MYSQL_RES* res = mysql_store_result(m); if (res == NULL) { if (mysql_field_count(m) != 0) mysql_raise(m); } else { VALUE robj = mysqlres2obj(res); rb_ensure(rb_yield, robj, res_free, robj); } #if MYSQL_VERSION_ID >= 40101 if ((loop = mysql_next_result(m)) > 0) mysql_raise(m); } while (loop == 0); #else } while (0); #endif return obj; } if (mysql_real_query(m, RSTRING_PTR(sql), RSTRING_LEN(sql)) != 0) mysql_raise(m); if (GetMysqlStruct(obj)->query_with_result == Qfalse) return obj; if (mysql_field_count(m) == 0) return Qnil; return store_result(obj); } #if MYSQL_VERSION_ID >= 40100 /* server_version() */ static VALUE server_version(VALUE obj) { return INT2NUM(mysql_get_server_version(GetHandler(obj))); } /* warning_count() */ static VALUE warning_count(VALUE obj) { return INT2NUM(mysql_warning_count(GetHandler(obj))); } /* commit() */ static VALUE commit(VALUE obj) { MYSQL* m = GetHandler(obj); if (mysql_commit(m) != 0) mysql_raise(m); return obj; } /* rollback() */ static VALUE rollback(VALUE obj) { MYSQL* m = GetHandler(obj); if (mysql_rollback(m) != 0) mysql_raise(m); return obj; } /* autocommit() */ static VALUE autocommit(VALUE obj, VALUE mode) { MYSQL* m = GetHandler(obj); int f; f = (mode == Qnil || mode == Qfalse || (rb_type(mode) == T_FIXNUM && NUM2INT(mode) == 0)) ? 0 : 1; if (mysql_autocommit(m, f) != 0) mysql_raise(m); return obj; } #endif #ifdef HAVE_MYSQL_SSL_SET /* ssl_set(key=nil, cert=nil, ca=nil, capath=nil, cipher=nil) */ static VALUE ssl_set(int argc, VALUE* argv, VALUE obj) { VALUE key, cert, ca, capath, cipher; char *s_key, *s_cert, *s_ca, *s_capath, *s_cipher; MYSQL* m = GetHandler(obj); rb_scan_args(argc, argv, "05", &key, &cert, &ca, &capath, &cipher); s_key = NILorSTRING(key); s_cert = NILorSTRING(cert); s_ca = NILorSTRING(ca); s_capath = NILorSTRING(capath); s_cipher = NILorSTRING(cipher); mysql_ssl_set(m, s_key, s_cert, s_ca, s_capath, s_cipher); return obj; } #endif #if MYSQL_VERSION_ID >= 40100 /* more_results() */ static VALUE more_results(VALUE obj) { if (mysql_more_results(GetHandler(obj)) == 0) return Qfalse; else return Qtrue; } static VALUE next_result(VALUE obj) { MYSQL* m = GetHandler(obj); int ret; ret = mysql_next_result(m); if (ret > 0) mysql_raise(m); if (ret == 0) return Qtrue; return Qfalse; } #endif #if MYSQL_VERSION_ID >= 40101 /* set_server_option(option) */ static VALUE set_server_option(VALUE obj, VALUE option) { MYSQL *m = GetHandler(obj); if (mysql_set_server_option(m, NUM2INT(option)) != 0) mysql_raise(m); return obj; } /* sqlstate() */ static VALUE sqlstate(VALUE obj) { MYSQL *m = GetHandler(obj); return rb_tainted_str_new2(mysql_sqlstate(m)); } #endif #if MYSQL_VERSION_ID >= 40102 /* stmt_init() */ static VALUE stmt_init(VALUE obj) { MYSQL *m = GetHandler(obj); MYSQL_STMT *s; struct mysql_stmt* stmt; my_bool true = 1; VALUE st_obj; if ((s = mysql_stmt_init(m)) == NULL) mysql_raise(m); if (mysql_stmt_attr_set(s, STMT_ATTR_UPDATE_MAX_LENGTH, &true)) rb_raise(rb_eArgError, "mysql_stmt_attr_set() failed"); st_obj = Data_Make_Struct(cMysqlStmt, struct mysql_stmt, 0, free_mysqlstmt, stmt); memset(stmt, 0, sizeof(*stmt)); stmt->stmt = s; stmt->closed = Qfalse; return st_obj; } static VALUE stmt_prepare(VALUE obj, VALUE query); /* prepare(query) */ static VALUE prepare(VALUE obj, VALUE query) { VALUE st; st = stmt_init(obj); return stmt_prepare(st, query); } #endif /* query_with_result() */ static VALUE query_with_result(VALUE obj) { return GetMysqlStruct(obj)->query_with_result? Qtrue: Qfalse; } /* query_with_result=(flag) */ static VALUE query_with_result_set(VALUE obj, VALUE flag) { if (TYPE(flag) != T_TRUE && TYPE(flag) != T_FALSE) rb_raise(rb_eTypeError, "invalid type, required true or false."); GetMysqlStruct(obj)->query_with_result = flag; return flag; } /* reconnect() */ static VALUE reconnect(VALUE obj) { return GetHandler(obj)->reconnect ? Qtrue : Qfalse; } /* reconnect=(flag) */ static VALUE reconnect_set(VALUE obj, VALUE flag) { GetHandler(obj)->reconnect = (flag == Qnil || flag == Qfalse) ? 0 : 1; return flag; } /*------------------------------- * Mysql::Result object method */ /* check if already freed */ static void check_free(VALUE obj) { struct mysql_res* resp = DATA_PTR(obj); if (resp->freed == Qtrue) rb_raise(eMysql, "Mysql::Result object is already freed"); } /* data_seek(offset) */ static VALUE data_seek(VALUE obj, VALUE offset) { check_free(obj); mysql_data_seek(GetMysqlRes(obj), NUM2INT(offset)); return obj; } /* fetch_field() */ static VALUE fetch_field(VALUE obj) { check_free(obj); return make_field_obj(mysql_fetch_field(GetMysqlRes(obj))); } /* fetch_fields() */ static VALUE fetch_fields(VALUE obj) { MYSQL_RES* res; MYSQL_FIELD* f; unsigned int n; VALUE ret; unsigned int i; check_free(obj); res = GetMysqlRes(obj); f = mysql_fetch_fields(res); n = mysql_num_fields(res); ret = rb_ary_new2(n); for (i=0; i= max) rb_raise(eMysql, "%d: out of range (max: %d)", n, max-1); #if MYSQL_VERSION_ID >= 32226 return make_field_obj(mysql_fetch_field_direct(res, n)); #else return make_field_obj(&mysql_fetch_field_direct(res, n)); #endif } /* fetch_lengths() */ static VALUE fetch_lengths(VALUE obj) { MYSQL_RES* res; unsigned int n; unsigned long* lengths; VALUE ary; unsigned int i; check_free(obj); res = GetMysqlRes(obj); n = mysql_num_fields(res); lengths = mysql_fetch_lengths(res); if (lengths == NULL) return Qnil; ary = rb_ary_new2(n); for (i=0; ires); resp->freed = Qtrue; store_result_count--; return Qnil; } /* num_fields() */ static VALUE num_fields(VALUE obj) { check_free(obj); return INT2NUM(mysql_num_fields(GetMysqlRes(obj))); } /* num_rows() */ static VALUE num_rows(VALUE obj) { check_free(obj); return INT2NUM(mysql_num_rows(GetMysqlRes(obj))); } /* row_seek(offset) */ static VALUE row_seek(VALUE obj, VALUE offset) { MYSQL_ROW_OFFSET prev_offset; if (CLASS_OF(offset) != cMysqlRowOffset) rb_raise(rb_eTypeError, "wrong argument type %s (expected Mysql::RowOffset)", rb_obj_classname(offset)); check_free(obj); prev_offset = mysql_row_seek(GetMysqlRes(obj), DATA_PTR(offset)); return Data_Wrap_Struct(cMysqlRowOffset, 0, NULL, prev_offset); } /* row_tell() */ static VALUE row_tell(VALUE obj) { MYSQL_ROW_OFFSET offset; check_free(obj); offset = mysql_row_tell(GetMysqlRes(obj)); return Data_Wrap_Struct(cMysqlRowOffset, 0, NULL, offset); } /* each {...} */ static VALUE each(VALUE obj) { VALUE row; check_free(obj); while ((row = fetch_row(obj)) != Qnil) rb_yield(row); return obj; } /* each_hash(with_table=false) {...} */ static VALUE each_hash(int argc, VALUE* argv, VALUE obj) { VALUE with_table; VALUE hash; check_free(obj); rb_scan_args(argc, argv, "01", &with_table); if (with_table == Qnil) with_table = Qfalse; while ((hash = fetch_hash2(obj, with_table)) != Qnil) rb_yield(hash); return obj; } /*------------------------------- * Mysql::Field object method */ /* hash */ static VALUE field_hash(VALUE obj) { VALUE h = rb_hash_new(); rb_hash_aset(h, rb_str_new2("name"), rb_iv_get(obj, "name")); rb_hash_aset(h, rb_str_new2("table"), rb_iv_get(obj, "table")); rb_hash_aset(h, rb_str_new2("def"), rb_iv_get(obj, "def")); rb_hash_aset(h, rb_str_new2("type"), rb_iv_get(obj, "type")); rb_hash_aset(h, rb_str_new2("length"), rb_iv_get(obj, "length")); rb_hash_aset(h, rb_str_new2("max_length"), rb_iv_get(obj, "max_length")); rb_hash_aset(h, rb_str_new2("flags"), rb_iv_get(obj, "flags")); rb_hash_aset(h, rb_str_new2("decimals"), rb_iv_get(obj, "decimals")); return h; } /* inspect */ static VALUE field_inspect(VALUE obj) { VALUE n = rb_iv_get(obj, "name"); VALUE s = rb_str_new(0, RSTRING_LEN(n) + 16); sprintf(RSTRING_PTR(s), "#", RSTRING_PTR(n)); return s; } #define DefineMysqlFieldMemberMethod(m)\ static VALUE field_##m(VALUE obj)\ {return rb_iv_get(obj, #m);} DefineMysqlFieldMemberMethod(name) DefineMysqlFieldMemberMethod(table) DefineMysqlFieldMemberMethod(def) DefineMysqlFieldMemberMethod(type) DefineMysqlFieldMemberMethod(length) DefineMysqlFieldMemberMethod(max_length) DefineMysqlFieldMemberMethod(flags) DefineMysqlFieldMemberMethod(decimals) #ifdef IS_NUM /* is_num? */ static VALUE field_is_num(VALUE obj) { return IS_NUM(NUM2INT(rb_iv_get(obj, "type"))) ? Qtrue : Qfalse; } #endif #ifdef IS_NOT_NULL /* is_not_null? */ static VALUE field_is_not_null(VALUE obj) { return IS_NOT_NULL(NUM2INT(rb_iv_get(obj, "flags"))) ? Qtrue : Qfalse; } #endif #ifdef IS_PRI_KEY /* is_pri_key? */ static VALUE field_is_pri_key(VALUE obj) { return IS_PRI_KEY(NUM2INT(rb_iv_get(obj, "flags"))) ? Qtrue : Qfalse; } #endif #if MYSQL_VERSION_ID >= 40102 /*------------------------------- * Mysql::Stmt object method */ /* check if stmt is already closed */ static void check_stmt_closed(VALUE obj) { struct mysql_stmt* s = DATA_PTR(obj); if (s->closed == Qtrue) rb_raise(eMysql, "Mysql::Stmt object is already closed"); } static void mysql_stmt_raise(MYSQL_STMT* s) { VALUE e = rb_exc_new2(eMysql, mysql_stmt_error(s)); rb_iv_set(e, "errno", INT2FIX(mysql_stmt_errno(s))); rb_iv_set(e, "sqlstate", rb_tainted_str_new2(mysql_stmt_sqlstate(s))); rb_exc_raise(e); } /* affected_rows() */ static VALUE stmt_affected_rows(VALUE obj) { struct mysql_stmt* s = DATA_PTR(obj); my_ulonglong n; check_stmt_closed(obj); n = mysql_stmt_affected_rows(s->stmt); return ULL2NUM(n); } #if 0 /* attr_get(option) */ static VALUE stmt_attr_get(VALUE obj, VALUE opt) { struct mysql_stmt* s = DATA_PTR(obj); check_stmt_closed(obj); if (NUM2INT(opt) == STMT_ATTR_UPDATE_MAX_LENGTH) { my_bool arg; mysql_stmt_attr_get(s->stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &arg); return arg == 1 ? Qtrue : Qfalse; } rb_raise(eMysql, "unknown option: %d", NUM2INT(opt)); } /* attr_set(option, arg) */ static VALUE stmt_attr_set(VALUE obj, VALUE opt, VALUE val) { struct mysql_stmt* s = DATA_PTR(obj); check_stmt_closed(obj); if (NUM2INT(opt) == STMT_ATTR_UPDATE_MAX_LENGTH) { my_bool arg; arg = (val == Qnil || val == Qfalse) ? 0 : 1; mysql_stmt_attr_set(s->stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &arg); return obj; } rb_raise(eMysql, "unknown option: %d", NUM2INT(opt)); } #endif /* bind_result(bind,...) */ static VALUE stmt_bind_result(int argc, VALUE *argv, VALUE obj) { struct mysql_stmt* s = DATA_PTR(obj); int i; MYSQL_FIELD *field; check_stmt_closed(obj); if (argc != s->result.n) rb_raise(eMysql, "bind_result: result value count(%d) != number of argument(%d)", s->result.n, argc); for (i = 0; i < argc; i++) { if (argv[i] == Qnil || argv[i] == rb_cNilClass) { field = mysql_fetch_fields(s->res); s->result.bind[i].buffer_type = field[i].type; } else if (argv[i] == rb_cString) s->result.bind[i].buffer_type = MYSQL_TYPE_STRING; else if (argv[i] == rb_cNumeric || argv[i] == rb_cInteger || argv[i] == rb_cFixnum) s->result.bind[i].buffer_type = MYSQL_TYPE_LONGLONG; else if (argv[i] == rb_cFloat) s->result.bind[i].buffer_type = MYSQL_TYPE_DOUBLE; else if (argv[i] == cMysqlTime) s->result.bind[i].buffer_type = MYSQL_TYPE_DATETIME; else rb_raise(rb_eTypeError, "unrecognized class: %s", RSTRING_PTR(rb_inspect(argv[i]))); if (mysql_stmt_bind_result(s->stmt, s->result.bind)) mysql_stmt_raise(s->stmt); } return obj; } /* close() */ static VALUE stmt_close(VALUE obj) { struct mysql_stmt* s = DATA_PTR(obj); check_stmt_closed(obj); mysql_stmt_close(s->stmt); s->closed = Qtrue; return Qnil; } /* data_seek(offset) */ static VALUE stmt_data_seek(VALUE obj, VALUE offset) { struct mysql_stmt* s = DATA_PTR(obj); check_stmt_closed(obj); mysql_stmt_data_seek(s->stmt, NUM2INT(offset)); return obj; } /* execute(arg,...) */ static VALUE stmt_execute(int argc, VALUE *argv, VALUE obj) { struct mysql_stmt *s = DATA_PTR(obj); MYSQL_STMT *stmt = s->stmt; int i; check_stmt_closed(obj); free_execute_memory(s); if (s->param.n != argc) rb_raise(eMysql, "execute: param_count(%d) != number of argument(%d)", s->param.n, argc); if (argc > 0) { memset(s->param.bind, 0, sizeof(*(s->param.bind))*argc); for (i = 0; i < argc; i++) { switch (TYPE(argv[i])) { case T_NIL: s->param.bind[i].buffer_type = MYSQL_TYPE_NULL; break; case T_FIXNUM: #if SIZEOF_INT < SIZEOF_LONG s->param.bind[i].buffer_type = MYSQL_TYPE_LONGLONG; s->param.bind[i].buffer = &(s->param.buffer[i]); *(LONG_LONG*)(s->param.bind[i].buffer) = FIX2LONG(argv[i]); #else s->param.bind[i].buffer_type = MYSQL_TYPE_LONG; s->param.bind[i].buffer = &(s->param.buffer[i]); *(int*)(s->param.bind[i].buffer) = FIX2INT(argv[i]); #endif break; case T_BIGNUM: s->param.bind[i].buffer_type = MYSQL_TYPE_LONGLONG; s->param.bind[i].buffer = &(s->param.buffer[i]); *(LONG_LONG*)(s->param.bind[i].buffer) = rb_big2ll(argv[i]); break; case T_FLOAT: s->param.bind[i].buffer_type = MYSQL_TYPE_DOUBLE; s->param.bind[i].buffer = &(s->param.buffer[i]); *(double*)(s->param.bind[i].buffer) = NUM2DBL(argv[i]); break; case T_STRING: s->param.bind[i].buffer_type = MYSQL_TYPE_STRING; s->param.bind[i].buffer = RSTRING_PTR(argv[i]); s->param.bind[i].buffer_length = RSTRING_LEN(argv[i]); s->param.length[i] = RSTRING_LEN(argv[i]); s->param.bind[i].length = &(s->param.length[i]); break; default: if (CLASS_OF(argv[i]) == rb_cTime) { MYSQL_TIME t; VALUE a = rb_funcall(argv[i], rb_intern("to_a"), 0); s->param.bind[i].buffer_type = MYSQL_TYPE_DATETIME; s->param.bind[i].buffer = &(s->param.buffer[i]); memset(&t, 0, sizeof(t)); /* avoid warning */ t.second_part = 0; t.neg = 0; t.second = FIX2INT(RARRAY_PTR(a)[0]); t.minute = FIX2INT(RARRAY_PTR(a)[1]); t.hour = FIX2INT(RARRAY_PTR(a)[2]); t.day = FIX2INT(RARRAY_PTR(a)[3]); t.month = FIX2INT(RARRAY_PTR(a)[4]); t.year = FIX2INT(RARRAY_PTR(a)[5]); *(MYSQL_TIME*)&(s->param.buffer[i]) = t; } else if (CLASS_OF(argv[i]) == cMysqlTime) { MYSQL_TIME t; s->param.bind[i].buffer_type = MYSQL_TYPE_DATETIME; s->param.bind[i].buffer = &(s->param.buffer[i]); memset(&t, 0, sizeof(t)); /* avoid warning */ t.second_part = 0; t.neg = 0; t.second = NUM2INT(rb_iv_get(argv[i], "second")); t.minute = NUM2INT(rb_iv_get(argv[i], "minute")); t.hour = NUM2INT(rb_iv_get(argv[i], "hour")); t.day = NUM2INT(rb_iv_get(argv[i], "day")); t.month = NUM2INT(rb_iv_get(argv[i], "month")); t.year = NUM2INT(rb_iv_get(argv[i], "year")); *(MYSQL_TIME*)&(s->param.buffer[i]) = t; } else rb_raise(rb_eTypeError, "unsupported type: %d", TYPE(argv[i])); } } if (mysql_stmt_bind_param(stmt, s->param.bind)) mysql_stmt_raise(stmt); } if (mysql_stmt_execute(stmt)) mysql_stmt_raise(stmt); if (s->res) { MYSQL_FIELD *field; if (mysql_stmt_store_result(stmt)) mysql_stmt_raise(stmt); field = mysql_fetch_fields(s->res); for (i = 0; i < s->result.n; i++) { switch(s->result.bind[i].buffer_type) { case MYSQL_TYPE_NULL: break; case MYSQL_TYPE_TINY: case MYSQL_TYPE_SHORT: case MYSQL_TYPE_YEAR: case MYSQL_TYPE_INT24: case MYSQL_TYPE_LONG: case MYSQL_TYPE_LONGLONG: case MYSQL_TYPE_FLOAT: case MYSQL_TYPE_DOUBLE: s->result.bind[i].buffer = xmalloc(8); s->result.bind[i].buffer_length = 8; memset(s->result.bind[i].buffer, 0, 8); break; case MYSQL_TYPE_DECIMAL: case MYSQL_TYPE_STRING: case MYSQL_TYPE_VAR_STRING: case MYSQL_TYPE_TINY_BLOB: case MYSQL_TYPE_BLOB: case MYSQL_TYPE_MEDIUM_BLOB: case MYSQL_TYPE_LONG_BLOB: #if MYSQL_VERSION_ID >= 50003 case MYSQL_TYPE_NEWDECIMAL: case MYSQL_TYPE_BIT: #endif s->result.bind[i].buffer = xmalloc(field[i].max_length); memset(s->result.bind[i].buffer, 0, field[i].max_length); s->result.bind[i].buffer_length = field[i].max_length; break; case MYSQL_TYPE_TIME: case MYSQL_TYPE_DATE: case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_TIMESTAMP: s->result.bind[i].buffer = xmalloc(sizeof(MYSQL_TIME)); s->result.bind[i].buffer_length = sizeof(MYSQL_TIME); memset(s->result.bind[i].buffer, 0, sizeof(MYSQL_TIME)); break; default: rb_raise(rb_eTypeError, "unknown buffer_type: %d", s->result.bind[i].buffer_type); } } if (mysql_stmt_bind_result(s->stmt, s->result.bind)) mysql_stmt_raise(s->stmt); } return obj; } /* fetch() */ static VALUE stmt_fetch(VALUE obj) { struct mysql_stmt* s = DATA_PTR(obj); VALUE ret; int i; int r; check_stmt_closed(obj); r = mysql_stmt_fetch(s->stmt); if (r == MYSQL_NO_DATA) return Qnil; #ifdef MYSQL_DATA_TRUNCATED if (r == MYSQL_DATA_TRUNCATED) rb_raise(rb_eRuntimeError, "unexpectedly data truncated"); #endif if (r == 1) mysql_stmt_raise(s->stmt); ret = rb_ary_new2(s->result.n); for (i = 0; i < s->result.n; i++) { if (s->result.is_null[i]) rb_ary_push(ret, Qnil); else { VALUE v; MYSQL_TIME *t; switch (s->result.bind[i].buffer_type) { case MYSQL_TYPE_TINY: if (s->result.bind[i].is_unsigned) v = UINT2NUM(*(unsigned char *)s->result.bind[i].buffer); else v = INT2NUM(*(signed char *)s->result.bind[i].buffer); break; case MYSQL_TYPE_SHORT: case MYSQL_TYPE_YEAR: if (s->result.bind[i].is_unsigned) v = UINT2NUM(*(unsigned short *)s->result.bind[i].buffer); else v = INT2NUM(*(short *)s->result.bind[i].buffer); break; case MYSQL_TYPE_INT24: case MYSQL_TYPE_LONG: if (s->result.bind[i].is_unsigned) v = UINT2NUM(*(unsigned int *)s->result.bind[i].buffer); else v = INT2NUM(*(int *)s->result.bind[i].buffer); break; case MYSQL_TYPE_LONGLONG: if (s->result.bind[i].is_unsigned) v = ULL2NUM(*(unsigned long long *)s->result.bind[i].buffer); else v = LL2NUM(*(long long *)s->result.bind[i].buffer); break; case MYSQL_TYPE_FLOAT: v = rb_float_new((double)(*(float *)s->result.bind[i].buffer)); break; case MYSQL_TYPE_DOUBLE: v = rb_float_new(*(double *)s->result.bind[i].buffer); break; case MYSQL_TYPE_TIME: case MYSQL_TYPE_DATE: case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_TIMESTAMP: t = (MYSQL_TIME *)s->result.bind[i].buffer; v = rb_obj_alloc(cMysqlTime); rb_funcall(v, rb_intern("initialize"), 8, INT2FIX(t->year), INT2FIX(t->month), INT2FIX(t->day), INT2FIX(t->hour), INT2FIX(t->minute), INT2FIX(t->second), (t->neg ? Qtrue : Qfalse), INT2FIX(t->second_part)); break; case MYSQL_TYPE_DECIMAL: case MYSQL_TYPE_STRING: case MYSQL_TYPE_VAR_STRING: case MYSQL_TYPE_TINY_BLOB: case MYSQL_TYPE_BLOB: case MYSQL_TYPE_MEDIUM_BLOB: case MYSQL_TYPE_LONG_BLOB: #if MYSQL_VERSION_ID >= 50003 case MYSQL_TYPE_NEWDECIMAL: case MYSQL_TYPE_BIT: #endif v = rb_tainted_str_new(s->result.bind[i].buffer, s->result.length[i]); break; default: rb_raise(rb_eTypeError, "unknown buffer_type: %d", s->result.bind[i].buffer_type); } rb_ary_push(ret, v); } } return ret; } /* each {...} */ static VALUE stmt_each(VALUE obj) { VALUE row; check_stmt_closed(obj); while ((row = stmt_fetch(obj)) != Qnil) rb_yield(row); return obj; } /* field_count() */ static VALUE stmt_field_count(VALUE obj) { struct mysql_stmt* s = DATA_PTR(obj); unsigned int n; check_stmt_closed(obj); n = mysql_stmt_field_count(s->stmt); return INT2NUM(n); } /* free_result() */ static VALUE stmt_free_result(VALUE obj) { struct mysql_stmt* s = DATA_PTR(obj); check_stmt_closed(obj); if (mysql_stmt_free_result(s->stmt)) mysql_stmt_raise(s->stmt); return obj; } /* insert_id() */ static VALUE stmt_insert_id(VALUE obj) { struct mysql_stmt* s = DATA_PTR(obj); my_ulonglong n; check_stmt_closed(obj); n = mysql_stmt_insert_id(s->stmt); return ULL2NUM(n); } /* num_rows() */ static VALUE stmt_num_rows(VALUE obj) { struct mysql_stmt* s = DATA_PTR(obj); my_ulonglong n; check_stmt_closed(obj); n = mysql_stmt_num_rows(s->stmt); return INT2NUM(n); } /* param_count() */ static VALUE stmt_param_count(VALUE obj) { struct mysql_stmt* s = DATA_PTR(obj); unsigned long n; check_stmt_closed(obj); n = mysql_stmt_param_count(s->stmt); return INT2NUM(n); } /* prepare(query) */ static VALUE stmt_prepare(VALUE obj, VALUE query) { struct mysql_stmt* s = DATA_PTR(obj); int n; int i; MYSQL_FIELD *field; free_mysqlstmt_memory(s); check_stmt_closed(obj); Check_Type(query, T_STRING); if (mysql_stmt_prepare(s->stmt, RSTRING_PTR(query), RSTRING_LEN(query))) mysql_stmt_raise(s->stmt); n = mysql_stmt_param_count(s->stmt); s->param.n = n; s->param.bind = xmalloc(sizeof(s->param.bind[0]) * n); s->param.length = xmalloc(sizeof(s->param.length[0]) * n); s->param.buffer = xmalloc(sizeof(s->param.buffer[0]) * n); s->res = mysql_stmt_result_metadata(s->stmt); if (s->res) { n = s->result.n = mysql_num_fields(s->res); s->result.bind = xmalloc(sizeof(s->result.bind[0]) * n); s->result.is_null = xmalloc(sizeof(s->result.is_null[0]) * n); s->result.length = xmalloc(sizeof(s->result.length[0]) * n); field = mysql_fetch_fields(s->res); memset(s->result.bind, 0, sizeof(s->result.bind[0]) * n); for (i = 0; i < n; i++) { s->result.bind[i].buffer_type = field[i].type; #if MYSQL_VERSION_ID < 50003 if (field[i].type == MYSQL_TYPE_DECIMAL) s->result.bind[i].buffer_type = MYSQL_TYPE_STRING; #endif s->result.bind[i].is_null = &(s->result.is_null[i]); s->result.bind[i].length = &(s->result.length[i]); s->result.bind[i].is_unsigned = ((field[i].flags & UNSIGNED_FLAG) != 0); } } else { if (mysql_stmt_errno(s->stmt)) mysql_stmt_raise(s->stmt); } return obj; } #if 0 /* reset() */ static VALUE stmt_reset(VALUE obj) { struct mysql_stmt* s = DATA_PTR(obj); check_stmt_closed(obj); if (mysql_stmt_reset(s->stmt)) mysql_stmt_raise(s->stmt); return obj; } #endif /* result_metadata() */ static VALUE stmt_result_metadata(VALUE obj) { struct mysql_stmt* s = DATA_PTR(obj); MYSQL_RES *res; check_stmt_closed(obj); res = mysql_stmt_result_metadata(s->stmt); if (res == NULL) { if (mysql_stmt_errno(s->stmt) != 0) mysql_stmt_raise(s->stmt); return Qnil; } return mysqlres2obj(res); } /* row_seek(offset) */ static VALUE stmt_row_seek(VALUE obj, VALUE offset) { struct mysql_stmt* s = DATA_PTR(obj); MYSQL_ROW_OFFSET prev_offset; if (CLASS_OF(offset) != cMysqlRowOffset) rb_raise(rb_eTypeError, "wrong argument type %s (expected Mysql::RowOffset)", rb_obj_classname(offset)); check_stmt_closed(obj); prev_offset = mysql_stmt_row_seek(s->stmt, DATA_PTR(offset)); return Data_Wrap_Struct(cMysqlRowOffset, 0, NULL, prev_offset); } /* row_tell() */ static VALUE stmt_row_tell(VALUE obj) { struct mysql_stmt* s = DATA_PTR(obj); MYSQL_ROW_OFFSET offset; check_stmt_closed(obj); offset = mysql_stmt_row_tell(s->stmt); return Data_Wrap_Struct(cMysqlRowOffset, 0, NULL, offset); } #if 0 /* send_long_data(col, data) */ static VALUE stmt_send_long_data(VALUE obj, VALUE col, VALUE data) { struct mysql_stmt* s = DATA_PTR(obj); int c; check_stmt_closed(obj); c = NUM2INT(col); if (0 <= c && c < s->param.n) { s->param.bind[c].buffer_type = MYSQL_TYPE_STRING; if (mysql_stmt_bind_param(s->stmt, s->param.bind)) mysql_stmt_raise(s->stmt); } if (mysql_stmt_send_long_data(s->stmt, c, RSTRING_PTR(data), RSTRING_LEN(data))) mysql_stmt_raise(s->stmt); return obj; } #endif /* sqlstate() */ static VALUE stmt_sqlstate(VALUE obj) { struct mysql_stmt* s = DATA_PTR(obj); return rb_tainted_str_new2(mysql_stmt_sqlstate(s->stmt)); } /*------------------------------- * Mysql::Time object method */ static VALUE time_initialize(int argc, VALUE* argv, VALUE obj) { VALUE year, month, day, hour, minute, second, neg, second_part; rb_scan_args(argc, argv, "08", &year, &month, &day, &hour, &minute, &second, &neg, &second_part); #define NILorFIXvalue(o) (NIL_P(o) ? INT2FIX(0) : (Check_Type(o, T_FIXNUM), o)) rb_iv_set(obj, "year", NILorFIXvalue(year)); rb_iv_set(obj, "month", NILorFIXvalue(month)); rb_iv_set(obj, "day", NILorFIXvalue(day)); rb_iv_set(obj, "hour", NILorFIXvalue(hour)); rb_iv_set(obj, "minute", NILorFIXvalue(minute)); rb_iv_set(obj, "second", NILorFIXvalue(second)); rb_iv_set(obj, "neg", (neg == Qnil || neg == Qfalse) ? Qfalse : Qtrue); rb_iv_set(obj, "second_part", NILorFIXvalue(second_part)); return obj; } static VALUE time_inspect(VALUE obj) { char buf[36]; sprintf(buf, "#", NUM2INT(rb_iv_get(obj, "year")), NUM2INT(rb_iv_get(obj, "month")), NUM2INT(rb_iv_get(obj, "day")), NUM2INT(rb_iv_get(obj, "hour")), NUM2INT(rb_iv_get(obj, "minute")), NUM2INT(rb_iv_get(obj, "second"))); return rb_str_new2(buf); } static VALUE time_to_s(VALUE obj) { char buf[20]; sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d", NUM2INT(rb_iv_get(obj, "year")), NUM2INT(rb_iv_get(obj, "month")), NUM2INT(rb_iv_get(obj, "day")), NUM2INT(rb_iv_get(obj, "hour")), NUM2INT(rb_iv_get(obj, "minute")), NUM2INT(rb_iv_get(obj, "second"))); return rb_str_new2(buf); } #define DefineMysqlTimeGetMethod(m)\ static VALUE time_get_##m(VALUE obj)\ {return rb_iv_get(obj, #m);} DefineMysqlTimeGetMethod(year) DefineMysqlTimeGetMethod(month) DefineMysqlTimeGetMethod(day) DefineMysqlTimeGetMethod(hour) DefineMysqlTimeGetMethod(minute) DefineMysqlTimeGetMethod(second) DefineMysqlTimeGetMethod(neg) DefineMysqlTimeGetMethod(second_part) #define DefineMysqlTimeSetMethod(m)\ static VALUE time_set_##m(VALUE obj, VALUE v)\ {rb_iv_set(obj, #m, NILorFIXvalue(v)); return v;} DefineMysqlTimeSetMethod(year) DefineMysqlTimeSetMethod(month) DefineMysqlTimeSetMethod(day) DefineMysqlTimeSetMethod(hour) DefineMysqlTimeSetMethod(minute) DefineMysqlTimeSetMethod(second) DefineMysqlTimeSetMethod(second_part) static VALUE time_set_neg(VALUE obj, VALUE v) { rb_iv_set(obj, "neg", (v == Qnil || v == Qfalse) ? Qfalse : Qtrue); return v; } static VALUE time_equal(VALUE obj, VALUE v) { if (CLASS_OF(v) == cMysqlTime && NUM2INT(rb_iv_get(obj, "year")) == NUM2INT(rb_iv_get(v, "year")) && NUM2INT(rb_iv_get(obj, "month")) == NUM2INT(rb_iv_get(v, "month")) && NUM2INT(rb_iv_get(obj, "day")) == NUM2INT(rb_iv_get(v, "day")) && NUM2INT(rb_iv_get(obj, "hour")) == NUM2INT(rb_iv_get(v, "hour")) && NUM2INT(rb_iv_get(obj, "minute")) == NUM2INT(rb_iv_get(v, "minute")) && NUM2INT(rb_iv_get(obj, "second")) == NUM2INT(rb_iv_get(v, "second")) && rb_iv_get(obj, "neg") == rb_iv_get(v, "neg") && NUM2INT(rb_iv_get(obj, "second_part")) == NUM2INT(rb_iv_get(v, "second_part"))) return Qtrue; return Qfalse; } #endif /*------------------------------- * Mysql::Error object method */ static VALUE error_error(VALUE obj) { return rb_iv_get(obj, "mesg"); } static VALUE error_errno(VALUE obj) { return rb_iv_get(obj, "errno"); } static VALUE error_sqlstate(VALUE obj) { return rb_iv_get(obj, "sqlstate"); } /*------------------------------- * Initialize */ void Init_mysql_api(void) { int i; int dots = 0; const char *lib = mysql_get_client_info(); for (i = 0; lib[i] != 0 && MYSQL_SERVER_VERSION[i] != 0; i++) { if (lib[i] == '.') { dots++; /* we only compare MAJOR and MINOR */ if (dots == 2) break; } if (lib[i] != MYSQL_SERVER_VERSION[i]) { rb_raise(rb_eRuntimeError, "Incorrect MySQL client library version! This gem was compiled for %s but the client library is %s.", MYSQL_SERVER_VERSION, lib); return; } } cMysql = rb_define_class("Mysql", rb_cObject); cMysqlRes = rb_define_class_under(cMysql, "Result", rb_cObject); cMysqlField = rb_define_class_under(cMysql, "Field", rb_cObject); #if MYSQL_VERSION_ID >= 40102 cMysqlStmt = rb_define_class_under(cMysql, "Stmt", rb_cObject); cMysqlRowOffset = rb_define_class_under(cMysql, "RowOffset", rb_cObject); cMysqlTime = rb_define_class_under(cMysql, "Time", rb_cObject); #endif eMysql = rb_define_class_under(cMysql, "Error", rb_eStandardError); rb_define_global_const("MysqlRes", cMysqlRes); rb_define_global_const("MysqlField", cMysqlField); rb_define_global_const("MysqlError", eMysql); /* Mysql class method */ rb_define_singleton_method(cMysql, "init", init, 0); rb_define_singleton_method(cMysql, "real_connect", real_connect, -1); rb_define_singleton_method(cMysql, "connect", real_connect, -1); rb_define_singleton_method(cMysql, "new", real_connect, -1); rb_define_singleton_method(cMysql, "escape_string", escape_string, 1); rb_define_singleton_method(cMysql, "quote", escape_string, 1); rb_define_singleton_method(cMysql, "client_info", client_info, 0); rb_define_singleton_method(cMysql, "get_client_info", client_info, 0); #if MYSQL_VERSION_ID >= 32332 rb_define_singleton_method(cMysql, "debug", my_debug, 1); #endif #if MYSQL_VERSION_ID >= 40000 rb_define_singleton_method(cMysql, "get_client_version", client_version, 0); rb_define_singleton_method(cMysql, "client_version", client_version, 0); #endif /* Mysql object method */ #if MYSQL_VERSION_ID >= 32200 rb_define_method(cMysql, "real_connect", real_connect2, -1); rb_define_method(cMysql, "connect", real_connect2, -1); rb_define_method(cMysql, "options", options, -1); #endif rb_define_method(cMysql, "initialize", initialize, -1); #if MYSQL_VERSION_ID >= 32332 rb_define_method(cMysql, "escape_string", real_escape_string, 1); rb_define_method(cMysql, "quote", real_escape_string, 1); #else rb_define_method(cMysql, "escape_string", escape_string, 1); rb_define_method(cMysql, "quote", escape_string, 1); #endif rb_define_method(cMysql, "client_info", client_info, 0); rb_define_method(cMysql, "get_client_info", client_info, 0); rb_define_method(cMysql, "affected_rows", affected_rows, 0); #if MYSQL_VERSION_ID >= 32303 rb_define_method(cMysql, "change_user", change_user, -1); #endif #if MYSQL_VERSION_ID >= 32321 rb_define_method(cMysql, "character_set_name", character_set_name, 0); #endif rb_define_method(cMysql, "close", my_close, 0); #if MYSQL_VERSION_ID < 40000 rb_define_method(cMysql, "create_db", create_db, 1); rb_define_method(cMysql, "drop_db", drop_db, 1); #endif #if MYSQL_VERSION_ID >= 32332 rb_define_method(cMysql, "dump_debug_info", dump_debug_info, 0); #endif rb_define_method(cMysql, "errno", my_errno, 0); rb_define_method(cMysql, "error", my_error, 0); rb_define_method(cMysql, "field_count", field_count, 0); #if MYSQL_VERSION_ID >= 40000 rb_define_method(cMysql, "get_client_version", client_version, 0); rb_define_method(cMysql, "client_version", client_version, 0); #endif rb_define_method(cMysql, "get_host_info", host_info, 0); rb_define_method(cMysql, "host_info", host_info, 0); rb_define_method(cMysql, "get_proto_info", proto_info, 0); rb_define_method(cMysql, "proto_info", proto_info, 0); rb_define_method(cMysql, "get_server_info", server_info, 0); rb_define_method(cMysql, "server_info", server_info, 0); rb_define_method(cMysql, "info", info, 0); rb_define_method(cMysql, "insert_id", insert_id, 0); rb_define_method(cMysql, "kill", my_kill, 1); rb_define_method(cMysql, "list_dbs", list_dbs, -1); rb_define_method(cMysql, "list_fields", list_fields, -1); rb_define_method(cMysql, "list_processes", list_processes, 0); rb_define_method(cMysql, "list_tables", list_tables, -1); #if MYSQL_VERSION_ID >= 32200 rb_define_method(cMysql, "ping", ping, 0); #endif rb_define_method(cMysql, "query", query, 1); rb_define_method(cMysql, "real_query", query, 1); rb_define_method(cMysql, "refresh", refresh, 1); rb_define_method(cMysql, "reload", reload, 0); rb_define_method(cMysql, "select_db", select_db, 1); rb_define_method(cMysql, "shutdown", my_shutdown, -1); rb_define_method(cMysql, "stat", my_stat, 0); rb_define_method(cMysql, "store_result", store_result, 0); rb_define_method(cMysql, "thread_id", thread_id, 0); rb_define_method(cMysql, "use_result", use_result, 0); #if MYSQL_VERSION_ID >= 40100 rb_define_method(cMysql, "get_server_version", server_version, 0); rb_define_method(cMysql, "server_version", server_version, 0); rb_define_method(cMysql, "warning_count", warning_count, 0); rb_define_method(cMysql, "commit", commit, 0); rb_define_method(cMysql, "rollback", rollback, 0); rb_define_method(cMysql, "autocommit", autocommit, 1); #endif #ifdef HAVE_MYSQL_SSL_SET rb_define_method(cMysql, "ssl_set", ssl_set, -1); #endif #if MYSQL_VERSION_ID >= 40102 rb_define_method(cMysql, "stmt_init", stmt_init, 0); rb_define_method(cMysql, "prepare", prepare, 1); #endif #if MYSQL_VERSION_ID >= 40100 rb_define_method(cMysql, "more_results", more_results, 0); rb_define_method(cMysql, "more_results?", more_results, 0); rb_define_method(cMysql, "next_result", next_result, 0); #endif #if MYSQL_VERSION_ID >= 40101 rb_define_method(cMysql, "set_server_option", set_server_option, 1); rb_define_method(cMysql, "sqlstate", sqlstate, 0); #endif rb_define_method(cMysql, "query_with_result", query_with_result, 0); rb_define_method(cMysql, "query_with_result=", query_with_result_set, 1); rb_define_method(cMysql, "reconnect", reconnect, 0); rb_define_method(cMysql, "reconnect=", reconnect_set, 1); /* Mysql constant */ rb_define_const(cMysql, "VERSION", INT2FIX(MYSQL_RUBY_VERSION)); #if MYSQL_VERSION_ID >= 32200 rb_define_const(cMysql, "OPT_CONNECT_TIMEOUT", INT2NUM(MYSQL_OPT_CONNECT_TIMEOUT)); rb_define_const(cMysql, "OPT_COMPRESS", INT2NUM(MYSQL_OPT_COMPRESS)); rb_define_const(cMysql, "OPT_NAMED_PIPE", INT2NUM(MYSQL_OPT_NAMED_PIPE)); rb_define_const(cMysql, "INIT_COMMAND", INT2NUM(MYSQL_INIT_COMMAND)); rb_define_const(cMysql, "READ_DEFAULT_FILE", INT2NUM(MYSQL_READ_DEFAULT_FILE)); rb_define_const(cMysql, "READ_DEFAULT_GROUP", INT2NUM(MYSQL_READ_DEFAULT_GROUP)); #endif #if MYSQL_VERSION_ID >= 32349 rb_define_const(cMysql, "SET_CHARSET_DIR", INT2NUM(MYSQL_SET_CHARSET_DIR)); rb_define_const(cMysql, "SET_CHARSET_NAME", INT2NUM(MYSQL_SET_CHARSET_NAME)); rb_define_const(cMysql, "OPT_LOCAL_INFILE", INT2NUM(MYSQL_OPT_LOCAL_INFILE)); #endif #if MYSQL_VERSION_ID >= 40100 rb_define_const(cMysql, "OPT_PROTOCOL", INT2NUM(MYSQL_OPT_PROTOCOL)); rb_define_const(cMysql, "SHARED_MEMORY_BASE_NAME", INT2NUM(MYSQL_SHARED_MEMORY_BASE_NAME)); #endif #if MYSQL_VERSION_ID >= 40101 rb_define_const(cMysql, "OPT_READ_TIMEOUT", INT2NUM(MYSQL_OPT_READ_TIMEOUT)); rb_define_const(cMysql, "OPT_WRITE_TIMEOUT", INT2NUM(MYSQL_OPT_WRITE_TIMEOUT)); rb_define_const(cMysql, "SECURE_AUTH", INT2NUM(MYSQL_SECURE_AUTH)); rb_define_const(cMysql, "OPT_GUESS_CONNECTION", INT2NUM(MYSQL_OPT_GUESS_CONNECTION)); rb_define_const(cMysql, "OPT_USE_EMBEDDED_CONNECTION", INT2NUM(MYSQL_OPT_USE_EMBEDDED_CONNECTION)); rb_define_const(cMysql, "OPT_USE_REMOTE_CONNECTION", INT2NUM(MYSQL_OPT_USE_REMOTE_CONNECTION)); rb_define_const(cMysql, "SET_CLIENT_IP", INT2NUM(MYSQL_SET_CLIENT_IP)); #endif rb_define_const(cMysql, "REFRESH_GRANT", INT2NUM(REFRESH_GRANT)); rb_define_const(cMysql, "REFRESH_LOG", INT2NUM(REFRESH_LOG)); rb_define_const(cMysql, "REFRESH_TABLES", INT2NUM(REFRESH_TABLES)); #ifdef REFRESH_HOSTS rb_define_const(cMysql, "REFRESH_HOSTS", INT2NUM(REFRESH_HOSTS)); #endif #ifdef REFRESH_STATUS rb_define_const(cMysql, "REFRESH_STATUS", INT2NUM(REFRESH_STATUS)); #endif #ifdef REFRESH_THREADS rb_define_const(cMysql, "REFRESH_THREADS", INT2NUM(REFRESH_THREADS)); #endif #ifdef REFRESH_SLAVE rb_define_const(cMysql, "REFRESH_SLAVE", INT2NUM(REFRESH_SLAVE)); #endif #ifdef REFRESH_MASTER rb_define_const(cMysql, "REFRESH_MASTER", INT2NUM(REFRESH_MASTER)); #endif #ifdef CLIENT_LONG_PASSWORD #endif #ifdef CLIENT_FOUND_ROWS rb_define_const(cMysql, "CLIENT_FOUND_ROWS", INT2NUM(CLIENT_FOUND_ROWS)); #endif #ifdef CLIENT_LONG_FLAG #endif #ifdef CLIENT_CONNECT_WITH_DB #endif #ifdef CLIENT_NO_SCHEMA rb_define_const(cMysql, "CLIENT_NO_SCHEMA", INT2NUM(CLIENT_NO_SCHEMA)); #endif #ifdef CLIENT_COMPRESS rb_define_const(cMysql, "CLIENT_COMPRESS", INT2NUM(CLIENT_COMPRESS)); #endif #ifdef CLIENT_ODBC rb_define_const(cMysql, "CLIENT_ODBC", INT2NUM(CLIENT_ODBC)); #endif #ifdef CLIENT_LOCAL_FILES rb_define_const(cMysql, "CLIENT_LOCAL_FILES", INT2NUM(CLIENT_LOCAL_FILES)); #endif #ifdef CLIENT_IGNORE_SPACE rb_define_const(cMysql, "CLIENT_IGNORE_SPACE", INT2NUM(CLIENT_IGNORE_SPACE)); #endif #ifdef CLIENT_CHANGE_USER rb_define_const(cMysql, "CLIENT_CHANGE_USER", INT2NUM(CLIENT_CHANGE_USER)); #endif #ifdef CLIENT_INTERACTIVE rb_define_const(cMysql, "CLIENT_INTERACTIVE", INT2NUM(CLIENT_INTERACTIVE)); #endif #ifdef CLIENT_SSL rb_define_const(cMysql, "CLIENT_SSL", INT2NUM(CLIENT_SSL)); #endif #ifdef CLIENT_IGNORE_SIGPIPE rb_define_const(cMysql, "CLIENT_IGNORE_SIGPIPE", INT2NUM(CLIENT_IGNORE_SIGPIPE)); #endif #ifdef CLIENT_TRANSACTIONS rb_define_const(cMysql, "CLIENT_TRANSACTIONS", INT2NUM(CLIENT_TRANSACTIONS)); #endif #ifdef CLIENT_MULTI_STATEMENTS rb_define_const(cMysql, "CLIENT_MULTI_STATEMENTS", INT2NUM(CLIENT_MULTI_STATEMENTS)); #endif #ifdef CLIENT_MULTI_RESULTS rb_define_const(cMysql, "CLIENT_MULTI_RESULTS", INT2NUM(CLIENT_MULTI_RESULTS)); #endif #if MYSQL_VERSION_ID >= 40101 rb_define_const(cMysql, "OPTION_MULTI_STATEMENTS_ON", INT2NUM(MYSQL_OPTION_MULTI_STATEMENTS_ON)); rb_define_const(cMysql, "OPTION_MULTI_STATEMENTS_OFF", INT2NUM(MYSQL_OPTION_MULTI_STATEMENTS_OFF)); #endif /* Mysql::Result object method */ rb_define_method(cMysqlRes, "data_seek", data_seek, 1); rb_define_method(cMysqlRes, "fetch_field", fetch_field, 0); rb_define_method(cMysqlRes, "fetch_fields", fetch_fields, 0); rb_define_method(cMysqlRes, "fetch_field_direct", fetch_field_direct, 1); rb_define_method(cMysqlRes, "fetch_lengths", fetch_lengths, 0); rb_define_method(cMysqlRes, "fetch_row", fetch_row, 0); rb_define_method(cMysqlRes, "fetch_hash", fetch_hash, -1); rb_define_method(cMysqlRes, "field_seek", field_seek, 1); rb_define_method(cMysqlRes, "field_tell", field_tell, 0); rb_define_method(cMysqlRes, "free", res_free, 0); rb_define_method(cMysqlRes, "num_fields", num_fields, 0); rb_define_method(cMysqlRes, "num_rows", num_rows, 0); rb_define_method(cMysqlRes, "row_seek", row_seek, 1); rb_define_method(cMysqlRes, "row_tell", row_tell, 0); rb_define_method(cMysqlRes, "each", each, 0); rb_define_method(cMysqlRes, "each_hash", each_hash, -1); /* MysqlField object method */ rb_define_method(cMysqlField, "name", field_name, 0); rb_define_method(cMysqlField, "table", field_table, 0); rb_define_method(cMysqlField, "def", field_def, 0); rb_define_method(cMysqlField, "type", field_type, 0); rb_define_method(cMysqlField, "length", field_length, 0); rb_define_method(cMysqlField, "max_length", field_max_length, 0); rb_define_method(cMysqlField, "flags", field_flags, 0); rb_define_method(cMysqlField, "decimals", field_decimals, 0); rb_define_method(cMysqlField, "hash", field_hash, 0); rb_define_method(cMysqlField, "inspect", field_inspect, 0); #ifdef IS_NUM rb_define_method(cMysqlField, "is_num?", field_is_num, 0); #endif #ifdef IS_NOT_NULL rb_define_method(cMysqlField, "is_not_null?", field_is_not_null, 0); #endif #ifdef IS_PRI_KEY rb_define_method(cMysqlField, "is_pri_key?", field_is_pri_key, 0); #endif /* Mysql::Field constant: TYPE */ rb_define_const(cMysqlField, "TYPE_TINY", INT2NUM(FIELD_TYPE_TINY)); #if MYSQL_VERSION_ID >= 32115 rb_define_const(cMysqlField, "TYPE_ENUM", INT2NUM(FIELD_TYPE_ENUM)); #endif rb_define_const(cMysqlField, "TYPE_DECIMAL", INT2NUM(FIELD_TYPE_DECIMAL)); rb_define_const(cMysqlField, "TYPE_SHORT", INT2NUM(FIELD_TYPE_SHORT)); rb_define_const(cMysqlField, "TYPE_LONG", INT2NUM(FIELD_TYPE_LONG)); rb_define_const(cMysqlField, "TYPE_FLOAT", INT2NUM(FIELD_TYPE_FLOAT)); rb_define_const(cMysqlField, "TYPE_DOUBLE", INT2NUM(FIELD_TYPE_DOUBLE)); rb_define_const(cMysqlField, "TYPE_NULL", INT2NUM(FIELD_TYPE_NULL)); rb_define_const(cMysqlField, "TYPE_TIMESTAMP", INT2NUM(FIELD_TYPE_TIMESTAMP)); rb_define_const(cMysqlField, "TYPE_LONGLONG", INT2NUM(FIELD_TYPE_LONGLONG)); rb_define_const(cMysqlField, "TYPE_INT24", INT2NUM(FIELD_TYPE_INT24)); rb_define_const(cMysqlField, "TYPE_DATE", INT2NUM(FIELD_TYPE_DATE)); rb_define_const(cMysqlField, "TYPE_TIME", INT2NUM(FIELD_TYPE_TIME)); rb_define_const(cMysqlField, "TYPE_DATETIME", INT2NUM(FIELD_TYPE_DATETIME)); #if MYSQL_VERSION_ID >= 32130 rb_define_const(cMysqlField, "TYPE_YEAR", INT2NUM(FIELD_TYPE_YEAR)); #endif #if MYSQL_VERSION_ID >= 50003 rb_define_const(cMysqlField, "TYPE_BIT", INT2NUM(FIELD_TYPE_BIT)); rb_define_const(cMysqlField, "TYPE_NEWDECIMAL", INT2NUM(FIELD_TYPE_NEWDECIMAL)); #endif rb_define_const(cMysqlField, "TYPE_SET", INT2NUM(FIELD_TYPE_SET)); rb_define_const(cMysqlField, "TYPE_BLOB", INT2NUM(FIELD_TYPE_BLOB)); rb_define_const(cMysqlField, "TYPE_STRING", INT2NUM(FIELD_TYPE_STRING)); #if MYSQL_VERSION_ID >= 40000 rb_define_const(cMysqlField, "TYPE_VAR_STRING", INT2NUM(FIELD_TYPE_VAR_STRING)); #endif rb_define_const(cMysqlField, "TYPE_CHAR", INT2NUM(FIELD_TYPE_CHAR)); /* Mysql::Field constant: FLAG */ rb_define_const(cMysqlField, "NOT_NULL_FLAG", INT2NUM(NOT_NULL_FLAG)); rb_define_const(cMysqlField, "PRI_KEY_FLAG", INT2NUM(PRI_KEY_FLAG)); rb_define_const(cMysqlField, "UNIQUE_KEY_FLAG", INT2NUM(UNIQUE_KEY_FLAG)); rb_define_const(cMysqlField, "MULTIPLE_KEY_FLAG", INT2NUM(MULTIPLE_KEY_FLAG)); rb_define_const(cMysqlField, "BLOB_FLAG", INT2NUM(BLOB_FLAG)); rb_define_const(cMysqlField, "UNSIGNED_FLAG", INT2NUM(UNSIGNED_FLAG)); rb_define_const(cMysqlField, "ZEROFILL_FLAG", INT2NUM(ZEROFILL_FLAG)); rb_define_const(cMysqlField, "BINARY_FLAG", INT2NUM(BINARY_FLAG)); #ifdef ENUM_FLAG rb_define_const(cMysqlField, "ENUM_FLAG", INT2NUM(ENUM_FLAG)); #endif #ifdef AUTO_INCREMENT_FLAG rb_define_const(cMysqlField, "AUTO_INCREMENT_FLAG", INT2NUM(AUTO_INCREMENT_FLAG)); #endif #ifdef TIMESTAMP_FLAG rb_define_const(cMysqlField, "TIMESTAMP_FLAG", INT2NUM(TIMESTAMP_FLAG)); #endif #ifdef SET_FLAG rb_define_const(cMysqlField, "SET_FLAG", INT2NUM(SET_FLAG)); #endif #ifdef NUM_FLAG rb_define_const(cMysqlField, "NUM_FLAG", INT2NUM(NUM_FLAG)); #endif #ifdef PART_KEY_FLAG rb_define_const(cMysqlField, "PART_KEY_FLAG", INT2NUM(PART_KEY_FLAG)); #endif #if MYSQL_VERSION_ID >= 40102 /* Mysql::Stmt object method */ rb_define_method(cMysqlStmt, "affected_rows", stmt_affected_rows, 0); #if 0 rb_define_method(cMysqlStmt, "attr_get", stmt_attr_get, 1); rb_define_method(cMysqlStmt, "attr_set", stmt_attr_set, 2); #endif rb_define_method(cMysqlStmt, "bind_result", stmt_bind_result, -1); rb_define_method(cMysqlStmt, "close", stmt_close, 0); rb_define_method(cMysqlStmt, "data_seek", stmt_data_seek, 1); rb_define_method(cMysqlStmt, "each", stmt_each, 0); rb_define_method(cMysqlStmt, "execute", stmt_execute, -1); rb_define_method(cMysqlStmt, "fetch", stmt_fetch, 0); rb_define_method(cMysqlStmt, "field_count", stmt_field_count, 0); rb_define_method(cMysqlStmt, "free_result", stmt_free_result, 0); rb_define_method(cMysqlStmt, "insert_id", stmt_insert_id, 0); rb_define_method(cMysqlStmt, "num_rows", stmt_num_rows, 0); rb_define_method(cMysqlStmt, "param_count", stmt_param_count, 0); rb_define_method(cMysqlStmt, "prepare", stmt_prepare, 1); #if 0 rb_define_method(cMysqlStmt, "reset", stmt_reset, 0); #endif rb_define_method(cMysqlStmt, "result_metadata", stmt_result_metadata, 0); rb_define_method(cMysqlStmt, "row_seek", stmt_row_seek, 1); rb_define_method(cMysqlStmt, "row_tell", stmt_row_tell, 0); #if 0 rb_define_method(cMysqlStmt, "send_long_data", stmt_send_long_data, 2); #endif rb_define_method(cMysqlStmt, "sqlstate", stmt_sqlstate, 0); #if 0 rb_define_const(cMysqlStmt, "ATTR_UPDATE_MAX_LENGTH", INT2NUM(STMT_ATTR_UPDATE_MAX_LENGTH)); #endif /* Mysql::Time object method */ rb_define_method(cMysqlTime, "initialize", time_initialize, -1); rb_define_method(cMysqlTime, "inspect", time_inspect, 0); rb_define_method(cMysqlTime, "to_s", time_to_s, 0); rb_define_method(cMysqlTime, "year", time_get_year, 0); rb_define_method(cMysqlTime, "month", time_get_month, 0); rb_define_method(cMysqlTime, "day", time_get_day, 0); rb_define_method(cMysqlTime, "hour", time_get_hour, 0); rb_define_method(cMysqlTime, "minute", time_get_minute, 0); rb_define_method(cMysqlTime, "second", time_get_second, 0); rb_define_method(cMysqlTime, "neg", time_get_neg, 0); rb_define_method(cMysqlTime, "second_part", time_get_second_part, 0); rb_define_method(cMysqlTime, "year=", time_set_year, 1); rb_define_method(cMysqlTime, "month=", time_set_month, 1); rb_define_method(cMysqlTime, "day=", time_set_day, 1); rb_define_method(cMysqlTime, "hour=", time_set_hour, 1); rb_define_method(cMysqlTime, "minute=", time_set_minute, 1); rb_define_method(cMysqlTime, "second=", time_set_second, 1); rb_define_method(cMysqlTime, "neg=", time_set_neg, 1); rb_define_method(cMysqlTime, "second_part=", time_set_second_part, 1); rb_define_method(cMysqlTime, "==", time_equal, 1); #endif /* Mysql::Error object method */ rb_define_method(eMysql, "error", error_error, 0); rb_define_method(eMysql, "errno", error_errno, 0); rb_define_method(eMysql, "sqlstate", error_sqlstate, 0); /* Mysql::Error constant */ #define rb_define_mysql_const(s) rb_define_const(eMysql, #s, INT2NUM(s)) #include "error_const.h" } mysql-2.9.1/COPYING0000644000004100000410000000467512414313001013754 0ustar www-datawww-dataRuby is copyrighted free software by Yukihiro Matsumoto . You can redistribute it and/or modify it under either the terms of the GPL (see the file GPL), or the conditions below: 1. You may make and give away verbatim copies of the source form of the software without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may modify your copy of the software in any way, provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or by allowing the author to include your modifications in the software. b) use the modified software only within your corporation or organization. c) give non-standard binaries non-standard names, with instructions on where to get the original software distribution. d) make other distribution arrangements with the author. 3. You may distribute the software in object code or binary form, provided that you do at least ONE of the following: a) distribute the binaries and library files of the software, together with instructions (in the manual page or equivalent) on where to get the original distribution. b) accompany the distribution with the machine-readable source of the software. c) give non-standard binaries non-standard names, with instructions on where to get the original software distribution. d) make other distribution arrangements with the author. 4. You may modify and include the part of the software into any other software (possibly commercial). But some files in the distribution are not written by the author, so that they are not under these terms. For the list of those files and their copying conditions, see the file LEGAL. 5. The scripts and library files supplied as input to or produced as output from the software do not automatically fall under the copyright of the software, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this software. 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.