rubyfb 0.5.2-x86-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. data/CHANGELOG +6 -0
  2. data/LICENSE +411 -0
  3. data/Manifest +73 -0
  4. data/README +460 -0
  5. data/Rakefile +20 -0
  6. data/examples/example01.rb +65 -0
  7. data/ext/AddUser.c +464 -0
  8. data/ext/AddUser.h +37 -0
  9. data/ext/Backup.c +783 -0
  10. data/ext/Backup.h +37 -0
  11. data/ext/Blob.c +421 -0
  12. data/ext/Blob.h +65 -0
  13. data/ext/Common.c +54 -0
  14. data/ext/Common.h +37 -0
  15. data/ext/Connection.c +863 -0
  16. data/ext/Connection.h +50 -0
  17. data/ext/DataArea.c +274 -0
  18. data/ext/DataArea.h +38 -0
  19. data/ext/Database.c +449 -0
  20. data/ext/Database.h +48 -0
  21. data/ext/FireRuby.c +240 -0
  22. data/ext/FireRuby.h +50 -0
  23. data/ext/FireRubyException.c +268 -0
  24. data/ext/FireRubyException.h +51 -0
  25. data/ext/Generator.c +689 -0
  26. data/ext/Generator.h +53 -0
  27. data/ext/RemoveUser.c +212 -0
  28. data/ext/RemoveUser.h +37 -0
  29. data/ext/Restore.c +855 -0
  30. data/ext/Restore.h +37 -0
  31. data/ext/ResultSet.c +809 -0
  32. data/ext/ResultSet.h +60 -0
  33. data/ext/Row.c +965 -0
  34. data/ext/Row.h +55 -0
  35. data/ext/ServiceManager.c +316 -0
  36. data/ext/ServiceManager.h +48 -0
  37. data/ext/Services.c +124 -0
  38. data/ext/Services.h +42 -0
  39. data/ext/Statement.c +785 -0
  40. data/ext/Statement.h +62 -0
  41. data/ext/Transaction.c +684 -0
  42. data/ext/Transaction.h +50 -0
  43. data/ext/TypeMap.c +1182 -0
  44. data/ext/TypeMap.h +51 -0
  45. data/ext/extconf.rb +28 -0
  46. data/ext/mkmf.bat +1 -0
  47. data/lib/SQLType.rb +224 -0
  48. data/lib/active_record/connection_adapters/rubyfb_adapter.rb +805 -0
  49. data/lib/mkdoc +1 -0
  50. data/lib/rubyfb.rb +2 -0
  51. data/lib/rubyfb_lib.so +0 -0
  52. data/lib/src.rb +1800 -0
  53. data/rubyfb.gemspec +31 -0
  54. data/test/AddRemoveUserTest.rb +56 -0
  55. data/test/BackupRestoreTest.rb +99 -0
  56. data/test/BlobTest.rb +57 -0
  57. data/test/CharacterSetTest.rb +63 -0
  58. data/test/ConnectionTest.rb +111 -0
  59. data/test/DDLTest.rb +54 -0
  60. data/test/DatabaseTest.rb +83 -0
  61. data/test/GeneratorTest.rb +50 -0
  62. data/test/KeyTest.rb +140 -0
  63. data/test/ResultSetTest.rb +162 -0
  64. data/test/RoleTest.rb +73 -0
  65. data/test/RowCountTest.rb +65 -0
  66. data/test/RowTest.rb +203 -0
  67. data/test/SQLTest.rb +182 -0
  68. data/test/SQLTypeTest.rb +101 -0
  69. data/test/ServiceManagerTest.rb +29 -0
  70. data/test/StatementTest.rb +135 -0
  71. data/test/TestSetup.rb +11 -0
  72. data/test/TransactionTest.rb +112 -0
  73. data/test/TypeTest.rb +92 -0
  74. data/test/UnitTest.rb +65 -0
  75. metadata +149 -0
data/ext/TypeMap.h ADDED
@@ -0,0 +1,51 @@
1
+ /*------------------------------------------------------------------------------
2
+ * TypeMap.h
3
+ *----------------------------------------------------------------------------*/
4
+ /**
5
+ * Copyright � Peter Wood, 2005
6
+ *
7
+ * The contents of this file are subject to the Mozilla Public License Version
8
+ * 1.1 (the "License"); you may not use this file except in compliance with the
9
+ * License. You may obtain a copy of the License at
10
+ *
11
+ * http://www.mozilla.org/MPL/
12
+ *
13
+ * Software distributed under the License is distributed on an "AS IS" basis,
14
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
15
+ * the specificlanguage governing rights and limitations under the License.
16
+ *
17
+ * The Original Code is the FireRuby extension for the Ruby language.
18
+ *
19
+ * The Initial Developer of the Original Code is Peter Wood. All Rights
20
+ * Reserved.
21
+ *
22
+ * @author Peter Wood
23
+ * @version 1.0
24
+ */
25
+ #ifndef FIRERUBY_TYPE_MAP_H
26
+ #define FIRERUBY_TYPE_MAP_H
27
+
28
+ #ifndef IBASE_H_INCLUDED
29
+ #include "ibase.h"
30
+ #define IBASE_H_INCLUDED
31
+ #endif
32
+
33
+ #ifndef RUBY_H_INCLUDED
34
+ #include "ruby.h"
35
+ #define RUBY_H_INCLUDED
36
+ #endif
37
+
38
+ #ifndef FIRERUBY_DATABASE_H
39
+ #include "ResultSet.h"
40
+ #endif
41
+
42
+ /* Function prototypes. */
43
+ VALUE toValue(XSQLVAR *, isc_db_handle *, isc_tr_handle *);
44
+ VALUE toArray(VALUE);
45
+ void setParameters(XSQLDA *, VALUE, VALUE);
46
+ VALUE getModule(const char *);
47
+ VALUE getClass(const char *);
48
+ VALUE getClassInModule(const char *, VALUE);
49
+ VALUE getModuleInModule(const char *, VALUE);
50
+
51
+ #endif /* FIRERUBY_TYPE_MAP_H */
data/ext/extconf.rb ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV['ARCHFLAGS']='-arch '+`arch`.strip if PLATFORM.include?("darwin")
4
+
5
+ require 'mkmf'
6
+
7
+ # Add the framework link for Mac OS X.
8
+ if PLATFORM.include?("darwin")
9
+ $LDFLAGS = $LDFLAGS + " -framework Firebird"
10
+ $CFLAGS = $CFLAGS + " -DOS_UNIX"
11
+ firebird_include="/Library/Frameworks/Firebird.framework/Headers"
12
+ firebird_lib="/Library/Frameworks/Firebird.framework/Libraries"
13
+ elsif PLATFORM.include?("win32")
14
+ $LDFLAGS = $LDFLAGS + " fbclient_ms.lib"
15
+ $CFLAGS = $CFLAGS + " -DOS_WIN32"
16
+ dir_config("win32")
17
+ dir_config("winsdk")
18
+ dir_config("dotnet")
19
+ elsif PLATFORM.include?("linux")
20
+ $LDFLAGS = $LDFLAGS + " -lfbclient -lpthread"
21
+ $CFLAGS = $CFLAGS + " -DOS_UNIX"
22
+ end
23
+
24
+ # Make sure the firebird stuff is included.
25
+ dir_config("firebird", firebird_include, firebird_lib)
26
+
27
+ # Generate the Makefile.
28
+ create_makefile("rubyfb_lib")
data/ext/mkmf.bat ADDED
@@ -0,0 +1 @@
1
+ ruby extconf.rb "--with-firebird-dir=c:\Program Files\Firebird\Firebird_1_5" "--with-win32-dir=C:\Program Files\Microsoft Visual Studio 8" "--with-winsdk-dir=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2" "--with-dotnet-dir=C:\Program Files\Microsoft Visual Studio 8\VC"
data/lib/SQLType.rb ADDED
@@ -0,0 +1,224 @@
1
+ #-------------------------------------------------------------------------------
2
+ # SQLType.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
+ module FireRuby
22
+ # This class is used to represent SQL table column tables.
23
+ class SQLType
24
+ # A definition for a base SQL type.
25
+ BIGINT = :BIGINT
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
+ # FireRubyException:: 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 FireRubyException.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 Firebird internal type to a SQLType base
170
+ # type.
171
+ #
172
+ # ==== Parameters
173
+ # type:: A reference to the Firebird field type value.
174
+ # subtype:: A reference to the Firebird field subtype value.
175
+ def SQLType.to_base_type(type, subtype)
176
+ case type
177
+ when 16 # BIGINT, DECIMAL, NUMERIC
178
+ case subtype
179
+ when 1 then SQLType::NUMERIC
180
+ when 2 then SQLType::DECIMAL
181
+ else SQLType::BIGINT
182
+ end
183
+
184
+ when 261 # BLOB
185
+ SQLType::BLOB
186
+
187
+ when 14 # CHAR
188
+ SQLType::CHAR
189
+
190
+ when 12 # DATE
191
+ SQLType::DATE
192
+
193
+ when 27 # DOUBLE
194
+ SQLType::DOUBLE
195
+
196
+ when 10 # FLOAT
197
+ SQLType::FLOAT
198
+
199
+ when 8 # INTEGER, DECIMAL, NUMERIC
200
+ case subtype
201
+ when 1 then SQLType::NUMERIC
202
+ when 2 then SQLType::DECIMAL
203
+ else SQLType::INTEGER
204
+ end
205
+
206
+ when 7 # SMALLINT, DECIMAL, NUMERIC
207
+ case subtype
208
+ when 1 then SQLType::NUMERIC
209
+ when 2 then SQLType::DECIMAL
210
+ else SQLType::SMALLINT
211
+ end
212
+
213
+ when 13 # TIME
214
+ SQLType::TIME
215
+
216
+ when 35 # TIMESTAMP
217
+ SQLType::TIMESTAMP
218
+
219
+ when 37 # VARCHAR
220
+ SQLType::VARCHAR
221
+ end
222
+ end
223
+ end # End of the SQLType class.
224
+ end # End of the FireRuby module.