`
Anleb
  • 浏览: 32982 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

MySQL 5.0.27 API备忘

阅读更多
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

tmtm.org
Requirement

MySQL 5.0.27
Ruby 1.8.5
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. if you specify multiple query, then repeat block. set_server_option(Mysql::OPTION_MULTI_STATEMENTS) is executed automatically.

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 type Ruby class
TINYINT, SMALLINT, MEDIUMINT, YEAR Fixnum
INT, BIGINT Fixnum or Bignum
FLOAT, DOUBLE Float
DECIMAL String
DATE, DATETIME, TIMESTAMP, TIME Mysql::Time
CHAR, VARCHAR, BINARY, VARBINARY, TINYBLOB, TINYTEXT, TINYBLOB, TINYTEXT, MEDIUMBLOB, MEDIUMTEXT, LONGBLOB, LONGTEXT, ENUM, SET, BIT String
NULL NilClass
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

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: Wed Dec 20 14:30:14 JST 2006
分享到:
评论

相关推荐

    mysql-5.0.27-win32.zip

    MySQL 5.0.27 是 MySQL 数据库管理系统的一个历史版本,专为 Windows 操作系统设计。这个版本在2008年发布,是 MySQL 5.0 系列的重要组成部分,提供了稳定性和性能的改进。MySQL 是一个开源、免费的关系型数据库管理...

    mysql5.0.27

    对于PHP开发者来说,MySQL 5.0.27的API和PHP的MySQL扩展(如mysqli和PDO_MySQL)提供了简单易用的接口,使得连接、操作数据库变得轻松。例如,可以使用预编译语句防止SQL注入攻击,使用事务来保证数据的一致性,以及...

    mysql-5.0.27-win32

    MySQL 5.0.27 是 MySQL 数据库管理系统的一个较早版本,专为 Windows 32 位操作系统设计。MySQL 是一个开源的关系型数据库系统,以其高效、稳定和易用性而闻名,广泛应用于 Web 开发,特别是与 Java 企业级应用...

    MySQL5.0.27_win32

    MySQL5.0.27_win32是MySQL数据库的一个早期版本,主要针对Windows 32位操作系统设计。这个版本以其快速的安装过程和较低的内存需求而受到欢迎,尤其适合那些刚开始学习数据库管理或者资源有限的环境。MySQL作为全球...

    mysql-5.0.27.tar.gz

    MySQL 5.0.27 是一个在Linux操作系统环境下广泛使用的开源关系型数据库管理系统(RDBMS)。这个版本是MySQL发展历史中的一个重要里程碑,它带来了许多功能改进和性能优化,旨在提升系统的稳定性和效率。 首先,...

    mysql.5.0.27.win32

    MySQL 5.0.27 是 MySQL 数据库管理系统的一个特定版本,专为在基于 Win32 的操作系统上运行而设计。这个版本发布于 MySQL 的早期发展时期,它提供了当时先进的数据库功能,支持多种数据类型、SQL 标准以及优化的性能...

    windows下mysql5.0.27详细安装带图.docx

    ### Windows 下 MySQL 5.0.27 的详细安装步骤及配置 #### 一、安装前准备 在开始安装 MySQL 5.0.27 之前,首先需要确保已经下载了正确的安装包 `mysql-5.0.27-win32.zip`。此版本适用于 Windows 平台,并且是针对 ...

    mysql-5.0.27-win32及mysql-front安装文件

    这个压缩包文件包含了"mysql-5.0.27-win32"和"MySQL-Front_Setup",这两个组件对于初学者来说是搭建和管理MySQL数据库的基础。 首先,我们来看"mysql-5.0.27-win32"。这是一款专为Windows操作系统设计的MySQL服务器...

    mysql-essential-5.0.27-win32.rar

    这个"mysql-essential-5.0.27-win32.rar"压缩包包含的是MySQL 5.0.27版本的Windows 32位安装程序,这是一个关键的历史版本,因为每个版本都有其特定的改进和修复。 首先,我们来看"mysql-essential-5.0.27-win32....

    mysql安装图解安装mysql-5.0.27+Setup

    MySQL是世界上最受欢迎的开源关系型数据库管理系统之一,其版本5.0.27是一个稳定且功能丰富的版本。本文将详细讲解如何使用提供的“mysql-5.0.27+Setup”压缩包进行MySQL的安装,以及如何理解安装过程中的关键步骤。...

    Windows XP + Apache 2.2.4 + PHP 5.2.0 + MySQL 5.0.27 + Zend Optimizer 3.2.0环境配置方法

    ### Windows XP + Apache 2.2.4 + PHP 5.2.0 + MySQL 5.0.27 + Zend Optimizer 3.2.0环境配置方法 #### Apache 2.2.4 的安装与配置 Apache 作为一款开源且功能强大的Web服务器软件,在Windows XP上安装和配置相对...

    mysql-essential-5.0.27

    `mysql-essential-5.0.27` 是MySQL的一个特定版本,该版本为5.0.27,主要面向Windows 32位操作系统。这个版本在当时是MySQL发展历史上的一个重要里程碑,因为它包含了诸多改进和修复,以提升性能、稳定性和安全性。 ...

    Windows XP + Apache 2.2.4 + PHP 5.2.0 + MySQL 5.0.27 + Zend Optimizer 3.2.0环境配置说明

    MySQL 5.0.27是关系型数据库管理系统,用于存储和管理网站数据。安装MySQL时,会创建一个服务器实例,要求设置root用户的密码。在配置阶段,需要确保MySQL服务能自动启动,并且可以通过命令行或图形界面工具(如...

    mysql安装图解 打开下载的mysql安装文件mysql-5.0.27-win32.zip

    在本文中,我们将详细讲解如何安装MySQL 5.0.27版本,这是针对Windows系统的安装过程。 首先,你需要下载MySQL的安装文件,例如`mysql-5.0.27-win32.zip`。完成下载后,通过双击该zip文件进行解压缩。解压缩后,...

    mysql-essential-5.0.27-win32

    在给定的"mysql-essential-5.0.27-win32"压缩包中,我们关注的是MySQL的一个特定版本,即5.0.27,适用于Windows 32位操作系统。这个版本被称为“精简版”,意味着它包含了运行MySQL服务所需的基本组件,但可能不包含...

Global site tag (gtag.js) - Google Analytics