rubyfb 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
data/ext/FireRuby.c CHANGED
@@ -49,11 +49,10 @@
49
49
  * @param key A string containing the name of the key to be retrieved.
50
50
  *
51
51
  */
52
- VALUE getFireRubySetting(const char *key)
53
- {
54
- VALUE settings = rb_gv_get("$FireRubySettings");
52
+ VALUE getFireRubySetting(const char *key) {
53
+ VALUE settings = rb_gv_get("$FireRubySettings");
55
54
 
56
- return(rb_hash_aref(settings, toSymbol(key)));
55
+ return(rb_hash_aref(settings, toSymbol(key)));
57
56
  }
58
57
 
59
58
 
@@ -65,12 +64,11 @@ VALUE getFireRubySetting(const char *key)
65
64
  * @param name A string that will be populated with the class name.
66
65
  *
67
66
  */
68
- void getClassName(VALUE object, char *name)
69
- {
70
- VALUE klass = rb_funcall(object, rb_intern("class"), 0),
71
- string = rb_funcall(klass, rb_intern("name"), 0);
67
+ void getClassName(VALUE object, char *name) {
68
+ VALUE klass = rb_funcall(object, rb_intern("class"), 0),
69
+ string = rb_funcall(klass, rb_intern("name"), 0);
72
70
 
73
- strcpy(name, StringValuePtr(string));
71
+ strcpy(name, StringValuePtr(string));
74
72
  }
75
73
 
76
74
 
@@ -82,9 +80,8 @@ void getClassName(VALUE object, char *name)
82
80
  * @return A Symbol object for the string passed in.
83
81
  *
84
82
  */
85
- VALUE toSymbol(const char *name)
86
- {
87
- return(rb_funcall(rb_str_new2(name), rb_intern("intern"), 0));
83
+ VALUE toSymbol(const char *name) {
84
+ return(rb_funcall(rb_str_new2(name), rb_intern("intern"), 0));
88
85
  }
89
86
 
90
87
 
@@ -98,103 +95,83 @@ VALUE toSymbol(const char *name)
98
95
  * @return A symbol giving the base type for the column.
99
96
  *
100
97
  */
101
- VALUE getColumnType(const XSQLVAR *column)
102
- {
103
- VALUE type = Qnil;
104
-
105
- switch((column->sqltype & ~1))
106
- {
107
- case SQL_BLOB:
108
- type = toSymbol("BLOB");
109
- break;
110
-
111
- case SQL_TYPE_DATE:
112
- type = toSymbol("DATE");
113
- break;
114
-
115
- case SQL_DOUBLE:
116
- type = toSymbol("DOUBLE");
117
- break;
118
-
119
- case SQL_FLOAT:
120
- type = toSymbol("FLOAT");
121
- break;
122
-
123
- case SQL_INT64:
124
- if(column->sqlsubtype != 0)
125
- {
126
- if(column->sqlsubtype == 1)
127
- {
128
- type = toSymbol("NUMERIC");
129
- }
130
- else if(column->sqlsubtype == 2)
131
- {
132
- type = toSymbol("DECIMAL");
133
- }
134
- }
135
- else
136
- {
137
- type = toSymbol("BIGINT");
138
- }
139
- break;
140
-
141
- case SQL_LONG:
142
- if(column->sqlsubtype != 0)
143
- {
144
- if(column->sqlsubtype == 1)
145
- {
146
- type = toSymbol("NUMERIC");
147
- }
148
- else if(column->sqlsubtype == 2)
149
- {
150
- type = toSymbol("DECIMAL");
151
- }
152
- }
153
- else
154
- {
155
- type = toSymbol("INTEGER");
156
- }
157
- break;
158
-
159
- case SQL_SHORT:
160
- if(column->sqlsubtype != 0)
161
- {
162
- if(column->sqlsubtype == 1)
163
- {
164
- type = toSymbol("NUMERIC");
165
- }
166
- else if(column->sqlsubtype == 2)
167
- {
168
- type = toSymbol("DECIMAL");
169
- }
170
- }
171
- else
172
- {
173
- type = toSymbol("SMALLINT");
174
- }
175
- break;
176
-
177
- case SQL_TEXT:
178
- type = toSymbol("CHAR");
179
- break;
180
-
181
- case SQL_TYPE_TIME:
182
- type = toSymbol("TIME");
183
- break;
184
-
185
- case SQL_TIMESTAMP:
186
- type = toSymbol("TIMESTAMP");
187
- break;
188
-
189
- case SQL_VARYING:
190
- type = toSymbol("VARCHAR");
191
- break;
192
-
193
- default:
194
- type = toSymbol("UNKNOWN");
195
- }
196
-
197
- return(type);
98
+ VALUE getColumnType(const XSQLVAR *column) {
99
+ VALUE type = Qnil;
100
+
101
+ switch((column->sqltype & ~1)) {
102
+ case SQL_BLOB:
103
+ type = toSymbol("BLOB");
104
+ break;
105
+
106
+ case SQL_TYPE_DATE:
107
+ type = toSymbol("DATE");
108
+ break;
109
+
110
+ case SQL_DOUBLE:
111
+ type = toSymbol("DOUBLE");
112
+ break;
113
+
114
+ case SQL_FLOAT:
115
+ type = toSymbol("FLOAT");
116
+ break;
117
+
118
+ case SQL_INT64:
119
+ if(column->sqlsubtype != 0) {
120
+ if(column->sqlsubtype == 1) {
121
+ type = toSymbol("NUMERIC");
122
+ } else if(column->sqlsubtype == 2) {
123
+ type = toSymbol("DECIMAL");
124
+ }
125
+ } else {
126
+ type = toSymbol("BIGINT");
127
+ }
128
+ break;
129
+
130
+ case SQL_LONG:
131
+ if(column->sqlsubtype != 0) {
132
+ if(column->sqlsubtype == 1) {
133
+ type = toSymbol("NUMERIC");
134
+ } else if(column->sqlsubtype == 2) {
135
+ type = toSymbol("DECIMAL");
136
+ }
137
+ } else {
138
+ type = toSymbol("INTEGER");
139
+ }
140
+ break;
141
+
142
+ case SQL_SHORT:
143
+ if(column->sqlsubtype != 0) {
144
+ if(column->sqlsubtype == 1) {
145
+ type = toSymbol("NUMERIC");
146
+ } else if(column->sqlsubtype == 2) {
147
+ type = toSymbol("DECIMAL");
148
+ }
149
+ } else {
150
+ type = toSymbol("SMALLINT");
151
+ }
152
+ break;
153
+
154
+ case SQL_TEXT:
155
+ type = toSymbol("CHAR");
156
+ break;
157
+
158
+ case SQL_TYPE_TIME:
159
+ type = toSymbol("TIME");
160
+ break;
161
+
162
+ case SQL_TIMESTAMP:
163
+ type = toSymbol("TIMESTAMP");
164
+ break;
165
+
166
+ case SQL_VARYING:
167
+ type = toSymbol("VARCHAR");
168
+ break;
169
+
170
+ default:
171
+ type = toSymbol("UNKNOWN");
172
+ }
173
+
174
+ return(type);
198
175
  }
199
176
 
200
177
 
@@ -204,37 +181,36 @@ VALUE getColumnType(const XSQLVAR *column)
204
181
  * and then creates the various extension classes within this module.
205
182
  *
206
183
  */
207
- void Init_rubyfb_lib(void)
208
- {
209
- VALUE module = rb_define_module("Rubyfb"),
210
- array = rb_ary_new(),
211
- hash = rb_hash_new();
212
-
213
- /* Initialise the configuration and make it available. */
214
- rb_ary_push(array, INT2FIX(MAJOR_VERSION_NO));
215
- rb_ary_push(array, INT2FIX(MINOR_VERSION_NO));
216
- rb_ary_push(array, INT2FIX(BUILD_NO));
217
- rb_hash_aset(hash, toSymbol("ALIAS_KEYS"), Qtrue);
218
- rb_hash_aset(hash, toSymbol("DATE_AS_DATE"), Qtrue);
219
- rb_gv_set("$FireRubyVersion", array);
220
- rb_gv_set("$FireRubySettings", hash);
221
-
222
- /* Require needed libraries. */
223
- rb_require("date");
224
-
225
- /* Initialise the library classes. */
226
- Init_Database(module);
227
- Init_Connection(module);
228
- Init_Transaction(module);
229
- Init_Statement(module);
230
- Init_ResultSet(module);
231
- Init_Generator(module);
232
- Init_FireRubyException(module);
233
- Init_Blob(module);
234
- Init_Row(module);
235
- Init_ServiceManager(module);
236
- Init_Backup(module);
237
- Init_AddUser(module);
238
- Init_RemoveUser(module);
239
- Init_Restore(module);
184
+ void Init_rubyfb_lib(void) {
185
+ VALUE module = rb_define_module("Rubyfb"),
186
+ array = rb_ary_new(),
187
+ hash = rb_hash_new();
188
+
189
+ /* Initialise the configuration and make it available. */
190
+ rb_ary_push(array, INT2FIX(MAJOR_VERSION_NO));
191
+ rb_ary_push(array, INT2FIX(MINOR_VERSION_NO));
192
+ rb_ary_push(array, INT2FIX(BUILD_NO));
193
+ rb_hash_aset(hash, toSymbol("ALIAS_KEYS"), Qtrue);
194
+ rb_hash_aset(hash, toSymbol("DATE_AS_DATE"), Qtrue);
195
+ rb_gv_set("$FireRubyVersion", array);
196
+ rb_gv_set("$FireRubySettings", hash);
197
+
198
+ /* Require needed libraries. */
199
+ rb_require("date");
200
+
201
+ /* Initialise the library classes. */
202
+ Init_Database(module);
203
+ Init_Connection(module);
204
+ Init_Transaction(module);
205
+ Init_Statement(module);
206
+ Init_ResultSet(module);
207
+ Init_Generator(module);
208
+ Init_FireRubyException(module);
209
+ Init_Blob(module);
210
+ Init_Row(module);
211
+ Init_ServiceManager(module);
212
+ Init_Backup(module);
213
+ Init_AddUser(module);
214
+ Init_RemoveUser(module);
215
+ Init_Restore(module);
240
216
  }
data/ext/FireRuby.h CHANGED
@@ -3,20 +3,20 @@
3
3
  *----------------------------------------------------------------------------*/
4
4
  /**
5
5
  * Copyright � Peter Wood, 2005
6
- *
6
+ *
7
7
  * The contents of this file are subject to the Mozilla Public License Version
8
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
9
+ * License. You may obtain a copy of the License at
10
10
  *
11
11
  * http://www.mozilla.org/MPL/
12
- *
12
+ *
13
13
  * Software distributed under the License is distributed on an "AS IS" basis,
14
14
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
15
15
  * the specificlanguage governing rights and limitations under the License.
16
- *
16
+ *
17
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
18
+ *
19
+ * The Initial Developer of the Original Code is Peter Wood. All Rights
20
20
  * Reserved.
21
21
  *
22
22
  * @author Peter Wood
@@ -25,26 +25,26 @@
25
25
  #ifndef FIRERUBY_FIRE_RUBY_H
26
26
  #define FIRERUBY_FIRE_RUBY_H
27
27
 
28
- /* Includes. */
28
+ /* Includes. */
29
29
  #ifndef RUBY_H_INCLUDED
30
30
  #include "ruby.h"
31
31
  #define RUBY_H_INCLUDED
32
32
  #endif
33
-
33
+
34
34
  #ifndef IBASE_H_INCLUDED
35
35
  #include "ibase.h"
36
36
  #define IBASE_H_INCLUDED
37
37
  #endif
38
-
39
- /* Definitions. */
38
+
39
+ /* Definitions. */
40
40
  #define MAJOR_VERSION_NO 0
41
41
  #define MINOR_VERSION_NO 4
42
42
  #define BUILD_NO 3
43
-
44
- /* Function definitions. */
45
- VALUE getFireRubySetting(const char *);
46
- void getClassName(VALUE, char *);
47
- VALUE toSymbol(const char *);
48
- VALUE getColumnType(const XSQLVAR *);
49
-
43
+
44
+ /* Function definitions. */
45
+ VALUE getFireRubySetting(const char *);
46
+ void getClassName(VALUE, char *);
47
+ VALUE toSymbol(const char *);
48
+ VALUE getColumnType(const XSQLVAR *);
49
+
50
50
  #endif /* FIRERUBY_FIRE_RUBY_H */
@@ -3,20 +3,20 @@
3
3
  *----------------------------------------------------------------------------*/
4
4
  /**
5
5
  * Copyright � Peter Wood, 2005
6
- *
6
+ *
7
7
  * The contents of this file are subject to the Mozilla Public License Version
8
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
9
+ * License. You may obtain a copy of the License at
10
10
  *
11
11
  * http://www.mozilla.org/MPL/
12
- *
12
+ *
13
13
  * Software distributed under the License is distributed on an "AS IS" basis,
14
14
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
15
15
  * the specificlanguage governing rights and limitations under the License.
16
- *
16
+ *
17
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
18
+ *
19
+ * The Initial Developer of the Original Code is Peter Wood. All Rights
20
20
  * Reserved.
21
21
  *
22
22
  * @author Peter Wood
@@ -28,47 +28,15 @@
28
28
  #include "time.h"
29
29
 
30
30
  /* Function prototypes. */
31
- static VALUE allocateFireRubyException(VALUE);
32
31
  static VALUE initializeFireRubyException(VALUE, VALUE);
33
32
  static VALUE getFireRubyExceptionSQLCode(VALUE);
34
33
  static VALUE getFireRubyExceptionDBCode(VALUE);
35
34
  static VALUE getFireRubyExceptionMessage(VALUE);
36
- VALUE decodeError(ISC_STATUS *, const char *, VALUE);
37
35
 
38
36
  /* Globals. */
39
37
  VALUE cFireRubyException;
40
38
 
41
39
 
42
- /**
43
- * This function integrates with the Ruby language to allow for the allocation
44
- * of new FireRubyException objects.
45
- *
46
- * @param klass A reference to the FireRubyException Class object.
47
- *
48
- * @return An instance of the FireRubyException class.
49
- *
50
- */
51
- static VALUE allocateFireRubyException(VALUE klass)
52
- {
53
- VALUE instance;
54
- ExceptionHandle *exception = ALLOC(ExceptionHandle);
55
-
56
- if(exception != NULL)
57
- {
58
- exception->when = (long)time(NULL);
59
- instance = Data_Wrap_Struct(klass, NULL, firerubyExceptionFree,
60
- exception);
61
- }
62
- else
63
- {
64
- rb_raise(rb_eNoMemError,
65
- "Memory allocation failure creating a FireRubyException object.");
66
- }
67
-
68
- return(instance);
69
- }
70
-
71
-
72
40
  /**
73
41
  * This function provides the initialize method for the FireRubyException
74
42
  * class.
@@ -79,20 +47,18 @@ static VALUE allocateFireRubyException(VALUE klass)
79
47
  * @return A reference to the initialized exception object.
80
48
  *
81
49
  */
82
- static VALUE initializeFireRubyException(VALUE self, VALUE message)
83
- {
84
- /* Check the input type. */
85
- if(TYPE(message) != T_STRING)
86
- {
87
- rb_raise(rb_eException,
88
- "Invalid message parameter specified for exception.");
89
- }
90
-
91
- rb_iv_set(self, "@message", message);
92
- rb_iv_set(self, "@sql_code", 0);
93
- rb_iv_set(self, "@db_code", 0);
94
-
95
- return(self);
50
+ static VALUE initializeFireRubyException(VALUE self, VALUE message) {
51
+ /* Check the input type. */
52
+ if(TYPE(message) != T_STRING) {
53
+ rb_raise(rb_eException,
54
+ "Invalid message parameter specified for exception.");
55
+ }
56
+
57
+ rb_iv_set(self, "@message", message);
58
+ rb_iv_set(self, "@sql_code", 0);
59
+ rb_iv_set(self, "@db_code", 0);
60
+
61
+ return(self);
96
62
  }
97
63
 
98
64
 
@@ -105,9 +71,8 @@ static VALUE initializeFireRubyException(VALUE self, VALUE message)
105
71
  * @return A reference to the requested code value.
106
72
  *
107
73
  */
108
- static VALUE getFireRubyExceptionSQLCode(VALUE self)
109
- {
110
- return(rb_iv_get(self, "@sql_code"));
74
+ static VALUE getFireRubyExceptionSQLCode(VALUE self) {
75
+ return(rb_iv_get(self, "@sql_code"));
111
76
  }
112
77
 
113
78
 
@@ -120,9 +85,8 @@ static VALUE getFireRubyExceptionSQLCode(VALUE self)
120
85
  * @return A reference to the requested code value.
121
86
  *
122
87
  */
123
- static VALUE getFireRubyExceptionDBCode(VALUE self)
124
- {
125
- return(rb_iv_get(self, "@db_code"));
88
+ static VALUE getFireRubyExceptionDBCode(VALUE self) {
89
+ return(rb_iv_get(self, "@db_code"));
126
90
  }
127
91
 
128
92
 
@@ -134,9 +98,8 @@ static VALUE getFireRubyExceptionDBCode(VALUE self)
134
98
  * @return A reference to the message for the exception.
135
99
  *
136
100
  */
137
- static VALUE getFireRubyExceptionMessage(VALUE self)
138
- {
139
- return(rb_iv_get(self, "@message"));
101
+ static VALUE getFireRubyExceptionMessage(VALUE self) {
102
+ return(rb_iv_get(self, "@message"));
140
103
  }
141
104
 
142
105
 
@@ -152,46 +115,41 @@ static VALUE getFireRubyExceptionMessage(VALUE self)
152
115
  * @return A reference to the full decode error message string.
153
116
  *
154
117
  */
155
- VALUE decodeException(ISC_STATUS *status, const char *prefix)
156
- {
157
- VALUE message = rb_str_new2(""),
158
- eol = rb_str_new2("\n");
159
- char text[512];
160
- int sqlCode = isc_sqlcode(status),
161
- dbCode = 0;
162
- ISC_STATUS **ptr = &status;
163
-
164
- /* Add the prefix message if it exists. */
165
- if(prefix != NULL && strlen(prefix) > 0)
166
- {
167
- rb_str_concat(message, rb_str_new2(prefix));
168
- rb_str_concat(message, eol);
169
- }
170
-
171
- if(status != NULL)
172
- {
173
- /* Decode the status array. */
174
- dbCode = status[1];
175
- while(fb_interpret(text, 512, ptr) != 0)
176
- {
177
- rb_str_concat(message, rb_str_new2(text));
178
- rb_str_concat(message, eol);
179
- memset(text, 0, 512);
180
- }
181
-
182
- isc_sql_interprete(sqlCode, text, 512);
183
- if(strlen(text) > 0)
184
- {
185
- rb_str_concat(message, rb_str_new2(text));
186
- }
187
-
188
- sprintf(text, "\nSQL Code = %d\n", sqlCode);
118
+ VALUE decodeException(const ISC_STATUS *status, const char *prefix) {
119
+ VALUE message = rb_str_new2(""),
120
+ eol = rb_str_new2("\n");
121
+ char text[512];
122
+ int sqlCode = isc_sqlcode(status),
123
+ dbCode = 0;
124
+ const ISC_STATUS **ptr = &status;
125
+
126
+ /* Add the prefix message if it exists. */
127
+ if(prefix != NULL && strlen(prefix) > 0) {
128
+ rb_str_concat(message, rb_str_new2(prefix));
129
+ rb_str_concat(message, eol);
130
+ }
131
+
132
+ if(status != NULL) {
133
+ /* Decode the status array. */
134
+ dbCode = status[1];
135
+ while(fb_interpret(text, 512, ptr) != 0) {
189
136
  rb_str_concat(message, rb_str_new2(text));
190
- sprintf(text, "Firebird Code = %d\n", dbCode);
137
+ rb_str_concat(message, eol);
138
+ memset(text, 0, 512);
139
+ }
140
+
141
+ isc_sql_interprete(sqlCode, text, 512);
142
+ if(strlen(text) > 0) {
191
143
  rb_str_concat(message, rb_str_new2(text));
192
- }
193
-
194
- return(message);
144
+ }
145
+
146
+ sprintf(text, "\nSQL Code = %d\n", sqlCode);
147
+ rb_str_concat(message, rb_str_new2(text));
148
+ sprintf(text, "Firebird Code = %d\n", dbCode);
149
+ rb_str_concat(message, rb_str_new2(text));
150
+ }
151
+
152
+ return(message);
195
153
  }
196
154
 
197
155
 
@@ -204,13 +162,8 @@ VALUE decodeException(ISC_STATUS *status, const char *prefix)
204
162
  * @return A reference to a newly created FireRubyException object.
205
163
  *
206
164
  */
207
- VALUE rb_fireruby_exception_new(const char *message)
208
- {
209
- VALUE exception = allocateFireRubyException(cFireRubyException);
210
-
211
- initializeFireRubyException(exception, rb_str_new2(message));
212
-
213
- return(exception);
165
+ VALUE rb_fireruby_exception_new(const char *message) {
166
+ return rb_funcall(cFireRubyException, rb_intern("new"), 1, rb_str_new2(message));
214
167
  }
215
168
 
216
169
 
@@ -223,29 +176,9 @@ VALUE rb_fireruby_exception_new(const char *message)
223
176
  * text generated by the decoding.
224
177
  *
225
178
  */
226
- void rb_fireruby_raise(ISC_STATUS *status, const char *message)
227
- {
228
- VALUE text = decodeException(status, message);
229
-
230
- rb_raise(cFireRubyException, StringValuePtr(text));
231
- }
232
-
233
-
234
- /**
235
- * This function integrates with the Ruby garbage collector to insure that the
236
- * resources associated with a FireRubyException object are completely released
237
- * when an object of this type is collected.
238
- *
239
- * @param exception A pointer to the ExceptionHandle structure associated
240
- * with a FireRubyException object that is being collected.
241
- *
242
- */
243
- void firerubyExceptionFree(void *exception)
244
- {
245
- if(exception != NULL)
246
- {
247
- free((ExceptionHandle *)exception);
248
- }
179
+ void rb_fireruby_raise(const ISC_STATUS *status, const char *message) {
180
+ VALUE text = decodeException(status, message);
181
+ rb_raise(cFireRubyException, "%s", StringValuePtr(text));
249
182
  }
250
183
 
251
184
 
@@ -256,13 +189,10 @@ void firerubyExceptionFree(void *exception)
256
189
  * @param module The module to create the class under.
257
190
  *
258
191
  */
259
- void Init_FireRubyException(VALUE module)
260
- {
261
- cFireRubyException = rb_define_class_under(module, "FireRubyException",
262
- rb_eStandardError);
263
- rb_define_alloc_func(cFireRubyException, allocateFireRubyException);
264
- rb_define_method(cFireRubyException, "initialize", initializeFireRubyException, 1);
265
- rb_define_method(cFireRubyException, "sql_code", getFireRubyExceptionSQLCode, 0);
266
- rb_define_method(cFireRubyException, "db_code", getFireRubyExceptionDBCode, 0);
267
- rb_define_method(cFireRubyException, "message", getFireRubyExceptionMessage, 0);
192
+ void Init_FireRubyException(VALUE module) {
193
+ cFireRubyException = rb_define_class_under(module, "FireRubyException", rb_eStandardError);
194
+ rb_define_method(cFireRubyException, "initialize", initializeFireRubyException, 1);
195
+ rb_define_method(cFireRubyException, "sql_code", getFireRubyExceptionSQLCode, 0);
196
+ rb_define_method(cFireRubyException, "db_code", getFireRubyExceptionDBCode, 0);
197
+ rb_define_method(cFireRubyException, "message", getFireRubyExceptionMessage, 0);
268
198
  }