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/Generator.h ADDED
@@ -0,0 +1,53 @@
1
+ /*------------------------------------------------------------------------------
2
+ * Generator.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_GENERATOR_H
26
+ #define FIRERUBY_GENERATOR_H
27
+
28
+ /* Includes. */
29
+ #ifndef FIRERUBY_FIRE_RUBY_EXCEPTION_H
30
+ #include "FireRubyException.h"
31
+ #endif
32
+
33
+ #ifndef FIRERUBY_CONNECTION_H
34
+ #include "Connection.h"
35
+ #endif
36
+
37
+ #ifndef RUBY_H_INCLUDED
38
+ #include "ruby.h"
39
+ #define RUBY_H_INCLUDED
40
+ #endif
41
+
42
+ /* Type definitions. */
43
+ typedef struct
44
+ {
45
+ isc_db_handle *connection;
46
+ } GeneratorHandle;
47
+
48
+ /* Function prototypes. */
49
+ void Init_Generator(VALUE);
50
+ VALUE rb_generator_new(VALUE, VALUE);
51
+ void generatorFree(void *);
52
+
53
+ #endif /* FIRERUBY_GENERATOR_H */
data/ext/RemoveUser.c ADDED
@@ -0,0 +1,212 @@
1
+ /*------------------------------------------------------------------------------
2
+ * RemoveUser.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 "RemoveUser.h"
28
+ #include "ibase.h"
29
+ #include "ServiceManager.h"
30
+
31
+ /* Function prototypes. */
32
+ static VALUE initializeRemoveUser(VALUE , VALUE);
33
+ static VALUE getUserName(VALUE);
34
+ static VALUE setUserName(VALUE, VALUE);
35
+ static void createRemoveUserBuffer(VALUE, char **, short *);
36
+
37
+
38
+ /* Globals. */
39
+ VALUE cRemoveUser;
40
+
41
+
42
+ /**
43
+ * This function provides the initialize method for the RemoveUser class.
44
+ *
45
+ * @param self A reference to the RemoveUser object being initialized.
46
+ * @param username A reference to a String containing the user name of the
47
+ * user to be removed.
48
+ *
49
+ * @return A reference to the newly initialized RemoveUser object.
50
+ *
51
+ */
52
+ VALUE initializeRemoveUser(VALUE self, VALUE username)
53
+ {
54
+ VALUE actual = rb_funcall(username, rb_intern("to_s"), 0),
55
+ value = Qnil;
56
+ int length = 0;
57
+
58
+ /* Check that the parameters are valid. */
59
+ value = rb_funcall(actual, rb_intern("length"), 0);
60
+ length = TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value);
61
+ if(length < 1 || length > 31)
62
+ {
63
+ rb_fireruby_raise(NULL,
64
+ "Invalid user name specified. A user name must not be "\
65
+ "blank and may have no more than 31 characters.");
66
+ }
67
+
68
+ /* Assign class values. */
69
+ rb_iv_set(self, "@user_name", actual);
70
+
71
+ return(self);
72
+ }
73
+
74
+
75
+ /**
76
+ * This function provides the user_name attribute accessor for the RemoveUser
77
+ * class.
78
+ *
79
+ * @param self A reference to the RemoveUser object to make the call on.
80
+ *
81
+ * @return A reference to the attribute value for the object.
82
+ *
83
+ */
84
+ VALUE getUserName(VALUE self)
85
+ {
86
+ return(rb_iv_get(self, "@user_name"));
87
+ }
88
+
89
+
90
+ /**
91
+ * This function provides the user_name attribute mutator for the RemoveUser
92
+ * class.
93
+ *
94
+ * @param self A reference to the RemoveUser object to make the call on.
95
+ * @param setting The new value for the attribute.
96
+ *
97
+ * @return A reference to the newly update RemoveUser object.
98
+ *
99
+ */
100
+ VALUE setUserName(VALUE self, VALUE setting)
101
+ {
102
+ VALUE actual = rb_funcall(setting, rb_intern("to_s"), 0),
103
+ value = rb_funcall(actual, rb_intern("length"), 0);
104
+ int length = 0;
105
+
106
+ length = TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value);
107
+ if(length < 1 || length > 31)
108
+ {
109
+ rb_fireruby_raise(NULL,
110
+ "Invalid user name specified. A user name must not be "\
111
+ "blank and may have no more than 31 characters.");
112
+ }
113
+ rb_iv_set(self, "@user_name", actual);
114
+
115
+ return(self);
116
+ }
117
+
118
+
119
+
120
+ /**
121
+ * This function provides the execute method for the RemoveUser class.
122
+ *
123
+ * @param self A reference to the RemoveUser object to be executed.
124
+ * @param manager A reference to the ServiceManager that will be used to
125
+ * execute the task.
126
+ *
127
+ * @return A reference to the RemoveUser object executed.
128
+ *
129
+ */
130
+ VALUE executeRemoveUser(VALUE self, VALUE manager)
131
+ {
132
+ ManagerHandle *handle = NULL;
133
+ char *buffer = NULL;
134
+ short length = 0;
135
+ ISC_STATUS status[20];
136
+
137
+ /* Check that the service manager is connected. */
138
+ Data_Get_Struct(manager, ManagerHandle, handle);
139
+ if(handle->handle == 0)
140
+ {
141
+ rb_fireruby_raise(NULL,
142
+ "Remove user error. Service manager not connected.");
143
+ }
144
+
145
+ createRemoveUserBuffer(self, &buffer, &length);
146
+
147
+ /* Start the service request. */
148
+ if(isc_service_start(status, &handle->handle, NULL, length, buffer))
149
+ {
150
+ free(buffer);
151
+ rb_fireruby_raise(status, "Error removing user.");
152
+ }
153
+ free(buffer);
154
+
155
+ return(self);
156
+ }
157
+
158
+
159
+ /**
160
+ * This function provides the execute method for the RemoveUser class.
161
+ *
162
+ * @param self A reference to the RemoveUser object to generate the buffer for.
163
+ * @param buffer A pointer to a pointer that will be set to contain the
164
+ * buffer contents.
165
+ * @param length A pointer to a short integer that will be assigned the length
166
+ * of the buffer.
167
+ *
168
+ */
169
+ void createRemoveUserBuffer(VALUE self, char **buffer, short *length)
170
+ {
171
+ VALUE value = Qnil;
172
+ char *offset = NULL;
173
+ int number = 0;
174
+
175
+ /* Calculate the required buffer length. */
176
+ *length = 1;
177
+ *length += strlen(STR2CSTR(rb_iv_get(self, "@user_name"))) + 3;
178
+
179
+ /* Create and populate the buffer. */
180
+ offset = *buffer = ALLOC_N(char, *length);
181
+ if(*buffer == NULL)
182
+ {
183
+ rb_raise(rb_eNoMemError,
184
+ "Memory allocation error preparing to remove user.");
185
+ }
186
+ memset(*buffer, 0, *length);
187
+
188
+ *offset++ = isc_action_svc_delete_user;
189
+
190
+ *offset++ = isc_spb_sec_username;
191
+ value = rb_iv_get(self, "@user_name");
192
+ number = strlen(STR2CSTR(value));
193
+ ADD_SPB_LENGTH(offset, number);
194
+ memcpy(offset, STR2CSTR(value), number);
195
+ offset += number;
196
+ }
197
+
198
+
199
+ /**
200
+ * This function initialize the RemoveUser class in the Ruby environment.
201
+ *
202
+ * @param module The module to create the new class definition under.
203
+ *
204
+ */
205
+ void Init_RemoveUser(VALUE module)
206
+ {
207
+ cRemoveUser = rb_define_class_under(module, "RemoveUser", rb_cObject);
208
+ rb_define_method(cRemoveUser, "initialize", initializeRemoveUser, 1);
209
+ rb_define_method(cRemoveUser, "user_name", getUserName, 0);
210
+ rb_define_method(cRemoveUser, "user_name=", setUserName, 1);
211
+ rb_define_method(cRemoveUser, "execute", executeRemoveUser, 1);
212
+ }
data/ext/RemoveUser.h ADDED
@@ -0,0 +1,37 @@
1
+ /*------------------------------------------------------------------------------
2
+ * RemoveUser.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_REMOVE_USER_H
26
+ #define FIRERUBY_REMOVE_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_RemoveUser(VALUE);
36
+
37
+ #endif /* FIRERUBY_REMOVE_USER_H */