sqlanywhere 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,16 @@
1
+ =CHANGE LOG
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
+
12
+ =====0.1.0 -- 2008/10/15
13
+ - Initial Release
14
+ - Wraps DBCAPI functionality
15
+ - Includes a simple unit test suite
16
+
data/LICENSE ADDED
@@ -0,0 +1,23 @@
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
+ *====================================================*/
data/README ADDED
@@ -0,0 +1,130 @@
1
+ =SQL Anywhere Ruby Driver
2
+
3
+ This is a native SQL Anywhere driver for Ruby. This library wraps the
4
+ functionality provided by the SQL Anywhere DBCAPI library. This driver
5
+ is intended to be a base-level library to be used by interface libraries
6
+ such as Ruby-DBI and ActiveRecord.
7
+
8
+ This driver can be used with SQL Anywhere 11 and SQL Anywhere 10.
9
+
10
+ This driver is licensed under the Apache License, Version 2.
11
+
12
+ ==Build Instructions
13
+
14
+ ===Requirements
15
+ * C Compiler
16
+ * Ruby
17
+ * RubyGem Package manager
18
+
19
+
20
+ ===All Platforms
21
+
22
+ To build the library (.so), use:
23
+
24
+ rake
25
+
26
+ To build and install the gem, use:
27
+
28
+ rake gem
29
+ rake install
30
+
31
+ The other rake tasks are
32
+
33
+ rake clean -> Cleans up all temp files (ex *.~)
34
+ rake clobber -> Cleans up all built files (ex *.gem, *.o, *.so)
35
+
36
+ ===Additional Install Notes for Windows
37
+
38
+ The popular One-Click Ruby Installer for Windows (RubyInstaller) is built using
39
+ Microsoft Visual C++ 6.0. Since problems can arise by combining binaries from
40
+ different compilers, we advise you use this compiler.
41
+
42
+ If you want to use a more recent version of the MS C++ compiler, you will need to make a few changes:
43
+
44
+ 1. Open the file: <RUBY DIR>\lib\ruby\1.8\i386-mswin32\config.h, and comment out the first three lines so they look like:
45
+
46
+ //#if _MSC_VER != 1200
47
+ //#error MSC version unmatch
48
+ //#endif
49
+
50
+ This removes the check for C++ Version 6.0
51
+
52
+ 2. Open <tt>rakefile</tt> and set:
53
+
54
+ APPLY_MANIFEST = true
55
+
56
+ This will add the manifest to the compiled binaries.
57
+
58
+ By default, rake will attempt to use Microsoft <tt>nmake</tt> when building under Windows. To use another make program, set:
59
+
60
+ USE_NMAKE_ON_WIN = FALSE
61
+
62
+ ==Running Unit Tests
63
+
64
+ 1. Change to the the <tt>test</tt> directory
65
+
66
+ cd test
67
+
68
+ 2. Create a testing database:
69
+
70
+ dbinit test
71
+
72
+ 3. Start the testing database:
73
+
74
+ dbeng11 test.db
75
+
76
+ 4. Create the test schema:
77
+
78
+ dbisql -c "eng=test;uid=dba;pwd=sql" test.sql
79
+
80
+ 5. Run the unit tests:
81
+
82
+ ruby sqlanywhere_test.rb
83
+
84
+ <b>If the tests fail to run, make sure you have set up the SQL Anywhere environment variables correctly.</b> For more information
85
+ review the online documentation here[http://dcx.sybase.com/index.php#http%3A%2F%2Fdcx.sybase.com%2F1100en%2Fdbadmin_en11%2Fda-envvar-sect1-3672410.html].
86
+
87
+ ==Sample
88
+
89
+ This script makes a connection, prints <tt>Successful Ruby Connection</tt> to the SQL
90
+ Anywhere console, then disconnects.
91
+
92
+ # load the SQLAnywhere gem
93
+ begin
94
+ require 'rubygems'
95
+ gem 'sqlanywhere'
96
+ unless defined? SQLAnywhere
97
+ require 'sqlanywhere'
98
+ end
99
+ end
100
+
101
+ # create an interface
102
+ api = SQLAnywhere::SQLAnywhereInterface.new()
103
+
104
+ # initialize the interface (loads the DLL/SO)
105
+ SQLAnywhere::API.sqlany_initialize_interface( api )
106
+
107
+ # initialize our api object
108
+ api.sqlany_init()
109
+
110
+ # create a connection
111
+ conn = api.sqlany_new_connection()
112
+
113
+ # establish a connection
114
+ api.sqlany_connect(conn, "uid=dba;pwd=sql")
115
+
116
+ # execute a query without a result set
117
+ api.sqlany_execute_immediate(conn, "MESSAGE 'Successful Ruby Connection'")
118
+
119
+ # disconnect from the database
120
+ api.sqlany_disconnect(conn)
121
+
122
+ # free the connection resources
123
+ api.sqlany_free_connection(conn)
124
+
125
+ # free resources the api object uses
126
+ api.sqlany_fini()
127
+
128
+ # close the interface
129
+ SQLAnywhere::API.sqlany_finalize_interface( api )
130
+
data/Rakefile ADDED
@@ -0,0 +1,207 @@
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
+ desc "Publish the RDOCs on RubyForge"
203
+ task :publish_rdoc => ["html/index.html"] do
204
+ system "pscp -r html/* efarrar@rubyforge.org:/var/www/gforge-projects/sqlanywhere/sqlanywhere"
205
+ end
206
+
207
+ 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/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
+