fireruby 0.1.0-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/CVS/Entries +10 -0
- data/doc/CVS/Repository +1 -0
- data/doc/CVS/Root +1 -0
- data/doc/README +39 -0
- data/doc/classes/CVS/Entries +2 -0
- data/doc/classes/CVS/Entries.Log +1 -0
- data/doc/classes/CVS/Repository +1 -0
- data/doc/classes/CVS/Root +1 -0
- data/doc/classes/FireRuby/CVS/Entries +8 -0
- data/doc/classes/FireRuby/CVS/Entries.Log +7 -0
- data/doc/classes/FireRuby/CVS/Repository +1 -0
- data/doc/classes/FireRuby/CVS/Root +1 -0
- data/doc/classes/FireRuby/Connection.html +364 -0
- data/doc/classes/FireRuby/Connection.src/CVS/Entries +10 -0
- data/doc/classes/FireRuby/Connection.src/CVS/Repository +1 -0
- data/doc/classes/FireRuby/Connection.src/CVS/Root +1 -0
- data/doc/classes/FireRuby/Connection.src/M000046.html +17 -0
- data/doc/classes/FireRuby/Connection.src/M000047.html +17 -0
- data/doc/classes/FireRuby/Connection.src/M000048.html +17 -0
- data/doc/classes/FireRuby/Connection.src/M000049.html +17 -0
- data/doc/classes/FireRuby/Connection.src/M000050.html +17 -0
- data/doc/classes/FireRuby/Connection.src/M000051.html +17 -0
- data/doc/classes/FireRuby/Connection.src/M000052.html +18 -0
- data/doc/classes/FireRuby/Connection.src/M000053.html +18 -0
- data/doc/classes/FireRuby/Connection.src/M000054.html +18 -0
- data/doc/classes/FireRuby/Database.html +292 -0
- data/doc/classes/FireRuby/Database.src/CVS/Entries +7 -0
- data/doc/classes/FireRuby/Database.src/CVS/Repository +1 -0
- data/doc/classes/FireRuby/Database.src/CVS/Root +1 -0
- data/doc/classes/FireRuby/Database.src/M000035.html +17 -0
- data/doc/classes/FireRuby/Database.src/M000036.html +17 -0
- data/doc/classes/FireRuby/Database.src/M000037.html +17 -0
- data/doc/classes/FireRuby/Database.src/M000038.html +18 -0
- data/doc/classes/FireRuby/Database.src/M000039.html +17 -0
- data/doc/classes/FireRuby/Database.src/M000040.html +17 -0
- data/doc/classes/FireRuby/FireRubyError.html +221 -0
- data/doc/classes/FireRuby/FireRubyError.src/CVS/Entries +6 -0
- data/doc/classes/FireRuby/FireRubyError.src/CVS/Repository +1 -0
- data/doc/classes/FireRuby/FireRubyError.src/CVS/Root +1 -0
- data/doc/classes/FireRuby/FireRubyError.src/M000041.html +17 -0
- data/doc/classes/FireRuby/FireRubyError.src/M000042.html +17 -0
- data/doc/classes/FireRuby/FireRubyError.src/M000043.html +17 -0
- data/doc/classes/FireRuby/FireRubyError.src/M000044.html +17 -0
- data/doc/classes/FireRuby/FireRubyError.src/M000045.html +17 -0
- data/doc/classes/FireRuby/Generator.html +343 -0
- data/doc/classes/FireRuby/Generator.src/CVS/Entries +9 -0
- data/doc/classes/FireRuby/Generator.src/CVS/Repository +1 -0
- data/doc/classes/FireRuby/Generator.src/CVS/Root +1 -0
- data/doc/classes/FireRuby/Generator.src/M000001.html +17 -0
- data/doc/classes/FireRuby/Generator.src/M000002.html +17 -0
- data/doc/classes/FireRuby/Generator.src/M000003.html +17 -0
- data/doc/classes/FireRuby/Generator.src/M000004.html +17 -0
- data/doc/classes/FireRuby/Generator.src/M000005.html +17 -0
- data/doc/classes/FireRuby/Generator.src/M000006.html +17 -0
- data/doc/classes/FireRuby/Generator.src/M000007.html +17 -0
- data/doc/classes/FireRuby/Generator.src/M000008.html +17 -0
- data/doc/classes/FireRuby/ResultSet.html +343 -0
- data/doc/classes/FireRuby/ResultSet.src/CVS/Entries +10 -0
- data/doc/classes/FireRuby/ResultSet.src/CVS/Repository +1 -0
- data/doc/classes/FireRuby/ResultSet.src/CVS/Root +1 -0
- data/doc/classes/FireRuby/ResultSet.src/M000026.html +17 -0
- data/doc/classes/FireRuby/ResultSet.src/M000027.html +17 -0
- data/doc/classes/FireRuby/ResultSet.src/M000028.html +17 -0
- data/doc/classes/FireRuby/ResultSet.src/M000029.html +17 -0
- data/doc/classes/FireRuby/ResultSet.src/M000030.html +17 -0
- data/doc/classes/FireRuby/ResultSet.src/M000031.html +17 -0
- data/doc/classes/FireRuby/ResultSet.src/M000032.html +17 -0
- data/doc/classes/FireRuby/ResultSet.src/M000033.html +17 -0
- data/doc/classes/FireRuby/ResultSet.src/M000034.html +17 -0
- data/doc/classes/FireRuby/Statement.html +349 -0
- data/doc/classes/FireRuby/Statement.src/CVS/Entries +10 -0
- data/doc/classes/FireRuby/Statement.src/CVS/Repository +1 -0
- data/doc/classes/FireRuby/Statement.src/CVS/Root +1 -0
- data/doc/classes/FireRuby/Statement.src/M000017.html +17 -0
- data/doc/classes/FireRuby/Statement.src/M000018.html +17 -0
- data/doc/classes/FireRuby/Statement.src/M000019.html +17 -0
- data/doc/classes/FireRuby/Statement.src/M000020.html +17 -0
- data/doc/classes/FireRuby/Statement.src/M000021.html +17 -0
- data/doc/classes/FireRuby/Statement.src/M000022.html +17 -0
- data/doc/classes/FireRuby/Statement.src/M000023.html +18 -0
- data/doc/classes/FireRuby/Statement.src/M000024.html +18 -0
- data/doc/classes/FireRuby/Statement.src/M000025.html +17 -0
- data/doc/classes/FireRuby/Transaction.html +484 -0
- data/doc/classes/FireRuby/Transaction.src/CVS/Entries +9 -0
- data/doc/classes/FireRuby/Transaction.src/CVS/Repository +1 -0
- data/doc/classes/FireRuby/Transaction.src/CVS/Root +1 -0
- data/doc/classes/FireRuby/Transaction.src/M000009.html +17 -0
- data/doc/classes/FireRuby/Transaction.src/M000010.html +17 -0
- data/doc/classes/FireRuby/Transaction.src/M000011.html +17 -0
- data/doc/classes/FireRuby/Transaction.src/M000012.html +17 -0
- data/doc/classes/FireRuby/Transaction.src/M000013.html +17 -0
- data/doc/classes/FireRuby/Transaction.src/M000014.html +17 -0
- data/doc/classes/FireRuby/Transaction.src/M000015.html +18 -0
- data/doc/classes/FireRuby/Transaction.src/M000016.html +17 -0
- data/doc/classes/FireRuby.html +116 -0
- data/doc/created.rid +1 -0
- data/doc/files/CVS/Entries +2 -0
- data/doc/files/CVS/Repository +1 -0
- data/doc/files/CVS/Root +1 -0
- data/doc/files/src_rb.html +119 -0
- data/doc/fr_class_index.html +34 -0
- data/doc/fr_file_index.html +27 -0
- data/doc/fr_method_index.html +80 -0
- data/doc/index.html +24 -0
- data/doc/license.txt +411 -0
- data/doc/rdoc-style.css +175 -0
- data/lib/CVS/Entries +4 -0
- data/lib/CVS/Repository +1 -0
- data/lib/CVS/Root +1 -0
- data/lib/fireruby.bundle +0 -0
- data/lib/fireruby.so +0 -0
- data/lib/mkdoc +1 -0
- data/lib/src.rb +736 -0
- data/test/CVS/Entries +17 -0
- data/test/CVS/Repository +1 -0
- data/test/CVS/Root +1 -0
- data/test/ConnectionTest.rb +91 -0
- data/test/DDLTest.rb +49 -0
- data/test/DatabaseTest.rb +84 -0
- data/test/GeneratorTest.rb +47 -0
- data/test/ResultSetTest.rb +96 -0
- data/test/SQLTest.rb +154 -0
- data/test/StatementTest.rb +101 -0
- data/test/TestSetup.rb +10 -0
- data/test/TransactionTest.rb +107 -0
- data/test/UnitTest.rb +10 -0
- data/test/example.c +91 -0
- data/test/fb.c +297 -0
- data/test/mfb +1 -0
- data/test/sql_unit_test.fdb +0 -0
- data/test/test.fdb +0 -0
- metadata +191 -0
@@ -0,0 +1,107 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'TestSetup'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'fireruby'
|
6
|
+
|
7
|
+
include FireRuby
|
8
|
+
|
9
|
+
class TransactionTest < Test::Unit::TestCase
|
10
|
+
CURDIR = "#{Dir.getwd}"
|
11
|
+
DB_FILE = "#{CURDIR}#{File::SEPARATOR}tx_unit_test.fdb"
|
12
|
+
|
13
|
+
def setup
|
14
|
+
if File::exist?(DB_FILE)
|
15
|
+
Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE).drop
|
16
|
+
end
|
17
|
+
|
18
|
+
@database = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD, 1024, nil)
|
19
|
+
@connections = []
|
20
|
+
@transactions = []
|
21
|
+
|
22
|
+
@connections.push(@database.connect)
|
23
|
+
@connections.push(@database.connect)
|
24
|
+
@connections.push(@database.connect)
|
25
|
+
end
|
26
|
+
|
27
|
+
def teardown
|
28
|
+
@transactions.each do |tx|
|
29
|
+
tx.rollback if tx.active?
|
30
|
+
end
|
31
|
+
@transactions.clear
|
32
|
+
@connections.each do |cxn|
|
33
|
+
cxn.close if cxn.open?
|
34
|
+
end
|
35
|
+
if File::exist?(DB_FILE)
|
36
|
+
Database.new(DB_USER_NAME, DB_PASSWORD, DB_FILE).drop
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test01
|
41
|
+
@transactions.push(@connections[0].start_transaction)
|
42
|
+
assert(@transactions[0].active?)
|
43
|
+
|
44
|
+
@transactions.push(Transaction.new(@connections[1]))
|
45
|
+
assert(@transactions[1].active?)
|
46
|
+
|
47
|
+
assert(@transactions[0].connections == [@connections[0]])
|
48
|
+
assert(@transactions[1].connections == [@connections[1]])
|
49
|
+
|
50
|
+
assert(@transactions[0].for_connection?(@connections[1]) == false)
|
51
|
+
assert(@transactions[1].for_connection?(@connections[0]) == false)
|
52
|
+
assert(@transactions[0].for_connection?(@connections[0]))
|
53
|
+
assert(@transactions[1].for_connection?(@connections[1]))
|
54
|
+
|
55
|
+
@transactions[0].commit
|
56
|
+
assert(@transactions[0].active? == false)
|
57
|
+
assert(@transactions[0].connections == [])
|
58
|
+
assert(@transactions[0].for_connection?(@connections[0]) == false)
|
59
|
+
assert(@transactions[0].for_connection?(@connections[1]) == false)
|
60
|
+
|
61
|
+
@transactions[1].rollback
|
62
|
+
assert(@transactions[1].active? == false)
|
63
|
+
assert(@transactions[1].connections == [])
|
64
|
+
assert(@transactions[1].for_connection?(@connections[0]) == false)
|
65
|
+
assert(@transactions[1].for_connection?(@connections[1]) == false)
|
66
|
+
|
67
|
+
@transactions[0] = Transaction.new([@connections[0], @connections[1]])
|
68
|
+
assert(@transactions[0].active? == true)
|
69
|
+
assert(@transactions[0].for_connection?(@connections[0]))
|
70
|
+
assert(@transactions[0].for_connection?(@connections[1]))
|
71
|
+
assert(@transactions[0].for_connection?(@connections[2]) == false)
|
72
|
+
|
73
|
+
@transactions[0].commit
|
74
|
+
assert(@transactions[0].active? == false)
|
75
|
+
assert(@transactions[0].connections == [])
|
76
|
+
assert(@transactions[0].for_connection?(@connections[0]) == false)
|
77
|
+
assert(@transactions[0].for_connection?(@connections[1]) == false)
|
78
|
+
assert(@transactions[0].for_connection?(@connections[2]) == false)
|
79
|
+
|
80
|
+
@transactions[0] = Transaction.new([@connections[0], @connections[2]])
|
81
|
+
assert(@transactions[0].active?)
|
82
|
+
@transactions[0].rollback
|
83
|
+
assert(@transactions[0].active? == false)
|
84
|
+
assert(@transactions[0].connections == [])
|
85
|
+
assert(@transactions[0].for_connection?(@connections[0]) == false)
|
86
|
+
assert(@transactions[0].for_connection?(@connections[1]) == false)
|
87
|
+
assert(@transactions[0].for_connection?(@connections[2]) == false)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test02
|
91
|
+
sql = []
|
92
|
+
sql.push("UPDATE RDB$EXCEPTIONS SET RDB$MESSAGE = 'WoooHooo'"\
|
93
|
+
"WHERE RDB$EXCEPTION_NAME = 'Lalala'")
|
94
|
+
sql.push("SELECT RDB$FIELD_NAME FROM RDB$FIELDS")
|
95
|
+
@transactions.push(Transaction.new(@connections[0]))
|
96
|
+
|
97
|
+
assert(@transactions[0].execute(sql[0]) == nil)
|
98
|
+
assert(@transactions[0].execute(sql[1]) != nil)
|
99
|
+
assert(@transactions[0].execute(sql[1]).class == ResultSet)
|
100
|
+
|
101
|
+
total = 0
|
102
|
+
@transactions[0].execute(sql[1]) do |row|
|
103
|
+
total += 1
|
104
|
+
end
|
105
|
+
assert(total = 88)
|
106
|
+
end
|
107
|
+
end
|
data/test/UnitTest.rb
ADDED
data/test/example.c
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
#include <ibase.h>
|
2
|
+
|
3
|
+
#define LASTLEN 20
|
4
|
+
#define FIRSTLEN 15
|
5
|
+
#define EXTLEN 4
|
6
|
+
|
7
|
+
typedef struct vary
|
8
|
+
{
|
9
|
+
short vary_length;
|
10
|
+
char vary_string[1];
|
11
|
+
} VARY;
|
12
|
+
|
13
|
+
ISC_STATUS status_vector[20],
|
14
|
+
retcode;
|
15
|
+
long SQLCODE;
|
16
|
+
XSQLDA *osqlda;
|
17
|
+
XSQLVAR *ovar;
|
18
|
+
short flag0,
|
19
|
+
flag1,
|
20
|
+
flag2;
|
21
|
+
char *str = "SELECT last_name, first_name, phone_ext FROM phone_list "\
|
22
|
+
"WHERE location = "Monterey" ORDER BY last_name, first_name";
|
23
|
+
char last_name[LASTLEN + 2];
|
24
|
+
char first_name[FIRSTLEN + 2];
|
25
|
+
char phone_ext[EXTLEN + 2];
|
26
|
+
VARY *vary;
|
27
|
+
|
28
|
+
/* Allocate an output XSQLDA osqlda. */
|
29
|
+
osqlda = (XSQLDA *)malloc(XSQLDA_LENGTH(3);
|
30
|
+
osqlda->version = SQLDA_VERSION1;
|
31
|
+
osqlda->sqln = 3;
|
32
|
+
|
33
|
+
/* Prepare the statement. */
|
34
|
+
isc_dsql_prepare(status_vector,
|
35
|
+
&tr_handle, /* Set in previous isc_start_transaction() call. */
|
36
|
+
&stmt_handle, /* Allocated previously by isc_dsql_allocate_statement() or isc_dsql_alloc_statement2() call. */
|
37
|
+
0,
|
38
|
+
str,
|
39
|
+
1,
|
40
|
+
osqlda);
|
41
|
+
|
42
|
+
if (status_vector[0] == 1 && status_vector[1])
|
43
|
+
{
|
44
|
+
/* Process error. */
|
45
|
+
isc_print_status(status_vector);
|
46
|
+
return(1);
|
47
|
+
}
|
48
|
+
|
49
|
+
/* Set up an output XSQLVAR structure to allocate space for each item to be returned. */
|
50
|
+
osqlda->sqlvar[0].sqldata = last_name;
|
51
|
+
osqlda->sqlvar[0].sqltype = SQL_VARYING + 1;
|
52
|
+
osqlda->sqlvar[0].sqlind = &flag0;
|
53
|
+
osqlda->sqlvar[1].sqldata = first_name;
|
54
|
+
osqlda->sqlvar[1].sqltype = SQL_VARYING + 1;
|
55
|
+
osqlda->sqlvar[1].sqlind = &flag1;
|
56
|
+
osqlda->sqlvar[2].sqldata = phone_ext;
|
57
|
+
osqlda->sqlvar[2].sqltype = SQL_VARYING + 1;
|
58
|
+
osqlda->sqlvar[2].sqlind = &flag2;
|
59
|
+
|
60
|
+
/* Execute the statement. */
|
61
|
+
isc_dsql_execute(status_vector,
|
62
|
+
&tr_handle, /* Set in previous isc_start_transaction() call. */
|
63
|
+
&stmt_handle, /* Allocated previously by isc_dsql_allocate_statement() or isc_dsql_alloc_statement2() call. */
|
64
|
+
1,
|
65
|
+
NULL);
|
66
|
+
|
67
|
+
if (status_vector[0] == 1 && status_vector[1])
|
68
|
+
{
|
69
|
+
/* Process error. */
|
70
|
+
isc_print_status(status_vector);
|
71
|
+
return(1);
|
72
|
+
}
|
73
|
+
|
74
|
+
printf("\n%-20s %-15s %-10s\n\n", "LAST NAME", "FIRST NAME", "EXTENSION");
|
75
|
+
|
76
|
+
/* Fetch and print the records in the select list one by one. */
|
77
|
+
while((retcode = isc_dsql_fetch( status_vector, &stmt_handle, 1, osqlda)) == 0)
|
78
|
+
{
|
79
|
+
vary = (VARY *)last_name;
|
80
|
+
printf("%-20.*s ", vary->vary_length, vary->vary_string);
|
81
|
+
vary = (VARY *)first_name;
|
82
|
+
printf("%-15.*s ", vary->vary_length, vary->vary_string);
|
83
|
+
vary = (VARY *)phone_ext;
|
84
|
+
printf("%-4.*s ", vary->vary_length, vary->vary_string);
|
85
|
+
}
|
86
|
+
|
87
|
+
if(retcode != 100L)
|
88
|
+
{
|
89
|
+
SQLCODE = isc_sqlcode(status_vector);
|
90
|
+
isc_print_sqlerror(SQLCODE, status_vector); return(1);
|
91
|
+
}
|
data/test/fb.c
ADDED
@@ -0,0 +1,297 @@
|
|
1
|
+
#include <stdio.h>
|
2
|
+
#include <string.h>
|
3
|
+
#include "ibase.h"
|
4
|
+
|
5
|
+
long *buffer;
|
6
|
+
unsigned int buffer_size;
|
7
|
+
|
8
|
+
void writeError(ISC_STATUS *);
|
9
|
+
void prepareXSQLDA(XSQLDA *);
|
10
|
+
unsigned int calculateSize(XSQLDA *);
|
11
|
+
void writeBuffer(void *, unsigned int);
|
12
|
+
|
13
|
+
#define USERNAME "sysdba"
|
14
|
+
#define PASSWORD "masterkey"
|
15
|
+
#define DATABASE "./test.fdb"
|
16
|
+
#define SQL "SELECT * FROM USERS"
|
17
|
+
#define ALIGN(ptr, n) ((ptr + n - 1) & ~(n - 1))
|
18
|
+
|
19
|
+
int main(void)
|
20
|
+
{
|
21
|
+
char dpb[100],
|
22
|
+
*location = dpb;
|
23
|
+
isc_db_handle db = 0;
|
24
|
+
short size = 0;
|
25
|
+
ISC_STATUS status[20];
|
26
|
+
unsigned int length = 0;
|
27
|
+
|
28
|
+
/* Prepare the DPB and connect to the database. */
|
29
|
+
memset(dpb, 0, 100);
|
30
|
+
*location++ = isc_dpb_version1;
|
31
|
+
|
32
|
+
size = strlen(USERNAME);
|
33
|
+
*location++ = isc_dpb_user_name;
|
34
|
+
*location++ = (char)size;
|
35
|
+
memcpy(location, USERNAME, size);
|
36
|
+
location += size;
|
37
|
+
|
38
|
+
size = strlen(PASSWORD);
|
39
|
+
*location++ = isc_dpb_password;
|
40
|
+
*location++ = (char)size;
|
41
|
+
memcpy(location, PASSWORD, size);
|
42
|
+
location += size;
|
43
|
+
|
44
|
+
length = strlen(USERNAME) + strlen(PASSWORD) + 5;
|
45
|
+
if(isc_attach_database(status, strlen(DATABASE), DATABASE, &db,
|
46
|
+
length, dpb) == 0)
|
47
|
+
{
|
48
|
+
isc_tr_handle tr = 0;
|
49
|
+
|
50
|
+
/* Start a transaction. */
|
51
|
+
if(isc_start_transaction(status, &tr, 1, &db, 0, NULL) == 0)
|
52
|
+
{
|
53
|
+
isc_stmt_handle stmt = 0;
|
54
|
+
|
55
|
+
/* Create a SQL statment. */
|
56
|
+
if(isc_dsql_allocate_statement(status, &db, &stmt) == 0)
|
57
|
+
{
|
58
|
+
XSQLDA *da = (XSQLDA *)malloc(XSQLDA_LENGTH(3));
|
59
|
+
|
60
|
+
/* Prepare the statement for execution. */
|
61
|
+
if(da != NULL)
|
62
|
+
{
|
63
|
+
da->version = SQLDA_VERSION1;
|
64
|
+
da->sqln = 3;
|
65
|
+
if(isc_dsql_prepare(status, &tr, &stmt, 0, SQL, 3, da) == 0)
|
66
|
+
{
|
67
|
+
XSQLDA *actual = NULL;
|
68
|
+
|
69
|
+
/* Check if the XSQLDA needs resizing. */
|
70
|
+
if(da->sqld > da->sqln)
|
71
|
+
{
|
72
|
+
/* Allocate the new XSQLDA. */
|
73
|
+
actual = (XSQLDA *)malloc(XSQLDA_LENGTH(da->sqld));
|
74
|
+
if(actual != NULL)
|
75
|
+
{
|
76
|
+
/* Bind the details to the new XSQLDA. */
|
77
|
+
actual->version = SQLDA_VERSION1;
|
78
|
+
actual->sqln = da->sqld;
|
79
|
+
if(isc_dsql_describe(status, &stmt, SQL_DIALECT_V6,
|
80
|
+
actual) != 0)
|
81
|
+
{
|
82
|
+
/* Print an error. */
|
83
|
+
fprintf(stderr, "DSQL describe call failed.\n");
|
84
|
+
writeError(status);
|
85
|
+
}
|
86
|
+
else
|
87
|
+
{
|
88
|
+
/* Slot the new XSQLDA into place. */
|
89
|
+
free(da);
|
90
|
+
printf("Assigning updated XSQLDA (%p).\n", actual);
|
91
|
+
da = actual;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
else
|
95
|
+
{
|
96
|
+
/* Print an error message. */
|
97
|
+
fprintf(stderr, "Error resizing XSQLDA.");
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
/* Prepare the XSQLDA for use. */
|
102
|
+
prepareXSQLDA(da);
|
103
|
+
|
104
|
+
/* Execute the statement. */
|
105
|
+
fprintf(stderr, "Calling isc_dsql_execute().\n");
|
106
|
+
if(isc_dsql_execute(status, &tr, &stmt, SQL_DIALECT_V6,
|
107
|
+
NULL) == 0)
|
108
|
+
{
|
109
|
+
/* Fetch a row of data. */
|
110
|
+
fprintf(stderr, "Calling isc_dsql_fetch().\n");
|
111
|
+
if(isc_dsql_fetch(status, &stmt, SQL_DIALECT_V6, da) != 0)
|
112
|
+
{
|
113
|
+
/* Print an error. */
|
114
|
+
fprintf(stderr, "Error performing SQL fetch.\n");
|
115
|
+
writeError(status);
|
116
|
+
}
|
117
|
+
else
|
118
|
+
{
|
119
|
+
writeBuffer(buffer, sizeof(long) * buffer_size);
|
120
|
+
}
|
121
|
+
}
|
122
|
+
else
|
123
|
+
{
|
124
|
+
/* Print an error. */
|
125
|
+
fprintf(stderr, "Error executing the SQL statement.\n");
|
126
|
+
writeError(status);
|
127
|
+
}
|
128
|
+
|
129
|
+
/* Free the XQSLDA memory. */
|
130
|
+
free(da);
|
131
|
+
}
|
132
|
+
else
|
133
|
+
{
|
134
|
+
/* Print an error and rollback the transaction. */
|
135
|
+
fprintf(stderr, "Error preparing the SQL statement.\n");
|
136
|
+
isc_rollback_transaction(status, &tr);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
/* Release the statement resources. */
|
141
|
+
isc_dsql_free_statement(status, &stmt, DSQL_drop);
|
142
|
+
}
|
143
|
+
else
|
144
|
+
{
|
145
|
+
/* Print an error and rollback the transaction. */
|
146
|
+
fprintf(stderr, "Error allocating the SQL statement.\n");
|
147
|
+
isc_rollback_transaction(status, &tr);
|
148
|
+
}
|
149
|
+
}
|
150
|
+
else
|
151
|
+
{
|
152
|
+
/* Print an error. */
|
153
|
+
fprintf(stderr, "Error starting a transaction.\n");
|
154
|
+
}
|
155
|
+
|
156
|
+
/* Close the database. */
|
157
|
+
isc_detach_database(status, &db);
|
158
|
+
printf("Database closed, program exiting.\n");
|
159
|
+
}
|
160
|
+
else
|
161
|
+
{
|
162
|
+
/* Print an error. */
|
163
|
+
fprintf(stderr, "Error connecting as %s/%s to the '%s' database.\n",
|
164
|
+
USERNAME, PASSWORD, DATABASE);
|
165
|
+
}
|
166
|
+
|
167
|
+
return(0);
|
168
|
+
}
|
169
|
+
|
170
|
+
|
171
|
+
void writeError(ISC_STATUS *status)
|
172
|
+
{
|
173
|
+
if(status != NULL && (status[0] == 1 && status[1] != 0))
|
174
|
+
{
|
175
|
+
char text[1024];
|
176
|
+
ISC_STATUS local[20];
|
177
|
+
long code = 0;
|
178
|
+
|
179
|
+
while(isc_interprete(text, &status))
|
180
|
+
{
|
181
|
+
fprintf(stderr, "%s\n", text);
|
182
|
+
}
|
183
|
+
code = isc_sqlcode(local);
|
184
|
+
isc_sql_interprete(code, text, 1024);
|
185
|
+
fprintf(stderr, "%s\n", text);
|
186
|
+
}
|
187
|
+
else
|
188
|
+
{
|
189
|
+
/* Write a simple message. */
|
190
|
+
printf("No error details available.\n");
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
|
195
|
+
void prepareXSQLDA(XSQLDA *da)
|
196
|
+
{
|
197
|
+
XSQLVAR *var = da->sqlvar;
|
198
|
+
int error = 0,
|
199
|
+
offset = 0,
|
200
|
+
length = 0,
|
201
|
+
align = 0;
|
202
|
+
short i;
|
203
|
+
|
204
|
+
buffer = (long *)malloc(sizeof(long) * calculateSize(da));
|
205
|
+
printf("Received %p for preparation.\n", da);
|
206
|
+
for(i = 0; i < da->sqln && error == 0; i++, var++)
|
207
|
+
{
|
208
|
+
int type = (var->sqltype & ~1);
|
209
|
+
|
210
|
+
length = align = var->sqllen;
|
211
|
+
switch(type)
|
212
|
+
{
|
213
|
+
case SQL_TEXT : /* Type: CHAR */
|
214
|
+
printf("Allocating memory for a CHAR (%d chars).\n", var->sqllen);
|
215
|
+
align = 1;
|
216
|
+
break;
|
217
|
+
|
218
|
+
case SQL_VARYING :
|
219
|
+
printf("Allocating memory for a VARCHAR (%d chars).\n", var->sqllen);
|
220
|
+
length += sizeof(short) + 1;
|
221
|
+
align = sizeof(short);
|
222
|
+
break;
|
223
|
+
} /* End of switch. */
|
224
|
+
|
225
|
+
/* Assign data pointers, correcting for alignment. */
|
226
|
+
offset = FB_ALIGN(offset, align);
|
227
|
+
var->sqldata = (char *)buffer + offset;
|
228
|
+
offset += length;
|
229
|
+
offset = FB_ALIGN(offset, sizeof(short));
|
230
|
+
var->sqlind = (short *)((char *)buffer + offset);
|
231
|
+
offset += sizeof(short);
|
232
|
+
} /* End of for loop. */
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
unsigned int calculateSize(XSQLDA *da)
|
237
|
+
{
|
238
|
+
unsigned int size = 0;
|
239
|
+
long total = 0;
|
240
|
+
int align,
|
241
|
+
length,
|
242
|
+
i;
|
243
|
+
XSQLVAR *var = da->sqlvar;
|
244
|
+
|
245
|
+
for(i = 0; i < da->sqln; i++, var++)
|
246
|
+
{
|
247
|
+
int type = (var->sqltype & ~1);
|
248
|
+
|
249
|
+
align = var->sqllen;
|
250
|
+
switch(type)
|
251
|
+
{
|
252
|
+
case SQL_TEXT :
|
253
|
+
align = 1;
|
254
|
+
break;
|
255
|
+
|
256
|
+
case SQL_VARYING :
|
257
|
+
align = sizeof(short);
|
258
|
+
length = var->sqllen + sizeof(short) + 1;
|
259
|
+
break;
|
260
|
+
|
261
|
+
default :
|
262
|
+
length = var->sqllen;
|
263
|
+
}
|
264
|
+
total = FB_ALIGN(total, align);
|
265
|
+
total += length;
|
266
|
+
total = FB_ALIGN(total, sizeof(short));
|
267
|
+
total += sizeof(short);
|
268
|
+
}
|
269
|
+
|
270
|
+
size = (unsigned int)(total / sizeof(long));
|
271
|
+
if(total % sizeof(long) > 0)
|
272
|
+
{
|
273
|
+
size++;
|
274
|
+
}
|
275
|
+
|
276
|
+
printf("%d bytes (%d longs) required for storage.\n", total, size);
|
277
|
+
buffer_size = size;
|
278
|
+
return(size);
|
279
|
+
}
|
280
|
+
|
281
|
+
|
282
|
+
void writeBuffer(void *buffer, unsigned int length)
|
283
|
+
{
|
284
|
+
char *offset = (char *)buffer;
|
285
|
+
unsigned int i;
|
286
|
+
|
287
|
+
for(i = 0; i < length; i++, offset++)
|
288
|
+
{
|
289
|
+
if(*offset < 32)
|
290
|
+
printf(".");
|
291
|
+
else
|
292
|
+
printf("%c", *offset);
|
293
|
+
if(i % 50 == 0)
|
294
|
+
printf("\n");
|
295
|
+
}
|
296
|
+
printf("\n");
|
297
|
+
}
|
data/test/mfb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gcc -g -o fb fb.c -framework Firebird -I/Library/Frameworks/Firebird.framework/Headers
|
Binary file
|
data/test/test.fdb
ADDED
Binary file
|