ruby-odbc-supported 1.0.0
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.
- checksums.yaml +7 -0
- data/COPYING +53 -0
- data/ChangeLog +369 -0
- data/GPL +340 -0
- data/MANIFEST +23 -0
- data/README.rdoc +133 -0
- data/Rakefile +32 -0
- data/doc/odbc.html +1346 -0
- data/ext/extconf.rb +127 -0
- data/ext/init.c +197 -0
- data/ext/odbc.c +8603 -0
- data/ext/utf8/extconf.rb +156 -0
- data/ext/utf8/init.c +12 -0
- data/ext/utf8/odbc.c +17 -0
- data/lib/cqgen.rb +561 -0
- data/ruby-odbc-supported.gemspec +16 -0
- data/test/00connect.rb +1 -0
- data/test/10create_table.rb +1 -0
- data/test/20insert.rb +6 -0
- data/test/30select.rb +69 -0
- data/test/40update.rb +4 -0
- data/test/50drop_table.rb +3 -0
- data/test/70close.rb +1 -0
- data/test/test.rb +32 -0
- data/test/utf8/test.rb +32 -0
- metadata +72 -0
data/ext/extconf.rb
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
require 'mkmf'
|
|
2
|
+
|
|
3
|
+
if ! defined? PLATFORM
|
|
4
|
+
PLATFORM = RUBY_PLATFORM
|
|
5
|
+
end
|
|
6
|
+
# 2.0+
|
|
7
|
+
#adding this for backward compatible
|
|
8
|
+
have_header('ruby/thread.h') && have_func('rb_thread_call_without_gvl', 'ruby/thread.h')
|
|
9
|
+
# 1.9-only
|
|
10
|
+
have_func('rb_thread_blocking_region')
|
|
11
|
+
|
|
12
|
+
def have_library_ex(lib, func="main", headers=nil)
|
|
13
|
+
checking_for "#{func}() in -l#{lib}" do
|
|
14
|
+
libs = append_library($libs, lib)
|
|
15
|
+
if !func.nil? && !func.empty? && COMMON_LIBS.include?(lib)
|
|
16
|
+
true
|
|
17
|
+
elsif try_func(func, libs, headers)
|
|
18
|
+
$libs = libs
|
|
19
|
+
true
|
|
20
|
+
else
|
|
21
|
+
false
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
dir_config("odbc")
|
|
27
|
+
have_header("version.h")
|
|
28
|
+
have_header("sql.h") || begin
|
|
29
|
+
puts "ERROR: sql.h not found"
|
|
30
|
+
exit 1
|
|
31
|
+
end
|
|
32
|
+
have_header("sqlext.h") || begin
|
|
33
|
+
puts "ERROR: sqlext.h not found"
|
|
34
|
+
exit 1
|
|
35
|
+
end
|
|
36
|
+
testdlopen = enable_config("dlopen", false)
|
|
37
|
+
begin
|
|
38
|
+
if PLATFORM !~ /(mingw|cygwin)/ then
|
|
39
|
+
header = "sqltypes.h"
|
|
40
|
+
else
|
|
41
|
+
header = ["windows.h", "sqltypes.h"]
|
|
42
|
+
end
|
|
43
|
+
if defined? have_type
|
|
44
|
+
have_type("SQLTCHAR", header)
|
|
45
|
+
else
|
|
46
|
+
throw
|
|
47
|
+
end
|
|
48
|
+
rescue
|
|
49
|
+
puts "WARNING: please check sqltypes.h for SQLTCHAR manually,"
|
|
50
|
+
puts "WARNING: if defined, modify CFLAGS in Makefile to contain"
|
|
51
|
+
puts "WARNING: the option -DHAVE_TYPE_SQLTCHAR"
|
|
52
|
+
end
|
|
53
|
+
begin
|
|
54
|
+
if PLATFORM !~ /(mingw|cygwin)/ then
|
|
55
|
+
header = "sqltypes.h"
|
|
56
|
+
else
|
|
57
|
+
header = ["windows.h", "sqltypes.h"]
|
|
58
|
+
end
|
|
59
|
+
if defined? have_type
|
|
60
|
+
have_type("SQLLEN", header)
|
|
61
|
+
else
|
|
62
|
+
throw
|
|
63
|
+
end
|
|
64
|
+
rescue
|
|
65
|
+
puts "WARNING: please check sqltypes.h for SQLLEN manually,"
|
|
66
|
+
puts "WARNING: if defined, modify CFLAGS in Makefile to contain"
|
|
67
|
+
puts "WARNING: the option -DHAVE_TYPE_SQLLEN"
|
|
68
|
+
end
|
|
69
|
+
begin
|
|
70
|
+
if PLATFORM !~ /(mingw|cygwin)/ then
|
|
71
|
+
header = "sqltypes.h"
|
|
72
|
+
else
|
|
73
|
+
header = ["windows.h", "sqltypes.h"]
|
|
74
|
+
end
|
|
75
|
+
if defined? have_type
|
|
76
|
+
have_type("SQLULEN", header)
|
|
77
|
+
else
|
|
78
|
+
throw
|
|
79
|
+
end
|
|
80
|
+
rescue
|
|
81
|
+
puts "WARNING: please check sqltypes.h for SQLULEN manually,"
|
|
82
|
+
puts "WARNING: if defined, modify CFLAGS in Makefile to contain"
|
|
83
|
+
puts "WARNING: the option -DHAVE_TYPE_SQLULEN"
|
|
84
|
+
end
|
|
85
|
+
$have_odbcinst_h = have_header("odbcinst.h")
|
|
86
|
+
|
|
87
|
+
if PLATFORM =~ /mswin32/ then
|
|
88
|
+
if !have_library_ex("odbc32", "SQLAllocConnect", "sql.h") ||
|
|
89
|
+
!have_library_ex("odbccp32", "SQLConfigDataSource", "odbcinst.h") ||
|
|
90
|
+
!have_library_ex("odbccp32", "SQLInstallerError", "odbcinst.h") ||
|
|
91
|
+
!have_library("user32", "CharUpper") then
|
|
92
|
+
puts "Can not locate odbc libraries"
|
|
93
|
+
exit 1
|
|
94
|
+
end
|
|
95
|
+
have_func("SQLInstallerError", "odbcinst.h")
|
|
96
|
+
# mingw untested !!!
|
|
97
|
+
elsif PLATFORM =~ /(mingw|cygwin)/ then
|
|
98
|
+
have_library("odbc32")
|
|
99
|
+
have_library("odbccp32")
|
|
100
|
+
have_library("user32")
|
|
101
|
+
elsif (testdlopen && PLATFORM !~ /(macos|darwin)/ && CONFIG["CC"] =~ /gcc/ && have_func("dlopen", "dlfcn.h") && have_library("dl", "dlopen")) then
|
|
102
|
+
$LDFLAGS+=" -Wl,-init -Wl,ruby_odbc_init -Wl,-fini -Wl,ruby_odbc_fini"
|
|
103
|
+
$CPPFLAGS+=" -DHAVE_SQLCONFIGDATASOURCE"
|
|
104
|
+
$CPPFLAGS+=" -DHAVE_SQLINSTALLERERROR"
|
|
105
|
+
$CPPFLAGS+=" -DUSE_DLOPEN_FOR_ODBC_LIBS"
|
|
106
|
+
if defined? have_type then
|
|
107
|
+
if have_type("SQLBIGINT", "sqltypes.h", "-DHAVE_LONG_LONG") then
|
|
108
|
+
$CPPFLAGS+=" -DHAVE_LONG_LONG"
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
else
|
|
112
|
+
have_library("odbc", "SQLAllocConnect") ||
|
|
113
|
+
have_library("iodbc", "SQLAllocConnect")
|
|
114
|
+
($have_odbcinst_h &&
|
|
115
|
+
have_library("odbcinst", "SQLConfigDataSource")) ||
|
|
116
|
+
($have_odbcinst_h &&
|
|
117
|
+
have_library("iodbcinst", "SQLConfigDataSource"))
|
|
118
|
+
$have_odbcinst_h &&
|
|
119
|
+
have_func("SQLInstallerError", "odbcinst.h")
|
|
120
|
+
if defined? have_type then
|
|
121
|
+
if have_type("SQLBIGINT", "sqltypes.h", "-DHAVE_LONG_LONG") then
|
|
122
|
+
$CPPFLAGS+=" -DHAVE_LONG_LONG"
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
create_makefile("odbc")
|
data/ext/init.c
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Part of ODBC-Ruby binding
|
|
3
|
+
* Copyright (c) 2006-2007 Christian Werner <chw@ch-werner.de>
|
|
4
|
+
*
|
|
5
|
+
* See the file "COPYING" for information on usage
|
|
6
|
+
* and redistribution of this file and for a
|
|
7
|
+
* DISCLAIMER OF ALL WARRANTIES.
|
|
8
|
+
*
|
|
9
|
+
* $Id: init.c,v 1.6 2007/04/07 09:39:08 chw Exp chw $
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
#include "ruby.h"
|
|
13
|
+
|
|
14
|
+
#ifdef USE_DLOPEN_FOR_ODBC_LIBS
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* This module acts as a drop-in replacement for linking with
|
|
18
|
+
* "-lodbc -lodbcinst" or "-liodbc -liodbcinst" when dlopen()
|
|
19
|
+
* is supported.
|
|
20
|
+
*
|
|
21
|
+
* Setting the environment variable RUBY_ODBC_DM can be used
|
|
22
|
+
* to force loading a specific driver manager shared library.
|
|
23
|
+
* Same logic is used with RUBY_ODBC_INST for the ODBC installer
|
|
24
|
+
* shared library.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
#include <dlfcn.h>
|
|
28
|
+
|
|
29
|
+
/* Create weak alias and function declarations. */
|
|
30
|
+
|
|
31
|
+
#define WEAKFUNC(name) \
|
|
32
|
+
int __attribute__((weak, alias("__"#name))) name (void); \
|
|
33
|
+
static int __attribute__((unused)) __ ## name (void) \
|
|
34
|
+
{ return -1; /* == SQL_ERROR */ }
|
|
35
|
+
|
|
36
|
+
#define WEAKFUNC_BOOL(name) \
|
|
37
|
+
int __attribute__((weak, alias("__"#name))) name (void); \
|
|
38
|
+
static int __attribute__((unused)) __ ## name (void) \
|
|
39
|
+
{ return 0; /* == BOOL/FALSE */ }
|
|
40
|
+
|
|
41
|
+
WEAKFUNC(SQLAllocConnect)
|
|
42
|
+
WEAKFUNC(SQLAllocEnv)
|
|
43
|
+
WEAKFUNC(SQLAllocStmt)
|
|
44
|
+
WEAKFUNC(SQLBindParameter)
|
|
45
|
+
WEAKFUNC(SQLCancel)
|
|
46
|
+
WEAKFUNC(SQLDescribeParam)
|
|
47
|
+
WEAKFUNC(SQLDisconnect)
|
|
48
|
+
WEAKFUNC(SQLExecute)
|
|
49
|
+
WEAKFUNC(SQLFetch)
|
|
50
|
+
WEAKFUNC(SQLFetchScroll)
|
|
51
|
+
WEAKFUNC(SQLFreeConnect)
|
|
52
|
+
WEAKFUNC(SQLFreeEnv)
|
|
53
|
+
WEAKFUNC(SQLFreeStmt)
|
|
54
|
+
WEAKFUNC(SQLGetData)
|
|
55
|
+
WEAKFUNC(SQLGetEnvAttr)
|
|
56
|
+
WEAKFUNC(SQLGetStmtOption)
|
|
57
|
+
WEAKFUNC(SQLMoreResults)
|
|
58
|
+
WEAKFUNC(SQLNumParams)
|
|
59
|
+
WEAKFUNC(SQLNumResultCols)
|
|
60
|
+
WEAKFUNC(SQLRowCount)
|
|
61
|
+
WEAKFUNC(SQLSetEnvAttr)
|
|
62
|
+
WEAKFUNC(SQLSetStmtOption)
|
|
63
|
+
WEAKFUNC(SQLTransact)
|
|
64
|
+
WEAKFUNC(SQLEndTran)
|
|
65
|
+
|
|
66
|
+
WEAKFUNC(SQLColAttributes)
|
|
67
|
+
WEAKFUNC(SQLColAttributesW)
|
|
68
|
+
WEAKFUNC(SQLColumns)
|
|
69
|
+
WEAKFUNC(SQLColumnsW)
|
|
70
|
+
WEAKFUNC(SQLConnect)
|
|
71
|
+
WEAKFUNC(SQLConnectW)
|
|
72
|
+
WEAKFUNC(SQLDataSources)
|
|
73
|
+
WEAKFUNC(SQLDataSourcesW)
|
|
74
|
+
WEAKFUNC(SQLDriverConnect)
|
|
75
|
+
WEAKFUNC(SQLDriverConnectW)
|
|
76
|
+
WEAKFUNC(SQLDrivers)
|
|
77
|
+
WEAKFUNC(SQLDriversW)
|
|
78
|
+
WEAKFUNC(SQLError)
|
|
79
|
+
WEAKFUNC(SQLErrorW)
|
|
80
|
+
WEAKFUNC(SQLExecDirect)
|
|
81
|
+
WEAKFUNC(SQLExecDirectW)
|
|
82
|
+
WEAKFUNC(SQLForeignKeys)
|
|
83
|
+
WEAKFUNC(SQLForeignKeysW)
|
|
84
|
+
WEAKFUNC(SQLGetConnectOption)
|
|
85
|
+
WEAKFUNC(SQLGetConnectOptionW)
|
|
86
|
+
WEAKFUNC(SQLGetCursorName)
|
|
87
|
+
WEAKFUNC(SQLGetCursorNameW)
|
|
88
|
+
WEAKFUNC(SQLGetInfo)
|
|
89
|
+
WEAKFUNC(SQLGetInfoW)
|
|
90
|
+
WEAKFUNC(SQLGetTypeInfo)
|
|
91
|
+
WEAKFUNC(SQLGetTypeInfoW)
|
|
92
|
+
WEAKFUNC(SQLPrepare)
|
|
93
|
+
WEAKFUNC(SQLPrepareW)
|
|
94
|
+
WEAKFUNC(SQLPrimaryKeys)
|
|
95
|
+
WEAKFUNC(SQLPrimaryKeysW)
|
|
96
|
+
WEAKFUNC(SQLProcedureColumns)
|
|
97
|
+
WEAKFUNC(SQLProcedureColumnsW)
|
|
98
|
+
WEAKFUNC(SQLProcedures)
|
|
99
|
+
WEAKFUNC(SQLProceduresW)
|
|
100
|
+
WEAKFUNC(SQLSetConnectOption)
|
|
101
|
+
WEAKFUNC(SQLSetConnectOptionW)
|
|
102
|
+
WEAKFUNC(SQLSetCursorName)
|
|
103
|
+
WEAKFUNC(SQLSetCursorNameW)
|
|
104
|
+
WEAKFUNC(SQLSpecialColumns)
|
|
105
|
+
WEAKFUNC(SQLSpecialColumnsW)
|
|
106
|
+
WEAKFUNC(SQLStatistics)
|
|
107
|
+
WEAKFUNC(SQLStatisticsW)
|
|
108
|
+
WEAKFUNC(SQLTablePrivileges)
|
|
109
|
+
WEAKFUNC(SQLTablePrivilegesW)
|
|
110
|
+
WEAKFUNC(SQLTables)
|
|
111
|
+
WEAKFUNC(SQLTablesW)
|
|
112
|
+
WEAKFUNC(SQLInstallerError)
|
|
113
|
+
WEAKFUNC(SQLInstallerErrorW)
|
|
114
|
+
|
|
115
|
+
WEAKFUNC_BOOL(SQLConfigDataSource)
|
|
116
|
+
WEAKFUNC_BOOL(SQLConfigDataSourceW)
|
|
117
|
+
WEAKFUNC_BOOL(SQLReadFileDSN)
|
|
118
|
+
WEAKFUNC_BOOL(SQLReadFileDSNW)
|
|
119
|
+
WEAKFUNC_BOOL(SQLWriteFileDSN)
|
|
120
|
+
WEAKFUNC_BOOL(SQLWriteFileDSNW)
|
|
121
|
+
|
|
122
|
+
/* Library initializer and finalizer. */
|
|
123
|
+
|
|
124
|
+
static void *lib_odbc = 0;
|
|
125
|
+
static void *lib_odbcinst = 0;
|
|
126
|
+
|
|
127
|
+
#define warn(msg) fputs(msg, stderr)
|
|
128
|
+
|
|
129
|
+
void
|
|
130
|
+
ruby_odbc_init()
|
|
131
|
+
{
|
|
132
|
+
int useiodbc = 0;
|
|
133
|
+
char *dm_name = getenv("RUBY_ODBC_DM");
|
|
134
|
+
char *inst_name = getenv("RUBY_ODBC_INST");
|
|
135
|
+
|
|
136
|
+
if (dm_name) {
|
|
137
|
+
lib_odbc = dlopen(dm_name, RTLD_NOW | RTLD_GLOBAL);
|
|
138
|
+
if (!lib_odbc) {
|
|
139
|
+
warn("WARNING: $RUBY_ODBC_DM not loaded.\n");
|
|
140
|
+
} else {
|
|
141
|
+
if (inst_name) {
|
|
142
|
+
lib_odbcinst = dlopen(inst_name, RTLD_NOW | RTLD_GLOBAL);
|
|
143
|
+
}
|
|
144
|
+
if (!lib_odbcinst) {
|
|
145
|
+
warn("WARNING: $RUBY_ODBC_INST not loaded.\n");
|
|
146
|
+
}
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
lib_odbc = dlopen("libodbc" DLEXT ".1", RTLD_NOW | RTLD_GLOBAL);
|
|
151
|
+
if (!lib_odbc) {
|
|
152
|
+
lib_odbc = dlopen("libodbc" DLEXT, RTLD_NOW | RTLD_GLOBAL);
|
|
153
|
+
}
|
|
154
|
+
if (!lib_odbc) {
|
|
155
|
+
lib_odbc = dlopen("libiodbc" DLEXT ".2", RTLD_NOW | RTLD_GLOBAL);
|
|
156
|
+
if (!lib_odbc) {
|
|
157
|
+
lib_odbc = dlopen("libiodbc" DLEXT, RTLD_NOW | RTLD_GLOBAL);
|
|
158
|
+
}
|
|
159
|
+
if (!lib_odbc) {
|
|
160
|
+
warn("WARNING: no ODBC driver manager found.\n");
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
useiodbc = 1;
|
|
164
|
+
}
|
|
165
|
+
lib_odbcinst = dlopen(useiodbc ?
|
|
166
|
+
"libiodbcinst" DLEXT ".2" : "libodbcinst" DLEXT ".1",
|
|
167
|
+
RTLD_NOW | RTLD_GLOBAL);
|
|
168
|
+
if (!lib_odbcinst) {
|
|
169
|
+
lib_odbcinst = dlopen(useiodbc ?
|
|
170
|
+
"libiodbcinst" DLEXT : "libodbcinst" DLEXT,
|
|
171
|
+
RTLD_NOW | RTLD_GLOBAL);
|
|
172
|
+
}
|
|
173
|
+
if (!lib_odbcinst) {
|
|
174
|
+
warn("WARNING: no ODBC installer library found.\n");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
void
|
|
179
|
+
ruby_odbc_fini()
|
|
180
|
+
{
|
|
181
|
+
if (lib_odbcinst) {
|
|
182
|
+
dlclose(lib_odbcinst);
|
|
183
|
+
lib_odbcinst = 0;
|
|
184
|
+
}
|
|
185
|
+
if (lib_odbc) {
|
|
186
|
+
dlclose(lib_odbc);
|
|
187
|
+
lib_odbc = 0;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
int
|
|
192
|
+
ruby_odbc_have_func(char *name, void *addr)
|
|
193
|
+
{
|
|
194
|
+
return name && addr && (dlsym(NULL, name) != addr);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
#endif
|