rubyfb 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
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/AddUser.c ADDED
@@ -0,0 +1,464 @@
1
+ /*------------------------------------------------------------------------------
2
+ * AddUser.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 "AddUser.h"
28
+ #include "ibase.h"
29
+ #include "ServiceManager.h"
30
+
31
+ /* Function prototypes. */
32
+ static VALUE initializeAddUser(int, VALUE *, VALUE);
33
+ static VALUE getUserName(VALUE);
34
+ static VALUE setUserName(VALUE, VALUE);
35
+ static VALUE getUserPassword(VALUE);
36
+ static VALUE setUserPassword(VALUE, VALUE);
37
+ static VALUE getUserFirstName(VALUE);
38
+ static VALUE setUserFirstName(VALUE, VALUE);
39
+ static VALUE getUserMiddleName(VALUE);
40
+ static VALUE setUserMiddleName(VALUE, VALUE);
41
+ static VALUE getUserLastName(VALUE);
42
+ static VALUE setUserLastName(VALUE, VALUE);
43
+ static void createAddUserBuffer(VALUE, char **, short *);
44
+
45
+
46
+ /* Globals. */
47
+ VALUE cAddUser;
48
+
49
+
50
+ /**
51
+ * This function provides the initialize method for the AddUser class.
52
+ *
53
+ * @param argc A count of the number of parameters passed to the method
54
+ * call.
55
+ * @param argv A pointer to the start of an array of VALUE entities that
56
+ * contain the method parameters.
57
+ * @param self A reference to the AddUser object being initialized.
58
+ *
59
+ * @return A reference to the newly initialized AddUser object.
60
+ *
61
+ */
62
+ VALUE initializeAddUser(int argc, VALUE *argv, VALUE self)
63
+ {
64
+ VALUE username = Qnil,
65
+ password = Qnil,
66
+ first = Qnil,
67
+ middle = Qnil,
68
+ last = Qnil,
69
+ value = Qnil;
70
+ int length = 0;
71
+
72
+ /* Check that sufficient parameters have been supplied. */
73
+ if(argc < 2)
74
+ {
75
+ rb_raise(rb_eArgError, "Wrong number of arguments (%d for %d).", argc, 2);
76
+ }
77
+
78
+ username = rb_funcall(argv[0], rb_intern("to_s"), 0);
79
+ password = rb_funcall(argv[1], rb_intern("to_s"), 0);
80
+ if(argc > 2)
81
+ {
82
+ first= rb_funcall(argv[2], rb_intern("to_s"), 0);
83
+ if(argc > 3)
84
+ {
85
+ middle = rb_funcall(argv[3], rb_intern("to_s"), 0);
86
+ if(argc > 4)
87
+ {
88
+ last = rb_funcall(argv[4], rb_intern("to_s"), 0);
89
+ }
90
+ }
91
+ }
92
+
93
+ /* Check that the parameters are valid. */
94
+ value = rb_funcall(username, rb_intern("length"), 0);
95
+ length = TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value);
96
+ if(length < 1 || length > 31)
97
+ {
98
+ rb_fireruby_raise(NULL,
99
+ "Invalid user name specified. A user name must not be "\
100
+ "blank and may have no more than 31 characters.");
101
+ }
102
+
103
+ value = rb_funcall(password, rb_intern("length"), 0);
104
+ length = TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value);
105
+ if(length < 1 || length > 31)
106
+ {
107
+ rb_fireruby_raise(NULL,
108
+ "Invalid password specified. A user password must not "\
109
+ "be blank and may have no more than 31 characters.");
110
+ }
111
+
112
+ /* Assign class values. */
113
+ rb_iv_set(self, "@user_name", username);
114
+ rb_iv_set(self, "@password", password);
115
+ rb_iv_set(self, "@first_name", first);
116
+ rb_iv_set(self, "@middle_name", middle);
117
+ rb_iv_set(self, "@last_name", last);
118
+
119
+ return(self);
120
+ }
121
+
122
+
123
+ /**
124
+ * This function provides the user_name attribute accessor for the AddUser
125
+ * class.
126
+ *
127
+ * @param self A reference to the AddUser object to make the call on.
128
+ *
129
+ * @return A reference to the attribute value for the object.
130
+ *
131
+ */
132
+ VALUE getUserName(VALUE self)
133
+ {
134
+ return(rb_iv_get(self, "@user_name"));
135
+ }
136
+
137
+
138
+ /**
139
+ * This function provides the user_name attribute mutator for the AddUser class.
140
+ *
141
+ * @param self A reference to the AddUser object to make the call on.
142
+ * @param setting The new value for the attribute.
143
+ *
144
+ * @return A reference to the newly update AddUser object.
145
+ *
146
+ */
147
+ VALUE setUserName(VALUE self, VALUE setting)
148
+ {
149
+ VALUE actual = rb_funcall(setting, rb_intern("to_s"), 0),
150
+ value = rb_funcall(actual, rb_intern("length"), 0);
151
+ int length = 0;
152
+
153
+ length = TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value);
154
+ if(length < 1 || length > 31)
155
+ {
156
+ rb_fireruby_raise(NULL,
157
+ "Invalid user name specified. A user name must not be "\
158
+ "blank and may have no more than 31 characters.");
159
+ }
160
+ rb_iv_set(self, "@user_name", actual);
161
+
162
+ return(self);
163
+ }
164
+
165
+
166
+ /**
167
+ * This function provides the password attribute accessor for the AddUser
168
+ * class.
169
+ *
170
+ * @param self A reference to the AddUser object to make the call on.
171
+ *
172
+ * @return A reference to the attribute value for the object.
173
+ *
174
+ */
175
+ VALUE getUserPassword(VALUE self)
176
+ {
177
+ return(rb_iv_get(self, "@password"));
178
+ }
179
+
180
+
181
+ /**
182
+ * This function provides the password attribute mutator for the AddUser class.
183
+ *
184
+ * @param self A reference to the AddUser object to make the call on.
185
+ * @param setting The new value for the attribute.
186
+ *
187
+ * @return A reference to the newly update AddUser object.
188
+ *
189
+ */
190
+ VALUE setUserPassword(VALUE self, VALUE setting)
191
+ {
192
+ VALUE actual = rb_funcall(setting, rb_intern("to_s"), 0),
193
+ value = rb_funcall(actual, rb_intern("length"), 0);
194
+ int length = 0;
195
+
196
+ length = TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value);
197
+ if(length < 1 || length > 31)
198
+ {
199
+ rb_fireruby_raise(NULL,
200
+ "Invalid password specified. A user password must not "\
201
+ "be blank and may have no more than 31 characters.");
202
+ }
203
+ rb_iv_set(self, "@password", actual);
204
+
205
+ return(self);
206
+ }
207
+
208
+
209
+ /**
210
+ * This function provides the first_name attribute accessor for the AddUser
211
+ * class.
212
+ *
213
+ * @param self A reference to the AddUser object to make the call on.
214
+ *
215
+ * @return A reference to the attribute value for the object.
216
+ *
217
+ */
218
+ VALUE getUserFirstName(VALUE self)
219
+ {
220
+ return(rb_iv_get(self, "@first_name"));
221
+ }
222
+
223
+
224
+ /**
225
+ * This function provides the first_name attribute mutator for the AddUser
226
+ * class.
227
+ *
228
+ * @param self A reference to the AddUser object to make the call on.
229
+ * @param setting The new value for the attribute.
230
+ *
231
+ * @return A reference to the newly update AddUser object.
232
+ *
233
+ */
234
+ VALUE setUserFirstName(VALUE self, VALUE setting)
235
+ {
236
+ rb_iv_set(self, "@first_name", setting);
237
+ return(self);
238
+ }
239
+
240
+
241
+ /**
242
+ * This function provides the middle_name attribute accessor for the AddUser
243
+ * class.
244
+ *
245
+ * @param self A reference to the AddUser object to make the call on.
246
+ *
247
+ * @return A reference to the attribute value for the object.
248
+ *
249
+ */
250
+ VALUE getUserMiddleName(VALUE self)
251
+ {
252
+ return(rb_iv_get(self, "@middle_name"));
253
+ }
254
+
255
+
256
+ /**
257
+ * This function provides the middle_name attribute mutator for the AddUser
258
+ * class.
259
+ *
260
+ * @param self A reference to the AddUser object to make the call on.
261
+ * @param setting The new value for the attribute.
262
+ *
263
+ * @return A reference to the newly update AddUser object.
264
+ *
265
+ */
266
+ VALUE setUserMiddleName(VALUE self, VALUE setting)
267
+ {
268
+ rb_iv_set(self, "@middle_name", setting);
269
+ return(self);
270
+ }
271
+
272
+
273
+ /**
274
+ * This function provides the last_name attribute accessor for the AddUser
275
+ * class.
276
+ *
277
+ * @param self A reference to the AddUser object to make the call on.
278
+ *
279
+ * @return A reference to the attribute value for the object.
280
+ *
281
+ */
282
+ VALUE getUserLastName(VALUE self)
283
+ {
284
+ return(rb_iv_get(self, "@last_name"));
285
+ }
286
+
287
+
288
+ /**
289
+ * This function provides the last_name attribute mutator for the AddUser
290
+ * class.
291
+ *
292
+ * @param self A reference to the AddUser object to make the call on.
293
+ * @param setting The new value for the attribute.
294
+ *
295
+ * @return A reference to the newly update AddUser object.
296
+ *
297
+ */
298
+ VALUE setUserLastName(VALUE self, VALUE setting)
299
+ {
300
+ rb_iv_set(self, "@last_name", setting);
301
+ return(self);
302
+ }
303
+
304
+
305
+ /**
306
+ * This function provides the execute method for the AddUser class.
307
+ *
308
+ * @param self A reference to the AddUser object to be executed.
309
+ * @param manager A reference to the ServiceManager that will be used to
310
+ * execute the task.
311
+ *
312
+ * @return A reference to the AddUser object executed.
313
+ *
314
+ */
315
+ VALUE executeAddUser(VALUE self, VALUE manager)
316
+ {
317
+ ManagerHandle *handle = NULL;
318
+ char *buffer = NULL;
319
+ short length = 0;
320
+ ISC_STATUS status[20];
321
+
322
+ /* Check that the service manager is connected. */
323
+ Data_Get_Struct(manager, ManagerHandle, handle);
324
+ if(handle->handle == 0)
325
+ {
326
+ rb_fireruby_raise(NULL,
327
+ "Add user error. Service manager not connected.");
328
+ }
329
+
330
+ createAddUserBuffer(self, &buffer, &length);
331
+
332
+ /* Start the service request. */
333
+ if(isc_service_start(status, &handle->handle, NULL, length, buffer))
334
+ {
335
+ free(buffer);
336
+ rb_fireruby_raise(status, "Error adding user.");
337
+ }
338
+ free(buffer);
339
+
340
+ return(self);
341
+ }
342
+
343
+
344
+ /**
345
+ * This function provides the execute method for the AddUser class.
346
+ *
347
+ * @param self A reference to the AddUser object to generate the buffer for.
348
+ * @param buffer A pointer to a pointer that will be set to contain the
349
+ * buffer contents.
350
+ * @param length A pointer to a short integer that will be assigned the length
351
+ * of the buffer.
352
+ *
353
+ */
354
+ void createAddUserBuffer(VALUE self, char **buffer, short *length)
355
+ {
356
+ VALUE value = Qnil,
357
+ first = Qnil,
358
+ middle = Qnil,
359
+ last = Qnil;
360
+ char *offset = NULL;
361
+ int number = 0;
362
+
363
+ /* Calculate the required buffer length. */
364
+ *length = 1;
365
+ *length += strlen(STR2CSTR(rb_iv_get(self, "@user_name"))) + 3;
366
+ *length += strlen(STR2CSTR(rb_iv_get(self, "@password"))) + 3;
367
+
368
+ value = rb_iv_get(self, "@first_name");
369
+ if(value != Qnil)
370
+ {
371
+ first = rb_funcall(value, rb_intern("to_s"), 0);
372
+ *length += strlen(STR2CSTR(first)) + 3;
373
+ }
374
+
375
+ value = rb_iv_get(self, "@middle_name");
376
+ if(value != Qnil)
377
+ {
378
+ middle = rb_funcall(value, rb_intern("to_s"), 0);
379
+ *length += strlen(STR2CSTR(middle)) + 3;
380
+ }
381
+
382
+ value = rb_iv_get(self, "@last_name");
383
+ if(value != Qnil)
384
+ {
385
+ last = rb_funcall(value, rb_intern("to_s"), 0);
386
+ *length += strlen(STR2CSTR(last)) + 3;
387
+ }
388
+
389
+ /* Create and populate the buffer. */
390
+ offset = *buffer = ALLOC_N(char, *length);
391
+ if(*buffer == NULL)
392
+ {
393
+ rb_raise(rb_eNoMemError,
394
+ "Memory allocation error preparing to add user.");
395
+ }
396
+ memset(*buffer, 0, *length);
397
+
398
+ *offset++ = isc_action_svc_add_user;
399
+
400
+ *offset++ = isc_spb_sec_username;
401
+ value = rb_iv_get(self, "@user_name");
402
+ number = strlen(STR2CSTR(value));
403
+ ADD_SPB_LENGTH(offset, number);
404
+ memcpy(offset, STR2CSTR(value), number);
405
+ offset += number;
406
+
407
+ *offset++ = isc_spb_sec_password;
408
+ value = rb_iv_get(self, "@password");
409
+ number = strlen(STR2CSTR(value));
410
+ ADD_SPB_LENGTH(offset, number);
411
+ memcpy(offset, STR2CSTR(value), number);
412
+ offset += number;
413
+
414
+ if(first != Qnil)
415
+ {
416
+ *offset++ = isc_spb_sec_firstname;
417
+ number = strlen(STR2CSTR(first));
418
+ ADD_SPB_LENGTH(offset, number);
419
+ memcpy(offset, STR2CSTR(first), number);
420
+ offset += number;
421
+ }
422
+
423
+ if(middle != Qnil)
424
+ {
425
+ *offset++ = isc_spb_sec_middlename;
426
+ number = strlen(STR2CSTR(middle));
427
+ ADD_SPB_LENGTH(offset, number);
428
+ memcpy(offset, STR2CSTR(middle), number);
429
+ offset += number;
430
+ }
431
+
432
+ if(last != Qnil)
433
+ {
434
+ *offset++ = isc_spb_sec_lastname;
435
+ number = strlen(STR2CSTR(last));
436
+ ADD_SPB_LENGTH(offset, number);
437
+ memcpy(offset, STR2CSTR(last), number);
438
+ offset += number;
439
+ }
440
+ }
441
+
442
+
443
+ /**
444
+ * This function initialize the AddUser class in the Ruby environment.
445
+ *
446
+ * @param module The module to create the new class definition under.
447
+ *
448
+ */
449
+ void Init_AddUser(VALUE module)
450
+ {
451
+ cAddUser = rb_define_class_under(module, "AddUser", rb_cObject);
452
+ rb_define_method(cAddUser, "initialize", initializeAddUser, -1);
453
+ rb_define_method(cAddUser, "user_name", getUserName, 0);
454
+ rb_define_method(cAddUser, "user_name=", setUserName, 1);
455
+ rb_define_method(cAddUser, "password", getUserPassword, 0);
456
+ rb_define_method(cAddUser, "password=", setUserPassword, 1);
457
+ rb_define_method(cAddUser, "first_name", getUserFirstName, 0);
458
+ rb_define_method(cAddUser, "first_name=", setUserFirstName, 1);
459
+ rb_define_method(cAddUser, "middle_name", getUserMiddleName, 0);
460
+ rb_define_method(cAddUser, "middle_name=", setUserMiddleName, 1);
461
+ rb_define_method(cAddUser, "last_name", getUserLastName, 0);
462
+ rb_define_method(cAddUser, "last_name=", setUserLastName, 1);
463
+ rb_define_method(cAddUser, "execute", executeAddUser, 1);
464
+ }
data/ext/AddUser.h ADDED
@@ -0,0 +1,37 @@
1
+ /*------------------------------------------------------------------------------
2
+ * AddUser.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_ADD_USER_H
26
+ #define FIRERUBY_ADD_USER_H
27
+
28
+ /* Includes. */
29
+ #ifndef RUBY_H_INCLUDED
30
+ #include "ruby.h"
31
+ #define RUBY_H_INCLUDED
32
+ #endif
33
+
34
+ /* Function prototypes. */
35
+ void Init_AddUser(VALUE);
36
+
37
+ #endif /* FIRERUBY_ADD_USER_H */