sqlanywhere 0.1.0-i486-linux → 0.1.1-i486-linux
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -1
- data/README +5 -1
- data/Rakefile +202 -0
- data/ext/Makefile +149 -0
- data/ext/extconf.rb +30 -0
- data/ext/sacapi.h +679 -0
- data/ext/sacapidll.c +162 -0
- data/ext/sacapidll.h +253 -0
- data/ext/sacapidll.o +0 -0
- data/ext/sqlanywhere.c +200 -176
- data/ext/sqlanywhere.o +0 -0
- data/ext/sqlanywhere.so +0 -0
- data/lib/sqlanywhere.so +0 -0
- data/test/sqlanywhere_test.rb +1 -0
- metadata +14 -5
data/CHANGELOG
CHANGED
@@ -1,7 +1,16 @@
|
|
1
1
|
=CHANGE LOG
|
2
2
|
|
3
|
+
=====0.1.1 -- 2008/11/06
|
4
|
+
- Created a source gem rake task
|
5
|
+
- Created a 'hint' file if the source gem is used directly
|
6
|
+
- Changed file permissions on archives
|
7
|
+
- Changed archives to be specific to platform (.zip on windows, .tar.gz
|
8
|
+
otherwise)
|
9
|
+
- Changed default rake task to only build library, not gem
|
10
|
+
- Added a gem rake task
|
11
|
+
|
3
12
|
=====0.1.0 -- 2008/10/15
|
4
13
|
- Initial Release
|
5
|
-
- Wraps DBCAPI
|
14
|
+
- Wraps DBCAPI functionality
|
6
15
|
- Includes a simple unit test suite
|
7
16
|
|
data/README
CHANGED
@@ -19,9 +19,13 @@ This driver is licensed under the Apache License, Version 2.
|
|
19
19
|
|
20
20
|
===All Platforms
|
21
21
|
|
22
|
-
To build
|
22
|
+
To build the library (.so), use:
|
23
23
|
|
24
24
|
rake
|
25
|
+
|
26
|
+
To build and install the gem, use:
|
27
|
+
|
28
|
+
rake gem
|
25
29
|
rake install
|
26
30
|
|
27
31
|
The other rake tasks are
|
data/Rakefile
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
#====================================================
|
2
|
+
#
|
3
|
+
# Copyright 2008 iAnywhere Solutions, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
#
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
# While not a requirement of the license, if you do modify this file, we
|
20
|
+
# would appreciate hearing about it. Please email sqlany_interfaces@sybase.com
|
21
|
+
#
|
22
|
+
#
|
23
|
+
#====================================================
|
24
|
+
|
25
|
+
require 'ftools'
|
26
|
+
require 'rbconfig'
|
27
|
+
require 'rake/clean'
|
28
|
+
require 'rake/rdoctask'
|
29
|
+
require 'rubygems'
|
30
|
+
require 'rubygems/builder'
|
31
|
+
|
32
|
+
# By default, windows will try to use nmake instead of make. If you are on windows but using
|
33
|
+
# a different compiler that uses standard make, set this to false.
|
34
|
+
USE_NMAKE_ON_WIN = true
|
35
|
+
|
36
|
+
# By default on windows, ruby expects to be compiled by Visual Studio C++ 6.0. If you are using
|
37
|
+
# a newer version of Visual Studio, you will need to apply a manifest to the dll. To apply the
|
38
|
+
# manifest set this to true.
|
39
|
+
APPLY_MANIFEST = false
|
40
|
+
|
41
|
+
PACKAGE_NAME = "sqlanywhere"
|
42
|
+
ARCH=Config::CONFIG['arch']
|
43
|
+
|
44
|
+
pkg_version = ""
|
45
|
+
|
46
|
+
# The package version of determined by parsing the c source file. This ensures the version is
|
47
|
+
# only ever specified ins a single place.
|
48
|
+
File.open(File.join("ext", "sqlanywhere.c") ) do |f|
|
49
|
+
f.grep( /const char\* VERSION/ ) do |line|
|
50
|
+
pkg_version = /\s*const char\* VERSION\s*=\s*["|']([^"']*)["|'];\s*/.match(line)[1]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# If we can't determine the version, throw up your hands and exit
|
55
|
+
raise RuntimeError, "Could not determine current package version!" if pkg_version.empty?
|
56
|
+
|
57
|
+
# The hint file will be automatically added to a souce_gem builds. If someone installs the source gem and
|
58
|
+
# tries to run it, they will get a LoadError telling them that they must compile the software. This file
|
59
|
+
# ONLY exists in a source gem
|
60
|
+
hint_file = "raise LoadError, \"You need to compile the sqlanywhere package for this particular platform. To compile the package, change to the sqlanywhere package directory and run rake:\n cd $GEM_HOME/sqlanywhere-#{pkg_version}\n rake\nFor more information on compiling, please read $GEM_HOME/sqlanywhere-#{pkg_version}/README\""
|
61
|
+
|
62
|
+
MAKE = (ARCH =~ /win32/ and USE_NMAKE_ON_WIN) ? 'nmake' : 'make'
|
63
|
+
|
64
|
+
spec = Gem::Specification.new do |spec|
|
65
|
+
spec.authors = ["Eric Farrar"]
|
66
|
+
spec.email = 'eric.farrar@ianywhere.com'
|
67
|
+
spec.name = 'sqlanywhere'
|
68
|
+
spec.summary = 'SQL Anywhere library for Ruby'
|
69
|
+
spec.description = <<-EOF
|
70
|
+
SQL Anywhere Driver for Ruby
|
71
|
+
EOF
|
72
|
+
spec.version = pkg_version
|
73
|
+
spec.autorequire = 'sqlanywhere'
|
74
|
+
spec.has_rdoc = true
|
75
|
+
spec.rubyforge_project = 'sqlanywhere'
|
76
|
+
spec.homepage = 'http://sqlanywhere.rubyforge.org'
|
77
|
+
spec.platform = Gem::Platform::CURRENT
|
78
|
+
spec.required_ruby_version = '>= 1.8.6'
|
79
|
+
spec.require_paths = ['lib']
|
80
|
+
spec.test_file = 'test/sqlanywhere_test.rb'
|
81
|
+
spec.rdoc_options << '--title' << 'SQL Anywhere Ruby Driver' <<
|
82
|
+
'--main' << 'README' <<
|
83
|
+
'--line-numbers'
|
84
|
+
spec.extra_rdoc_files = ['README', 'CHANGELOG', 'LICENSE', 'ext/sqlanywhere.c']
|
85
|
+
end
|
86
|
+
|
87
|
+
# The default task is to build the library (.dll or .so)
|
88
|
+
desc "Build the library"
|
89
|
+
task :default => ["lib/sqlanywhere.so"]
|
90
|
+
|
91
|
+
# Builds the binary gem for this platform
|
92
|
+
desc "Build the gem"
|
93
|
+
task :gem => ["sqlanywhere-#{pkg_version}-#{spec.platform}.gem"]
|
94
|
+
|
95
|
+
file "sqlanywhere-#{pkg_version}-#{spec.platform}.gem" => ["Rakefile",
|
96
|
+
"test/test.sql",
|
97
|
+
"test/sqlanywhere_test.rb",
|
98
|
+
"README",
|
99
|
+
"CHANGELOG",
|
100
|
+
"LICENSE",
|
101
|
+
"lib/sqlanywhere.so"] do
|
102
|
+
# Get the updated list of files to include in the gem
|
103
|
+
spec.files = Dir['ext/**/*'] + Dir['lib/**/*'] + Dir['test/**/*'] + Dir['CHANGELOG'] + Dir['LICENSE'] + Dir['README'] + Dir['Rakefile']
|
104
|
+
# Set the gem to be platform specific since it includes compiled binaries
|
105
|
+
spec.platform = Gem::Platform::CURRENT
|
106
|
+
Gem::Builder.new(spec).build
|
107
|
+
end
|
108
|
+
|
109
|
+
# Builds the source gem for any platform
|
110
|
+
desc "Build the source gem"
|
111
|
+
task :source_gem => ["sqlanywhere-#{pkg_version}.gem"]
|
112
|
+
|
113
|
+
file "sqlanywhere-#{pkg_version}.gem" => ["Rakefile",
|
114
|
+
"test/test.sql",
|
115
|
+
"test/sqlanywhere_test.rb",
|
116
|
+
"README",
|
117
|
+
"CHANGELOG",
|
118
|
+
"LICENSE"] do
|
119
|
+
# Create the hint file in the lib directory
|
120
|
+
File.open(File.join("lib", "sqlanywhere.rb"), "w") do |f|
|
121
|
+
f.puts hint_file
|
122
|
+
end
|
123
|
+
# Get the updated list of files to include in the gem
|
124
|
+
spec.files = Dir['ext/**/*'] + Dir['lib/**/*'] + Dir['test/**/*'] + Dir['CHANGELOG'] + Dir['LICENSE'] + Dir['README'] + Dir['Rakefile']
|
125
|
+
# Since this contains no compilked binaries, set it to be platform RUBY
|
126
|
+
spec.platform = Gem::Platform::RUBY
|
127
|
+
Gem::Builder.new(spec).build
|
128
|
+
# Delete the hint file
|
129
|
+
File.unlink(File.join("lib", "sqlanywhere.rb"))
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
file "lib/sqlanywhere.so" => ["ext/sqlanywhere.so"] do
|
134
|
+
# If the hint file exists, delete it
|
135
|
+
File.unlink(File.join("lib", "sqlanywhere.rb")) if File.exists?(File.join("lib", "sqlanywhere.rb"))
|
136
|
+
File.copy(File.join("ext", "sqlanywhere.so"), "lib")
|
137
|
+
end
|
138
|
+
|
139
|
+
file "ext/sqlanywhere.so" => ["ext/sqlanywhere.c"] do
|
140
|
+
sh "cd ext && ruby extconf.rb"
|
141
|
+
sh "cd ext && #{MAKE}"
|
142
|
+
sh "cd ext && mt -outputresource:sqlanywhere.so;2 -manifest sqlanywhere.so.manifest" if APPLY_MANIFEST
|
143
|
+
end
|
144
|
+
|
145
|
+
desc "Install the gem"
|
146
|
+
task :install => [:gem] do
|
147
|
+
sh "gem install sqlanywhere-#{pkg_version}-#{spec.platform}.gem"
|
148
|
+
end
|
149
|
+
|
150
|
+
# This builds the distributables. On windows it builds a platform specific gem, a source gem, and a souce zip archive.
|
151
|
+
# On other platforms this builds a platform specific gem, a source gem, and a source tar.gz archive.
|
152
|
+
desc "Build distributables (src zip, src tar.gz, gem)"
|
153
|
+
task :dist do |t|
|
154
|
+
puts "Cleaning Build Environment..."
|
155
|
+
Rake.application['clobber'].invoke
|
156
|
+
|
157
|
+
files = Dir.glob('*')
|
158
|
+
|
159
|
+
puts "Creating #{File.join('build', PACKAGE_NAME)}-#{pkg_version} directory..."
|
160
|
+
FileUtils.mkdir_p "#{File.join('build', PACKAGE_NAME)}-#{pkg_version}"
|
161
|
+
|
162
|
+
puts "Copying files to #{File.join('build', PACKAGE_NAME)}-#{pkg_version}..."
|
163
|
+
FileUtils.cp_r files, "#{File.join('build', PACKAGE_NAME)}-#{pkg_version}"
|
164
|
+
|
165
|
+
if( ARCH =~ /win32/ ) then
|
166
|
+
system "attrib -R #{File.join('build', PACKAGE_NAME)}-#{pkg_version} /S"
|
167
|
+
else
|
168
|
+
system "find #{File.join('build', PACKAGE_NAME)}-#{pkg_version} -type d -exec chmod 755 {} \\;"
|
169
|
+
system "find #{File.join('build', PACKAGE_NAME)}-#{pkg_version} -type f -exec chmod 644 {} \\;"
|
170
|
+
end
|
171
|
+
|
172
|
+
if( ARCH =~ /win32/ ) then
|
173
|
+
puts "Creating #{File.join('build', PACKAGE_NAME)}-#{pkg_version}.zip..."
|
174
|
+
system "cd build && zip -q -r #{PACKAGE_NAME}-#{pkg_version}.zip #{PACKAGE_NAME}-#{pkg_version}"
|
175
|
+
else
|
176
|
+
puts "Creating #{File.join('build', PACKAGE_NAME)}-#{pkg_version}.tar..."
|
177
|
+
system "tar cf #{File.join('build', PACKAGE_NAME)}-#{pkg_version}.tar -C build #{PACKAGE_NAME}-#{pkg_version}"
|
178
|
+
|
179
|
+
puts "GZipping to create #{File.join('build', PACKAGE_NAME, PACKAGE_NAME)}-#{pkg_version}.tar.gz..."
|
180
|
+
system "gzip #{File.join('build', PACKAGE_NAME)}-#{pkg_version}.tar"
|
181
|
+
end
|
182
|
+
|
183
|
+
puts "Building GEM source distributable..."
|
184
|
+
Rake.application['source_gem'].invoke
|
185
|
+
|
186
|
+
puts "Copying source GEM to #{File.join('build', PACKAGE_NAME)}-#{pkg_version}.gem..."
|
187
|
+
FileUtils.cp "#{PACKAGE_NAME}-#{pkg_version}.gem", "build"
|
188
|
+
|
189
|
+
puts "Building GEM binary distributable..."
|
190
|
+
Rake.application['gem'].invoke
|
191
|
+
|
192
|
+
puts "Copying binary GEM to #{File.join('build', PACKAGE_NAME)}-#{pkg_version}-#{spec.platform}.gem..."
|
193
|
+
FileUtils.cp "#{PACKAGE_NAME}-#{pkg_version}-#{spec.platform}.gem", "build"
|
194
|
+
end
|
195
|
+
|
196
|
+
Rake::RDocTask.new do |rd|
|
197
|
+
rd.title = "SQL Anywhere Ruby Driver"
|
198
|
+
rd.main = "README"
|
199
|
+
rd.rdoc_files.include('README', 'CHANGELOG', 'LICENSE', 'ext/sqlanywhere.c')
|
200
|
+
end
|
201
|
+
|
202
|
+
CLOBBER.include("sqlanywhere-#{pkg_version}-#{spec.platform}.gem", "sqlanywhere-#{pkg_version}.gem", "lib/*", "ext/*.obj", "ext/*.def", "ext/*.so", "ext/*.log", "ext/*.exp", "ext/*.lib", "ext/*.pdb", "ext/Makefile", "ext/*.so.manifest", "ext/*.o", "build/**/*", "build")
|
data/ext/Makefile
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
#### Start of system configuration section. ####
|
5
|
+
|
6
|
+
srcdir = .
|
7
|
+
topdir = /usr/lib/ruby/1.8/i486-linux
|
8
|
+
hdrdir = $(topdir)
|
9
|
+
VPATH = $(srcdir):$(topdir):$(hdrdir)
|
10
|
+
prefix = $(DESTDIR)/usr
|
11
|
+
exec_prefix = $(prefix)
|
12
|
+
sitedir = $(DESTDIR)/usr/local/lib/site_ruby
|
13
|
+
rubylibdir = $(libdir)/ruby/$(ruby_version)
|
14
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
15
|
+
dvidir = $(docdir)
|
16
|
+
datarootdir = $(prefix)/share
|
17
|
+
archdir = $(rubylibdir)/$(arch)
|
18
|
+
sbindir = $(exec_prefix)/sbin
|
19
|
+
psdir = $(docdir)
|
20
|
+
localedir = $(datarootdir)/locale
|
21
|
+
htmldir = $(docdir)
|
22
|
+
datadir = $(datarootdir)
|
23
|
+
includedir = $(prefix)/include
|
24
|
+
infodir = $(prefix)/share/info
|
25
|
+
sysconfdir = $(DESTDIR)/etc
|
26
|
+
mandir = $(prefix)/share/man
|
27
|
+
libdir = $(exec_prefix)/lib
|
28
|
+
sharedstatedir = $(prefix)/com
|
29
|
+
oldincludedir = $(DESTDIR)/usr/include
|
30
|
+
pdfdir = $(docdir)
|
31
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
32
|
+
bindir = $(exec_prefix)/bin
|
33
|
+
localstatedir = $(DESTDIR)/var
|
34
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
35
|
+
libexecdir = $(prefix)/lib/ruby1.8
|
36
|
+
|
37
|
+
CC = cc
|
38
|
+
LIBRUBY = $(LIBRUBY_SO)
|
39
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
40
|
+
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
|
41
|
+
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
42
|
+
|
43
|
+
RUBY_EXTCONF_H =
|
44
|
+
CFLAGS = -fPIC -fno-strict-aliasing -g -O2 -fPIC
|
45
|
+
INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
|
46
|
+
CPPFLAGS =
|
47
|
+
CXXFLAGS = $(CFLAGS)
|
48
|
+
DLDFLAGS = -L. -rdynamic -Wl,-export-dynamic
|
49
|
+
LDSHARED = $(CC) -shared
|
50
|
+
AR = ar
|
51
|
+
EXEEXT =
|
52
|
+
|
53
|
+
RUBY_INSTALL_NAME = ruby1.8
|
54
|
+
RUBY_SO_NAME = ruby1.8
|
55
|
+
arch = i486-linux
|
56
|
+
sitearch = i486-linux
|
57
|
+
ruby_version = 1.8
|
58
|
+
ruby = /usr/bin/ruby1.8
|
59
|
+
RUBY = $(ruby)
|
60
|
+
RM = rm -f
|
61
|
+
MAKEDIRS = mkdir -p
|
62
|
+
INSTALL = /usr/bin/install -c
|
63
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
64
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
65
|
+
COPY = cp
|
66
|
+
|
67
|
+
#### End of system configuration section. ####
|
68
|
+
|
69
|
+
preload =
|
70
|
+
|
71
|
+
libpath = . $(libdir)
|
72
|
+
LIBPATH = -L"." -L"$(libdir)"
|
73
|
+
DEFFILE =
|
74
|
+
|
75
|
+
CLEANFILES =
|
76
|
+
DISTCLEANFILES =
|
77
|
+
|
78
|
+
extout =
|
79
|
+
extout_prefix =
|
80
|
+
target_prefix =
|
81
|
+
LOCAL_LIBS =
|
82
|
+
LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl -lcrypt -lm -lc
|
83
|
+
SRCS = sacapidll.c sqlanywhere.c
|
84
|
+
OBJS = sacapidll.o sqlanywhere.o
|
85
|
+
TARGET = sqlanywhere
|
86
|
+
DLLIB = $(TARGET).so
|
87
|
+
EXTSTATIC =
|
88
|
+
STATIC_LIB =
|
89
|
+
|
90
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
91
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
92
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
93
|
+
|
94
|
+
TARGET_SO = $(DLLIB)
|
95
|
+
CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
|
96
|
+
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
|
97
|
+
|
98
|
+
all: $(DLLIB)
|
99
|
+
static: $(STATIC_LIB)
|
100
|
+
|
101
|
+
clean:
|
102
|
+
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
103
|
+
|
104
|
+
distclean: clean
|
105
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
106
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
107
|
+
|
108
|
+
realclean: distclean
|
109
|
+
install: install-so install-rb
|
110
|
+
|
111
|
+
install-so: $(RUBYARCHDIR)
|
112
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
113
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
114
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
115
|
+
install-rb: pre-install-rb install-rb-default
|
116
|
+
install-rb-default: pre-install-rb-default
|
117
|
+
pre-install-rb: Makefile
|
118
|
+
pre-install-rb-default: Makefile
|
119
|
+
$(RUBYARCHDIR):
|
120
|
+
$(MAKEDIRS) $@
|
121
|
+
|
122
|
+
site-install: site-install-so site-install-rb
|
123
|
+
site-install-so: install-so
|
124
|
+
site-install-rb: install-rb
|
125
|
+
|
126
|
+
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
127
|
+
|
128
|
+
.cc.o:
|
129
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
130
|
+
|
131
|
+
.cxx.o:
|
132
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
133
|
+
|
134
|
+
.cpp.o:
|
135
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
136
|
+
|
137
|
+
.C.o:
|
138
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
139
|
+
|
140
|
+
.c.o:
|
141
|
+
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
|
142
|
+
|
143
|
+
$(DLLIB): $(OBJS)
|
144
|
+
@-$(RM) $@
|
145
|
+
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
$(OBJS): ruby.h defines.h
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#====================================================
|
2
|
+
#
|
3
|
+
# Copyright 2008 iAnywhere Solutions, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
#
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
# While not a requirement of the license, if you do modify this file, we
|
20
|
+
# would appreciate hearing about it. Please email sqlany_interfaces@sybase.com
|
21
|
+
#
|
22
|
+
#
|
23
|
+
#====================================================
|
24
|
+
|
25
|
+
require 'mkmf'
|
26
|
+
|
27
|
+
dir_config('SQLANY')
|
28
|
+
|
29
|
+
create_makefile("sqlanywhere")
|
30
|
+
|
data/ext/sacapi.h
ADDED
@@ -0,0 +1,679 @@
|
|
1
|
+
/* ====================================================
|
2
|
+
*
|
3
|
+
* Copyright 2008 iAnywhere Solutions, Inc.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
*
|
15
|
+
* See the License for the specific language governing permissions and
|
16
|
+
* limitations under the License.
|
17
|
+
*
|
18
|
+
* While not a requirement of the license, if you do modify this file, we
|
19
|
+
* would appreciate hearing about it. Please email
|
20
|
+
* sqlany_interfaces@sybase.com
|
21
|
+
*
|
22
|
+
* ====================================================
|
23
|
+
*/
|
24
|
+
|
25
|
+
#ifndef SACAPI_H
|
26
|
+
#define SACAPI_H
|
27
|
+
|
28
|
+
/** \mainpage SQL Anywhere C API
|
29
|
+
*
|
30
|
+
* \section intro_sec Introduction
|
31
|
+
* The purpose of this API is to simplify creating C/C++ wrapper drivers for various interpreted languages
|
32
|
+
* such as PHP, Perl, Python, Ruby, and others. This API layer sits on top of DBLIB and was implemented
|
33
|
+
* using Embedded SQL. This API is not a replacement of DBLIB. It is just a way to simplify creating applications
|
34
|
+
* from C/C++ code without having to learn all the details of Embedded SQL.
|
35
|
+
* For more information on the implementation, please refer to the file sqlany_imp.sqc.
|
36
|
+
*
|
37
|
+
* \section distribution Distribution of the API
|
38
|
+
* The API is built as a DLL (shared object on UNIX). The name of the DLL is \b dbcapi.dll
|
39
|
+
* ( \b libdbcapi.so on UNIX). This DLL is linked statically to DBLIB of the SQL Anywhere version that it was
|
40
|
+
* built against. When dbcapi.dll is loaded, the corresponding dblibX.dll is loaded by the OS. Applications that
|
41
|
+
* interface with dbcapi.dll can either link directly to it or load it dynamically. For dynamic
|
42
|
+
* loading of the DLL, please refer to the Dynamic Loading section below.
|
43
|
+
*
|
44
|
+
* The file sacapi.h is the main header file for the API. It describes all the data types and the entry
|
45
|
+
* points of the API.
|
46
|
+
*
|
47
|
+
* \section dynamic_loading Dynamically Loading the DLL
|
48
|
+
* The header file sacapidll.h contains the proper code to dynamically load the DLL. An application would
|
49
|
+
* need to include the sacapidll.h header file and compile in sacapidll.c with their source.
|
50
|
+
* sqlany_initialize_interface() can be used to dynamically load the DLL and lookup all the entry points.
|
51
|
+
*
|
52
|
+
* \section threading_support Threading Support
|
53
|
+
* The C API library is thread-unaware, meaning that the library does not perform any tasks that require
|
54
|
+
* mutual exclusion. In order to allow the library to work in threaded applications, there is only one rule to
|
55
|
+
* follow: <b>no more than one request is allowed on a single connection </b>. With this rule, the application
|
56
|
+
* is responsible for doing mutual exclusion when accessing any connection-specific resource. This includes
|
57
|
+
* connection handles, prepared statements, and result set objects.
|
58
|
+
*
|
59
|
+
* \version 1.0
|
60
|
+
*/
|
61
|
+
|
62
|
+
/** \file sacapi.h
|
63
|
+
* Main API header file.
|
64
|
+
* This file describes all the data types and entry points of the API.
|
65
|
+
*/
|
66
|
+
|
67
|
+
/** A define to indicate the current API level
|
68
|
+
*/
|
69
|
+
#define SQLANY_CURRENT_API_VERSION 0x1
|
70
|
+
|
71
|
+
/** Error buffer size
|
72
|
+
*/
|
73
|
+
#define SACAPI_ERROR_SIZE 256
|
74
|
+
|
75
|
+
#if defined(__cplusplus)
|
76
|
+
extern "C" {
|
77
|
+
#endif
|
78
|
+
|
79
|
+
/** A handle to a connection object
|
80
|
+
*/
|
81
|
+
typedef struct a_sqlany_connection a_sqlany_connection;
|
82
|
+
|
83
|
+
/** A handle to a statement object
|
84
|
+
*/
|
85
|
+
typedef struct a_sqlany_stmt a_sqlany_stmt;
|
86
|
+
|
87
|
+
#ifdef WIN32
|
88
|
+
/** A portable 32-bit signed value */
|
89
|
+
typedef __int32 sacapi_i32;
|
90
|
+
/** A portable 32-bit unsigned value */
|
91
|
+
typedef unsigned __int32 sacapi_u32;
|
92
|
+
/** A portable boolean value */
|
93
|
+
typedef sacapi_i32 sacapi_bool;
|
94
|
+
#else
|
95
|
+
/** A portable 32-bit signed value */
|
96
|
+
typedef signed int sacapi_i32;
|
97
|
+
/** A portable 32-bit unsigned value */
|
98
|
+
typedef unsigned int sacapi_u32;
|
99
|
+
/** A portable boolean value */
|
100
|
+
typedef sacapi_i32 sacapi_bool;
|
101
|
+
#endif
|
102
|
+
|
103
|
+
// TODO:Character set issues
|
104
|
+
|
105
|
+
|
106
|
+
/** Data type enumeration.
|
107
|
+
* This enum is used to specify the data type that is being passed in or retrieved.
|
108
|
+
*/
|
109
|
+
typedef enum a_sqlany_data_type
|
110
|
+
{
|
111
|
+
A_INVALID_TYPE, /*!< Invalid data type */
|
112
|
+
A_BINARY, /*!< Binary data : binary data is treated as-is and no character set conversion is performed */
|
113
|
+
A_STRING, /*!< String data : data where character set conversion is performed */
|
114
|
+
A_DOUBLE, /*!< Double data : includes float values */
|
115
|
+
A_VAL64, /*!< 64-bit integer */
|
116
|
+
A_UVAL64, /*!< 64-bit unsigned integer */
|
117
|
+
A_VAL32, /*!< 32-bit integer */
|
118
|
+
A_UVAL32, /*!< 32-bit unsigned integer */
|
119
|
+
A_VAL16, /*!< 16-bit integer */
|
120
|
+
A_UVAL16, /*!< 16-bit unsigned integer */
|
121
|
+
A_VAL8, /*!< 8-bit integer */
|
122
|
+
A_UVAL8 /*!< 8-bit unsigned integer */
|
123
|
+
} a_sqlany_data_type;
|
124
|
+
|
125
|
+
/** A data value structure.
|
126
|
+
* This structure describes the attributes of a data value.
|
127
|
+
*/
|
128
|
+
typedef struct a_sqlany_data_value
|
129
|
+
{
|
130
|
+
char * buffer; /*!< Pointer to user supplied buffer of data */
|
131
|
+
size_t buffer_size; /*!< The size of the buffer */
|
132
|
+
size_t * length; /*!< The number of valid bytes in the buffer. Must be less than buffer_size */
|
133
|
+
a_sqlany_data_type type; /*!< The type of the data */
|
134
|
+
sacapi_bool * is_null; /*!< Whether the value is NULL or not */
|
135
|
+
} a_sqlany_data_value;
|
136
|
+
|
137
|
+
/** A data direction enumeration.
|
138
|
+
*/
|
139
|
+
typedef enum a_sqlany_data_direction
|
140
|
+
{
|
141
|
+
DD_INVALID = 0x0, /*!< Invalid data direction */
|
142
|
+
DD_INPUT = 0x1, /*!< Input only host variables */
|
143
|
+
DD_OUTPUT = 0x2, /*!< Output only host variables */
|
144
|
+
DD_INPUT_OUTPUT = 0x3 /*!< Input and Output host variables */
|
145
|
+
} a_sqlany_data_direction;
|
146
|
+
|
147
|
+
/** A bind parameter structure.
|
148
|
+
* This structure is used to bind parameters for prepared statements for execution.
|
149
|
+
* \sa sqlany_execute()
|
150
|
+
*/
|
151
|
+
typedef struct a_sqlany_bind_param
|
152
|
+
{
|
153
|
+
a_sqlany_data_direction direction; /*!< The direction of the data (input, output, input_output) */
|
154
|
+
a_sqlany_data_value value; /*!< The actual value of the data */
|
155
|
+
char *name; /*!< Name of the bind parameter. This is only used by
|
156
|
+
sqlany_describe_bind_param(). */
|
157
|
+
} a_sqlany_bind_param;
|
158
|
+
|
159
|
+
/** An enumeration of the native types of values as described by the server.
|
160
|
+
* \sa sqlany_get_column_info(), a_sqlany_column_info
|
161
|
+
*/
|
162
|
+
typedef enum a_sqlany_native_type
|
163
|
+
{
|
164
|
+
DT_NOTYPE = 0,
|
165
|
+
DT_DATE = 384,
|
166
|
+
DT_TIME = 388,
|
167
|
+
DT_TIMESTAMP = 392,
|
168
|
+
DT_VARCHAR = 448,
|
169
|
+
DT_FIXCHAR = 452,
|
170
|
+
DT_LONGVARCHAR = 456,
|
171
|
+
DT_STRING = 460,
|
172
|
+
DT_DOUBLE = 480,
|
173
|
+
DT_FLOAT = 482,
|
174
|
+
DT_DECIMAL = 484,
|
175
|
+
DT_INT = 496,
|
176
|
+
DT_SMALLINT = 500,
|
177
|
+
DT_BINARY = 524,
|
178
|
+
DT_LONGBINARY = 528,
|
179
|
+
DT_TINYINT = 604,
|
180
|
+
DT_BIGINT = 608,
|
181
|
+
DT_UNSINT = 612,
|
182
|
+
DT_UNSSMALLINT = 616,
|
183
|
+
DT_UNSBIGINT = 620,
|
184
|
+
DT_BIT = 624,
|
185
|
+
DT_LONGNVARCHAR = 640
|
186
|
+
} a_sqlany_native_type;
|
187
|
+
|
188
|
+
/** A column info structure.
|
189
|
+
* This structure returns metadata information about a column.
|
190
|
+
* sqlany_get_column_info() can be used to populate this structure.
|
191
|
+
*/
|
192
|
+
typedef struct a_sqlany_column_info
|
193
|
+
{
|
194
|
+
char * name; /*!< The name of the column (null-terminated ).
|
195
|
+
The string can be referenced
|
196
|
+
as long as the result set object is not freed. */
|
197
|
+
a_sqlany_data_type type; /*!< The type of the column data */
|
198
|
+
a_sqlany_native_type native_type; /*!< The native type of the column in the
|
199
|
+
database */
|
200
|
+
unsigned short precision; /*!< Precision */
|
201
|
+
unsigned short scale; /*!< Scale */
|
202
|
+
size_t max_size; /*!< The maximum size a data value in this column
|
203
|
+
can take */
|
204
|
+
sacapi_bool nullable; /*!< If a value in the column can be null or not */
|
205
|
+
} a_sqlany_column_info;
|
206
|
+
|
207
|
+
/** A bind parameter info structure.
|
208
|
+
* This structure allows the user to get information about the currently bound parameters.
|
209
|
+
* sqlany_get_bind_param_info() can be used to populate this structure.
|
210
|
+
*/
|
211
|
+
typedef struct a_sqlany_bind_param_info
|
212
|
+
{
|
213
|
+
char * name; /*!< Name of the parameter */
|
214
|
+
a_sqlany_data_direction direction; /*!< Parameter direction */
|
215
|
+
|
216
|
+
a_sqlany_data_value input_value; /*!< Information about the bound input value */
|
217
|
+
a_sqlany_data_value output_value; /*!< Information about the bound output value */
|
218
|
+
} a_sqlany_bind_param_info;
|
219
|
+
|
220
|
+
/** A data info structure.
|
221
|
+
* This structure returns metadata information about a column value in a result set.
|
222
|
+
* sqlany_get_data_info() can be used
|
223
|
+
* to populate this structure with information about what was last retrieved by a fetch operation.
|
224
|
+
*/
|
225
|
+
typedef struct a_sqlany_data_info
|
226
|
+
{
|
227
|
+
a_sqlany_data_type type; /*!< Type of the data in the column. */
|
228
|
+
sacapi_bool is_null; /*!< If the last fetched data is NULL or not.
|
229
|
+
This field is only valid after a successful fetch operation. */
|
230
|
+
size_t data_size; /*!< The total number of bytes available to be fetched.
|
231
|
+
This field is only valid after a successful fetch operation. */
|
232
|
+
} a_sqlany_data_info;
|
233
|
+
|
234
|
+
/** Initialize the interface.
|
235
|
+
* \param app_name A string that names the API used, for example "PHP", "PERL", or "RUBY".
|
236
|
+
* \param api_version The current API version that the application is using.
|
237
|
+
* This should normally be SQLANY_CURRENT_API_VERSION.
|
238
|
+
* \param version_available An optional argument to return the maximum API version that is supported.
|
239
|
+
* \return 1 on success, 0 otherwise
|
240
|
+
* \sa sqlany_fini()
|
241
|
+
* \par Quick Example:
|
242
|
+
* \code
|
243
|
+
sacapi_u32 api_version;
|
244
|
+
if( sqlany_init( "PHP", SQLANY_CURRENT_API_VERSION, &api_version ) ) {
|
245
|
+
printf( "Interface initialized successfully!\n" );
|
246
|
+
} else {
|
247
|
+
printf( "Failed to initialize the interface! Supported version=%d\n", api_version );
|
248
|
+
}
|
249
|
+
* \endcode
|
250
|
+
*/
|
251
|
+
sacapi_bool sqlany_init( const char * app_name, sacapi_u32 api_version, sacapi_u32 * version_available );
|
252
|
+
|
253
|
+
/** Finalize the interface.
|
254
|
+
* Frees any resources allocated by the API.
|
255
|
+
* \sa sqlany_init()
|
256
|
+
*/
|
257
|
+
void sqlany_fini( void );
|
258
|
+
|
259
|
+
/** Creates a connection object.
|
260
|
+
* An API connection object needs to be created before a database connection is established. Errors can be retrieved
|
261
|
+
* from the connection object. Only one request can be processed on a connection at a time. In addition,
|
262
|
+
* not more than one thread is allowed to access a connection object at a time. If multiple threads attempt
|
263
|
+
* to access a connection object simultaneously, then undefined behaviour/crashes will occur.
|
264
|
+
* \return A connection object
|
265
|
+
* \sa sqlany_connect(), sqlany_disconnect()
|
266
|
+
*/
|
267
|
+
a_sqlany_connection * sqlany_new_connection( void );
|
268
|
+
|
269
|
+
/** Frees the resources associated with a connection object.
|
270
|
+
* \param sqlany_conn A connection object that was created by sqlany_new_connection().
|
271
|
+
*/
|
272
|
+
void sqlany_free_connection( a_sqlany_connection *sqlany_conn );
|
273
|
+
|
274
|
+
/** Creates a connection object based on a supplied DBLIB SQLCA pointer.
|
275
|
+
* \param arg A void * pointer to a DBLIB SQLCA object.
|
276
|
+
* \return A connection object.
|
277
|
+
* \sa sqlany_execute(), sqlany_execute_direct(), sqlany_execute_immediate(), sqlany_prepare()
|
278
|
+
*/
|
279
|
+
a_sqlany_connection * sqlany_make_connection( void * arg );
|
280
|
+
|
281
|
+
/** Establish a connection.
|
282
|
+
* This function establishes a connection to a SQL Anywhere server using the supplied connection object and
|
283
|
+
* the supplied connection string. The connection object must first be allocated using sqlany_new_connection().
|
284
|
+
* \param sqlany_conn A connection object that was created by sqlany_new_connection().
|
285
|
+
* \param str A SQL Anywhere connection string.
|
286
|
+
* \return 1 if the connection was established successfully, or 0 otherwise. The error code and message can be
|
287
|
+
* retrieved using sqlany_error().
|
288
|
+
* \sa sqlany_new_connection(), sqlany_error()
|
289
|
+
* \par Quick Example:
|
290
|
+
* \code
|
291
|
+
a_sqlany_connection * sqlany_conn;
|
292
|
+
sqlany_conn = sqlany_new_connection();
|
293
|
+
if( !sqlany_connect( sqlany_conn, "uid=dba;pwd=sql" ) ) {
|
294
|
+
char reason[SACAPI_ERROR_SIZE];
|
295
|
+
sacapi_i32 code;
|
296
|
+
code = sqlany_error( sqlany_conn, reason, sizeof(reason) );
|
297
|
+
printf( "Connection failed. Code: %d Reason: %s\n", code, reason );
|
298
|
+
} else {
|
299
|
+
printf( "Connected successfully!\n" );
|
300
|
+
sqlany_disconnect( sqlany_conn );
|
301
|
+
}
|
302
|
+
sqlany_free_connection( sqlany_conn );
|
303
|
+
* \endcode
|
304
|
+
*/
|
305
|
+
sacapi_bool sqlany_connect( a_sqlany_connection * sqlany_conn, const char * str );
|
306
|
+
|
307
|
+
/** Disconnect an already established connection.
|
308
|
+
* This function disconnects a SQL Anywhere connection.
|
309
|
+
* Any uncommited transactions will be rolled back.
|
310
|
+
* \param sqlany_conn A connection object with a connection established using sqlany_connect().
|
311
|
+
* \return 1 on success; 0 otherwise
|
312
|
+
* \sa sqlany_connect()
|
313
|
+
*/
|
314
|
+
sacapi_bool sqlany_disconnect( a_sqlany_connection * sqlany_conn );
|
315
|
+
|
316
|
+
/** Execute a SQL statement immediately without returning a result set.
|
317
|
+
* Execute the specified SQL statement immediately.
|
318
|
+
* This function is useful for SQL statements that do not return a result set.
|
319
|
+
* \param sqlany_conn A connection object with a connection established using sqlany_connect().
|
320
|
+
* \param sql A string respresenting the SQL statement to be executed.
|
321
|
+
* \return 1 on success, 0 otherwise
|
322
|
+
*/
|
323
|
+
sacapi_bool sqlany_execute_immediate( a_sqlany_connection * sqlany_conn, const char * sql );
|
324
|
+
|
325
|
+
/** Prepare a SQL statement.
|
326
|
+
* This function prepares the supplied SQL string. Execution does not happen until sqlany_execute() is
|
327
|
+
* called. The returned statement object should be freed using sqlany_free_stmt().
|
328
|
+
* \param sqlany_conn A connection object with a connection established using sqlany_connect().
|
329
|
+
* \param sql_str The SQL statement to be prepared.
|
330
|
+
* \return A handle to a SQL Anywhere statement object. The statement object can be used by sqlany_execute()
|
331
|
+
* to execute the statement.
|
332
|
+
* \sa sqlany_free_stmt(), sqlany_connect(), sqlany_execute()
|
333
|
+
* \par Quick Example:
|
334
|
+
* \code
|
335
|
+
char * str;
|
336
|
+
a_sqlany_stmt * stmt;
|
337
|
+
|
338
|
+
str = "select * from employees where salary >= ?";
|
339
|
+
stmt = sqlany_prepare( sqlany_conn, str );
|
340
|
+
if( stmt == NULL ) {
|
341
|
+
// Failed to prepare statement, call sqlany_error() for more info
|
342
|
+
}
|
343
|
+
* \endcode
|
344
|
+
*/
|
345
|
+
a_sqlany_stmt * sqlany_prepare( a_sqlany_connection * sqlany_conn, const char * sql_str );
|
346
|
+
|
347
|
+
/** Frees resources associated with a prepared statement object.
|
348
|
+
* This function frees the resources associated with a prepared statement object.
|
349
|
+
* \param sqlany_stmt A statement object that was returned from sqlany_prepare().
|
350
|
+
* \sa sqlany_prepare()
|
351
|
+
*/
|
352
|
+
void sqlany_free_stmt( a_sqlany_stmt * sqlany_stmt );
|
353
|
+
|
354
|
+
/** Returns the number of parameters that are expected for a prepared statement.
|
355
|
+
* \param sqlany_stmt A statement object that was returned from sqlany_prepare().
|
356
|
+
* \return The number of parameters that are expected. -1 if the sqlany_stmt object is not valid.
|
357
|
+
*/
|
358
|
+
sacapi_i32 sqlany_num_params( a_sqlany_stmt * sqlany_stmt );
|
359
|
+
|
360
|
+
/** Describes the bind parameters of a prepared statement.
|
361
|
+
* This function allows the caller to determine information about parameters to a prepared statement. Depending
|
362
|
+
* on the type of the prepared statement (call to stored procedured or a DML), only some information will be provided.
|
363
|
+
* The information that will always be provided is the direction of the parameters (input, output, or input-output).
|
364
|
+
* \param sqlany_stmt A statement that was prepared successfully using sqlany_prepare().
|
365
|
+
* \param index The index of the parameter. This should be a number between 0 and sqlany_num_params()-1;
|
366
|
+
* \param param A a_sqlany_bind_param structure that will be populated with information.
|
367
|
+
* \return 1 on success or 0 on failure.
|
368
|
+
*/
|
369
|
+
sacapi_bool sqlany_describe_bind_param( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, a_sqlany_bind_param * param );
|
370
|
+
|
371
|
+
/** Bind a user supplied buffer as a parameter to the prepared statement.
|
372
|
+
* \param sqlany_stmt A statement that was prepared successfully using sqlany_prepare().
|
373
|
+
* \param index The index of the parameter. This should be a number between 0 and sqlany_num_params()-1.
|
374
|
+
* \param param A a_sqlany_bind_param structure that describes the parameter that is to be bound.
|
375
|
+
* \return 1 on success or 0 on failure.
|
376
|
+
*/
|
377
|
+
sacapi_bool sqlany_bind_param( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, a_sqlany_bind_param * param );
|
378
|
+
|
379
|
+
/** Send data as part of a bound parameter.
|
380
|
+
* This function can be used to send a large amount of data for a bound parameter.
|
381
|
+
* \param sqlany_stmt A statement that was prepared successfully using sqlany_prepare().
|
382
|
+
* \param index The index of the parameter. This should be a number between 0 and sqlany_num_params()-1.
|
383
|
+
* \param buffer The data to be sent.
|
384
|
+
* \param size The number of bytes to send.
|
385
|
+
* \return 1 on success or 0 on failure.
|
386
|
+
* \sa sa_prepare()
|
387
|
+
*/
|
388
|
+
sacapi_bool sqlany_send_param_data( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, char * buffer, size_t size );
|
389
|
+
|
390
|
+
/** Reset a statement to its prepared state condition.
|
391
|
+
* \param sqlany_stmt A statement that was prepared successfully using sqlany_prepare().
|
392
|
+
* \return 1 on success, 0 on failure.
|
393
|
+
* \sa sqlany_prepare()
|
394
|
+
*/
|
395
|
+
sacapi_bool sqlany_reset( a_sqlany_stmt * sqlany_stmt );
|
396
|
+
|
397
|
+
/** Get bound parameter info.
|
398
|
+
* This function retrieves information about the parameters that were bound using sqlany_bind_param().
|
399
|
+
* \param sqlany_stmt A statement that was prepared successfully using sqlany_prepare().
|
400
|
+
* \param index The index of the parameter. This should be a number between 0 and sqlany_num_params()-1.
|
401
|
+
* \param info A sqlany_bind_param_info buffer that will be populated with the bound parameter's information.
|
402
|
+
* \return 1 on success or 0 on failure.
|
403
|
+
* \sa sqlany_bind_param(), sqlany_describe_bind_param(), sqlany_prepare()
|
404
|
+
*/
|
405
|
+
sacapi_bool sqlany_get_bind_param_info( a_sqlany_stmt * sqlany_stmt, sacapi_u32 index, a_sqlany_bind_param_info * info );
|
406
|
+
|
407
|
+
/** Execute a prepared statement.
|
408
|
+
* This function executes a prepared statement.
|
409
|
+
* The user can check if the statement returns a result set or not
|
410
|
+
* by checking the result of sqlany_num_cols().
|
411
|
+
* \param sqlany_stmt A statement that was prepared successfully using sqlany_prepare().
|
412
|
+
* \return 1 if the statement is executed successfully, 0 otherwise.
|
413
|
+
* \sa sqlany_prepare()
|
414
|
+
* \par Quick Example:
|
415
|
+
* \code
|
416
|
+
// This example shows how to execute a statement that does not return a result set
|
417
|
+
a_sqlany_stmt * stmt;
|
418
|
+
int i;
|
419
|
+
a_sqlany_bind_param param;
|
420
|
+
|
421
|
+
stmt = sqlany_prepare( sqlany_conn, "insert into moe(id,value) values( ?,? )" );
|
422
|
+
if( stmt ) {
|
423
|
+
sqlany_describe_bind_param( stmt, 0, ¶m );
|
424
|
+
param.value.buffer = (char *)&i;
|
425
|
+
param.value.type = A_VAL32;
|
426
|
+
sqlany_bind_param( stmt, 0, ¶m );
|
427
|
+
|
428
|
+
sqlany_describe_bind_param( stmt, 1, ¶m );
|
429
|
+
param.value.buffer = (char *)&i;
|
430
|
+
param.value.type = A_VAL32;
|
431
|
+
sqlany_bind_param( stmt, 1, ¶m );
|
432
|
+
|
433
|
+
for( i = 0; i < 10; i++ ) {
|
434
|
+
if( !sqlany_execute( stmt ) ) {
|
435
|
+
// call sqlany_error()
|
436
|
+
}
|
437
|
+
}
|
438
|
+
sqlany_free_stmt( stmt );
|
439
|
+
}
|
440
|
+
* \endcode
|
441
|
+
*/
|
442
|
+
sacapi_bool sqlany_execute( a_sqlany_stmt * sqlany_stmt );
|
443
|
+
|
444
|
+
/** Executes a SQL statement and possibly returns a result set.
|
445
|
+
* This function executes the SQL statement specified by the string argument.
|
446
|
+
* This function is suitable if you want to prepare and then execute a statement,
|
447
|
+
* and can be used instead of calling sqlany_prepare() followed by sqlany_execute().
|
448
|
+
* This function can \b not be used for executing a SQL statement with parameters.
|
449
|
+
* \param sqlany_conn A connection object with a connection established using sqlany_connect().
|
450
|
+
* \param sql_str A SQL string. The SQL string should not have parameters (i.e. '?' marks ).
|
451
|
+
* \return A statement handle if the function executes successfully, NULL otherwise.
|
452
|
+
* \sa sqlany_fetch_absolute(), sqlany_fetch_next(), sqlany_num_cols(), sqlany_get_column()
|
453
|
+
* \par Quick Example:
|
454
|
+
* \code
|
455
|
+
stmt = sqlany_execute_direct( sqlany_conn, "select * from employees" ) ) {
|
456
|
+
if( stmt ) {
|
457
|
+
while( sqlany_fetch_next( stmt ) ) {
|
458
|
+
int i;
|
459
|
+
for( i = 0; i < sqlany_num_cols( stmt ); i++ ) {
|
460
|
+
// Get column i data
|
461
|
+
}
|
462
|
+
}
|
463
|
+
sqlany_free_stmt( stmt );
|
464
|
+
}
|
465
|
+
* \endcode
|
466
|
+
*/
|
467
|
+
a_sqlany_stmt * sqlany_execute_direct( a_sqlany_connection * sqlany_conn, const char * sql_str );
|
468
|
+
|
469
|
+
/** Fetch data at a specific row number in the result set.
|
470
|
+
* This function moves the current row in the result set to the row number specified and fetches the data at that row.
|
471
|
+
* \param sqlany_stmt A statement object that was executed by
|
472
|
+
* sqlany_execute() or sqlany_execute_direct().
|
473
|
+
* \param row_num The row number to be fetched. The first row is 1, the last row is -1.
|
474
|
+
* \return 1 if the fetch was successfully, 0 otherwise.
|
475
|
+
* \sa sqlany_execute_direct(), sqlany_execute(), sqlany_error(), sqlany_fetch_next()
|
476
|
+
*/
|
477
|
+
sacapi_bool sqlany_fetch_absolute( a_sqlany_stmt * sqlany_stmt, sacapi_i32 row_num );
|
478
|
+
|
479
|
+
/** Fetch the next row from the result set.
|
480
|
+
* This function fetches the next row from the result set.
|
481
|
+
* When the result object is first created, the current row
|
482
|
+
* pointer is set to before the first row (i.e. row 0).
|
483
|
+
* This function first advances the row pointer and then fetches
|
484
|
+
* the data at the new row.
|
485
|
+
* \param sqlany_stmt A statement object that was executed by
|
486
|
+
* sqlany_execute() or sqlany_execute_direct().
|
487
|
+
* \return 1 if a row was fetched successfully, 0 otherwise.
|
488
|
+
* \sa sqlany_fetch_absolute(), sqlany_execute_direct(), sqlany_execute(), sqlany_error()
|
489
|
+
*/
|
490
|
+
sacapi_bool sqlany_fetch_next( a_sqlany_stmt * sqlany_stmt );
|
491
|
+
|
492
|
+
/** Advance to the next result set in a multiple result set query.
|
493
|
+
* If a query (such as a call to a stored procedure) returns multiple result sets, then this function
|
494
|
+
* advances from the current result set to the next.
|
495
|
+
* \param sqlany_stmt A statement object that was executed by
|
496
|
+
* sqlany_execute() or sqlany_execute_direct().
|
497
|
+
* \return 1 if was successfully able to advance to the next result set, 0 otherwise.
|
498
|
+
* \sa sqlany_execute_direct(), sqlany_execute()
|
499
|
+
* \par Quick Example:
|
500
|
+
* \code
|
501
|
+
stmt = sqlany_execute_direct( sqlany_conn, "call my_multiple_results_procedure()" );
|
502
|
+
if( result ) {
|
503
|
+
do {
|
504
|
+
while( sqlany_fetch_next( stmt ) ) {
|
505
|
+
// get column data
|
506
|
+
}
|
507
|
+
} while( sqlany_get_next_result( stmt ) );
|
508
|
+
sqlany_free_stmt( stmt );
|
509
|
+
}
|
510
|
+
* \endcode
|
511
|
+
*/
|
512
|
+
sacapi_bool sqlany_get_next_result( a_sqlany_stmt * sqlany_stmt );
|
513
|
+
|
514
|
+
/** Returns the number of rows affected by execution of the prepared statement.
|
515
|
+
* \param sqlany_stmt A statement that was prepared and executed successfully with no result set returned.
|
516
|
+
* \return The number of rows affected or -1 on failure.
|
517
|
+
* \sa sqlany_execute(), sqlany_execute_direct()
|
518
|
+
*/
|
519
|
+
sacapi_i32 sqlany_affected_rows( a_sqlany_stmt * sqlany_stmt );
|
520
|
+
|
521
|
+
/** Returns number of columns in the result set.
|
522
|
+
* \param sqlany_stmt A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
|
523
|
+
* \return The number of columns in the result set or -1 on a failure.
|
524
|
+
* \sa sqlany_execute_direct(), sqlany_prepare()
|
525
|
+
*/
|
526
|
+
sacapi_i32 sqlany_num_cols( a_sqlany_stmt * sqlany_stmt );
|
527
|
+
|
528
|
+
/** Returns number of rows in the result set.
|
529
|
+
* By default this function only returns an estimate. To return an exact count, users must set the ROW_COUNTS option
|
530
|
+
* on the connection. Refer to SQL Anywhere documentation for the SQL syntax to set this option.
|
531
|
+
* \param sqlany_stmt A statement object that was executed by
|
532
|
+
* sqlany_execute() or sqlany_execute_direct().
|
533
|
+
* \return The number rows in the result set. If the number of rows is an estimate, the number returned will be
|
534
|
+
* negative and the estimate is the absolute value of the returned integer. If the number of rows is exact, then the
|
535
|
+
* value returned will be positive.
|
536
|
+
* \sa sqlany_execute_direct(), sqlany_execute()
|
537
|
+
*/
|
538
|
+
sacapi_i32 sqlany_num_rows( a_sqlany_stmt * sqlany_stmt );
|
539
|
+
|
540
|
+
/** Retrieve the data fetched for the specified column.
|
541
|
+
* This function fills the supplied buffer with the value fetched for the
|
542
|
+
* specified column. For A_BINARY and A_STRING * data types,
|
543
|
+
* buffer->buffer will point to an internal buffer associated with the result set.
|
544
|
+
* The content of the pointer buffer should not be relied on or altered
|
545
|
+
* as it will change when a new row is fetched or when the result set
|
546
|
+
* object is freed. Users should copy the data out of those pointers into their
|
547
|
+
* own buffers. The length field indicates the number of valid characters that
|
548
|
+
* buffer->buffer points to. The data returned in buffer->buffer is \b not
|
549
|
+
* null-terminated. This function fetches all of the returned value from the server.
|
550
|
+
* For example, if the column contains
|
551
|
+
* a 2GB blob, this function will attempt to allocate enough memory to hold that value.
|
552
|
+
* If this is not desired, sqlany_get_data() should be used instead.
|
553
|
+
* \param sqlany_stmt A statement object that was executed by
|
554
|
+
* sqlany_execute() or sqlany_execute_direct().
|
555
|
+
* \param col_index The number of the column to be retrieved.
|
556
|
+
* A column number is between 0 and sqlany_num_cols()-1.
|
557
|
+
* \param buffer A a_sqlany_data_value object that will be filled with the data fetched for column col_index.
|
558
|
+
* \return 1 on success or 0 for failure. A failure can happen if any of the parameters is invalid or if there is
|
559
|
+
* not enough memory to retrieve the full value from the server.
|
560
|
+
* \sa sqlany_execute_direct(), sqlany_execute()
|
561
|
+
*/
|
562
|
+
sacapi_bool sqlany_get_column( a_sqlany_stmt * sqlany_stmt, sacapi_u32 col_index, a_sqlany_data_value * buffer );
|
563
|
+
|
564
|
+
/** Retrieve the data fetched for the specified column into the supplied buffer memory.
|
565
|
+
* \param sqlany_stmt A statement object that was executed by
|
566
|
+
* sqlany_execute() or sqlany_execute_direct().
|
567
|
+
* \param col_index The number of the column to be retrieved.
|
568
|
+
* A column number is between 0 and sqlany_num_cols()-1.
|
569
|
+
* \param offset The starting offset of the data to get.
|
570
|
+
* \param buffer A buffer to be filled with the contents of the column. The buffer pointer must be aligned correctly
|
571
|
+
* for the data type that will be copied into it.
|
572
|
+
* \param size The size of the buffer in bytes. The function will fail
|
573
|
+
* if a size greater than 2GB is specified.
|
574
|
+
* \return The number of bytes successfully copied into the supplied buffer.
|
575
|
+
* This number will not exceed 2GB.
|
576
|
+
* 0 indicates no data remains to be copied. A -1 indicates a failure.
|
577
|
+
*/
|
578
|
+
sacapi_i32 sqlany_get_data( a_sqlany_stmt * sqlany_stmt, sacapi_u32 col_index, size_t offset, void * buffer, size_t size );
|
579
|
+
|
580
|
+
/** Retrieves information about the data that was fetched by the last fetch operation.
|
581
|
+
* \param sqlany_stmt A statement object that was executed by
|
582
|
+
* sqlany_execute() or sqlany_execute_direct().
|
583
|
+
* \param col_index The column number.
|
584
|
+
* A column number is between 0 and sqlany_num_cols()-1.
|
585
|
+
* \param buffer A data info buffer to be filled with the metadata about the data fetched.
|
586
|
+
* \return 1 on success, and 0 on failure. Failure is returned if any of the supplied parameters is invalid.
|
587
|
+
*/
|
588
|
+
sacapi_bool sqlany_get_data_info( a_sqlany_stmt * sqlany_stmt, sacapi_u32 col_index, a_sqlany_data_info * buffer );
|
589
|
+
|
590
|
+
/** Retrieves column metadata information.
|
591
|
+
* This function fills the a_sqlany_column_info structure with information about the column.
|
592
|
+
* \param sqlany_stmt A statement object that was created by sqlany_prepare() or sqlany_execute_direct().
|
593
|
+
* \param col_index The column number.
|
594
|
+
* A column number is between 0 and sqlany_num_cols()-1.
|
595
|
+
* \param buffer A column info structure to be filled with information about the column.
|
596
|
+
* \return 1 on success. Returns 0 if the column index is out of range,
|
597
|
+
* or if the statement does not return a result set.
|
598
|
+
* \sa sqlany_execute_direct(), sqlany_prepare()
|
599
|
+
*/
|
600
|
+
sacapi_bool sqlany_get_column_info( a_sqlany_stmt * sqlany_stmt, sacapi_u32 col_index, a_sqlany_column_info * buffer );
|
601
|
+
|
602
|
+
/** Commit the current transaction.
|
603
|
+
* \param sqlany_conn The connection object on which the commit operation is to be performed.
|
604
|
+
* \return 1 on success, 0 otherwise.
|
605
|
+
* \sa sqlany_rollback()
|
606
|
+
*/
|
607
|
+
sacapi_bool sqlany_commit( a_sqlany_connection * sqlany_conn );
|
608
|
+
|
609
|
+
/** Rollback the current transaction.
|
610
|
+
* \param sqlany_conn The connection object on which the rollback operation is to be performed.
|
611
|
+
* \return 1 on success, 0 otherwise.
|
612
|
+
* \sa sqlany_commit()
|
613
|
+
*/
|
614
|
+
sacapi_bool sqlany_rollback( a_sqlany_connection * sqlany_conn );
|
615
|
+
|
616
|
+
/** Returns the current client version.
|
617
|
+
* This function fills the buffer passed with the major, minor, patch, and build number of the client library.
|
618
|
+
* The buffer will be null-terminated.
|
619
|
+
* \param buffer The buffer to be filled with the client version.
|
620
|
+
* \param len The length of the buffer.
|
621
|
+
* \return 1 on success; 0 otherwise
|
622
|
+
*/
|
623
|
+
sacapi_bool sqlany_client_version( char * buffer, size_t len );
|
624
|
+
|
625
|
+
/** Retrieves the last error code and message.
|
626
|
+
* This function can be used to retrieve the last error code and message stored in the connection object.
|
627
|
+
* \param sqlany_conn A connection object that was returned from sqlany_new_connection().
|
628
|
+
* \param buffer A buffer that will be filled with the error message.
|
629
|
+
* \param size Size of the supplied buffer.
|
630
|
+
* \return The last error code. Positive values are warnings, negative values are errors, and 0 is success.
|
631
|
+
*/
|
632
|
+
sacapi_i32 sqlany_error( a_sqlany_connection * sqlany_conn, char * buffer, size_t size );
|
633
|
+
|
634
|
+
/** Retrieve the current SQL state.
|
635
|
+
* \param sqlany_conn A connection object that was returned from sqlany_new_connection().
|
636
|
+
* \param buffer A buffer that will be filled with the SQL state.
|
637
|
+
* \param size The size of the buffer.
|
638
|
+
* \return The number of bytes copied into the buffer.
|
639
|
+
*/
|
640
|
+
size_t sqlany_sqlstate( a_sqlany_connection * sqlany_conn, char * buffer, size_t size );
|
641
|
+
|
642
|
+
/** Clears the last stored error code
|
643
|
+
* \param sqlany_conn A connection object that was returned from sqlany_new_connection().
|
644
|
+
*/
|
645
|
+
void sqlany_clear_error( a_sqlany_connection * sqlany_conn );
|
646
|
+
|
647
|
+
#if defined(__cplusplus)
|
648
|
+
}
|
649
|
+
#endif
|
650
|
+
|
651
|
+
/** \example connecting.cpp
|
652
|
+
* This is an example of how to create a connection object and connect with it to SQL Anywhere.
|
653
|
+
*/
|
654
|
+
|
655
|
+
/** \example fetching_a_result_set.cpp
|
656
|
+
* This example shows how to fetch data from a result set.
|
657
|
+
*/
|
658
|
+
|
659
|
+
/** \example preparing_statements.cpp
|
660
|
+
* This example shows how to prepare and execute a statement.
|
661
|
+
*/
|
662
|
+
|
663
|
+
/** \example fetching_multiple_from_sp.cpp
|
664
|
+
* This example shows how to fetch multiple result sets from a stored procedure.
|
665
|
+
*/
|
666
|
+
|
667
|
+
/** \example send_retrieve_part_blob.cpp
|
668
|
+
* This example shows how to insert a blob in chunks and retrieve it in chunks too.
|
669
|
+
*/
|
670
|
+
|
671
|
+
/** \example send_retrieve_full_blob.cpp
|
672
|
+
* This example shows how to insert and retrieve a blob in one chunk .
|
673
|
+
*/
|
674
|
+
|
675
|
+
/** \example dbcapi_isql.cpp
|
676
|
+
* This example shows how to write an ISQL application using dbcapi.
|
677
|
+
*/
|
678
|
+
|
679
|
+
#endif
|