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/Row.h ADDED
@@ -0,0 +1,55 @@
1
+ /*------------------------------------------------------------------------------
2
+ * Row.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_ROW_H
26
+ #define FIRERUBY_ROW_H
27
+
28
+ /* Includes. */
29
+ #ifndef RUBY_H_INCLUDED
30
+ #include "ruby.h"
31
+ #define RUBY_H_INCLUDED
32
+ #endif
33
+
34
+ /* Type definitions. */
35
+ typedef struct
36
+ {
37
+ char name[32],
38
+ alias[32];
39
+ VALUE value,
40
+ type;
41
+ } ColumnHandle;
42
+
43
+ typedef struct
44
+ {
45
+ unsigned int size,
46
+ number;
47
+ ColumnHandle *columns;
48
+ } RowHandle;
49
+
50
+ /* Function prototypes. */
51
+ void Init_Row(VALUE);
52
+ void freeRow(void *);
53
+ VALUE rb_row_new(VALUE, VALUE, VALUE);
54
+
55
+ #endif // FIRERUBY_ROW_H
@@ -0,0 +1,316 @@
1
+ /*------------------------------------------------------------------------------
2
+ * ServiceManager.c
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
+
26
+ /* Includes. */
27
+ #include "ServiceManager.h"
28
+ #include "Common.h"
29
+
30
+ /* Function prototypes. */
31
+ static VALUE allocateServiceManager(VALUE);
32
+ static VALUE initializeServiceManager(VALUE, VALUE);
33
+ static VALUE connectServiceManager(VALUE, VALUE, VALUE);
34
+ static VALUE disconnectServiceManager(VALUE);
35
+ static VALUE isServiceManagerConnected(VALUE);
36
+ static VALUE executeServiceTasks(int, VALUE *, VALUE);
37
+
38
+ /* Globals. */
39
+ VALUE cServiceManager;
40
+
41
+
42
+ /**
43
+ * This function integrates with the Ruby memory allocation functionality to
44
+ * allow for the creation of new ServiceManager objects.
45
+ *
46
+ * @param klass A reference to the ServiceManager Class object.
47
+ *
48
+ * @return A reference to the newly allocated ServiceManager object.
49
+ *
50
+ */
51
+ VALUE allocateServiceManager(VALUE klass)
52
+ {
53
+ VALUE instance = Qnil;
54
+ ManagerHandle *manager = ALLOC(ManagerHandle);
55
+
56
+ if(manager == NULL)
57
+ {
58
+ rb_raise(rb_eNoMemError,
59
+ "Memory allocation failure creating a service manager.");
60
+ }
61
+ manager->handle = NULL;
62
+ instance = Data_Wrap_Struct(klass, NULL, serviceManagerFree, manager);
63
+
64
+ return(instance);
65
+ }
66
+
67
+
68
+ /**
69
+ * This method provides the initialize method for the ServiceManager class.
70
+ *
71
+ * @param self A reference to the ServiceManager object to be initialized.
72
+ * @param host The name of the database host for the service manager.
73
+ *
74
+ */
75
+ VALUE initializeServiceManager(VALUE self, VALUE host)
76
+ {
77
+ VALUE text = rb_funcall(host, rb_intern("to_s"), 0);
78
+
79
+ rb_iv_set(self, "@host", text);
80
+
81
+ return(self);
82
+ }
83
+
84
+
85
+ /**
86
+ * This function provides the connect method for the ServiceManager class.
87
+ *
88
+ * @param self A reference to the ServiceManager object to be connected.
89
+ * @param user A string containing the user that will be used for service
90
+ * execution.
91
+ * @param password A string containing the user password that will be used
92
+ * for service execution.
93
+ *
94
+ * @return A reference to the newly connected ServiceManager object.
95
+ *
96
+ */
97
+ VALUE connectServiceManager(VALUE self, VALUE user, VALUE password)
98
+ {
99
+ ManagerHandle *manager = NULL;
100
+ char *buffer = NULL,
101
+ *position = NULL,
102
+ *text = NULL,
103
+ *service = NULL;
104
+ short length = 2,
105
+ size = 0;
106
+ VALUE host = rb_iv_get(self, "@host");
107
+ ISC_STATUS status[20];
108
+
109
+ Data_Get_Struct(self, ManagerHandle, manager);
110
+ if(manager->handle != 0)
111
+ {
112
+ rb_fireruby_raise(NULL, "Service manager already connected.");
113
+ }
114
+
115
+ /* Calculate the size of the service parameter buffer. */
116
+ length += strlen(STR2CSTR(user)) + 2;
117
+ length += strlen(STR2CSTR(password)) + 2;
118
+
119
+ /* Create the service parameter buffer. */
120
+ position = buffer = ALLOC_N(char, length);
121
+ if(position == NULL)
122
+ {
123
+ rb_raise(rb_eNoMemError,
124
+ "Memory allocation failure creating service parameter buffer.");
125
+ }
126
+ memset(buffer, 0, length);
127
+
128
+ /* Populate the service parameter buffer. */
129
+ *position++ = isc_spb_version;
130
+ *position++ = isc_spb_current_version;
131
+
132
+ text = STR2CSTR(user);
133
+ size = strlen(text);
134
+ *position++ = isc_spb_user_name;
135
+ *position++ = size;
136
+ strncpy(position, text, size);
137
+ position += size;
138
+
139
+ text = STR2CSTR(password);
140
+ size = strlen(text);
141
+ *position++ = isc_spb_password;
142
+ *position++ = size;
143
+ strncpy(position, text, size);
144
+
145
+ /* Create the service name. */
146
+ size = strlen(STR2CSTR(host)) + 13;
147
+ service = ALLOC_N(char, size);
148
+ if(service == NULL)
149
+ {
150
+ free(buffer);
151
+ rb_raise(rb_eNoMemError,
152
+ "Memory allocation failure service manager service name.");
153
+ }
154
+ memset(service, 0, size);
155
+ sprintf(service, "%s:service_mgr", STR2CSTR(host));
156
+
157
+ /* Make the attachment call. */
158
+ if(isc_service_attach(status, 0, service, &manager->handle, length,
159
+ buffer))
160
+ {
161
+ free(buffer);
162
+ free(service);
163
+ rb_fireruby_raise(status, "Error connecting service manager.");
164
+ }
165
+
166
+ /* Clean up. */
167
+ free(buffer);
168
+ free(service);
169
+
170
+ return(self);
171
+ }
172
+
173
+
174
+ /**
175
+ * This function provides the disconnect method for the ServiceManager class.
176
+ *
177
+ * @param self A reference to the ServiceManager object to be disconnected.
178
+ *
179
+ * @return A reference to the disconnected ServiceManager object.
180
+ *
181
+ */
182
+ VALUE disconnectServiceManager(VALUE self)
183
+ {
184
+ ManagerHandle *manager = NULL;
185
+
186
+ Data_Get_Struct(self, ManagerHandle, manager);
187
+ if(manager->handle != 0)
188
+ {
189
+ ISC_STATUS status[20];
190
+
191
+ if(isc_service_detach(status, &manager->handle))
192
+ {
193
+ rb_fireruby_raise(status, "Error disconnecting service manager.");
194
+ }
195
+ manager->handle = 0;
196
+ }
197
+
198
+ return(self);
199
+ }
200
+
201
+
202
+ /**
203
+ * This function provides the connected? method of the ServiceManager class.
204
+ *
205
+ * @param self A reference to the ServiceManager object to be checked.
206
+ *
207
+ * @return True if the manager is connected, false otherwise.
208
+ *
209
+ */
210
+ VALUE isServiceManagerConnected(VALUE self)
211
+ {
212
+ VALUE result = Qfalse;
213
+ ManagerHandle *manager = NULL;
214
+
215
+ Data_Get_Struct(self, ManagerHandle, manager);
216
+ if(manager->handle != 0)
217
+ {
218
+ result = Qtrue;
219
+ }
220
+
221
+ return(result);
222
+ }
223
+
224
+
225
+ /**
226
+ * This function provides the execute method for the ServiceManager class.
227
+ *
228
+ * @param argc A count of the number of arguments passed to the function
229
+ * call.
230
+ * @param argv A pointer to the start of an array of VALUE entities that are
231
+ * the function parameters.
232
+ * @param self A reference to the ServiceManager object that the call is
233
+ * being made on.
234
+ *
235
+ * @return A reference to the ServiceManager class.
236
+ *
237
+ */
238
+ VALUE executeServiceTasks(int argc, VALUE *argv, VALUE self)
239
+ {
240
+ if(argc > 0)
241
+ {
242
+ int i;
243
+
244
+ for(i = 0; i < argc; i++)
245
+ {
246
+ rb_funcall(argv[i], rb_intern("execute"), 1, self);
247
+ }
248
+ }
249
+
250
+ return(self);
251
+ }
252
+
253
+
254
+ /**
255
+ * This function integrates with the Ruby garbage collection functionality to
256
+ * insure that the resources associated with a ServiceManager object a fully
257
+ * released whenever the object gets collected.
258
+ *
259
+ * @param manager A reference to the ManagerHandle associated with the
260
+ * ServiceManager being collected.
261
+ *
262
+ */
263
+ void serviceManagerFree(void *manager)
264
+ {
265
+ if(manager != NULL)
266
+ {
267
+ ManagerHandle *handle = (ManagerHandle *)manager;
268
+
269
+ if(handle->handle != 0)
270
+ {
271
+ ISC_STATUS status[20];
272
+
273
+ isc_service_detach(status, &handle->handle);
274
+ }
275
+ free(handle);
276
+ }
277
+ }
278
+
279
+
280
+ /**
281
+ * This function provides a programmatic means of creating a ServiceManager
282
+ * object.
283
+ *
284
+ * @param host A reference to the host that the service manager will connect
285
+ * to.
286
+ *
287
+ * @return A reference to the newly created ServiceManager object.
288
+ *
289
+ */
290
+ VALUE rb_service_manager_new(VALUE host)
291
+ {
292
+ VALUE manager = allocateServiceManager(cServiceManager);
293
+
294
+ initializeServiceManager(manager, host);
295
+
296
+ return(manager);
297
+ }
298
+
299
+
300
+ /**
301
+ * This function initialize the ServiceManager class in the Ruby environment.
302
+ *
303
+ * @param module The module to create the new class definition under.
304
+ *
305
+ */
306
+ void Init_ServiceManager(VALUE module)
307
+ {
308
+ cServiceManager = rb_define_class_under(module, "ServiceManager", rb_cObject);
309
+ rb_define_alloc_func(cServiceManager, allocateServiceManager);
310
+ rb_define_method(cServiceManager, "initialize", initializeServiceManager, 1);
311
+ rb_define_method(cServiceManager, "initialize_copy", forbidObjectCopy, 1);
312
+ rb_define_method(cServiceManager, "connect", connectServiceManager, 2);
313
+ rb_define_method(cServiceManager, "disconnect", disconnectServiceManager, 0);
314
+ rb_define_method(cServiceManager, "connected?", isServiceManagerConnected, 0);
315
+ rb_define_method(cServiceManager, "execute", executeServiceTasks, -1);
316
+ }
@@ -0,0 +1,48 @@
1
+ /*------------------------------------------------------------------------------
2
+ * ServiceManager.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_SERVICE_MANAGER_H
26
+ #define FIRERUBY_SERVICE_MANAGER_H
27
+
28
+ /* Includes. */
29
+ #ifndef FIRERUBY_FIRE_RUBY_H
30
+ #include "FireRuby.h"
31
+ #endif
32
+
33
+ #ifndef FIRERUBY_FIRE_RUBY_EXCEPTION_H
34
+ #include "FireRubyException.h"
35
+ #endif
36
+
37
+ /* Type definitions. */
38
+ typedef struct
39
+ {
40
+ isc_svc_handle handle;
41
+ } ManagerHandle;
42
+
43
+ /* Function prototypes. */
44
+ void Init_ServiceManager(VALUE);
45
+ void serviceManagerFree(void *);
46
+ VALUE rb_service_manager_new(VALUE);
47
+
48
+ #endif /* FIRERUBY_SERVICE_MANAGER_H */
data/ext/Services.c ADDED
@@ -0,0 +1,124 @@
1
+ /*------------------------------------------------------------------------------
2
+ * Services.c
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
+
26
+ #include "Services.h"
27
+ #include "FireRubyException.h"
28
+ #ifdef OS_UNIX
29
+ #include <unistd.h>
30
+ #endif
31
+
32
+ /* Defines. */
33
+ #define START_BUFFER_SIZE 1024
34
+
35
+
36
+ /**
37
+ * This function is used to query the status of a service, returning any of
38
+ * the output generated by the service operation.
39
+ *
40
+ * @param handle A pointer to the service manager handle to be used to query
41
+ * the service.
42
+ *
43
+ * @return Either a String object containing the output from the service query
44
+ * or nil if there is no output.
45
+ *
46
+ */
47
+ VALUE queryService(isc_svc_handle *handle)
48
+ {
49
+ VALUE result = Qnil;
50
+ int size = START_BUFFER_SIZE;
51
+ short done = 0;
52
+
53
+ /* Query the service until it has completed. */
54
+ while(!done)
55
+ {
56
+ ISC_STATUS status[20];
57
+ char *output = NULL,
58
+ *offset = NULL,
59
+ *log = NULL,
60
+ request[] = {isc_info_svc_to_eof};
61
+ short len = 0;
62
+
63
+ /* Allocate the output buffer. */
64
+ offset = output = ALLOC_N(char, size);
65
+ if(output == NULL)
66
+ {
67
+ rb_raise(rb_eNoMemError,
68
+ "Memory allocation failure querying service status.");
69
+ }
70
+ memset(output, 0, size);
71
+
72
+ /* Make the service info request. */
73
+ done = 1;
74
+ if(isc_service_query(status, handle, NULL, 0, NULL, sizeof(request),
75
+ request, size, output))
76
+ {
77
+ free(output);
78
+ rb_fireruby_raise(status, "Error querying service status.");
79
+ }
80
+
81
+ do
82
+ {
83
+ switch(*offset++)
84
+ {
85
+ case isc_info_svc_to_eof :
86
+ len = isc_vax_integer(offset, 2);
87
+ offset += 2;
88
+ if(len > 0)
89
+ {
90
+ log = ALLOC_N(char, len + 1);
91
+ if(log == NULL)
92
+ {
93
+ free(output);
94
+ rb_raise(rb_eNoMemError,
95
+ "Memory allocation failure querying service status.");
96
+ }
97
+
98
+ memset(log, 0, len + 1);
99
+ memcpy(log, offset, len);
100
+
101
+ result = rb_str_new2(log);
102
+ free(log);
103
+ }
104
+ break;
105
+
106
+ case isc_info_truncated :
107
+ done = 0;
108
+ size = size * 2;
109
+ break;
110
+ }
111
+ } while(*offset);
112
+
113
+ /* Clean up. */
114
+ free(output);
115
+
116
+ /* Snooze if we're not done. */
117
+ if(!done)
118
+ {
119
+ sleep(1);
120
+ }
121
+ }
122
+
123
+ return(result);
124
+ }
data/ext/Services.h ADDED
@@ -0,0 +1,42 @@
1
+ /*------------------------------------------------------------------------------
2
+ * Services.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_SERVICES_H
26
+ #define FIRERUBY_SERVICES_H
27
+
28
+ /* Includes. */
29
+ #ifndef IBASE_H_INCLUDED
30
+ #include "ibase.h"
31
+ #define IBASE_H_INCLUDED
32
+ #endif
33
+
34
+ #ifndef RUBY_H_INCLUDED
35
+ #include "ruby.h"
36
+ #define RUBY_H_INCLUDED
37
+ #endif
38
+
39
+ /* Function prototypes. */
40
+ VALUE queryService(isc_svc_handle *);
41
+
42
+ #endif /* FIRERUBY_SERVICES_H */