rubyfb 0.5.2-x86-mswin32-60

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 (77) hide show
  1. data/CHANGELOG +6 -0
  2. data/LICENSE +411 -0
  3. data/Manifest +75 -0
  4. data/README +460 -0
  5. data/Rakefile +21 -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 +810 -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 +30 -0
  46. data/lib/SQLType.rb +224 -0
  47. data/lib/active_record/connection_adapters/rubyfb_adapter.rb +805 -0
  48. data/lib/mkdoc +1 -0
  49. data/lib/rubyfb.rb +2 -0
  50. data/lib/rubyfb_lib.so +0 -0
  51. data/lib/src.rb +1800 -0
  52. data/mswin32fb/fbclient_ms.lib +0 -0
  53. data/mswin32fb/ibase.h +2555 -0
  54. data/mswin32fb/iberror.h +1741 -0
  55. data/rubyfb.gemspec +31 -0
  56. data/test/AddRemoveUserTest.rb +56 -0
  57. data/test/BackupRestoreTest.rb +99 -0
  58. data/test/BlobTest.rb +57 -0
  59. data/test/CharacterSetTest.rb +63 -0
  60. data/test/ConnectionTest.rb +111 -0
  61. data/test/DDLTest.rb +54 -0
  62. data/test/DatabaseTest.rb +83 -0
  63. data/test/GeneratorTest.rb +50 -0
  64. data/test/KeyTest.rb +140 -0
  65. data/test/ResultSetTest.rb +162 -0
  66. data/test/RoleTest.rb +73 -0
  67. data/test/RowCountTest.rb +65 -0
  68. data/test/RowTest.rb +203 -0
  69. data/test/SQLTest.rb +182 -0
  70. data/test/SQLTypeTest.rb +101 -0
  71. data/test/ServiceManagerTest.rb +29 -0
  72. data/test/StatementTest.rb +135 -0
  73. data/test/TestSetup.rb +11 -0
  74. data/test/TransactionTest.rb +112 -0
  75. data/test/TypeTest.rb +92 -0
  76. data/test/UnitTest.rb +65 -0
  77. metadata +143 -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 */
data/ext/Restore.c ADDED
@@ -0,0 +1,855 @@
1
+ /*------------------------------------------------------------------------------
2
+ * Restore.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 "Restore.h"
28
+ #include "ibase.h"
29
+ #include "ServiceManager.h"
30
+ #include "Services.h"
31
+
32
+ /* Function prototypes. */
33
+ static VALUE initializeRestore(VALUE, VALUE, VALUE);
34
+ static VALUE getRestoreFile(VALUE);
35
+ static VALUE setRestoreFile(VALUE, VALUE);
36
+ static VALUE getRestoreDatabase(VALUE);
37
+ static VALUE setRestoreDatabase(VALUE, VALUE);
38
+ static VALUE getRestoreCacheBuffers(VALUE);
39
+ static VALUE setRestoreCacheBuffers(VALUE, VALUE);
40
+ static VALUE getRestorePageSize(VALUE);
41
+ static VALUE setRestorePageSize(VALUE, VALUE);
42
+ static VALUE getRestoreAccessMode(VALUE);
43
+ static VALUE setRestoreAccessMode(VALUE, VALUE);
44
+ static VALUE getRestoreBuildIndices(VALUE);
45
+ static VALUE setRestoreBuildIndices(VALUE, VALUE);
46
+ static VALUE getRestoreCreateShadows(VALUE);
47
+ static VALUE setRestoreCreateShadows(VALUE, VALUE);
48
+ static VALUE getRestoreCheckValidity(VALUE);
49
+ static VALUE setRestoreCheckValidity(VALUE, VALUE);
50
+ static VALUE getRestoreCommitTables(VALUE);
51
+ static VALUE setRestoreCommitTables(VALUE, VALUE);
52
+ static VALUE getRestoreMode(VALUE);
53
+ static VALUE setRestoreMode(VALUE, VALUE);
54
+ static VALUE getRestoreUseAllSpace(VALUE);
55
+ static VALUE setRestoreUseAllSpace(VALUE, VALUE);
56
+ static VALUE executeRestore(VALUE, VALUE);
57
+ static VALUE getRestoreLog(VALUE);
58
+ static void createRestoreBuffer(VALUE, VALUE, VALUE, char **, short *);
59
+
60
+
61
+ /* Globals. */
62
+ VALUE cRestore;
63
+
64
+ /* Definitions. */
65
+ #define CACHE_BUFFERS INT2FIX(isc_spb_res_buffers)
66
+ #define PAGE_SIZE INT2FIX(isc_spb_res_page_size)
67
+ #define ACCESS_MODE INT2FIX(isc_spb_res_access_mode)
68
+ #define READ_ONLY INT2FIX(isc_spb_prp_am_readonly)
69
+ #define READ_WRITE INT2FIX(isc_spb_prp_am_readwrite)
70
+ #define BUILD_INDICES rb_str_new2("BUILD_INDICES")
71
+ #define NO_SHADOWS rb_str_new2("NO_SHADOWS")
72
+ #define VALIDITY_CHECKS rb_str_new2("VALIDITY_CHECKS")
73
+ #define COMMIT_TABLES rb_str_new2("COMMIT_TABLES")
74
+ #define RESTORE_MODE rb_str_new2("RESTORE_MODE")
75
+ #define REPLACE_DATABASE INT2FIX(isc_spb_res_replace)
76
+ #define CREATE_DATABASE INT2FIX(isc_spb_res_create)
77
+ #define USE_ALL_SPACE rb_str_new2("USE_ALL_SPACE")
78
+
79
+ /**
80
+ * This function provides the initialize method for the Restore class.
81
+ *
82
+ * @param self A reference to the Restore object to be initialized.
83
+ * @param file A reference to a String or File containing the path/name
84
+ * of the database backup file to restore from.
85
+ * @param database A reference to a String or File containing the path/name
86
+ * of the database file to be restored to.
87
+ *
88
+ * @return A reference to the newly initialized Restore object.
89
+ *
90
+ */
91
+ VALUE initializeRestore(VALUE self, VALUE file, VALUE database)
92
+ {
93
+ VALUE from = Qnil,
94
+ to = rb_hash_new(),
95
+ options = rb_hash_new();
96
+
97
+ /* Extract the parameters. */
98
+ if(TYPE(file) == T_FILE)
99
+ {
100
+ from = rb_funcall(file, rb_intern("path"), 0);
101
+ }
102
+ else
103
+ {
104
+ from = rb_funcall(file, rb_intern("to_s"), 0);
105
+ }
106
+
107
+ if(TYPE(database) == T_FILE)
108
+ {
109
+ to = rb_funcall(database, rb_intern("path"), 0);
110
+ }
111
+ else
112
+ {
113
+ to = rb_funcall(database, rb_intern("to_s"), 0);
114
+ }
115
+ rb_hash_aset(options, RESTORE_MODE, CREATE_DATABASE);
116
+
117
+ /* Store the object attributes. */
118
+ rb_iv_set(self, "@backup_file", from);
119
+ rb_iv_set(self, "@database", to);
120
+ rb_iv_set(self, "@options", options);
121
+ rb_iv_set(self, "@log", Qnil);
122
+
123
+ return(self);
124
+ }
125
+
126
+
127
+ /**
128
+ * This function provides the backup_file attribute accessor for the Restore
129
+ * class.
130
+ *
131
+ * @param self A reference to the Restore object to fetch the attribute from.
132
+ *
133
+ * @return A reference to the attribute value.
134
+ *
135
+ */
136
+ VALUE getRestoreFile(VALUE self)
137
+ {
138
+ return(rb_iv_get(self, "@backup_file"));
139
+ }
140
+
141
+
142
+ /**
143
+ * This function provides the backup_file attribute accessor for the Restore
144
+ * class.
145
+ *
146
+ * @param self A reference to the Restore object to fetch the attribute
147
+ * from.
148
+ * @param setting A reference to the new attribute value.
149
+ *
150
+ * @return A reference to the newly update Restore object.
151
+ *
152
+ */
153
+ VALUE setRestoreFile(VALUE self, VALUE setting)
154
+ {
155
+ VALUE actual = Qnil;
156
+
157
+ if(TYPE(setting) == T_FILE)
158
+ {
159
+ actual = rb_funcall(setting, rb_intern("path"), 0);
160
+ }
161
+ else
162
+ {
163
+ actual = rb_funcall(setting, rb_intern("to_s"), 0);
164
+ }
165
+ rb_iv_set(self, "@backup_file", actual);
166
+
167
+ return(self);
168
+ }
169
+
170
+
171
+ /**
172
+ * This function provides the database attribute accessor for the Restore
173
+ * class.
174
+ *
175
+ * @param self A reference to the Restore object to fetch the attribute from.
176
+ *
177
+ * @return A reference to the attribute value.
178
+ *
179
+ */
180
+ VALUE getRestoreDatabase(VALUE self)
181
+ {
182
+ return(rb_iv_get(self, "@database"));
183
+ }
184
+
185
+
186
+ /**
187
+ * This function provides the database attribute accessor for the Restore
188
+ * class.
189
+ *
190
+ * @param self A reference to the Restore object to fetch the attribute
191
+ * from.
192
+ * @param setting A reference to the new attribute value.
193
+ *
194
+ * @return A reference to the newly update Restore object.
195
+ *
196
+ */
197
+ VALUE setRestoreDatabase(VALUE self, VALUE setting)
198
+ {
199
+ VALUE actual = Qnil;
200
+
201
+ if(TYPE(setting) == T_FILE)
202
+ {
203
+ actual = rb_funcall(setting, rb_intern("path"), 0);
204
+ }
205
+ else
206
+ {
207
+ actual = rb_funcall(setting, rb_intern("to_s"), 0);
208
+ }
209
+ rb_iv_set(self, "@database", actual);
210
+
211
+ return(self);
212
+ }
213
+
214
+
215
+ /**
216
+ * This function provides the cache_buffers attribute accessor for the Restore
217
+ * class.
218
+ *
219
+ * @param self A reference to the Restore object to access the attribute on.
220
+ *
221
+ * @return A reference to the current cache buffers setting.
222
+ *
223
+ */
224
+ VALUE getRestoreCacheBuffers(VALUE self)
225
+ {
226
+ return(rb_hash_aref(rb_iv_get(self, "@options"), CACHE_BUFFERS));
227
+ }
228
+
229
+
230
+ /**
231
+ * This function provides the cache_buffers attribute mutator for the Restore
232
+ * class.
233
+ *
234
+ * @param self A reference to the Restore object to set the attribute on.
235
+ * @param setting A reference to the new setting for the attribute.
236
+ *
237
+ * @return A reference to the newly updated Restore object.
238
+ *
239
+ */
240
+ VALUE setRestoreCacheBuffers(VALUE self, VALUE setting)
241
+ {
242
+ if(rb_obj_is_kind_of(setting, rb_cInteger) == Qfalse)
243
+ {
244
+ rb_fireruby_raise(NULL,
245
+ "Invalid cache buffers setting specified for database "\
246
+ "restore.");
247
+ }
248
+ rb_hash_aset(rb_iv_get(self, "@options"), CACHE_BUFFERS, setting);
249
+
250
+ return(self);
251
+ }
252
+
253
+
254
+ /**
255
+ * This function provides the page_size attribute accessor for the Restore
256
+ * class.
257
+ *
258
+ * @param self A reference to the Restore object to access the attribute on.
259
+ *
260
+ * @return A reference to the current cache buffers setting.
261
+ *
262
+ */
263
+ VALUE getRestorePageSize(VALUE self)
264
+ {
265
+ return(rb_hash_aref(rb_iv_get(self, "@options"), PAGE_SIZE));
266
+ }
267
+
268
+
269
+ /**
270
+ * This function provides the page_size attribute mutator for the Restore
271
+ * class.
272
+ *
273
+ * @param self A reference to the Restore object to set the attribute on.
274
+ * @param setting A reference to the new setting for the attribute.
275
+ *
276
+ * @return A reference to the newly updated Restore object.
277
+ *
278
+ */
279
+ VALUE setRestorePageSize(VALUE self, VALUE setting)
280
+ {
281
+ if(rb_obj_is_kind_of(setting, rb_cInteger) == Qfalse)
282
+ {
283
+ rb_fireruby_raise(NULL,
284
+ "Invalid page size setting specified for database "\
285
+ "restore.");
286
+ }
287
+ rb_hash_aset(rb_iv_get(self, "@options"), PAGE_SIZE, setting);
288
+
289
+ return(self);
290
+ }
291
+
292
+
293
+ /**
294
+ * This function provides the access_mode attribute accessor for the Restore
295
+ * class.
296
+ *
297
+ * @param self A reference to the Restore object to access the attribute on.
298
+ *
299
+ * @return A reference to the current cache buffers setting.
300
+ *
301
+ */
302
+ VALUE getRestoreAccessMode(VALUE self)
303
+ {
304
+ return(rb_hash_aref(rb_iv_get(self, "@options"), ACCESS_MODE));
305
+ }
306
+
307
+
308
+ /**
309
+ * This function provides the access_mode attribute mutator for the Restore
310
+ * class.
311
+ *
312
+ * @param self A reference to the Restore object to set the attribute on.
313
+ * @param setting A reference to the new setting for the attribute.
314
+ *
315
+ * @return A reference to the newly updated Restore object.
316
+ *
317
+ */
318
+ VALUE setRestoreAccessMode(VALUE self, VALUE setting)
319
+ {
320
+ int value = 0;
321
+
322
+ if(rb_obj_is_kind_of(setting, rb_cInteger) == Qfalse)
323
+ {
324
+ rb_fireruby_raise(NULL,
325
+ "Invalid access mode setting specified for database "\
326
+ "restore.");
327
+ }
328
+
329
+ value = TYPE(setting) == T_FIXNUM ? FIX2INT(setting) : NUM2INT(setting);
330
+ if(value != isc_spb_prp_am_readonly && value != isc_spb_prp_am_readwrite)
331
+ {
332
+ rb_fireruby_raise(NULL,
333
+ "Invalid access mode value specified for database "\
334
+ "restore.");
335
+ }
336
+
337
+ rb_hash_aset(rb_iv_get(self, "@options"), ACCESS_MODE, setting);
338
+
339
+ return(self);
340
+ }
341
+
342
+
343
+ /**
344
+ * This function provides the build_indices attribute accessor for the Restore
345
+ * class.
346
+ *
347
+ * @param self A reference to the Restore object to access the attribute on.
348
+ *
349
+ * @return A reference to the current cache buffers setting.
350
+ *
351
+ */
352
+ VALUE getRestoreBuildIndices(VALUE self)
353
+ {
354
+ VALUE result = Qtrue,
355
+ setting = rb_hash_aref(rb_iv_get(self, "@options"), BUILD_INDICES);
356
+
357
+ if(setting != Qnil)
358
+ {
359
+ result = setting;
360
+ }
361
+
362
+ return(result);
363
+ }
364
+
365
+
366
+ /**
367
+ * This function provides the build_indices attribute mutator for the Restore
368
+ * class.
369
+ *
370
+ * @param self A reference to the Restore object to set the attribute on.
371
+ * @param setting A reference to the new setting for the attribute.
372
+ *
373
+ * @return A reference to the newly updated Restore object.
374
+ *
375
+ */
376
+ VALUE setRestoreBuildIndices(VALUE self, VALUE setting)
377
+ {
378
+ if(setting != Qfalse && setting != Qtrue)
379
+ {
380
+ rb_fireruby_raise(NULL,
381
+ "Invalid build indices setting specified for database "\
382
+ "restore.");
383
+ }
384
+ rb_hash_aset(rb_iv_get(self, "@options"), BUILD_INDICES, setting);
385
+
386
+ return(self);
387
+ }
388
+
389
+
390
+ /**
391
+ * This function provides the create_shadows attribute accessor for the Restore
392
+ * class.
393
+ *
394
+ * @param self A reference to the Restore object to access the attribute on.
395
+ *
396
+ * @return A reference to the current cache buffers setting.
397
+ *
398
+ */
399
+ VALUE getRestoreCreateShadows(VALUE self)
400
+ {
401
+ VALUE result = Qfalse,
402
+ setting = rb_hash_aref(rb_iv_get(self, "@options"), NO_SHADOWS);
403
+
404
+ if(setting != Qnil)
405
+ {
406
+ result = setting;
407
+ }
408
+
409
+ return(result);
410
+ }
411
+
412
+
413
+ /**
414
+ * This function provides the create_shadows attribute mutator for the Restore
415
+ * class.
416
+ *
417
+ * @param self A reference to the Restore object to set the attribute on.
418
+ * @param setting A reference to the new setting for the attribute.
419
+ *
420
+ * @return A reference to the newly updated Restore object.
421
+ *
422
+ */
423
+ VALUE setRestoreCreateShadows(VALUE self, VALUE setting)
424
+ {
425
+ if(setting != Qfalse && setting != Qtrue)
426
+ {
427
+ rb_fireruby_raise(NULL,
428
+ "Invalid create shadows setting specified for "\
429
+ "database restore.");
430
+ }
431
+ rb_hash_aset(rb_iv_get(self, "@options"), NO_SHADOWS, setting);
432
+
433
+ return(self);
434
+ }
435
+
436
+
437
+ /**
438
+ * This function provides the validity_checks attribute accessor for the Restore
439
+ * class.
440
+ *
441
+ * @param self A reference to the Restore object to access the attribute on.
442
+ *
443
+ * @return A reference to the current cache buffers setting.
444
+ *
445
+ */
446
+ VALUE getRestoreCheckValidity(VALUE self)
447
+ {
448
+ VALUE result = Qtrue,
449
+ setting = rb_hash_aref(rb_iv_get(self, "@options"), VALIDITY_CHECKS);
450
+
451
+ if(setting != Qnil)
452
+ {
453
+ result = setting;
454
+ }
455
+
456
+ return(result);
457
+ }
458
+
459
+
460
+ /**
461
+ * This function provides the validity_checks attribute mutator for the Restore
462
+ * class.
463
+ *
464
+ * @param self A reference to the Restore object to set the attribute on.
465
+ * @param setting A reference to the new setting for the attribute.
466
+ *
467
+ * @return A reference to the newly updated Restore object.
468
+ *
469
+ */
470
+ VALUE setRestoreCheckValidity(VALUE self, VALUE setting)
471
+ {
472
+ if(setting != Qfalse && setting != Qtrue)
473
+ {
474
+ rb_fireruby_raise(NULL,
475
+ "Invalid validity checks setting specified for "\
476
+ "database restore.");
477
+ }
478
+ rb_hash_aset(rb_iv_get(self, "@options"), VALIDITY_CHECKS, setting);
479
+
480
+ return(self);
481
+ }
482
+
483
+
484
+ /**
485
+ * This function provides the commit_tables attribute accessor for the Restore
486
+ * class.
487
+ *
488
+ * @param self A reference to the Restore object to access the attribute on.
489
+ *
490
+ * @return A reference to the current cache buffers setting.
491
+ *
492
+ */
493
+ VALUE getRestoreCommitTables(VALUE self)
494
+ {
495
+ VALUE result = Qfalse,
496
+ setting = rb_hash_aref(rb_iv_get(self, "@options"), COMMIT_TABLES);
497
+
498
+ if(setting != Qnil)
499
+ {
500
+ result = setting;
501
+ }
502
+
503
+ return(result);
504
+ }
505
+
506
+
507
+ /**
508
+ * This function provides the commit_tables attribute mutator for the Restore
509
+ * class.
510
+ *
511
+ * @param self A reference to the Restore object to set the attribute on.
512
+ * @param setting A reference to the new setting for the attribute.
513
+ *
514
+ * @return A reference to the newly updated Restore object.
515
+ *
516
+ */
517
+ VALUE setRestoreCommitTables(VALUE self, VALUE setting)
518
+ {
519
+ if(setting != Qfalse && setting != Qtrue)
520
+ {
521
+ rb_fireruby_raise(NULL,
522
+ "Invalid commit tables setting specified for "\
523
+ "database restore.");
524
+ }
525
+ rb_hash_aset(rb_iv_get(self, "@options"), COMMIT_TABLES, setting);
526
+
527
+ return(self);
528
+ }
529
+
530
+
531
+ /**
532
+ * This function provides the mode attribute accessor for the Restore class.
533
+ *
534
+ * @param self A reference to the Restore object to access the attribute on.
535
+ *
536
+ * @return A reference to the current cache buffers setting.
537
+ *
538
+ */
539
+ VALUE getRestoreMode(VALUE self)
540
+ {
541
+ VALUE result = Qfalse,
542
+ setting = rb_hash_aref(rb_iv_get(self, "@options"), RESTORE_MODE);
543
+
544
+ if(setting != Qnil)
545
+ {
546
+ result = setting;
547
+ }
548
+
549
+ return(result);
550
+ }
551
+
552
+
553
+ /**
554
+ * This function provides the mode attribute mutator for the Restore class.
555
+ *
556
+ * @param self A reference to the Restore object to set the attribute on.
557
+ * @param setting A reference to the new setting for the attribute.
558
+ *
559
+ * @return A reference to the newly updated Restore object.
560
+ *
561
+ */
562
+ VALUE setRestoreMode(VALUE self, VALUE setting)
563
+ {
564
+ int value;
565
+
566
+ if(rb_obj_is_kind_of(setting, rb_cInteger) == Qfalse)
567
+ {
568
+ rb_fireruby_raise(NULL,
569
+ "Invalid mode setting specified for database restore.");
570
+ }
571
+
572
+ value = TYPE(setting) == T_FIXNUM ? FIX2INT(setting) : NUM2INT(setting);
573
+ if(value != isc_spb_res_create && value != isc_spb_res_replace)
574
+ {
575
+ rb_fireruby_raise(NULL,
576
+ "Unrecognised mode setting specified for database "\
577
+ "restore.");
578
+ }
579
+ rb_hash_aset(rb_iv_get(self, "@options"), RESTORE_MODE, setting);
580
+
581
+ return(self);
582
+ }
583
+
584
+
585
+ /**
586
+ * This function provides the use_all_space attribute accessor for the Restore
587
+ * class.
588
+ *
589
+ * @param self A reference to the Restore object to access the attribute on.
590
+ *
591
+ * @return A reference to the current cache buffers setting.
592
+ *
593
+ */
594
+ VALUE getRestoreUseAllSpace(VALUE self)
595
+ {
596
+ VALUE result = Qfalse,
597
+ setting = rb_hash_aref(rb_iv_get(self, "@options"), USE_ALL_SPACE);
598
+
599
+ if(setting != Qnil)
600
+ {
601
+ result = setting;
602
+ }
603
+
604
+ return(result);
605
+ }
606
+
607
+
608
+ /**
609
+ * This function provides the use_all+_space attribute mutator for the Restore
610
+ * class.
611
+ *
612
+ * @param self A reference to the Restore object to set the attribute on.
613
+ * @param setting A reference to the new setting for the attribute.
614
+ *
615
+ * @return A reference to the newly updated Restore object.
616
+ *
617
+ */
618
+ VALUE setRestoreUseAllSpace(VALUE self, VALUE setting)
619
+ {
620
+ if(setting != Qfalse && setting != Qtrue)
621
+ {
622
+ rb_fireruby_raise(NULL,
623
+ "Invalid space usage setting specified for database "\
624
+ "restore.");
625
+ }
626
+ rb_hash_aset(rb_iv_get(self, "@options"), USE_ALL_SPACE, setting);
627
+
628
+ return(self);
629
+ }
630
+
631
+
632
+ /**
633
+ * This function provides the execute method for the Restore class.
634
+ *
635
+ * @param self A reference to the Restore object to call the method on.
636
+ * @param manager A reference to the ServiceManager that will be used to
637
+ * execute the task.
638
+ *
639
+ * @return A reference to the Restore object executed.
640
+ *
641
+ */
642
+ VALUE executeRestore(VALUE self, VALUE manager)
643
+ {
644
+ ManagerHandle *handle = NULL;
645
+ char *buffer = NULL;
646
+ short length = 0;
647
+ ISC_STATUS status[20];
648
+
649
+ /* Check that the service manager is connected. */
650
+ Data_Get_Struct(manager, ManagerHandle, handle);
651
+ if(handle->handle == 0)
652
+ {
653
+ rb_fireruby_raise(NULL,
654
+ "Database restore error. Service manager not connected.");
655
+ }
656
+
657
+ createRestoreBuffer(rb_iv_get(self, "@backup_file"),
658
+ rb_iv_get(self, "@database"),
659
+ rb_iv_get(self, "@options"), &buffer, &length);
660
+
661
+ /* Start the service request. */
662
+ if(isc_service_start(status, &handle->handle, NULL, length, buffer))
663
+ {
664
+ free(buffer);
665
+ rb_fireruby_raise(status, "Error performing database restore.");
666
+ }
667
+ free(buffer);
668
+
669
+ /* Query the service until it is complete. */
670
+ rb_iv_set(self, "@log", queryService(&handle->handle));
671
+
672
+ return(self);
673
+ }
674
+
675
+
676
+ /**
677
+ * This function provides the log attribute accessor for the Restore class.
678
+ *
679
+ * @param self A reference to the Restore object to execute the method on.
680
+ *
681
+ * @return A reference to the log attribute value.
682
+ *
683
+ */
684
+ VALUE getRestoreLog(VALUE self)
685
+ {
686
+ return(rb_iv_get(self, "@log"));
687
+ }
688
+
689
+
690
+ /**
691
+ * This function create the service parameter buffer used in executing a Restore
692
+ * object.
693
+ *
694
+ * @param file A reference to a String containing the path and name of
695
+ * the backup file to restore the database from.
696
+ * @param database A reference to a String containing the path and name for
697
+ * the restored database.
698
+ * @param options A reference to a Hash containing the options to be used
699
+ * in restoring the database.
700
+ * @param buffer A pointer to a pointer to a character array that will be
701
+ * set to the created service parameter buffer (allocated off
702
+ * the heap).
703
+ * @param length A pointer to a short integer that will be assigned the
704
+ * length of the service parameter buffer created.
705
+ *
706
+ */
707
+ void createRestoreBuffer(VALUE file, VALUE database, VALUE options,
708
+ char **buffer, short *length)
709
+ {
710
+ char *offset = NULL;
711
+ int number = 0;
712
+ long mask = 0;
713
+ VALUE cache = rb_hash_aref(options, CACHE_BUFFERS),
714
+ page = rb_hash_aref(options, PAGE_SIZE),
715
+ mode = rb_hash_aref(options, ACCESS_MODE),
716
+ policy = rb_hash_aref(options, RESTORE_MODE);
717
+
718
+ /* Determine the length of the buffer. */
719
+ *length = 7;
720
+ *length += strlen(STR2CSTR(file)) + 3;
721
+ *length += strlen(STR2CSTR(database)) + 3;
722
+ if(cache != Qnil)
723
+ {
724
+ *length += 5;
725
+ }
726
+ if(page != Qnil)
727
+ {
728
+ *length += 5;
729
+ }
730
+ if(mode != Qnil)
731
+ {
732
+ *length += 2;
733
+ }
734
+
735
+ /* Create and populate the buffer. */
736
+ offset = *buffer = ALLOC_N(char, *length);
737
+ if(buffer == NULL)
738
+ {
739
+ rb_raise(rb_eNoMemError,
740
+ "Memory allocation error preparing database restore.");
741
+ }
742
+ memset(*buffer, 8, *length);
743
+
744
+ *offset++ = isc_action_svc_restore;
745
+
746
+ number = strlen(STR2CSTR(file));
747
+ *offset++ = isc_spb_bkp_file;
748
+ ADD_SPB_LENGTH(offset, number);
749
+ memcpy(offset, STR2CSTR(file), number);
750
+ offset += number;
751
+
752
+ number = strlen(STR2CSTR(database));
753
+ *offset++ = isc_spb_dbname;
754
+ ADD_SPB_LENGTH(offset, number);
755
+ memcpy(offset, STR2CSTR(database), number);
756
+ offset += number;
757
+
758
+ if(cache != Qnil)
759
+ {
760
+ long value;
761
+
762
+ value = TYPE(cache) == T_FIXNUM ? FIX2INT(cache) : NUM2INT(cache);
763
+ *offset++ = isc_spb_res_buffers;
764
+ ADD_SPB_NUMERIC(offset, value);
765
+ }
766
+
767
+ if(page != Qnil)
768
+ {
769
+ long value;
770
+
771
+ value = TYPE(page) == T_FIXNUM ? FIX2INT(page) : NUM2INT(page);
772
+ *offset++ = isc_spb_res_page_size;
773
+ ADD_SPB_NUMERIC(offset, value);
774
+ }
775
+
776
+ if(mode != Qnil)
777
+ {
778
+ *offset++ = isc_spb_res_access_mode;
779
+ *offset++ = (char)FIX2INT(mode);
780
+ }
781
+
782
+ mask = FIX2INT(policy);
783
+
784
+ if(rb_hash_aref(options, BUILD_INDICES) == Qfalse)
785
+ {
786
+ mask |= isc_spb_res_deactivate_idx;
787
+ }
788
+
789
+ if(rb_hash_aref(options, NO_SHADOWS) == Qtrue)
790
+ {
791
+ mask |= isc_spb_res_no_shadow;
792
+ }
793
+
794
+ if(rb_hash_aref(options, VALIDITY_CHECKS) == Qfalse)
795
+ {
796
+ mask |= isc_spb_res_no_validity;
797
+ }
798
+
799
+ if(rb_hash_aref(options, COMMIT_TABLES) == Qtrue)
800
+ {
801
+ mask |= isc_spb_res_one_at_a_time;
802
+ }
803
+
804
+ if(rb_hash_aref(options, USE_ALL_SPACE) == Qtrue)
805
+ {
806
+ mask |= isc_spb_res_use_all_space;
807
+ }
808
+
809
+ *offset++ = isc_spb_options;
810
+ ADD_SPB_NUMERIC(offset, mask);
811
+
812
+ *offset++ = isc_spb_verbose;
813
+ }
814
+
815
+
816
+ /**
817
+ * This function initialize the Restore class in the Ruby environment.
818
+ *
819
+ * @param module The module to create the new class definition under.
820
+ *
821
+ */
822
+ void Init_Restore(VALUE module)
823
+ {
824
+ cRestore = rb_define_class_under(module, "Restore", rb_cObject);
825
+ rb_define_method(cRestore, "initialize", initializeRestore, 2);
826
+ rb_define_method(cRestore, "backup_file", getRestoreFile, 0);
827
+ rb_define_method(cRestore, "backup_file=", setRestoreFile, 1);
828
+ rb_define_method(cRestore, "database", getRestoreDatabase, 0);
829
+ rb_define_method(cRestore, "database=", setRestoreDatabase, 1);
830
+ rb_define_method(cRestore, "cache_buffers", getRestoreCacheBuffers, 0);
831
+ rb_define_method(cRestore, "cache_buffers=", setRestoreCacheBuffers, 1);
832
+ rb_define_method(cRestore, "page_size", getRestorePageSize, 0);
833
+ rb_define_method(cRestore, "page_size=", setRestorePageSize, 1);
834
+ rb_define_method(cRestore, "access_mode", getRestoreAccessMode, 0);
835
+ rb_define_method(cRestore, "access_mode=", setRestoreAccessMode, 1);
836
+ rb_define_method(cRestore, "build_indices", getRestoreBuildIndices, 0);
837
+ rb_define_method(cRestore, "build_indices=", setRestoreBuildIndices, 1);
838
+ rb_define_method(cRestore, "no_shadows", getRestoreCreateShadows, 0);
839
+ rb_define_method(cRestore, "no_shadows=", setRestoreCreateShadows, 1);
840
+ rb_define_method(cRestore, "check_validity", getRestoreCheckValidity, 0);
841
+ rb_define_method(cRestore, "check_validity=", setRestoreCheckValidity, 1);
842
+ rb_define_method(cRestore, "commit_tables", getRestoreCommitTables, 0);
843
+ rb_define_method(cRestore, "commit_tables=", setRestoreCommitTables, 1);
844
+ rb_define_method(cRestore, "restore_mode", getRestoreMode, 0);
845
+ rb_define_method(cRestore, "restore_mode=", setRestoreMode, 1);
846
+ rb_define_method(cRestore, "use_all_space", getRestoreUseAllSpace, 0);
847
+ rb_define_method(cRestore, "use_all_space=", setRestoreUseAllSpace, 1);
848
+ rb_define_method(cRestore, "execute", executeRestore, 1);
849
+ rb_define_method(cRestore, "log", getRestoreLog, 0);
850
+
851
+ rb_define_const(cRestore, "ACCESS_READ_ONLY", INT2FIX(isc_spb_prp_am_readonly));
852
+ rb_define_const(cRestore, "ACCESS_READ_WRITE", INT2FIX(isc_spb_prp_am_readwrite));
853
+ rb_define_const(cRestore, "MODE_CREATE", INT2FIX(isc_spb_res_replace));
854
+ rb_define_const(cRestore, "MODE_REPLACE", INT2FIX(isc_spb_res_create));
855
+ }