ydbi 0.5.7 → 0.5.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +4 -0
- data/lib/dbi/version.rb +1 -1
- data/readme.md +4 -3
- data/test/dbi/tc_dbi.rb +1 -1
- metadata +7 -125
- data/.github/workflows/ruby.yml +0 -35
- data/.gitignore +0 -8
- data/.travis.yml +0 -15
- data/Gemfile +0 -5
- data/Rakefile +0 -10
- data/TODO +0 -44
- data/bench/bench.rb +0 -79
- data/build/rake_task_lib.rb +0 -186
- data/doc/DBD_SPEC.rdoc +0 -88
- data/doc/DBI_SPEC.rdoc +0 -157
- data/doc/homepage/contact.html +0 -62
- data/doc/homepage/development.html +0 -124
- data/doc/homepage/index.html +0 -83
- data/doc/homepage/ruby-dbi.css +0 -91
- data/lib/dbd/Mysql.rb +0 -137
- data/lib/dbd/ODBC.rb +0 -89
- data/lib/dbd/Pg.rb +0 -188
- data/lib/dbd/SQLite.rb +0 -97
- data/lib/dbd/SQLite3.rb +0 -124
- data/lib/dbd/mysql/database.rb +0 -405
- data/lib/dbd/mysql/driver.rb +0 -125
- data/lib/dbd/mysql/statement.rb +0 -188
- data/lib/dbd/odbc/database.rb +0 -128
- data/lib/dbd/odbc/driver.rb +0 -38
- data/lib/dbd/odbc/statement.rb +0 -137
- data/lib/dbd/pg/database.rb +0 -504
- data/lib/dbd/pg/exec.rb +0 -47
- data/lib/dbd/pg/statement.rb +0 -160
- data/lib/dbd/pg/tuples.rb +0 -121
- data/lib/dbd/pg/type.rb +0 -209
- data/lib/dbd/sqlite/database.rb +0 -151
- data/lib/dbd/sqlite/statement.rb +0 -125
- data/lib/dbd/sqlite3/database.rb +0 -201
- data/lib/dbd/sqlite3/statement.rb +0 -78
- data/prototypes/types2.rb +0 -237
- data/setup.rb +0 -1585
- data/test/DBD_TESTS +0 -50
- data/test/TESTING +0 -16
- data/test/dbd/general/test_database.rb +0 -206
- data/test/dbd/general/test_statement.rb +0 -326
- data/test/dbd/general/test_types.rb +0 -296
- data/test/dbd/mysql/base.rb +0 -26
- data/test/dbd/mysql/down.sql +0 -19
- data/test/dbd/mysql/test_blob.rb +0 -18
- data/test/dbd/mysql/test_new_methods.rb +0 -7
- data/test/dbd/mysql/test_patches.rb +0 -111
- data/test/dbd/mysql/up.sql +0 -28
- data/test/dbd/odbc/base.rb +0 -30
- data/test/dbd/odbc/down.sql +0 -19
- data/test/dbd/odbc/test_new_methods.rb +0 -12
- data/test/dbd/odbc/test_ping.rb +0 -10
- data/test/dbd/odbc/test_statement.rb +0 -44
- data/test/dbd/odbc/test_transactions.rb +0 -58
- data/test/dbd/odbc/up.sql +0 -33
- data/test/dbd/postgresql/base.rb +0 -31
- data/test/dbd/postgresql/down.sql +0 -31
- data/test/dbd/postgresql/test_arrays.rb +0 -179
- data/test/dbd/postgresql/test_async.rb +0 -121
- data/test/dbd/postgresql/test_blob.rb +0 -36
- data/test/dbd/postgresql/test_bytea.rb +0 -87
- data/test/dbd/postgresql/test_ping.rb +0 -10
- data/test/dbd/postgresql/test_timestamp.rb +0 -77
- data/test/dbd/postgresql/test_transactions.rb +0 -58
- data/test/dbd/postgresql/testdbipg.rb +0 -307
- data/test/dbd/postgresql/up.sql +0 -60
- data/test/dbd/sqlite/base.rb +0 -32
- data/test/dbd/sqlite/test_database.rb +0 -30
- data/test/dbd/sqlite/test_driver.rb +0 -68
- data/test/dbd/sqlite/test_statement.rb +0 -112
- data/test/dbd/sqlite/up.sql +0 -25
- data/test/dbd/sqlite3/base.rb +0 -32
- data/test/dbd/sqlite3/test_database.rb +0 -77
- data/test/dbd/sqlite3/test_driver.rb +0 -67
- data/test/dbd/sqlite3/test_statement.rb +0 -88
- data/test/dbd/sqlite3/up.sql +0 -33
- data/test/ts_dbd.rb +0 -131
- data/ydbi.gemspec +0 -23
data/lib/dbd/SQLite.rb
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
###############################################################################
|
3
|
-
#
|
4
|
-
# DBD::SQLite - a DBD for SQLite for versions < 3
|
5
|
-
#
|
6
|
-
# Uses Jamis Buck's 'sqlite-ruby' driver to interface with SQLite directly
|
7
|
-
#
|
8
|
-
# (c) 2008 Erik Hollensbe & Christopher Maujean.
|
9
|
-
#
|
10
|
-
# TODO
|
11
|
-
#
|
12
|
-
# fetch_scroll implementation?
|
13
|
-
# columns and column_info differ too much and have too much copied code, refactor
|
14
|
-
# there are probably some edge cases with transactions
|
15
|
-
#
|
16
|
-
################################################################################
|
17
|
-
#++
|
18
|
-
|
19
|
-
begin
|
20
|
-
require 'rubygems'
|
21
|
-
gem 'sqlite-ruby'
|
22
|
-
gem 'dbi'
|
23
|
-
rescue Exception => e
|
24
|
-
end
|
25
|
-
|
26
|
-
require 'dbi'
|
27
|
-
require 'sqlite'
|
28
|
-
|
29
|
-
module DBI
|
30
|
-
module DBD
|
31
|
-
#
|
32
|
-
# DBD::SQLite - Database Driver for SQLite versions 2.x and lower.
|
33
|
-
#
|
34
|
-
# Requires DBI and the 'sqlite-ruby' gem to work.
|
35
|
-
#
|
36
|
-
# Only things that extend DBI's results are documented.
|
37
|
-
#
|
38
|
-
class SQLite
|
39
|
-
VERSION = "0.1.2"
|
40
|
-
DESCRIPTION = "SQLite 2.x DBI DBD"
|
41
|
-
|
42
|
-
#
|
43
|
-
# returns 'SQLite'
|
44
|
-
#
|
45
|
-
# See DBI::TypeUtil#convert for more information.
|
46
|
-
#
|
47
|
-
def self.driver_name
|
48
|
-
"SQLite"
|
49
|
-
end
|
50
|
-
|
51
|
-
#
|
52
|
-
# Validates that the SQL has no literal NUL characters. (ASCII 0)
|
53
|
-
#
|
54
|
-
# SQLite apparently really hates it when you do that.
|
55
|
-
#
|
56
|
-
# It will raise DBI::DatabaseError should it find any.
|
57
|
-
#
|
58
|
-
def self.check_sql(sql)
|
59
|
-
# XXX I'm starting to think this is less of a problem with SQLite
|
60
|
-
# and more with the old C DBD
|
61
|
-
raise DBI::DatabaseError, "Bad SQL: SQL cannot contain nulls" if sql =~ /\0/
|
62
|
-
end
|
63
|
-
|
64
|
-
#
|
65
|
-
# Split a type definition into parts via String#match and return the whole result.
|
66
|
-
#
|
67
|
-
def self.parse_type(type_name)
|
68
|
-
type_name.match(/^([^\(]+)(\((\d+)(,(\d+))?\))?$/)
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
# See DBI::BaseDriver.
|
73
|
-
#
|
74
|
-
class Driver < DBI::BaseDriver
|
75
|
-
def initialize
|
76
|
-
super "0.4.0"
|
77
|
-
end
|
78
|
-
|
79
|
-
def connect(dbname, user, auth, attr_hash)
|
80
|
-
return Database.new(dbname, user, auth, attr_hash)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
require 'dbd/sqlite/database'
|
88
|
-
require 'dbd/sqlite/statement'
|
89
|
-
|
90
|
-
DBI::TypeUtil.register_conversion(DBI::DBD::SQLite.driver_name) do |obj|
|
91
|
-
case obj
|
92
|
-
when ::NilClass
|
93
|
-
["NULL", false]
|
94
|
-
else
|
95
|
-
[obj, true]
|
96
|
-
end
|
97
|
-
end
|
data/lib/dbd/SQLite3.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# DBD::SQLite3
|
3
|
-
#
|
4
|
-
# copyright (c) 2005 Jun Mukai <mukai@jmuk.org>
|
5
|
-
# Compatibility patches by Erik Hollensbe <erik@hollensbe.org>
|
6
|
-
#
|
7
|
-
# All rights reserved.
|
8
|
-
#
|
9
|
-
# Redistribution and use in source and binary forms, with or without
|
10
|
-
# modification, are permitted provided that the following conditions
|
11
|
-
# are met:
|
12
|
-
# 1. Redistributions of source code must retain the above copyright
|
13
|
-
# notice, this list of conditions and the following disclaimer.
|
14
|
-
# 2. Redistributions in binary form must reproduce the above copyright
|
15
|
-
# notice, this list of conditions and the following disclaimer in the
|
16
|
-
# documentation and/or other materials provided with the distribution.
|
17
|
-
# 3. The name of the author may not be used to endorse or promote products
|
18
|
-
# derived from this software without specific prior written permission.
|
19
|
-
#
|
20
|
-
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21
|
-
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22
|
-
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
23
|
-
# THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
24
|
-
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
25
|
-
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
26
|
-
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
27
|
-
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
28
|
-
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
29
|
-
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
-
#++
|
31
|
-
|
32
|
-
begin
|
33
|
-
require 'rubygems'
|
34
|
-
gem 'sqlite3-ruby'
|
35
|
-
gem 'dbi'
|
36
|
-
rescue LoadError
|
37
|
-
end
|
38
|
-
|
39
|
-
require 'dbi'
|
40
|
-
require 'sqlite3'
|
41
|
-
require 'sqlite3/version'
|
42
|
-
|
43
|
-
module DBI
|
44
|
-
module DBD
|
45
|
-
#
|
46
|
-
# DBD::SQLite3 - Database Driver for SQLite versions 3.x
|
47
|
-
#
|
48
|
-
# Requires DBI and the 'sqlite3-ruby' gem to work.
|
49
|
-
#
|
50
|
-
# Only things that extend DBI's results are documented.
|
51
|
-
#
|
52
|
-
module SQLite3
|
53
|
-
VERSION = "1.2.5"
|
54
|
-
DESCRIPTION = "SQLite 3.x DBD for DBI"
|
55
|
-
|
56
|
-
#
|
57
|
-
# returns 'SQLite3'
|
58
|
-
#
|
59
|
-
# See DBI::TypeUtil#convert for more information.
|
60
|
-
#
|
61
|
-
def self.driver_name
|
62
|
-
"SQLite3"
|
63
|
-
end
|
64
|
-
|
65
|
-
#
|
66
|
-
# Validates that the SQL has no literal NUL characters. (ASCII 0)
|
67
|
-
#
|
68
|
-
# SQLite apparently really hates it when you do that.
|
69
|
-
#
|
70
|
-
# It will raise DBI::DatabaseError should it find any.
|
71
|
-
#
|
72
|
-
def self.parse_type(type_name)
|
73
|
-
# FIXME plucked from SQLite driver, this needs to be in DBI proper
|
74
|
-
return ['varchar'] unless type_name
|
75
|
-
type_name.match(/^([^\(\s]+)\s*(\(\s*(\d+)\s*(,\s*(\d+))?\s*\))?$/)
|
76
|
-
end
|
77
|
-
|
78
|
-
#
|
79
|
-
# See DBI::BaseDriver.
|
80
|
-
#
|
81
|
-
class Driver < DBI::BaseDriver
|
82
|
-
def initialize
|
83
|
-
@dbs = []
|
84
|
-
super "0.4.0"
|
85
|
-
end
|
86
|
-
|
87
|
-
def connect(dbname, user, auth, attr)
|
88
|
-
raise DBI::InterfaceError, "dbname must be a string" unless dbname.kind_of? String
|
89
|
-
raise DBI::InterfaceError, "dbname must have some length" unless dbname.length > 0
|
90
|
-
raise DBI::InterfaceError, "attrs must be a hash" unless attr.kind_of? Hash
|
91
|
-
db = DBI::DBD::SQLite3::Database.new(dbname, attr)
|
92
|
-
@dbs.push(db)
|
93
|
-
db
|
94
|
-
end
|
95
|
-
|
96
|
-
def disconnect_all()
|
97
|
-
@dbs.each{|db| db.disconnect()}
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
require 'dbd/sqlite3/database'
|
105
|
-
require 'dbd/sqlite3/statement'
|
106
|
-
|
107
|
-
DBI::TypeUtil.register_conversion(DBI::DBD::SQLite3.driver_name) do |obj|
|
108
|
-
newobj = case obj
|
109
|
-
when ::TrueClass
|
110
|
-
'1'
|
111
|
-
when ::FalseClass
|
112
|
-
'0'
|
113
|
-
else
|
114
|
-
# SQLite3 is managing its own conversion right now, until I'm happy let's keep it that way
|
115
|
-
obj.dup rescue obj
|
116
|
-
end
|
117
|
-
if newobj.kind_of?(::Symbol)
|
118
|
-
newobj.to_s
|
119
|
-
elsif newobj.object_id == obj.object_id
|
120
|
-
[newobj, true]
|
121
|
-
else
|
122
|
-
[newobj, false]
|
123
|
-
end
|
124
|
-
end
|
data/lib/dbd/mysql/database.rb
DELETED
@@ -1,405 +0,0 @@
|
|
1
|
-
module DBI::DBD::Mysql
|
2
|
-
#
|
3
|
-
# Models the DBI::BaseDatabase API to create DBI::DatabaseHandle objects.
|
4
|
-
#
|
5
|
-
class Database < DBI::BaseDatabase
|
6
|
-
include Util
|
7
|
-
|
8
|
-
#
|
9
|
-
# Hash to translate MySQL type names to DBI SQL type constants
|
10
|
-
#
|
11
|
-
# Only used in #mysql_type_info.
|
12
|
-
#
|
13
|
-
#--
|
14
|
-
# Eli Green:
|
15
|
-
# The hope is that we don't ever need to just assume the default values.
|
16
|
-
# However, in some cases (notably floats and doubles), I have seen
|
17
|
-
# "show fields from table" return absolutely zero information about size
|
18
|
-
# and precision. Sigh. I probably should have made a struct to store
|
19
|
-
# this info in ... but I didn't.
|
20
|
-
#++
|
21
|
-
MYSQL_to_XOPEN = {
|
22
|
-
"TINYINT" => [DBI::SQL_TINYINT, 1, nil],
|
23
|
-
"SMALLINT" => [DBI::SQL_SMALLINT, 6, nil],
|
24
|
-
"MEDIUMINT" => [DBI::SQL_SMALLINT, 6, nil],
|
25
|
-
"INT" => [DBI::SQL_INTEGER, 11, nil],
|
26
|
-
"INTEGER" => [DBI::SQL_INTEGER, 11, nil],
|
27
|
-
"BIGINT" => [DBI::SQL_BIGINT, 25, nil],
|
28
|
-
"INT24" => [DBI::SQL_BIGINT, 25, nil],
|
29
|
-
"REAL" => [DBI::SQL_REAL, 12, nil],
|
30
|
-
"FLOAT" => [DBI::SQL_FLOAT, 12, nil],
|
31
|
-
"DECIMAL" => [DBI::SQL_DECIMAL, 12, nil],
|
32
|
-
"NUMERIC" => [DBI::SQL_NUMERIC, 12, nil],
|
33
|
-
"DOUBLE" => [DBI::SQL_DOUBLE, 22, nil],
|
34
|
-
"CHAR" => [DBI::SQL_CHAR, 1, nil],
|
35
|
-
"VARCHAR" => [DBI::SQL_VARCHAR, 255, nil],
|
36
|
-
"DATE" => [DBI::SQL_DATE, 10, nil],
|
37
|
-
"TIME" => [DBI::SQL_TIME, 8, nil],
|
38
|
-
"TIMESTAMP" => [DBI::SQL_TIMESTAMP, 19, nil],
|
39
|
-
"DATETIME" => [DBI::SQL_TIMESTAMP, 19, nil],
|
40
|
-
"TINYBLOB" => [DBI::SQL_BINARY, 255, nil],
|
41
|
-
"BLOB" => [DBI::SQL_VARBINARY, 65535, nil],
|
42
|
-
"MEDIUMBLOB" => [DBI::SQL_VARBINARY, 16277215, nil],
|
43
|
-
"LONGBLOB" => [DBI::SQL_LONGVARBINARY, 2147483657, nil],
|
44
|
-
"TINYTEXT" => [DBI::SQL_VARCHAR, 255, nil],
|
45
|
-
"TEXT" => [DBI::SQL_LONGVARCHAR, 65535, nil],
|
46
|
-
"MEDIUMTEXT" => [DBI::SQL_LONGVARCHAR, 16277215, nil],
|
47
|
-
"LONGTEXT" => [DBI::SQL_LONGVARCHAR, 2147483657, nil],
|
48
|
-
"ENUM" => [DBI::SQL_CHAR, 255, nil],
|
49
|
-
"SET" => [DBI::SQL_CHAR, 255, nil],
|
50
|
-
"BIT" => [DBI::SQL_BIT, 8, nil],
|
51
|
-
nil => [DBI::SQL_OTHER, nil, nil]
|
52
|
-
}
|
53
|
-
|
54
|
-
|
55
|
-
#
|
56
|
-
# This maps type names to DBI Types.
|
57
|
-
#
|
58
|
-
TYPE_MAP = {}
|
59
|
-
|
60
|
-
::Mysql::Field.constants.grep(/^TYPE_/).each do |const|
|
61
|
-
mysql_type = MysqlField.const_get(const) # numeric type code
|
62
|
-
coercion_method = DBI::Type::Varchar # default coercion method
|
63
|
-
case const.to_s
|
64
|
-
when 'TYPE_TINY'
|
65
|
-
mysql_type_name = 'TINYINT'
|
66
|
-
coercion_method = DBI::Type::Integer
|
67
|
-
when 'TYPE_SHORT'
|
68
|
-
mysql_type_name = 'SMALLINT'
|
69
|
-
coercion_method = DBI::Type::Integer
|
70
|
-
when 'TYPE_INT24'
|
71
|
-
mysql_type_name = 'MEDIUMINT'
|
72
|
-
coercion_method = DBI::Type::Integer
|
73
|
-
when 'TYPE_LONG'
|
74
|
-
mysql_type_name = 'INT'
|
75
|
-
coercion_method = DBI::Type::Integer
|
76
|
-
when 'TYPE_LONGLONG'
|
77
|
-
mysql_type_name = 'BIGINT'
|
78
|
-
coercion_method = DBI::Type::Integer
|
79
|
-
when 'TYPE_FLOAT'
|
80
|
-
mysql_type_name = 'FLOAT'
|
81
|
-
coercion_method = DBI::Type::Float
|
82
|
-
when 'TYPE_DOUBLE'
|
83
|
-
mysql_type_name = 'DOUBLE'
|
84
|
-
coercion_method = DBI::Type::Float
|
85
|
-
when 'TYPE_VAR_STRING', 'TYPE_STRING'
|
86
|
-
mysql_type_name = 'VARCHAR' # questionable?
|
87
|
-
coercion_method = DBI::Type::Varchar
|
88
|
-
when 'TYPE_DATE'
|
89
|
-
mysql_type_name = 'DATE'
|
90
|
-
coercion_method = DBI::DBD::Mysql::Type::Date
|
91
|
-
when 'TYPE_TIME'
|
92
|
-
mysql_type_name = 'TIME'
|
93
|
-
coercion_method = DBI::Type::Timestamp
|
94
|
-
when 'TYPE_DATETIME', 'TYPE_TIMESTAMP'
|
95
|
-
mysql_type_name = 'DATETIME'
|
96
|
-
coercion_method = DBI::Type::Timestamp
|
97
|
-
when 'TYPE_CHAR'
|
98
|
-
mysql_type_name = 'TINYINT' # questionable?
|
99
|
-
when 'TYPE_TINY_BLOB'
|
100
|
-
mysql_type_name = 'TINYBLOB' # questionable?
|
101
|
-
when 'TYPE_MEDIUM_BLOB'
|
102
|
-
mysql_type_name = 'MEDIUMBLOB' # questionable?
|
103
|
-
when 'TYPE_LONG_BLOB'
|
104
|
-
mysql_type_name = 'LONGBLOB' # questionable?
|
105
|
-
when 'TYPE_GEOMETRY'
|
106
|
-
mysql_type_name = 'BLOB' # questionable?
|
107
|
-
when 'TYPE_YEAR',
|
108
|
-
'TYPE_DECIMAL', # questionable?
|
109
|
-
'TYPE_BLOB', # questionable?
|
110
|
-
'TYPE_ENUM',
|
111
|
-
'TYPE_SET',
|
112
|
-
'TYPE_BIT',
|
113
|
-
'TYPE_NULL'
|
114
|
-
mysql_type_name = const.to_s.sub(/^TYPE_/, '')
|
115
|
-
else
|
116
|
-
mysql_type_name = 'UNKNOWN'
|
117
|
-
end
|
118
|
-
TYPE_MAP[mysql_type] = [mysql_type_name, coercion_method]
|
119
|
-
end
|
120
|
-
TYPE_MAP[nil] = ['UNKNOWN', DBI::Type::Varchar]
|
121
|
-
TYPE_MAP[246] = ['NUMERIC', DBI::Type::Decimal]
|
122
|
-
|
123
|
-
#
|
124
|
-
# Constructor. Attributes supported:
|
125
|
-
#
|
126
|
-
# * AutoCommit: Commit after each executed statement. This will raise
|
127
|
-
# a DBI::NotSupportedError if the backend does not support
|
128
|
-
# transactions.
|
129
|
-
#
|
130
|
-
def initialize(handle, attr)
|
131
|
-
super
|
132
|
-
# check server version to determine transaction capability
|
133
|
-
ver_str = @handle.get_server_info
|
134
|
-
major, minor, teeny = ver_str.split(".")
|
135
|
-
teeny.sub!(/\D*$/, "") # strip any non-numeric suffix if present
|
136
|
-
server_version = major.to_i*10000 + minor.to_i*100 + teeny.to_i
|
137
|
-
# It's not until 3.23.17 that SET AUTOCOMMIT,
|
138
|
-
# BEGIN, COMMIT, and ROLLBACK all are available
|
139
|
-
@have_transactions = (server_version >= 32317)
|
140
|
-
# assume that the connection begins in AutoCommit mode
|
141
|
-
@attr['AutoCommit'] = true
|
142
|
-
@mutex = Mutex.new
|
143
|
-
end
|
144
|
-
|
145
|
-
def disconnect
|
146
|
-
self.rollback unless @attr['AutoCommit']
|
147
|
-
@handle.close
|
148
|
-
rescue MyError => err
|
149
|
-
error(err)
|
150
|
-
end
|
151
|
-
|
152
|
-
def database_name
|
153
|
-
sth = Statement.new(self, @handle, "select DATABASE()", @mutex)
|
154
|
-
sth.execute
|
155
|
-
res = sth.fetch
|
156
|
-
sth.finish
|
157
|
-
return res[0]
|
158
|
-
end
|
159
|
-
|
160
|
-
def ping
|
161
|
-
begin
|
162
|
-
@handle.ping
|
163
|
-
return true
|
164
|
-
rescue MyError
|
165
|
-
return false
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def tables
|
170
|
-
@handle.list_tables
|
171
|
-
rescue MyError => err
|
172
|
-
error(err)
|
173
|
-
end
|
174
|
-
|
175
|
-
#
|
176
|
-
# See DBI::BaseDatabase#columns.
|
177
|
-
#
|
178
|
-
# Extra attributes:
|
179
|
-
#
|
180
|
-
# * sql_type: XOPEN integer constant relating to type.
|
181
|
-
# * nullable: true if the column allows NULL as a value.
|
182
|
-
# * indexed: true if the column belongs to an index.
|
183
|
-
# * primary: true if the column is a part of a primary key.
|
184
|
-
# * unique: true if the values in this column are unique.
|
185
|
-
# * default: the default value if this column is not explicitly set.
|
186
|
-
#
|
187
|
-
def columns(table)
|
188
|
-
dbh = DBI::DatabaseHandle.new(self)
|
189
|
-
uniques = []
|
190
|
-
dbh.execute("SHOW INDEX FROM #{table}") do |sth|
|
191
|
-
sth.each do |row|
|
192
|
-
uniques << row[4] if row[1] == 0
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
ret = nil
|
197
|
-
dbh.execute("SHOW FIELDS FROM #{table}") do |sth|
|
198
|
-
ret = sth.collect do |row|
|
199
|
-
name, type, nullable, key, default, extra = row
|
200
|
-
#type = row[1]
|
201
|
-
#size = type[type.index('(')+1..type.index(')')-1]
|
202
|
-
#size = 0
|
203
|
-
#type = type[0..type.index('(')-1]
|
204
|
-
|
205
|
-
sqltype, type, size, decimal = mysql_type_info(row[1])
|
206
|
-
col = Hash.new
|
207
|
-
col['name'] = name
|
208
|
-
col['sql_type'] = sqltype
|
209
|
-
col['type_name'] = type
|
210
|
-
col['nullable'] = nullable == "YES"
|
211
|
-
col['indexed'] = key != ""
|
212
|
-
col['primary'] = key == "PRI"
|
213
|
-
col['unique'] = uniques.index(name) != nil
|
214
|
-
col['precision'] = size
|
215
|
-
col['scale'] = decimal
|
216
|
-
col['default'] = row[4]
|
217
|
-
|
218
|
-
case col['type_name']
|
219
|
-
when 'timestamp'
|
220
|
-
col['dbi_type'] = DBI::Type::Timestamp
|
221
|
-
end
|
222
|
-
|
223
|
-
col
|
224
|
-
end # collect
|
225
|
-
end # execute
|
226
|
-
|
227
|
-
ret
|
228
|
-
end
|
229
|
-
|
230
|
-
def do(stmt, *bindvars)
|
231
|
-
st = Statement.new(self, @handle, stmt, @mutex)
|
232
|
-
st.bind_params(*bindvars)
|
233
|
-
res = st.execute
|
234
|
-
st.finish
|
235
|
-
return res
|
236
|
-
rescue MyError => err
|
237
|
-
error(err)
|
238
|
-
end
|
239
|
-
|
240
|
-
|
241
|
-
def prepare(statement)
|
242
|
-
Statement.new(self, @handle, statement, @mutex)
|
243
|
-
end
|
244
|
-
|
245
|
-
#
|
246
|
-
# MySQL has several backends, some of which may not support commits.
|
247
|
-
# If the backend this database uses doesn't, calling this method will
|
248
|
-
# raise a DBI::NotSupportedError.
|
249
|
-
#
|
250
|
-
def commit
|
251
|
-
if @have_transactions
|
252
|
-
self.do("COMMIT")
|
253
|
-
else
|
254
|
-
raise NotSupportedError
|
255
|
-
end
|
256
|
-
rescue MyError => err
|
257
|
-
error(err)
|
258
|
-
end
|
259
|
-
|
260
|
-
#
|
261
|
-
# See #commit for information regarding transactionless database
|
262
|
-
# backends.
|
263
|
-
#
|
264
|
-
def rollback
|
265
|
-
if @have_transactions
|
266
|
-
self.do("ROLLBACK")
|
267
|
-
else
|
268
|
-
raise NotSupportedError
|
269
|
-
end
|
270
|
-
rescue MyError => err
|
271
|
-
error(err)
|
272
|
-
end
|
273
|
-
|
274
|
-
|
275
|
-
# def quote(value)
|
276
|
-
# case value
|
277
|
-
# when String
|
278
|
-
# "'#{@handle.quote(value)}'"
|
279
|
-
# when DBI::Binary
|
280
|
-
# "'#{@handle.quote(value.to_s)}'"
|
281
|
-
# when TrueClass
|
282
|
-
# "'1'"
|
283
|
-
# when FalseClass
|
284
|
-
# "'0'"
|
285
|
-
# else
|
286
|
-
# super
|
287
|
-
# end
|
288
|
-
# end
|
289
|
-
|
290
|
-
#
|
291
|
-
# See DBI::DBD::MySQL::Database.new for supported attributes and usage.
|
292
|
-
#
|
293
|
-
def []=(attr, value)
|
294
|
-
case attr
|
295
|
-
when 'AutoCommit'
|
296
|
-
if @have_transactions
|
297
|
-
self.do("SET AUTOCOMMIT=" + (value ? "1" : "0"))
|
298
|
-
else
|
299
|
-
raise NotSupportedError
|
300
|
-
end
|
301
|
-
else
|
302
|
-
raise NotSupportedError
|
303
|
-
end
|
304
|
-
|
305
|
-
@attr[attr] = value
|
306
|
-
end
|
307
|
-
|
308
|
-
private # -------------------------------------------------
|
309
|
-
|
310
|
-
#
|
311
|
-
# Given a type name, weans some basic information from that and returns
|
312
|
-
# it in a format similar to columns.
|
313
|
-
#
|
314
|
-
# Return is an array of +sqltype+, +type+, +size+, and +decimal+.
|
315
|
-
# +sqltype+ is the XOPEN type, and +type+ is the string with the
|
316
|
-
# parameters removed.
|
317
|
-
#
|
318
|
-
# +size+ and +decimal+ refer to +precision+ and +scale+ in most cases,
|
319
|
-
# but not always for all types. Please consult the documentation for
|
320
|
-
# your MySQL version.
|
321
|
-
#
|
322
|
-
#
|
323
|
-
def mysql_type_info(typedef)
|
324
|
-
sqltype, type, size, decimal = nil, nil, nil, nil
|
325
|
-
|
326
|
-
pos = typedef.index('(')
|
327
|
-
if not pos.nil?
|
328
|
-
type = typedef[0..pos-1]
|
329
|
-
size = typedef[pos+1..-2]
|
330
|
-
pos = size.index(',')
|
331
|
-
if not pos.nil?
|
332
|
-
size, decimal = size.split(',', 2)
|
333
|
-
decimal = decimal.to_i
|
334
|
-
end
|
335
|
-
size = size.to_i
|
336
|
-
else
|
337
|
-
type = typedef
|
338
|
-
end
|
339
|
-
|
340
|
-
type_info = MYSQL_to_XOPEN[type.upcase] || MYSQL_to_XOPEN[nil]
|
341
|
-
sqltype = type_info[0]
|
342
|
-
if size.nil? then size = type_info[1] end
|
343
|
-
if decimal.nil? then decimal = type_info[2] end
|
344
|
-
return sqltype, type, size, decimal
|
345
|
-
end
|
346
|
-
|
347
|
-
#--
|
348
|
-
# Driver-specific functions ------------------------------------------------
|
349
|
-
#++
|
350
|
-
|
351
|
-
public
|
352
|
-
|
353
|
-
def __createdb(db)
|
354
|
-
@handle.create_db(db)
|
355
|
-
end
|
356
|
-
|
357
|
-
def __dropdb(db)
|
358
|
-
@handle.drop_db(db)
|
359
|
-
end
|
360
|
-
|
361
|
-
def __shutdown
|
362
|
-
@handle.shutdown
|
363
|
-
end
|
364
|
-
|
365
|
-
def __reload
|
366
|
-
@handle.reload
|
367
|
-
end
|
368
|
-
|
369
|
-
def __insert_id
|
370
|
-
@handle.insert_id
|
371
|
-
end
|
372
|
-
|
373
|
-
def __thread_id
|
374
|
-
@handle.thread_id
|
375
|
-
end
|
376
|
-
|
377
|
-
def __info
|
378
|
-
@handle.info
|
379
|
-
end
|
380
|
-
|
381
|
-
def __host_info
|
382
|
-
@handle.host_info
|
383
|
-
end
|
384
|
-
|
385
|
-
def __proto_info
|
386
|
-
@handle.proto_info
|
387
|
-
end
|
388
|
-
|
389
|
-
def __server_info
|
390
|
-
@handle.server_info
|
391
|
-
end
|
392
|
-
|
393
|
-
def __client_info
|
394
|
-
@handle.client_info
|
395
|
-
end
|
396
|
-
|
397
|
-
def __client_version
|
398
|
-
@handle.client_version
|
399
|
-
end
|
400
|
-
|
401
|
-
def __stat
|
402
|
-
@handle.stat
|
403
|
-
end
|
404
|
-
end # class Database
|
405
|
-
end
|