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.
- data/CHANGELOG +6 -0
- data/LICENSE +411 -0
- data/Manifest +73 -0
- data/README +460 -0
- data/Rakefile +20 -0
- data/examples/example01.rb +65 -0
- data/ext/AddUser.c +464 -0
- data/ext/AddUser.h +37 -0
- data/ext/Backup.c +783 -0
- data/ext/Backup.h +37 -0
- data/ext/Blob.c +421 -0
- data/ext/Blob.h +65 -0
- data/ext/Common.c +54 -0
- data/ext/Common.h +37 -0
- data/ext/Connection.c +863 -0
- data/ext/Connection.h +50 -0
- data/ext/DataArea.c +274 -0
- data/ext/DataArea.h +38 -0
- data/ext/Database.c +449 -0
- data/ext/Database.h +48 -0
- data/ext/FireRuby.c +240 -0
- data/ext/FireRuby.h +50 -0
- data/ext/FireRubyException.c +268 -0
- data/ext/FireRubyException.h +51 -0
- data/ext/Generator.c +689 -0
- data/ext/Generator.h +53 -0
- data/ext/RemoveUser.c +212 -0
- data/ext/RemoveUser.h +37 -0
- data/ext/Restore.c +855 -0
- data/ext/Restore.h +37 -0
- data/ext/ResultSet.c +809 -0
- data/ext/ResultSet.h +60 -0
- data/ext/Row.c +965 -0
- data/ext/Row.h +55 -0
- data/ext/ServiceManager.c +316 -0
- data/ext/ServiceManager.h +48 -0
- data/ext/Services.c +124 -0
- data/ext/Services.h +42 -0
- data/ext/Statement.c +785 -0
- data/ext/Statement.h +62 -0
- data/ext/Transaction.c +684 -0
- data/ext/Transaction.h +50 -0
- data/ext/TypeMap.c +1182 -0
- data/ext/TypeMap.h +51 -0
- data/ext/extconf.rb +28 -0
- data/ext/mkmf.bat +1 -0
- data/lib/SQLType.rb +224 -0
- data/lib/active_record/connection_adapters/rubyfb_adapter.rb +805 -0
- data/lib/mkdoc +1 -0
- data/lib/rubyfb.rb +2 -0
- data/lib/rubyfb_lib.so +0 -0
- data/lib/src.rb +1800 -0
- data/rubyfb.gemspec +31 -0
- data/test/AddRemoveUserTest.rb +56 -0
- data/test/BackupRestoreTest.rb +99 -0
- data/test/BlobTest.rb +57 -0
- data/test/CharacterSetTest.rb +63 -0
- data/test/ConnectionTest.rb +111 -0
- data/test/DDLTest.rb +54 -0
- data/test/DatabaseTest.rb +83 -0
- data/test/GeneratorTest.rb +50 -0
- data/test/KeyTest.rb +140 -0
- data/test/ResultSetTest.rb +162 -0
- data/test/RoleTest.rb +73 -0
- data/test/RowCountTest.rb +65 -0
- data/test/RowTest.rb +203 -0
- data/test/SQLTest.rb +182 -0
- data/test/SQLTypeTest.rb +101 -0
- data/test/ServiceManagerTest.rb +29 -0
- data/test/StatementTest.rb +135 -0
- data/test/TestSetup.rb +11 -0
- data/test/TransactionTest.rb +112 -0
- data/test/TypeTest.rb +92 -0
- data/test/UnitTest.rb +65 -0
- metadata +149 -0
data/ext/FireRuby.c
ADDED
@@ -0,0 +1,240 @@
|
|
1
|
+
/*------------------------------------------------------------------------------
|
2
|
+
* FireRuby.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 "FireRuby.h"
|
28
|
+
#include <string.h>
|
29
|
+
#include "AddUser.h"
|
30
|
+
#include "Blob.h"
|
31
|
+
#include "Backup.h"
|
32
|
+
#include "Database.h"
|
33
|
+
#include "Connection.h"
|
34
|
+
#include "FireRubyException.h"
|
35
|
+
#include "Generator.h"
|
36
|
+
#include "RemoveUser.h"
|
37
|
+
#include "ResultSet.h"
|
38
|
+
#include "ServiceManager.h"
|
39
|
+
#include "Statement.h"
|
40
|
+
#include "Transaction.h"
|
41
|
+
#include "Restore.h"
|
42
|
+
#include "Row.h"
|
43
|
+
|
44
|
+
|
45
|
+
/**
|
46
|
+
* This function provides an encapsulation of extracting a setting from the
|
47
|
+
* global FireRuby settings hash.
|
48
|
+
*
|
49
|
+
* @param key A string containing the name of the key to be retrieved.
|
50
|
+
*
|
51
|
+
*/
|
52
|
+
VALUE getFireRubySetting(const char *key)
|
53
|
+
{
|
54
|
+
VALUE settings = rb_gv_get("$FireRubySettings");
|
55
|
+
|
56
|
+
return(rb_hash_aref(settings, toSymbol(key)));
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
/**
|
61
|
+
* This function provides a convenience mechanism to obtain the class name for
|
62
|
+
* an object, useful in debugging.
|
63
|
+
*
|
64
|
+
* @param object A reference to the objec to get the class name for.
|
65
|
+
* @param name A string that will be populated with the class name.
|
66
|
+
*
|
67
|
+
*/
|
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);
|
72
|
+
|
73
|
+
strcpy(name, STR2CSTR(string));
|
74
|
+
}
|
75
|
+
|
76
|
+
|
77
|
+
/**
|
78
|
+
* This method takes a string and generates a Symbol object from it.
|
79
|
+
*
|
80
|
+
* @param name A string containing the text to be made into a Symbol.
|
81
|
+
*
|
82
|
+
* @return A Symbol object for the string passed in.
|
83
|
+
*
|
84
|
+
*/
|
85
|
+
VALUE toSymbol(const char *name)
|
86
|
+
{
|
87
|
+
return(rb_funcall(rb_str_new2(name), rb_intern("intern"), 0));
|
88
|
+
}
|
89
|
+
|
90
|
+
|
91
|
+
/**
|
92
|
+
* This function attempts to deduce the type for a SQL field from the XSQLVAR
|
93
|
+
* structure that is used to describe it.
|
94
|
+
*
|
95
|
+
* @param column A pointer to the XSQLVAR structure for the column to work
|
96
|
+
* the type out for.
|
97
|
+
*
|
98
|
+
* @return A symbol giving the base type for the column.
|
99
|
+
*
|
100
|
+
*/
|
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);
|
198
|
+
}
|
199
|
+
|
200
|
+
|
201
|
+
/**
|
202
|
+
* This function is required by the Ruby interpreter to load and initialize
|
203
|
+
* the extension details. The function creates a module called 'FireRuby'
|
204
|
+
* and then creates the various extension classes within this module.
|
205
|
+
*
|
206
|
+
*/
|
207
|
+
void Init_rubyfb_lib(void)
|
208
|
+
{
|
209
|
+
VALUE module = rb_define_module("FireRuby"),
|
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);
|
240
|
+
}
|
data/ext/FireRuby.h
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
/*------------------------------------------------------------------------------
|
2
|
+
* FireRuby.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_FIRE_RUBY_H
|
26
|
+
#define FIRERUBY_FIRE_RUBY_H
|
27
|
+
|
28
|
+
/* Includes. */
|
29
|
+
#ifndef RUBY_H_INCLUDED
|
30
|
+
#include "ruby.h"
|
31
|
+
#define RUBY_H_INCLUDED
|
32
|
+
#endif
|
33
|
+
|
34
|
+
#ifndef IBASE_H_INCLUDED
|
35
|
+
#include "ibase.h"
|
36
|
+
#define IBASE_H_INCLUDED
|
37
|
+
#endif
|
38
|
+
|
39
|
+
/* Definitions. */
|
40
|
+
#define MAJOR_VERSION_NO 0
|
41
|
+
#define MINOR_VERSION_NO 4
|
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
|
+
|
50
|
+
#endif /* FIRERUBY_FIRE_RUBY_H */
|
@@ -0,0 +1,268 @@
|
|
1
|
+
/*------------------------------------------------------------------------------
|
2
|
+
* FireRubyException.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 "FireRubyException.h"
|
28
|
+
#include "time.h"
|
29
|
+
|
30
|
+
/* Function prototypes. */
|
31
|
+
static VALUE allocateFireRubyException(VALUE);
|
32
|
+
static VALUE initializeFireRubyException(VALUE, VALUE);
|
33
|
+
static VALUE getFireRubyExceptionSQLCode(VALUE);
|
34
|
+
static VALUE getFireRubyExceptionDBCode(VALUE);
|
35
|
+
static VALUE getFireRubyExceptionMessage(VALUE);
|
36
|
+
VALUE decodeError(ISC_STATUS *, const char *, VALUE);
|
37
|
+
|
38
|
+
/* Globals. */
|
39
|
+
VALUE cFireRubyException;
|
40
|
+
|
41
|
+
|
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
|
+
/**
|
73
|
+
* This function provides the initialize method for the FireRubyException
|
74
|
+
* class.
|
75
|
+
*
|
76
|
+
* @param self A reference to the exception object being initialized.
|
77
|
+
* @param message A string containing an error message for the exception.
|
78
|
+
*
|
79
|
+
* @return A reference to the initialized exception object.
|
80
|
+
*
|
81
|
+
*/
|
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);
|
96
|
+
}
|
97
|
+
|
98
|
+
|
99
|
+
/**
|
100
|
+
* This function provides the accessor for the SQL code attribute of the
|
101
|
+
* FireRubyException class.
|
102
|
+
*
|
103
|
+
* @param self A reference to the exception to fetch the code from.
|
104
|
+
*
|
105
|
+
* @return A reference to the requested code value.
|
106
|
+
*
|
107
|
+
*/
|
108
|
+
static VALUE getFireRubyExceptionSQLCode(VALUE self)
|
109
|
+
{
|
110
|
+
return(rb_iv_get(self, "@sql_code"));
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
/**
|
115
|
+
* This function provides the accessor for the database code attribute of the
|
116
|
+
* FireRubyException class.
|
117
|
+
*
|
118
|
+
* @param self A reference to the exception to fetch the code from.
|
119
|
+
*
|
120
|
+
* @return A reference to the requested code value.
|
121
|
+
*
|
122
|
+
*/
|
123
|
+
static VALUE getFireRubyExceptionDBCode(VALUE self)
|
124
|
+
{
|
125
|
+
return(rb_iv_get(self, "@db_code"));
|
126
|
+
}
|
127
|
+
|
128
|
+
|
129
|
+
/**
|
130
|
+
* This function provides the message method for the FireRubyException class.
|
131
|
+
*
|
132
|
+
* @param self A reference to the exception object to fetch the message from.
|
133
|
+
*
|
134
|
+
* @return A reference to the message for the exception.
|
135
|
+
*
|
136
|
+
*/
|
137
|
+
static VALUE getFireRubyExceptionMessage(VALUE self)
|
138
|
+
{
|
139
|
+
return(rb_iv_get(self, "@message"));
|
140
|
+
}
|
141
|
+
|
142
|
+
|
143
|
+
/**
|
144
|
+
* This function decodes the contents of a Firebird ISC_STATUS array into a
|
145
|
+
* String object.
|
146
|
+
*
|
147
|
+
* @param status A pointer to the status array to be decoded.
|
148
|
+
* @param prefix An initial message that may be added to the exception as
|
149
|
+
* part of the decoding. Ignored if it is NULL or has zero
|
150
|
+
* length.
|
151
|
+
*
|
152
|
+
* @return A reference to the full decode error message string.
|
153
|
+
*
|
154
|
+
*/
|
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);
|
189
|
+
rb_str_concat(message, rb_str_new2(text));
|
190
|
+
sprintf(text, "Firebird Code = %d\n", dbCode);
|
191
|
+
rb_str_concat(message, rb_str_new2(text));
|
192
|
+
}
|
193
|
+
|
194
|
+
return(message);
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
/**
|
199
|
+
* This function provides a means to programmatically create a new instance of
|
200
|
+
* the FireRubyException class.
|
201
|
+
*
|
202
|
+
* @param message A string containing the error message for the exception.
|
203
|
+
*
|
204
|
+
* @return A reference to a newly created FireRubyException object.
|
205
|
+
*
|
206
|
+
*/
|
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);
|
214
|
+
}
|
215
|
+
|
216
|
+
|
217
|
+
/**
|
218
|
+
* This function raises a new FireRuby exception.
|
219
|
+
*
|
220
|
+
* @param status A pointer to the Firebird status vector containing the error
|
221
|
+
* details.
|
222
|
+
* @param message A string containing a message to be prefixed to the error
|
223
|
+
* text generated by the decoding.
|
224
|
+
*
|
225
|
+
*/
|
226
|
+
void rb_fireruby_raise(ISC_STATUS *status, const char *message)
|
227
|
+
{
|
228
|
+
VALUE text = decodeException(status, message);
|
229
|
+
|
230
|
+
rb_raise(cFireRubyException, STR2CSTR(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
|
+
}
|
249
|
+
}
|
250
|
+
|
251
|
+
|
252
|
+
/**
|
253
|
+
* This function creates the FireRubyException class within the Ruby environment
|
254
|
+
* under the module specified as a parameter.
|
255
|
+
*
|
256
|
+
* @param module The module to create the class under.
|
257
|
+
*
|
258
|
+
*/
|
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);
|
268
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
/*------------------------------------------------------------------------------
|
2
|
+
* FireRubyException.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_FIRE_RUBY_EXCEPTION_H
|
26
|
+
#define FIRERUBY_FIRE_RUBY_EXCEPTION_H
|
27
|
+
|
28
|
+
/* Includes. */
|
29
|
+
#ifndef RUBY_H_INCLUDED
|
30
|
+
#include "ruby.h"
|
31
|
+
#define RUBY_H_INCLUDED
|
32
|
+
#endif
|
33
|
+
|
34
|
+
#ifndef IBASE_H_INCLUDED
|
35
|
+
#include "ibase.h"
|
36
|
+
#define IBASE_H_INCLUDED
|
37
|
+
#endif
|
38
|
+
|
39
|
+
/* Type definitions. */
|
40
|
+
typedef struct
|
41
|
+
{
|
42
|
+
long when;
|
43
|
+
} ExceptionHandle;
|
44
|
+
|
45
|
+
/* Function prototypes. */
|
46
|
+
void Init_FireRubyException(VALUE);
|
47
|
+
VALUE rb_fireruby_exception_new(const char *);
|
48
|
+
void rb_fireruby_raise(ISC_STATUS *, const char *);
|
49
|
+
void firerubyExceptionFree(void *);
|
50
|
+
|
51
|
+
#endif /* FIRERUBY_FIRE_RUBY_EXCEPTION_H */
|