ibruby 0.5.1-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/README +463 -0
- data/doc/license.txt +411 -0
- data/examples/example01.rb +65 -0
- data/lib/SQLType.rb +230 -0
- data/lib/ib_lib.so +0 -0
- data/lib/ibruby.rb +22 -0
- data/lib/mkdoc +1 -0
- data/lib/src.rb +1794 -0
- data/test/AddRemoveUserTest.rb +55 -0
- data/test/BackupRestoreTest.rb +99 -0
- data/test/BooleanTest.rb +113 -0
- data/test/CharacterSetTest.rb +63 -0
- data/test/ConnectionTest.rb +111 -0
- data/test/DDLTest.rb +54 -0
- data/test/DatabaseTest.rb +83 -0
- data/test/GeneratorTest.rb +50 -0
- data/test/KeyTest.rb +140 -0
- data/test/ResultSetTest.rb +164 -0
- data/test/RoleTest.rb +104 -0
- data/test/RowCountTest.rb +65 -0
- data/test/RowTest.rb +205 -0
- data/test/SQLTest.rb +182 -0
- data/test/SQLTypeTest.rb +101 -0
- data/test/ServiceManagerTest.rb +29 -0
- data/test/StatementTest.rb +135 -0
- data/test/TestSetup.rb +11 -0
- data/test/TransactionTest.rb +112 -0
- data/test/TypeTest.rb +92 -0
- data/test/UnitTest.rb +64 -0
- metadata +77 -0
data/lib/SQLType.rb
ADDED
@@ -0,0 +1,230 @@
|
|
1
|
+
#-------------------------------------------------------------------------------
|
2
|
+
# SQLType.rb
|
3
|
+
#-------------------------------------------------------------------------------
|
4
|
+
# Copyright � Peter Wood, 2005; Richard Vowles, 2006
|
5
|
+
#
|
6
|
+
# The contents of this file are subject to the Mozilla Public License Version
|
7
|
+
# 1.1 (the "License"); you may not use this file except in compliance with the
|
8
|
+
# License. You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.mozilla.org/MPL/
|
11
|
+
#
|
12
|
+
# Software distributed under the License is distributed on an "AS IS" basis,
|
13
|
+
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
14
|
+
# the specificlanguage governing rights and limitations under the License.
|
15
|
+
#
|
16
|
+
# The Original Code is the FireRuby extension for the Ruby language.
|
17
|
+
#
|
18
|
+
# The Initial Developer of the Original Code is Peter Wood. All Rights
|
19
|
+
# Reserved.
|
20
|
+
|
21
|
+
module IBRuby
|
22
|
+
# This class is used to represent SQL table column tables.
|
23
|
+
class SQLType
|
24
|
+
# A definition for a base SQL type.
|
25
|
+
BOOLEAN = :BOOLEAN
|
26
|
+
|
27
|
+
# A definition for a base SQL type.
|
28
|
+
BLOB = :BLOB
|
29
|
+
|
30
|
+
# A definition for a base SQL type.
|
31
|
+
CHAR = :CHAR
|
32
|
+
|
33
|
+
# A definition for a base SQL type.
|
34
|
+
DATE = :DATE
|
35
|
+
|
36
|
+
# A definition for a base SQL type.
|
37
|
+
DECIMAL = :DECIMAL
|
38
|
+
|
39
|
+
# A definition for a base SQL type.
|
40
|
+
DOUBLE = :DOUBLE
|
41
|
+
|
42
|
+
# A definition for a base SQL type.
|
43
|
+
FLOAT = :FLOAT
|
44
|
+
|
45
|
+
# A definition for a base SQL type.
|
46
|
+
INTEGER = :INTEGER
|
47
|
+
|
48
|
+
# A definition for a base SQL type.
|
49
|
+
NUMERIC = :NUMERIC
|
50
|
+
|
51
|
+
# A definition for a base SQL type.
|
52
|
+
SMALLINT = :SMALLINT
|
53
|
+
|
54
|
+
# A definition for a base SQL type.
|
55
|
+
TIME = :TIME
|
56
|
+
|
57
|
+
# A definition for a base SQL type.
|
58
|
+
TIMESTAMP = :TIMESTAMP
|
59
|
+
|
60
|
+
# A definition for a base SQL type.
|
61
|
+
VARCHAR = :VARCHAR
|
62
|
+
|
63
|
+
# Attribute accessor.
|
64
|
+
attr_reader :type, :length, :precision, :scale, :subtype
|
65
|
+
|
66
|
+
|
67
|
+
# This is the constructor for the SQLType class.
|
68
|
+
#
|
69
|
+
# ==== Parameters
|
70
|
+
# type:: The base type for the SQLType object. Must be one of the
|
71
|
+
# base types defined within the class.
|
72
|
+
# length:: The length setting for the type. Defaults to nil.
|
73
|
+
# precision:: The precision setting for the type. Defaults to nil.
|
74
|
+
# scale:: The scale setting for the type. Defaults to nil.
|
75
|
+
# subtype:: The SQL sub-type setting. Defaults to nil.
|
76
|
+
def initialize(type, length=nil, precision=nil, scale=nil, subtype=nil)
|
77
|
+
@type = type
|
78
|
+
@length = length
|
79
|
+
@precision = precision
|
80
|
+
@scale = scale
|
81
|
+
@subtype = subtype
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
# This class method fetches the type details for a named table. The
|
86
|
+
# method returns a hash that links column names to SQLType objects.
|
87
|
+
#
|
88
|
+
# ==== Parameters
|
89
|
+
# table:: A string containing the name of the table.
|
90
|
+
# connection:: A reference to the connection to be used to determine
|
91
|
+
# the type information.
|
92
|
+
#
|
93
|
+
# ==== Exception
|
94
|
+
# IBRubyException:: Generated if an invalid table name is specified
|
95
|
+
# or an SQL error occurs.
|
96
|
+
def SQLType.for_table(table, connection)
|
97
|
+
# Check for naughty table names.
|
98
|
+
if /\s+/ =~ table
|
99
|
+
raise IBRubyException.new("'#{table}' is not a valid table name.")
|
100
|
+
end
|
101
|
+
|
102
|
+
types = {}
|
103
|
+
begin
|
104
|
+
sql = "SELECT RF.RDB$FIELD_NAME, F.RDB$FIELD_TYPE, "\
|
105
|
+
"F.RDB$FIELD_LENGTH, F.RDB$FIELD_PRECISION, "\
|
106
|
+
"F.RDB$FIELD_SCALE * -1, F.RDB$FIELD_SUB_TYPE "\
|
107
|
+
"FROM RDB$RELATION_FIELDS RF, RDB$FIELDS F "\
|
108
|
+
"WHERE RF.RDB$RELATION_NAME = UPPER('#{table}') "\
|
109
|
+
"AND RF.RDB$FIELD_SOURCE = F.RDB$FIELD_NAME"
|
110
|
+
|
111
|
+
connection.start_transaction do |tx|
|
112
|
+
tx.execute(sql) do |row|
|
113
|
+
sql_type = SQLType.to_base_type(row[1], row[5])
|
114
|
+
type = nil
|
115
|
+
case sql_type
|
116
|
+
when BLOB
|
117
|
+
type = SQLType.new(sql_type, nil, nil, nil, row[5])
|
118
|
+
|
119
|
+
when CHAR, VARCHAR
|
120
|
+
type = SQLType.new(sql_type, row[2])
|
121
|
+
|
122
|
+
when DECIMAL, NUMERIC
|
123
|
+
type = SQLType.new(sql_type, nil, row[3], row[4])
|
124
|
+
|
125
|
+
else
|
126
|
+
type = SQLType.new(sql_type)
|
127
|
+
end
|
128
|
+
types[row[0].strip] = type
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
133
|
+
types
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
# This method overloads the equivalence test operator for the SQLType
|
138
|
+
# class.
|
139
|
+
#
|
140
|
+
# ==== Parameters
|
141
|
+
# object:: A reference to the object to be compared with.
|
142
|
+
def ==(object)
|
143
|
+
result = false
|
144
|
+
if object.instance_of?(SQLType)
|
145
|
+
result = (@type == object.type &&
|
146
|
+
@length == object.length &&
|
147
|
+
@precision == object.precision &&
|
148
|
+
@scale == object.scale &&
|
149
|
+
@subtype == object.subtype)
|
150
|
+
end
|
151
|
+
result
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
# This method generates a textual description for a SQLType object.
|
156
|
+
def to_s
|
157
|
+
if @type == SQLType::DECIMAL or @type == SQLType::NUMERIC
|
158
|
+
"#{@type.id2name}(#{@precision},#{@scale})"
|
159
|
+
elsif @type == SQLType::BLOB
|
160
|
+
"#{@type.id2name} SUB TYPE #{@subtype}"
|
161
|
+
elsif @type == SQLType::CHAR or @type == SQLType::VARCHAR
|
162
|
+
"#{@type.id2name}(#{@length})"
|
163
|
+
else
|
164
|
+
@type.id2name
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
# This class method converts a InterBase internal type to a SQLType base
|
170
|
+
# type.
|
171
|
+
#
|
172
|
+
# ==== Parameters
|
173
|
+
# type:: A reference to the Interbase field type value.
|
174
|
+
# subtype:: A reference to the Interbase field subtype value.
|
175
|
+
def SQLType.to_base_type(type, subtype)
|
176
|
+
case type
|
177
|
+
when 16 # DECIMAL, NUMERIC
|
178
|
+
if subtype
|
179
|
+
subtype == 1 ? SQLType::NUMERIC : SQLType::DECIMAL
|
180
|
+
else
|
181
|
+
SQLType::BIGINT
|
182
|
+
end
|
183
|
+
when 17 # BOOLEAN
|
184
|
+
SQLType::BOOLEAN
|
185
|
+
|
186
|
+
when 261 # BLOB
|
187
|
+
SQLType::BLOB
|
188
|
+
|
189
|
+
when 14 # CHAR
|
190
|
+
SQLType::CHAR
|
191
|
+
|
192
|
+
when 12 # DATE
|
193
|
+
SQLType::DATE
|
194
|
+
|
195
|
+
when 27 # DOUBLE, DECIMAL, NUMERIC
|
196
|
+
if subtype
|
197
|
+
subtype == 1 ? SQLType::NUMERIC : SQLType::DECIMAL
|
198
|
+
else
|
199
|
+
SQLType::DOUBLE
|
200
|
+
end
|
201
|
+
|
202
|
+
when 10 # FLOAT
|
203
|
+
SQLType::FLOAT
|
204
|
+
|
205
|
+
when 8 # INTEGER, DECIMAL, NUMERIC
|
206
|
+
if subtype
|
207
|
+
subtype == 1 ? SQLType::NUMERIC : SQLType::DECIMAL
|
208
|
+
else
|
209
|
+
SQLType::INTEGER
|
210
|
+
end
|
211
|
+
|
212
|
+
when 7 # SMALLINT, DECIMAL, NUMERIC
|
213
|
+
if subtype
|
214
|
+
subtype == 1 ? SQLType::NUMERIC : SQLType::DECIMAL
|
215
|
+
else
|
216
|
+
SQLType::SMALLINT
|
217
|
+
end
|
218
|
+
|
219
|
+
when 13 # TIME
|
220
|
+
SQLType::TIME
|
221
|
+
|
222
|
+
when 35 # TIMESTAMP
|
223
|
+
SQLType::TIMESTAMP
|
224
|
+
|
225
|
+
when 37 # VARCHAR
|
226
|
+
SQLType::VARCHAR
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end # End of the SQLType class.
|
230
|
+
end # End of the FireRuby module.
|
data/lib/ib_lib.so
ADDED
Binary file
|
data/lib/ibruby.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#-------------------------------------------------------------------------------
|
2
|
+
# ibruby.rb
|
3
|
+
#-------------------------------------------------------------------------------
|
4
|
+
# Copyright � Peter Wood, 2005
|
5
|
+
#
|
6
|
+
# The contents of this file are subject to the Mozilla Public License Version
|
7
|
+
# 1.1 (the "License"); you may not use this file except in compliance with the
|
8
|
+
# License. You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.mozilla.org/MPL/
|
11
|
+
#
|
12
|
+
# Software distributed under the License is distributed on an "AS IS" basis,
|
13
|
+
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
14
|
+
# the specificlanguage governing rights and limitations under the License.
|
15
|
+
#
|
16
|
+
# The Original Code is the FireRuby extension for the Ruby language.
|
17
|
+
#
|
18
|
+
# The Initial Developer of the Original Code is Peter Wood. All Rights
|
19
|
+
# Reserved.
|
20
|
+
|
21
|
+
require 'ib_lib'
|
22
|
+
require 'SQLType'
|
data/lib/mkdoc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rdoc -m README src.rb README
|