MySQL/Ruby

[English]


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

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

ɬÍפʤâ¤Î

¤³¤ì¤é°Ê³°¤Ç¤â 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
2009-02-01
version 2.8.1
2008-09-29
version 2.8
version 2.7.7
2008-06-20
version 2.8pre4
2008-06-17
version 2.8pre3
version 2.7.6
2008-03-08
version 2.8pre2
version 2.7.5
2007-12-26
version 2.8pre1
2007-08-22
version 2.7.4
2006-12-20
version 2.7.3
2006-10-28
version 2.7.2
2006-06-04
version 2.7.1
2005-08-22
version 2.7
2005-08-16
version 2.7-beta3
2005-08-02
version 2.7-beta2
2005-07-24
version 2.7-beta
2005-07-31
version 2.6.3
2005-07-26
version 2.6.2
2005-06-28
version 2.6.1
2005-04-25
version 2.6
2005-02-12
version 2.5.2
2004-09-20
version 2.5.1
2004-08-31
version 2.5
2003-08-10
version 2.4.5
2003-02-23
version 2.4.4a
2003-01-29
version 2.4.4
2003-01-05
version 2.4.3c
2002-12-24
version 2.4.3b
2002-11-07
version 2.4.3a
2002-09-10
version 2.4.3
2002-01-07
version 2.4.2
2001-12-02
version 2.4.1
2001-10-12
version 2.4.0
2001-03-25
version 2.3.2a
2001-03-19
version 2.3.2
2000-09-02
version 2.3.1
2000-07-22
version 2.3.0
2000-05-27
version 2.2.1a
2000-05-10
version 2.2.1
1999-09-28
version 2.2.0
1999-09-24
version 2.1.7
1999-06-17
version 2.1.6
1999-06-12
version 2.1.5
1999-05-30
version 2.1.4
1999-04-13
version 2.1.3
1999-02-01
version 2.1.2
1999-01-24
version 2.1.1
1999-01-17
version 2.1
1998-11-29
version 2.0.1
1998-11-15
version 2.0
1998-08-13
version 1.0

ºî¼Ô

e-mail: ¤È¤ß¤¿¤Þ¤µ¤Ò¤í [email protected] http://tmtm.org


TOMITA Masahiro
Last modified: Sun Feb 1 17:48:26 JST 2009