ydbi 0.5.7 → 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +4 -0
  3. data/lib/dbi/version.rb +1 -1
  4. data/readme.md +4 -3
  5. data/test/dbi/tc_dbi.rb +1 -1
  6. metadata +7 -125
  7. data/.github/workflows/ruby.yml +0 -35
  8. data/.gitignore +0 -8
  9. data/.travis.yml +0 -15
  10. data/Gemfile +0 -5
  11. data/Rakefile +0 -10
  12. data/TODO +0 -44
  13. data/bench/bench.rb +0 -79
  14. data/build/rake_task_lib.rb +0 -186
  15. data/doc/DBD_SPEC.rdoc +0 -88
  16. data/doc/DBI_SPEC.rdoc +0 -157
  17. data/doc/homepage/contact.html +0 -62
  18. data/doc/homepage/development.html +0 -124
  19. data/doc/homepage/index.html +0 -83
  20. data/doc/homepage/ruby-dbi.css +0 -91
  21. data/lib/dbd/Mysql.rb +0 -137
  22. data/lib/dbd/ODBC.rb +0 -89
  23. data/lib/dbd/Pg.rb +0 -188
  24. data/lib/dbd/SQLite.rb +0 -97
  25. data/lib/dbd/SQLite3.rb +0 -124
  26. data/lib/dbd/mysql/database.rb +0 -405
  27. data/lib/dbd/mysql/driver.rb +0 -125
  28. data/lib/dbd/mysql/statement.rb +0 -188
  29. data/lib/dbd/odbc/database.rb +0 -128
  30. data/lib/dbd/odbc/driver.rb +0 -38
  31. data/lib/dbd/odbc/statement.rb +0 -137
  32. data/lib/dbd/pg/database.rb +0 -504
  33. data/lib/dbd/pg/exec.rb +0 -47
  34. data/lib/dbd/pg/statement.rb +0 -160
  35. data/lib/dbd/pg/tuples.rb +0 -121
  36. data/lib/dbd/pg/type.rb +0 -209
  37. data/lib/dbd/sqlite/database.rb +0 -151
  38. data/lib/dbd/sqlite/statement.rb +0 -125
  39. data/lib/dbd/sqlite3/database.rb +0 -201
  40. data/lib/dbd/sqlite3/statement.rb +0 -78
  41. data/prototypes/types2.rb +0 -237
  42. data/setup.rb +0 -1585
  43. data/test/DBD_TESTS +0 -50
  44. data/test/TESTING +0 -16
  45. data/test/dbd/general/test_database.rb +0 -206
  46. data/test/dbd/general/test_statement.rb +0 -326
  47. data/test/dbd/general/test_types.rb +0 -296
  48. data/test/dbd/mysql/base.rb +0 -26
  49. data/test/dbd/mysql/down.sql +0 -19
  50. data/test/dbd/mysql/test_blob.rb +0 -18
  51. data/test/dbd/mysql/test_new_methods.rb +0 -7
  52. data/test/dbd/mysql/test_patches.rb +0 -111
  53. data/test/dbd/mysql/up.sql +0 -28
  54. data/test/dbd/odbc/base.rb +0 -30
  55. data/test/dbd/odbc/down.sql +0 -19
  56. data/test/dbd/odbc/test_new_methods.rb +0 -12
  57. data/test/dbd/odbc/test_ping.rb +0 -10
  58. data/test/dbd/odbc/test_statement.rb +0 -44
  59. data/test/dbd/odbc/test_transactions.rb +0 -58
  60. data/test/dbd/odbc/up.sql +0 -33
  61. data/test/dbd/postgresql/base.rb +0 -31
  62. data/test/dbd/postgresql/down.sql +0 -31
  63. data/test/dbd/postgresql/test_arrays.rb +0 -179
  64. data/test/dbd/postgresql/test_async.rb +0 -121
  65. data/test/dbd/postgresql/test_blob.rb +0 -36
  66. data/test/dbd/postgresql/test_bytea.rb +0 -87
  67. data/test/dbd/postgresql/test_ping.rb +0 -10
  68. data/test/dbd/postgresql/test_timestamp.rb +0 -77
  69. data/test/dbd/postgresql/test_transactions.rb +0 -58
  70. data/test/dbd/postgresql/testdbipg.rb +0 -307
  71. data/test/dbd/postgresql/up.sql +0 -60
  72. data/test/dbd/sqlite/base.rb +0 -32
  73. data/test/dbd/sqlite/test_database.rb +0 -30
  74. data/test/dbd/sqlite/test_driver.rb +0 -68
  75. data/test/dbd/sqlite/test_statement.rb +0 -112
  76. data/test/dbd/sqlite/up.sql +0 -25
  77. data/test/dbd/sqlite3/base.rb +0 -32
  78. data/test/dbd/sqlite3/test_database.rb +0 -77
  79. data/test/dbd/sqlite3/test_driver.rb +0 -67
  80. data/test/dbd/sqlite3/test_statement.rb +0 -88
  81. data/test/dbd/sqlite3/up.sql +0 -33
  82. data/test/ts_dbd.rb +0 -131
  83. data/ydbi.gemspec +0 -23
@@ -1,125 +0,0 @@
1
- module DBI::DBD::Mysql
2
- #
3
- # Models the DBI::BaseDriver API to create DBI::DriverHandle objects.
4
- #
5
- class Driver < DBI::BaseDriver
6
- include Util
7
-
8
- def initialize
9
- super("0.4.0")
10
- end
11
-
12
- def default_user
13
- ['', nil]
14
- end
15
-
16
- #
17
- # Parameters in the dbname as follows:
18
- #
19
- # * host: host to connect to
20
- # * port: port to connect to
21
- # * socket: connect to a specific unix socket instead of a TCP socket.
22
- # * flag: an OR'd collection of flags to pass to the lower-level
23
- # connection attempt.
24
- # * mysql_read_default_file: FIXME
25
- # * mysql_read_default_group: FIXME
26
- # * mysql_compression: FIXME
27
- # * mysql_local_infile: FIXME
28
- # * mysql_client_found_rows: FIXME boolean, modifies the 'flag'
29
- # setting above.
30
- def connect(dbname, user, auth, attr)
31
- # connect to database server
32
- hash = DBI::Utils.parse_params(dbname)
33
-
34
- hash['host'] ||= 'localhost'
35
-
36
- # these two connection parameters should be passed as numbers
37
- hash['port'] = hash['port'].to_i unless hash['port'].nil?
38
- hash['flag'] = hash['flag'].nil? ? 0 : hash['flag'] = hash['flag'].to_i
39
-
40
- handle = ::Mysql.init
41
-
42
- # Look for options in connect string to be handled
43
- # through mysql_options() before connecting
44
- !hash['mysql_read_default_file'].nil? and
45
- handle.options(::Mysql::READ_DEFAULT_FILE,
46
- hash['mysql_read_default_file'])
47
- !hash['mysql_read_default_group'].nil? and
48
- handle.options(::Mysql::READ_DEFAULT_GROUP,
49
- hash['mysql_read_default_group'])
50
- # The following options can be handled either using mysql_options()
51
- # or in the flag argument to connect().
52
- hash['mysql_compression'].to_i != 0 and
53
- handle.options(::Mysql::OPT_COMPRESS, nil)
54
- hash['mysql_local_infile'].to_i != 0 and
55
- handle.options(::Mysql::OPT_LOCAL_INFILE, true)
56
-
57
- # Look for options to be handled in the flags argument to connect()
58
- if !hash['mysql_client_found_rows'].nil?
59
- if hash['mysql_client_found_rows'].to_i != 0
60
- hash['flag'] |= ::Mysql::CLIENT_FOUND_ROWS
61
- else
62
- hash['flag'] &= ~::Mysql::CLIENT_FOUND_ROWS
63
- end
64
- end
65
-
66
- handle.connect(hash['host'], user, auth, hash['database'], hash['port'], hash['socket'], hash['flag'])
67
-
68
- return Database.new(handle, attr)
69
- rescue MyError => err
70
- error(err)
71
- end
72
-
73
- def data_sources
74
- handle = ::Mysql.new
75
- res = handle.list_dbs.collect {|db| "dbi:Mysql:database=#{db}" }
76
- handle.close
77
- return res
78
- rescue MyError => err
79
- error(err)
80
- end
81
-
82
- #--
83
- # Driver-specific functions ------------------------------------------------
84
- #++
85
-
86
- public
87
-
88
- def __createdb(db, host, user, password, port=nil, sock=nil, flag=nil)
89
- handle = ::Mysql.connect(host, user, password, nil, port, sock, flag)
90
- begin
91
- handle.create_db(db)
92
- ensure
93
- handle.close if handle
94
- end
95
- end
96
-
97
- def __dropdb(db, host, user, password, port=nil, sock=nil, flag=nil)
98
- handle = ::Mysql.connect(host, user, password, nil, port, sock, flag)
99
- begin
100
- handle.drop_db(db)
101
- ensure
102
- handle.close if handle
103
- end
104
- end
105
-
106
- def __shutdown(host, user, password, port=nil, sock=nil, flag=nil)
107
- handle = ::Mysql.connect(host, user, password, nil, port, sock, flag)
108
- begin
109
- handle.shutdown
110
- ensure
111
- handle.close if handle
112
- end
113
- end
114
-
115
- def __reload(host, user, password, port=nil, sock=nil, flag=nil)
116
- handle = ::Mysql.connect(host, user, password, nil, port, sock, flag)
117
- begin
118
- handle.reload
119
- ensure
120
- handle.close if handle
121
- end
122
- end
123
-
124
- end # class Driver
125
- end
@@ -1,188 +0,0 @@
1
- module DBI::DBD::Mysql
2
- #
3
- # Models the DBI::BaseStatement API to create DBI::StatementHandle objects.
4
- #
5
- class Statement < DBI::BaseStatement
6
- include Util
7
-
8
- def initialize(parent, handle, statement, mutex)
9
- super(nil)
10
-
11
- @parent, @handle, @mutex = parent, handle, mutex
12
- @params = []
13
-
14
- @prep_stmt = DBI::SQL::PreparedStatement.new(@parent, statement)
15
- end
16
-
17
- #
18
- # See DBI::BaseStatement#bind_param. This method will also raise
19
- # DBI::InterfaceError if +param+ is not a Fixnum, to prevent incorrect
20
- # binding.
21
- #
22
- def bind_param(param, value, attribs)
23
- raise InterfaceError, "only ? parameters supported" unless param.is_a? Fixnum
24
- @params[param-1] = value
25
- end
26
-
27
- #
28
- # See DBI::BaseStatement#execute. If DBI thinks this is a query via DBI::SQL.query?(),
29
- # it will force the row processed count to 0. Otherwise, it will return
30
- # what MySQL thinks is the row processed count.
31
- #
32
- def execute
33
- sql = @prep_stmt.bind(@params)
34
- @mutex.synchronize {
35
- @handle.query_with_result = true
36
- @res_handle = @handle.query(sql)
37
- @column_info = self.column_info
38
- @current_row = 0
39
- @rows = DBI::SQL.query?(sql) ? 0 : @handle.affected_rows
40
- }
41
- rescue MyError => err
42
- error(err)
43
- end
44
-
45
- def finish
46
- @res_handle.free if @res_handle
47
- rescue MyError => err
48
- error(err)
49
- end
50
-
51
- #
52
- # Helper method to aid #fetch. Do not call directly.
53
- #
54
- def fill_array(rowdata)
55
- return nil if rowdata.nil?
56
- return rowdata.dup
57
- end
58
-
59
- def fetch
60
- @current_row += 1
61
- fill_array(@res_handle.fetch_row)
62
- rescue MyError => err
63
- error(err)
64
- end
65
-
66
- #
67
- # See DBI::BaseStatement#fetch_scroll. These additional constants are also supported:
68
- #
69
- # * DBI::SQL_FETCH_PRIOR: Fetch the row previous to the current one.
70
- # * DBI::SQL_FETCH_FIRST: Fetch the first row.
71
- # * DBI::SQL_FETCH_ABSOLUTE: Fetch the row at the offset provided.
72
- # * DBI::SQL_FETCH_RELATIVE: Fetch the row at the current point + offset.
73
- #
74
- def fetch_scroll(direction, offset)
75
- case direction
76
- when DBI::SQL_FETCH_NEXT
77
- @current_row += 1
78
- fill_array(@res_handle.fetch_row)
79
- when DBI::SQL_FETCH_PRIOR
80
- @res_handle.data_seek(@current_row - 1)
81
- fill_array(@res_handle.fetch_row)
82
- when DBI::SQL_FETCH_FIRST
83
- @current_row = 1
84
- @res_handle.data_seek(@current_row - 1)
85
- fill_array(@res_handle.fetch_row)
86
- when DBI::SQL_FETCH_LAST
87
- @current_row = @res_handle.num_rows
88
- @res_handle.data_seek(@current_row - 1)
89
- fill_array(@res_handle.fetch_row)
90
- when DBI::SQL_FETCH_ABSOLUTE
91
- @current_row = offset + 1
92
- @res_handle.data_seek(@current_row - 1)
93
- fill_array(@res_handle.fetch_row)
94
- when DBI::SQL_FETCH_RELATIVE
95
- @current_row += offset + 1
96
- @res_handle.data_seek(@current_row - 1)
97
- fill_array(@res_handle.fetch_row)
98
- else
99
- raise NotSupportedError
100
- end
101
- #end
102
- end
103
-
104
- #
105
- # See DBI::BaseStatement#column_info, and DBI::DBD::Mysql::Database#columns.
106
- #
107
- # This method provides all the attributes the +columns+ method
108
- # provides, and a few others:
109
- #
110
- # * mysql_type: These correspond to constants in the Mysql::Types
111
- # package, in the lower-level 'mysql' package.
112
- # * mysql_type_name: A text representation of +mysql_type+.
113
- # * mysql_length: The length of the column.
114
- # * mysql_max_length: The max length of the column. FIXME DESCRIBE
115
- # DIFFERENCE
116
- # * mysql_flags: Internal MySQL flags on this column.
117
- #
118
- def column_info
119
- retval = []
120
-
121
- return [] if @res_handle.nil?
122
-
123
- unique_key_flag = MysqlField.const_get(:UNIQUE_KEY_FLAG)
124
- multiple_key_flag = MysqlField.const_get(:MULTIPLE_KEY_FLAG)
125
- indexed = (unique_key_flag | multiple_key_flag)
126
-
127
- # Note: Cannot get 'default' column attribute because MysqlField.def
128
- # is set only by mysql_list_fields()
129
-
130
- @res_handle.fetch_fields.each {|col|
131
- mysql_type_name, dbi_type = Database::TYPE_MAP[col.type] rescue [nil, nil]
132
- xopen_info = Database::MYSQL_to_XOPEN[mysql_type_name] ||
133
- Database::MYSQL_to_XOPEN[nil]
134
- sql_type = xopen_info[0]
135
- type_name = DBI::SQL_TYPE_NAMES[sql_type]
136
-
137
- retval << {
138
- # Standard Ruby DBI column attributes
139
- 'name' => col.name,
140
- 'sql_type' => sql_type,
141
- 'type_name' => type_name,
142
- # XXX it seems mysql counts the literal decimal point when weighing in the "length".
143
- 'precision' => type_name == "NUMERIC" ? col.length - 2 : col.length,
144
- 'scale' => col.decimals,
145
- 'nullable' => !col.is_not_null?,
146
- 'indexed' => ((col.flags & indexed) != 0) ||
147
- col.is_pri_key?,
148
- 'primary' => col.is_pri_key?,
149
- 'unique' => ((col.flags & unique_key_flag) != 0) ||
150
- col.is_pri_key?,
151
- # MySQL-specific attributes (signified by leading "mysql_")
152
- 'mysql_type' => col.type,
153
- 'mysql_type_name' => mysql_type_name,
154
- 'mysql_length' => col.length,
155
- 'mysql_max_length' => col.max_length,
156
- 'mysql_flags' => col.flags
157
- }
158
-
159
- if retval[-1]['sql_type'] == DBI::SQL_TINYINT and retval[-1]['precision'] == 1
160
- retval[-1]['dbi_type'] = DBI::Type::Boolean
161
- elsif dbi_type
162
- retval[-1]['dbi_type'] = dbi_type
163
- end
164
- }
165
- retval
166
- rescue MyError => err
167
- error(err)
168
- end
169
-
170
- def rows
171
- @rows
172
- end
173
-
174
- # def []=(attr, value)
175
- # case attr
176
- # when 'mysql_use_result'
177
- # @attr['mysql_store_result'] = ! value
178
- # @attr['mysql_use_result'] = value
179
- # when 'mysql_store_result'
180
- # @attr['mysql_use_result'] = ! value
181
- # @attr['mysql_store_result'] = value
182
- # else
183
- # raise NotSupportedError
184
- # end
185
- # end
186
-
187
- end # class Statement
188
- end
@@ -1,128 +0,0 @@
1
- #
2
- # See DBI::BaseDatabase.
3
- #
4
- class DBI::DBD::ODBC::Database < DBI::BaseDatabase
5
- def disconnect
6
- @handle.rollback
7
- @handle.disconnect
8
- rescue DBI::DBD::ODBC::ODBCErr => err
9
- raise DBI::DatabaseError.new(err.message)
10
- end
11
-
12
- def database_name
13
- @handle.get_info('SQL_DATABASE_NAME')
14
- end
15
-
16
- def ping
17
- @handle.connected?
18
- end
19
-
20
- #
21
- # See DBI::BaseDatabase#columns. Additional Attributes:
22
- #
23
- # * nullable: boolean, true if NULLs are allowed in this column.
24
- #
25
- def columns(table)
26
- cols = []
27
-
28
- stmt = @handle.columns(table)
29
- stmt.ignorecase = true
30
-
31
- stmt.each_hash do |row|
32
- info = Hash.new
33
- cols << info
34
-
35
- info['name'] = row['COLUMN_NAME']
36
- info['type_name'] = row['TYPE_NAME']
37
- info['sql_type'] = row['DATA_TYPE']
38
- info['nullable'] =
39
- case row['NULLABLE']
40
- when 1
41
- true
42
- when 0
43
- false
44
- else
45
- nil
46
- end
47
- info['precision'] = row['PRECISION']
48
- info['scale'] = row['SCALE']
49
- end
50
-
51
- stmt.drop
52
- cols
53
- rescue DBI::DBD::ODBC::ODBCErr => err
54
- raise DBI::DatabaseError.new(err.message)
55
- end
56
-
57
- def tables
58
- stmt = @handle.tables
59
- stmt.ignorecase = true
60
- tabs = []
61
- stmt.each_hash {|row|
62
- tabs << row["TABLE_NAME"]
63
- }
64
- stmt.drop
65
- tabs
66
- rescue DBI::DBD::ODBC::ODBCErr => err
67
- raise DBI::DatabaseError.new(err.message)
68
- end
69
-
70
- def prepare(statement)
71
- DBI::DBD::ODBC::Statement.new(@handle.prepare(statement), statement)
72
- rescue DBI::DBD::ODBC::ODBCErr => err
73
- raise DBI::DatabaseError.new(err.message)
74
- end
75
-
76
- def do(statement, *bindvars)
77
- @handle.do(statement, *bindvars)
78
- rescue DBI::DBD::ODBC::ODBCErr => err
79
- raise DBI::DatabaseError.new(err.message)
80
- end
81
-
82
- def execute(statement, *bindvars)
83
- stmt = @handle.run(statement, *bindvars)
84
- DBI::DBD::ODBC::Statement.new(stmt, statement)
85
- rescue DBI::DBD::ODBC::ODBCErr => err
86
- raise DBI::DatabaseError.new(err.message)
87
- end
88
-
89
- #
90
- # Additional Attributes on the DatabaseHandle:
91
- #
92
- # * AutoCommit: force a commit after each statement execution.
93
- # * odbc_ignorecase: Be case-insensitive in operations.
94
- # * odbc_timeout: Return after a certain time regardless of whether the operation returned anything.
95
- #
96
- def []=(attr, value)
97
- case attr
98
- when 'AutoCommit'
99
- @handle.autocommit(value)
100
- when 'odbc_ignorecase'
101
- @handle.ignorecase(value)
102
- when 'odbc_timeout'
103
- @handle.timeout(value)
104
- else
105
- if attr =~ /^odbc_/ or attr != /_/
106
- raise DBI::NotSupportedError, "Option '#{attr}' not supported"
107
- else # option for some other driver - quitly ignore
108
- return
109
- end
110
- end
111
- @attr[attr] = value
112
- rescue DBI::DBD::ODBC::ODBCErr => err
113
- raise DBI::DatabaseError.new(err.message)
114
- end
115
-
116
- def commit
117
- @handle.commit
118
- rescue DBI::DBD::ODBC::ODBCErr => err
119
- raise DBI::DatabaseError.new(err.message)
120
- end
121
-
122
- def rollback
123
- @handle.rollback
124
- rescue DBI::DBD::ODBC::ODBCErr => err
125
- raise DBI::DatabaseError.new(err.message)
126
- end
127
-
128
- end # class Database
@@ -1,38 +0,0 @@
1
- #
2
- # See DBI::BaseDriver
3
- #
4
- class DBI::DBD::ODBC::Driver < DBI::BaseDriver
5
- def initialize
6
- super("0.4.0")
7
- end
8
-
9
- def data_sources
10
- ::ODBC.datasources.collect {|dsn| "dbi:ODBC:" + dsn.name }
11
- rescue DBI::DBD::ODBC::ODBCErr => err
12
- raise DBI::DatabaseError.new(err.message)
13
- end
14
-
15
- def connect(dbname, user, auth, attr)
16
- driver_attrs = dbname.split(';')
17
-
18
- if driver_attrs.size > 1
19
- # DNS-less connection
20
- drv = ::ODBC::Driver.new
21
- drv.name = 'Driver1'
22
- driver_attrs.each do |param|
23
- pv = param.split('=')
24
- next if pv.size < 2
25
- drv.attrs[pv[0]] = pv[1]
26
- end
27
- db = ::ODBC::Database.new
28
- handle = db.drvconnect(drv)
29
- else
30
- # DNS given
31
- handle = ::ODBC.connect(dbname, user, auth)
32
- end
33
-
34
- return DBI::DBD::ODBC::Database.new(handle, attr)
35
- rescue DBI::DBD::ODBC::ODBCErr => err
36
- raise DBI::DatabaseError.new(err.message)
37
- end
38
- end