Class: Mysql
- Inherits:
-
Object
- Object
- Mysql
- Defined in:
- lib/active_record/vendor/mysql.rb,
lib/active_record/vendor/mysql411.rb
Overview
Extend the Mysql class to work with MySQL 4.1.1+ servers. After version 4.1.1 the password hashing function (and some other connection details) have changed rendering the previous Mysql class unable to connect:
Defined Under Namespace
Classes: Error, Field, Net, Random, Result
Constant Summary collapse
- VERSION =
"4.0-ruby-0.2.4"
- MAX_PACKET_LENGTH =
256*256*256-1
- MAX_ALLOWED_PACKET =
1024*1024*1024
- MYSQL_UNIX_ADDR =
"/tmp/mysql.sock"
- MYSQL_PORT =
3306
- PROTOCOL_VERSION =
10
- COM_SLEEP =
Command
0
- COM_QUIT =
1
- COM_INIT_DB =
2
- COM_QUERY =
3
- COM_FIELD_LIST =
4
- COM_CREATE_DB =
5
- COM_DROP_DB =
6
- COM_REFRESH =
7
- COM_SHUTDOWN =
8
- COM_STATISTICS =
9
- COM_PROCESS_INFO =
10
- COM_CONNECT =
11
- COM_PROCESS_KILL =
12
- COM_DEBUG =
13
- COM_PING =
14
- COM_TIME =
15
- COM_DELAYED_INSERT =
16
- COM_CHANGE_USER =
17
- COM_BINLOG_DUMP =
18
- COM_TABLE_DUMP =
19
- COM_CONNECT_OUT =
20
- COM_REGISTER_SLAVE =
21
- CLIENT_LONG_PASSWORD =
Client flag
1
- CLIENT_FOUND_ROWS =
1 << 1
- CLIENT_LONG_FLAG =
1 << 2
- CLIENT_CONNECT_WITH_DB =
1 << 3
- CLIENT_NO_SCHEMA =
1 << 4
- CLIENT_COMPRESS =
1 << 5
- CLIENT_ODBC =
1 << 6
- CLIENT_LOCAL_FILES =
1 << 7
- CLIENT_IGNORE_SPACE =
1 << 8
- CLIENT_INTERACTIVE =
1 << 10
- CLIENT_SSL =
1 << 11
- CLIENT_IGNORE_SIGPIPE =
1 << 12
- CLIENT_TRANSACTIONS =
1 << 13
- CLIENT_CAPABILITIES =
CLIENT_LONG_PASSWORD|CLIENT_LONG_FLAG|CLIENT_TRANSACTIONS
- OPT_CONNECT_TIMEOUT =
Connection Option
0
- OPT_COMPRESS =
1
- OPT_NAMED_PIPE =
2
- INIT_COMMAND =
3
- READ_DEFAULT_FILE =
4
- READ_DEFAULT_GROUP =
5
- SET_CHARSET_DIR =
6
- SET_CHARSET_NAME =
7
- OPT_LOCAL_INFILE =
8
- SERVER_STATUS_IN_TRANS =
Server Status
1
- SERVER_STATUS_AUTOCOMMIT =
2
- REFRESH_GRANT =
Refresh parameter
1
- REFRESH_LOG =
2
- REFRESH_TABLES =
4
- REFRESH_HOSTS =
8
- REFRESH_STATUS =
16
- REFRESH_THREADS =
32
- REFRESH_SLAVE =
64
- REFRESH_MASTER =
128
- CLIENT_PROTOCOL_41 =
512
- CLIENT_SECURE_CONNECTION =
32768
Instance Attribute Summary collapse
-
#affected_rows ⇒ Object
readonly
Returns the value of attribute affected_rows.
-
#field_count ⇒ Object
readonly
Returns the value of attribute field_count.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#insert_id ⇒ Object
readonly
Returns the value of attribute insert_id.
-
#query_with_result ⇒ Object
Returns the value of attribute query_with_result.
-
#status ⇒ Object
Returns the value of attribute status.
-
#thread_id ⇒ Object
readonly
Returns the value of attribute thread_id.
Class Method Summary collapse
- .connect ⇒ Object
- .debug(str) ⇒ Object
- .escape_string(str) ⇒ Object (also: quote)
- .get_client_info ⇒ Object (also: client_info)
- .init ⇒ Object
- .real_connect(*args) ⇒ Object
Instance Method Summary collapse
- #change_user(user = "", passwd = "", db = "") ⇒ Object
- #character_set_name ⇒ Object
- #client_info ⇒ Object
- #close ⇒ Object
- #create_db(db) ⇒ Object
- #drop_db(db) ⇒ Object
- #dump_debug_info ⇒ Object
- #escape_string(str) ⇒ Object
- #get_client_info ⇒ Object
- #get_host_info ⇒ Object (also: #host_info)
- #get_proto_info ⇒ Object (also: #proto_info)
- #get_server_info ⇒ Object (also: #server_info)
-
#initialize(*args) ⇒ Mysql
constructor
A new instance of Mysql.
- #inspect ⇒ Object
- #kill(id) ⇒ Object
- #list_dbs(db = nil) ⇒ Object
- #list_fields(table, field = nil) ⇒ Object
- #list_processes ⇒ Object
- #list_tables(table = nil) ⇒ Object
-
#make_client_auth_packet_41(flag, user, password, db) ⇒ Object
Pack the authentication information into depending upon whether an initial database has been specified.
-
#old_read_one_row ⇒ Object
The 4.1 protocol changed the length of the END packet.
-
#old_read_query_result ⇒ Object
In this instance the read_query_result method in mysql is bound to read 5 field parameters which is expanded to 7 in the 4.1 protocol.
-
#old_skip_result ⇒ Object
The 4.1 protocol changed the length of the END packet.
-
#old_unpack_fields ⇒ Object
The field description structure is changed for the 4.1 protocol passing more data and a different packing form.
- #options(option, arg = nil) ⇒ Object
- #ping ⇒ Object
- #query(query) ⇒ Object
- #quote ⇒ Object
- #read_one_row(field_count) ⇒ Object
- #read_one_row_41(field_count) ⇒ Object
- #read_query_result ⇒ Object
- #read_query_result_41 ⇒ Object
- #real_connect(host = nil, user = nil, passwd = nil, db = nil, port = nil, socket = nil, flag = nil) ⇒ Object (also: #connect)
- #real_query(query) ⇒ Object
- #refresh(r) ⇒ Object
- #reload ⇒ Object
-
#scramble411(password, seed, old_ver) ⇒ Object
SERVER: public_seed=create_random_string() send(public_seed).
- #select_db(db) ⇒ Object
- #shutdown ⇒ Object
- #skip_result ⇒ Object
- #skip_result_41 ⇒ Object
- #stat ⇒ Object
- #store_result ⇒ Object
- #unpack_fields(data, long_flag_protocol) ⇒ Object
- #unpack_fields_41(data, long_flag_protocol) ⇒ Object
- #use_result ⇒ Object
- #version_meets_minimum?(major, minor, revision) ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ Mysql
Returns a new instance of Mysql.
85 86 87 88 89 90 91 92 93 |
# File 'lib/active_record/vendor/mysql.rb', line 85 def initialize(*args) @client_flag = 0 @max_allowed_packet = MAX_ALLOWED_PACKET @query_with_result = true @status = :STATUS_READY if args[0] != :INIT then real_connect(*args) end end |
Instance Attribute Details
#affected_rows ⇒ Object (readonly)
Returns the value of attribute affected_rows.
309 310 311 |
# File 'lib/active_record/vendor/mysql.rb', line 309 def affected_rows @affected_rows end |
#field_count ⇒ Object (readonly)
Returns the value of attribute field_count.
309 310 311 |
# File 'lib/active_record/vendor/mysql.rb', line 309 def field_count @field_count end |
#info ⇒ Object (readonly)
Returns the value of attribute info.
309 310 311 |
# File 'lib/active_record/vendor/mysql.rb', line 309 def info @info end |
#insert_id ⇒ Object (readonly)
Returns the value of attribute insert_id.
309 310 311 |
# File 'lib/active_record/vendor/mysql.rb', line 309 def insert_id @insert_id end |
#query_with_result ⇒ Object
Returns the value of attribute query_with_result.
310 311 312 |
# File 'lib/active_record/vendor/mysql.rb', line 310 def query_with_result @query_with_result end |
#status ⇒ Object
Returns the value of attribute status.
310 311 312 |
# File 'lib/active_record/vendor/mysql.rb', line 310 def status @status end |
#thread_id ⇒ Object (readonly)
Returns the value of attribute thread_id.
309 310 311 |
# File 'lib/active_record/vendor/mysql.rb', line 309 def thread_id @thread_id end |
Class Method Details
.connect ⇒ Object
1092 1093 1094 |
# File 'lib/active_record/vendor/mysql.rb', line 1092 def real_connect(*args) Mysql::new(*args) end |
.debug(str) ⇒ Object
1112 1113 1114 |
# File 'lib/active_record/vendor/mysql.rb', line 1112 def debug(str) raise "not implemented" end |
.escape_string(str) ⇒ Object Also known as: quote
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 |
# File 'lib/active_record/vendor/mysql.rb', line 1094 def escape_string(str) str.gsub(/([\0\n\r\032\'\"\\])/) do case $1 when "\0" then "\\0" when "\n" then "\\n" when "\r" then "\\r" when "\032" then "\\Z" else "\\"+$1 end end end |
.get_client_info ⇒ Object Also known as: client_info
1107 1108 1109 |
# File 'lib/active_record/vendor/mysql.rb', line 1107 def get_client_info() Mysql::VERSION end |
Instance Method Details
#change_user(user = "", passwd = "", db = "") ⇒ Object
184 185 186 187 188 189 190 |
# File 'lib/active_record/vendor/mysql.rb', line 184 def change_user(user="", passwd="", db="") data = user+"\0"+scramble(passwd, @scramble_buff, @protocol_version==9)+"\0"+db command COM_CHANGE_USER, data @user = user @passwd = passwd @db = db end |
#character_set_name ⇒ Object
192 193 194 |
# File 'lib/active_record/vendor/mysql.rb', line 192 def character_set_name() raise "not implemented" end |
#client_info ⇒ Object
143 144 145 |
# File 'lib/active_record/vendor/mysql.rb', line 143 def get_client_info() VERSION end |
#close ⇒ Object
196 197 198 199 200 201 |
# File 'lib/active_record/vendor/mysql.rb', line 196 def close() @status = :STATUS_READY command COM_QUIT, nil, true @net.close self end |
#create_db(db) ⇒ Object
203 204 205 206 |
# File 'lib/active_record/vendor/mysql.rb', line 203 def create_db(db) command COM_CREATE_DB, db self end |
#drop_db(db) ⇒ Object
208 209 210 211 |
# File 'lib/active_record/vendor/mysql.rb', line 208 def drop_db(db) command COM_DROP_DB, db self end |
#dump_debug_info ⇒ Object
213 214 215 216 |
# File 'lib/active_record/vendor/mysql.rb', line 213 def dump_debug_info() command COM_DEBUG self end |
#escape_string(str) ⇒ Object
135 136 137 |
# File 'lib/active_record/vendor/mysql.rb', line 135 def escape_string(str) Mysql::escape_string str end |
#get_client_info ⇒ Object
140 141 142 |
# File 'lib/active_record/vendor/mysql.rb', line 140 def get_client_info() VERSION end |
#get_host_info ⇒ Object Also known as: host_info
218 219 220 |
# File 'lib/active_record/vendor/mysql.rb', line 218 def get_host_info() @host_info end |
#get_proto_info ⇒ Object Also known as: proto_info
223 224 225 |
# File 'lib/active_record/vendor/mysql.rb', line 223 def get_proto_info() @protocol_version end |
#get_server_info ⇒ Object Also known as: server_info
228 229 230 |
# File 'lib/active_record/vendor/mysql.rb', line 228 def get_server_info() @server_version end |
#inspect ⇒ Object
337 338 339 |
# File 'lib/active_record/vendor/mysql.rb', line 337 def inspect() "#<#{self.class}>" end |
#kill(id) ⇒ Object
233 234 235 236 |
# File 'lib/active_record/vendor/mysql.rb', line 233 def kill(id) command COM_PROCESS_KILL, Net::int4str(id) self end |
#list_dbs(db = nil) ⇒ Object
238 239 240 241 242 |
# File 'lib/active_record/vendor/mysql.rb', line 238 def list_dbs(db=nil) real_query "show databases #{db}" @status = :STATUS_READY read_rows(1).flatten end |
#list_fields(table, field = nil) ⇒ Object
244 245 246 247 248 249 250 251 |
# File 'lib/active_record/vendor/mysql.rb', line 244 def list_fields(table, field=nil) command COM_FIELD_LIST, "#{table}\0#{field}", true f = read_rows 6 fields = unpack_fields(f, @server_capabilities & CLIENT_LONG_FLAG != 0) res = Result::new self, fields, f.length res.eof = true res end |
#list_processes ⇒ Object
253 254 255 256 257 258 259 260 |
# File 'lib/active_record/vendor/mysql.rb', line 253 def list_processes() data = command COM_PROCESS_INFO @field_count = get_length data fields = read_rows 5 @fields = unpack_fields(fields, @server_capabilities & CLIENT_LONG_FLAG != 0) @status = :STATUS_GET_RESULT store_result end |
#list_tables(table = nil) ⇒ Object
262 263 264 265 266 |
# File 'lib/active_record/vendor/mysql.rb', line 262 def list_tables(table=nil) real_query "show tables #{table}" @status = :STATUS_READY read_rows(1).flatten end |
#make_client_auth_packet_41(flag, user, password, db) ⇒ Object
Pack the authentication information into depending upon whether an initial database has been specified
110 111 112 113 114 115 116 117 118 |
# File 'lib/active_record/vendor/mysql411.rb', line 110 def make_client_auth_packet_41( flag, user, password, db ) if db && @server_capabilities & CLIENT_CONNECT_WITH_DB != 0 template = "VVcx23a#{user.size+1}cA#{password.size}a#{db.size+1}" else template = "VVcx23a#{user.size+1}cA#{password.size}x" end [ flag, @max_allowed_packet, @server_language, user, password.size, password, db ].pack( template ) end |
#old_read_one_row ⇒ Object
The 4.1 protocol changed the length of the END packet
175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/active_record/vendor/mysql411.rb', line 175 def read_one_row(field_count) data = read return if data[0] == 254 and data.length == 1 rec = [] field_count.times do len = get_length data if len == nil then rec << len else rec << data.slice!(0,len) end end rec end |
#old_read_query_result ⇒ Object
In this instance the read_query_result method in mysql is bound to read 5 field parameters which is expanded to 7 in the 4.1 protocol. So in this case we redefine this entire method in order to write “read_rows 7” instead of “read_rows 5”!
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/active_record/vendor/mysql411.rb', line 267 def read_query_result() data = read @field_count = get_length(data) if @field_count == nil then # LOAD DATA LOCAL INFILE File::open(data) do |f| write f.read end write "" # mark EOF data = read @field_count = get_length(data) end if @field_count == 0 then @affected_rows = get_length(data, true) @insert_id = get_length(data, true) if @server_capabilities & CLIENT_TRANSACTIONS != 0 then a = data.slice!(0,2) @server_status = a[0]+a[1]*256 end if data.size > 0 and get_length(data) then @info = data end else @extra_info = get_length(data, true) fields = read_rows 5 @fields = unpack_fields(fields, @server_capabilities & CLIENT_LONG_FLAG != 0) @status = :STATUS_GET_RESULT end self end |
#old_skip_result ⇒ Object
The 4.1 protocol changed the length of the END packet
203 204 205 206 207 208 209 210 211 |
# File 'lib/active_record/vendor/mysql411.rb', line 203 def skip_result() if @status == :STATUS_USE_RESULT then loop do data = read break if data[0] == 254 and data.length == 1 end @status = :STATUS_READY end end |
#old_unpack_fields ⇒ Object
The field description structure is changed for the 4.1 protocol passing more data and a different packing form. NOTE: The 4.1 protocol now passes back a “catalog” name for each field which is a new feature. Since AR has nowhere to put it I’m throwing it away. Possibly this is not the best idea?
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/active_record/vendor/mysql411.rb', line 229 def unpack_fields(data, long_flag_protocol) ret = [] data.each do |f| table = org_table = f[0] name = f[1] length = f[2][0]+f[2][1]*256+f[2][2]*256*256 type = f[3][0] if long_flag_protocol then flags = f[4][0]+f[4][1]*256 decimals = f[4][2] else flags = f[4][0] decimals = f[4][1] end def_value = f[5] max_length = 0 ret << Field::new(table, org_table, name, length, type, flags, decimals, def_value, max_length) end ret end |
#options(option, arg = nil) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/active_record/vendor/mysql.rb', line 145 def (option, arg=nil) if option == OPT_LOCAL_INFILE then if arg == false or arg == 0 then @client_flag &= ~CLIENT_LOCAL_FILES else @client_flag |= CLIENT_LOCAL_FILES end else raise "not implemented" end end |
#ping ⇒ Object
268 269 270 271 |
# File 'lib/active_record/vendor/mysql.rb', line 268 def ping() command COM_PING self end |
#query(query) ⇒ Object
273 274 275 276 277 278 279 280 281 282 |
# File 'lib/active_record/vendor/mysql.rb', line 273 def query(query) real_query query if not @query_with_result then return self end if @field_count == 0 then return nil end store_result end |
#quote ⇒ Object
138 139 140 |
# File 'lib/active_record/vendor/mysql.rb', line 138 def escape_string(str) Mysql::escape_string str end |
#read_one_row(field_count) ⇒ Object
312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/active_record/vendor/mysql.rb', line 312 def read_one_row(field_count) data = read return if data[0] == 254 and data.length == 1 rec = [] field_count.times do len = get_length data if len == nil then rec << len else rec << data.slice!(0,len) end end rec end |
#read_one_row_41(field_count) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/active_record/vendor/mysql411.rb', line 185 def read_one_row_41( field_count ) data = read return if data[0] == 254 and data.length < 9 rec = [] field_count.times do len = get_length data if len == nil then rec << len else rec << data.slice!(0,len) end end rec end |
#read_query_result ⇒ Object
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/active_record/vendor/mysql.rb', line 343 def read_query_result() data = read @field_count = get_length(data) if @field_count == nil then # LOAD DATA LOCAL INFILE File::open(data) do |f| write f.read end write "" # mark EOF data = read @field_count = get_length(data) end if @field_count == 0 then @affected_rows = get_length(data, true) @insert_id = get_length(data, true) if @server_capabilities & CLIENT_TRANSACTIONS != 0 then a = data.slice!(0,2) @server_status = a[0]+a[1]*256 end if data.size > 0 and get_length(data) then @info = data end else @extra_info = get_length(data, true) fields = read_rows 5 @fields = unpack_fields(fields, @server_capabilities & CLIENT_LONG_FLAG != 0) @status = :STATUS_GET_RESULT end self end |
#read_query_result_41 ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/active_record/vendor/mysql411.rb', line 277 def read_query_result_41 data = read @field_count = get_length(data) if @field_count == nil then # LOAD DATA LOCAL INFILE File::open(data) do |f| write f.read end write "" # mark EOF data = read @field_count = get_length(data) end if @field_count == 0 then @affected_rows = get_length(data, true) @insert_id = get_length(data, true) if @server_capabilities & CLIENT_TRANSACTIONS != 0 then a = data.slice!(0,2) @server_status = a[0]+a[1]*256 end if data.size > 0 and get_length(data) then @info = data end else @extra_info = get_length(data, true) fields = read_rows 7 @fields = unpack_fields(fields, @server_capabilities & CLIENT_LONG_FLAG != 0) @status = :STATUS_GET_RESULT end self end |
#real_connect(host = nil, user = nil, passwd = nil, db = nil, port = nil, socket = nil, flag = nil) ⇒ Object Also known as: connect
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/active_record/vendor/mysql.rb', line 95 def real_connect(host=nil, user=nil, passwd=nil, db=nil, port=nil, socket=nil, flag=nil) @server_status = SERVER_STATUS_AUTOCOMMIT if (host == nil or host == "localhost") and defined? UNIXSocket then unix_socket = socket || ENV["MYSQL_UNIX_PORT"] || MYSQL_UNIX_ADDR sock = UNIXSocket::new(unix_socket) @host_info = Error::err(Error::CR_LOCALHOST_CONNECTION) @unix_socket = unix_socket else sock = TCPSocket::new(host, port||ENV["MYSQL_TCP_PORT"]||(Socket::getservbyname("mysql","tcp") rescue MYSQL_PORT)) @host_info = sprintf Error::err(Error::CR_TCP_CONNECTION), host end @host = host ? host.dup : nil sock.setsockopt Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true @net = Net::new sock a = read @protocol_version = a.slice!(0) @server_version, a = a.split(/\0/,2) @thread_id, @scramble_buff = a.slice!(0,13).unpack("La8") if a.size >= 2 then @server_capabilities, = a.slice!(0,2).unpack("v") end if a.size >= 16 then @server_language, @server_status = a.unpack("cv") end flag = 0 if flag == nil flag |= @client_flag | CLIENT_CAPABILITIES flag |= CLIENT_CONNECT_WITH_DB if db data = Net::int2str(flag)+Net::int3str(@max_allowed_packet)+(user||"")+"\0"+scramble(passwd, @scramble_buff, @protocol_version==9) if db and @server_capabilities & CLIENT_CONNECT_WITH_DB != 0 then data << "\0"+db @db = db.dup end write data read self end |
#real_query(query) ⇒ Object
157 158 159 160 161 |
# File 'lib/active_record/vendor/mysql.rb', line 157 def real_query(query) command COM_QUERY, query, true read_query_result self end |
#refresh(r) ⇒ Object
284 285 286 287 |
# File 'lib/active_record/vendor/mysql.rb', line 284 def refresh(r) command COM_REFRESH, r.chr self end |
#reload ⇒ Object
289 290 291 292 |
# File 'lib/active_record/vendor/mysql.rb', line 289 def reload() refresh REFRESH_GRANT self end |
#scramble411(password, seed, old_ver) ⇒ Object
SERVER: public_seed=create_random_string()
send(public_seed)
CLIENT: recv(public_seed)
hash_stage1=sha1("password")
hash_stage2=sha1(hash_stage1)
reply=xor(hash_stage1, sha1(public_seed,hash_stage2)
#this three steps are done in scramble()
send(reply)
SERVER: recv(reply)
hash_stage1=xor(reply, sha1(public_seed,hash_stage2))
candidate_hash2=sha1(hash_stage1)
check(candidate_hash2==hash_stage2)
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/active_record/vendor/mysql411.rb', line 141 def scramble411( password, seed, old_ver ) return "" if password == nil or password == "" raise "old version password is not implemented" if old_ver # print "Seed Bytes = " # seed.each_byte { |b| print "0x#{b.to_s( 16 )}, " } # puts stage1 = Digest::SHA1.digest( password ) stage2 = Digest::SHA1.digest( stage1 ) dgst = Digest::SHA1.new dgst << seed dgst << stage2 stage3 = dgst.digest # stage1.zip( stage3 ).map { |a, b| (a ^ b).chr }.join scrambled = ( 0 ... stage3.size ).map { |i| stage3[i] ^ stage1[i] } scrambled = scrambled.map { |x| x.chr } scrambled.join end |
#select_db(db) ⇒ Object
294 295 296 297 298 |
# File 'lib/active_record/vendor/mysql.rb', line 294 def select_db(db) command COM_INIT_DB, db @db = db self end |
#shutdown ⇒ Object
300 301 302 303 |
# File 'lib/active_record/vendor/mysql.rb', line 300 def shutdown() command COM_SHUTDOWN self end |
#skip_result ⇒ Object
327 328 329 330 331 332 333 334 335 |
# File 'lib/active_record/vendor/mysql.rb', line 327 def skip_result() if @status == :STATUS_USE_RESULT then loop do data = read break if data[0] == 254 and data.length == 1 end @status = :STATUS_READY end end |
#skip_result_41 ⇒ Object
213 214 215 216 217 218 219 220 221 |
# File 'lib/active_record/vendor/mysql411.rb', line 213 def skip_result_41() if @status == :STATUS_USE_RESULT then loop do data = read break if data[0] == 254 and data.length == 1 end @status = :STATUS_READY end end |
#stat ⇒ Object
305 306 307 |
# File 'lib/active_record/vendor/mysql.rb', line 305 def stat() command COM_STATISTICS end |
#store_result ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/active_record/vendor/mysql.rb', line 172 def store_result() if @status != :STATUS_GET_RESULT then error Error::CR_COMMANDS_OUT_OF_SYNC end @status = :STATUS_READY data = read_rows @field_count res = Result::new self, @fields, @field_count, data @fields = nil @affected_rows = data.length res end |
#unpack_fields(data, long_flag_protocol) ⇒ Object
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/active_record/vendor/mysql.rb', line 373 def unpack_fields(data, long_flag_protocol) ret = [] data.each do |f| table = org_table = f[0] name = f[1] length = f[2][0]+f[2][1]*256+f[2][2]*256*256 type = f[3][0] if long_flag_protocol then flags = f[4][0]+f[4][1]*256 decimals = f[4][2] else flags = f[4][0] decimals = f[4][1] end def_value = f[5] max_length = 0 ret << Field::new(table, org_table, name, length, type, flags, decimals, def_value, max_length) end ret end |
#unpack_fields_41(data, long_flag_protocol) ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/active_record/vendor/mysql411.rb', line 239 def unpack_fields_41( data, long_flag_protocol ) ret = [] data.each do |f| catalog_name = f[0] database_name = f[1] table_name_alias = f[2] table_name = f[3] column_name_alias = f[4] column_name = f[5] charset = f[6][0] + f[6][1]*256 length = f[6][2] + f[6][3]*256 + f[6][4]*256*256 + f[6][5]*256*256*256 type = f[6][6] flags = f[6][7] + f[6][8]*256 decimals = f[6][9] def_value = f[7] max_length = 0 ret << Field::new(table_name, table_name, column_name_alias, length, type, flags, decimals, def_value, max_length) end ret end |
#use_result ⇒ Object
163 164 165 166 167 168 169 170 |
# File 'lib/active_record/vendor/mysql.rb', line 163 def use_result() if @status != :STATUS_GET_RESULT then error Error::CR_COMMANDS_OUT_OF_SYNC end res = Result::new self, @fields, @field_count @status = :STATUS_USE_RESULT res end |
#version_meets_minimum?(major, minor, revision) ⇒ Boolean
120 121 122 |
# File 'lib/active_record/vendor/mysql411.rb', line 120 def version_meets_minimum?( major, minor, revision ) @major_ver >= major && @minor_ver >= minor && @revision_num >= revision end |