nuodb 1.0.0.rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/nuodb.rb ADDED
@@ -0,0 +1,31 @@
1
+ #
2
+ # Copyright (c) 2012, NuoDB, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of NuoDB, Inc. nor the names of its contributors may
14
+ # be used to endorse or promote products derived from this software
15
+ # without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL NUODB, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
21
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23
+ # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ #
28
+
29
+ require 'nuodb/version'
30
+ require 'nuodb/error'
31
+ require 'nuodb/nuodb'
@@ -0,0 +1,42 @@
1
+ #
2
+ # Copyright (c) 2012, NuoDB, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of NuoDB, Inc. nor the names of its contributors may
14
+ # be used to endorse or promote products derived from this software
15
+ # without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL NUODB, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
21
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23
+ # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ #
28
+
29
+ module NuoDB
30
+
31
+ class Error < StandardError
32
+
33
+ attr_accessor :error_code
34
+
35
+ def initialize(message=nil, error_code = nil)
36
+ super(message)
37
+ @error_code = error_code
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,31 @@
1
+ #
2
+ # Copyright (c) 2012, NuoDB, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # * Redistributions of source code must retain the above copyright
9
+ # notice, this list of conditions and the following disclaimer.
10
+ # * Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in the
12
+ # documentation and/or other materials provided with the distribution.
13
+ # * Neither the name of NuoDB, Inc. nor the names of its contributors may
14
+ # be used to endorse or promote products derived from this software
15
+ # without specific prior written permission.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
+ # DISCLAIMED. IN NO EVENT SHALL NUODB, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
21
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23
+ # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ #
28
+
29
+ module NuoDB
30
+ VERSION = '1.0.0.rc.1'
31
+ end
data/nuodb.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/nuodb/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'nuodb'
6
+ gem.version = NuoDB::VERSION
7
+ gem.authors = %w('Robert Buck')
8
+ gem.email = %w(support@nuodb.com)
9
+ gem.description = %q{An easy to use database API for the NuoDB distributed database.}
10
+ gem.summary = %q{Native Ruby driver for NuoDB.}
11
+ gem.homepage = 'http://nuodb.github.com/ruby-nuodb/'
12
+ gem.license = 'BSD'
13
+
14
+ gem.rdoc_options = %w(--charset=UTF-8)
15
+ gem.extra_rdoc_files = %w[README.rdoc]
16
+
17
+ gem.extensions = %w(ext/nuodb/extconf.rb)
18
+
19
+ gem.add_development_dependency('rake', '~> 0.9')
20
+ gem.add_development_dependency('rdoc', '~> 3.10')
21
+
22
+ gem.files = `git ls-files`.split($\)
23
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
24
+ gem.require_paths = %w(lib ext)
25
+ end
@@ -0,0 +1,267 @@
1
+ #! /usr/local/bin/ruby
2
+
3
+ #
4
+ # Copyright (c) 2012, NuoDB, Inc.
5
+ # All rights reserved.
6
+ #
7
+ # Redistribution and use in source and binary forms, with or without
8
+ # modification, are permitted provided that the following conditions are met:
9
+ #
10
+ # * Redistributions of source code must retain the above copyright
11
+ # notice, this list of conditions and the following disclaimer.
12
+ # * Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ # * Neither the name of NuoDB, Inc. nor the names of its contributors may
16
+ # be used to endorse or promote products derived from this software
17
+ # without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ # DISCLAIMED. IN NO EVENT SHALL NUODB, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
23
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
25
+ # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ #
30
+
31
+ require 'test/unit'
32
+ require 'ostruct'
33
+ require 'nuodb'
34
+
35
+ CONFIG = OpenStruct.new
36
+ CONFIG.database = ENV['NUODB_DATABASE'] || 'test@localhost'
37
+ CONFIG.schema = ENV['NUODB_SCHEMA'] || 'test'
38
+ CONFIG.username = ENV['NUODB_USERNAME'] || 'cloud'
39
+ CONFIG.password = ENV['NUODB_PASSWORD'] || 'user'
40
+
41
+ class TC_Nuodb < Test::Unit::TestCase
42
+
43
+ def setup()
44
+ @database = CONFIG.database
45
+ @schema = CONFIG.schema
46
+ @username = CONFIG.username
47
+ @password = CONFIG.password
48
+ end
49
+
50
+ def teardown()
51
+ end
52
+
53
+ #def test_version()
54
+ # con = NuoDB::Connection.createSqlConnection @database, @schema, @username, @password
55
+ # dmd = con.getMetaData
56
+ # assert_match /^1\./, dmd.getDatabaseVersion
57
+ #end
58
+
59
+ def test_select_from_dual()
60
+ con = NuoDB::Connection.createSqlConnection @database, @schema, @username, @password
61
+ stmt = con.createStatement
62
+ assert_not_nil stmt
63
+ have_result = stmt.execute "select 1 from dual"
64
+ assert_equal true, have_result
65
+ end
66
+
67
+ def test_get_schema()
68
+ con = NuoDB::Connection.createSqlConnection @database, @schema, @username, @password
69
+ s = con.getSchema
70
+ assert_equal @schema.upcase, s
71
+ puts 'passed'
72
+ end
73
+
74
+ def test_ping()
75
+ con = NuoDB::Connection.createSqlConnection @database, @schema, @username, @password
76
+ assert_equal true, con.ping
77
+ end
78
+
79
+ def test_auto_commit_flag()
80
+ con = NuoDB::Connection.createSqlConnection @database, @schema, @username, @password
81
+ assert con.autocommit?
82
+ con.autocommit = false
83
+ assert !con.autocommit?
84
+ con.autocommit = true
85
+ assert con.autocommit?
86
+ end
87
+
88
+ def test_statement()
89
+ con = NuoDB::Connection.createSqlConnection @database, @schema, @username, @password
90
+ stmt = con.createStatement
91
+ assert_not_nil stmt
92
+ have_result = stmt.execute "drop table test_nuodb if exists"
93
+ assert_equal false, have_result
94
+ assert_nil stmt.getResultSet
95
+ have_result = stmt.execute <<EOS
96
+ create table test_nuodb (
97
+ i integer,
98
+ d double,
99
+ s string,
100
+ b boolean,
101
+ x integer generated always,
102
+ primary key (i))
103
+ EOS
104
+ assert_equal false, have_result
105
+ assert_nil stmt.getResultSet
106
+
107
+ stmt = con.createStatement
108
+ assert_not_nil stmt
109
+
110
+ have_result = stmt.execute "select * from test_nuodb"
111
+ assert_equal true, have_result
112
+ assert_equal(-1, stmt.getUpdateCount)
113
+ assert_nil stmt.getGeneratedKeys
114
+ result = stmt.getResultSet
115
+ assert_not_nil result
116
+ assert_equal false, result.next
117
+
118
+ result = stmt.executeQuery "select * from test_nuodb"
119
+ assert_equal(-1, stmt.getUpdateCount)
120
+ assert_nil stmt.getGeneratedKeys
121
+ assert_not_nil result
122
+ assert_equal false, result.next
123
+
124
+ meta = result.getMetaData
125
+ assert_not_nil meta
126
+ assert_equal 5, meta.getColumnCount
127
+
128
+ assert_equal "I", meta.getColumnName(1)
129
+ assert_equal :SQL_INTEGER, meta.getType(1)
130
+
131
+ assert_equal "D", meta.getColumnName(2)
132
+ assert_equal :SQL_DOUBLE, meta.getType(2)
133
+
134
+ assert_equal "S", meta.getColumnName(3)
135
+ assert_equal :SQL_STRING, meta.getType(3)
136
+
137
+ assert_equal "B", meta.getColumnName(4)
138
+ assert_equal :SQL_BOOLEAN, meta.getType(4)
139
+
140
+ assert_equal "X", meta.getColumnName(5)
141
+ assert_equal :SQL_INTEGER, meta.getType(5)
142
+
143
+ have_result = stmt.execute "insert into test_nuodb(i,d,s,b) values(10,1.1,'one',true)"
144
+ assert_equal false, have_result
145
+ assert_nil stmt.getResultSet
146
+ assert_equal 1, stmt.getUpdateCount
147
+ k = stmt.getGeneratedKeys
148
+ assert_not_nil k
149
+ assert_equal true, k.next
150
+ assert k.getInteger(1) > 0
151
+ assert_equal false, k.next
152
+
153
+ have_result = stmt.execute "update test_nuodb set s='update' where i=999"
154
+ assert_equal false, have_result
155
+ assert_nil stmt.getResultSet
156
+ assert_equal(-1, stmt.getUpdateCount)
157
+ assert_nil stmt.getGeneratedKeys
158
+
159
+ have_result = stmt.execute "update test_nuodb set s='update' where i=10"
160
+ assert_equal false, have_result
161
+ assert_nil stmt.getResultSet
162
+ assert_equal 1, stmt.getUpdateCount
163
+ assert_nil stmt.getGeneratedKeys
164
+
165
+ r = stmt.executeQuery "select * from test_nuodb"
166
+ assert_not_nil r
167
+ assert_equal true, r.next
168
+ assert_equal 10, r.getInteger(1)
169
+ assert_equal 1.1, r.getDouble(2)
170
+ assert_equal 'update', r.getString(3)
171
+ assert_equal true, r.getBoolean(4)
172
+
173
+ assert_equal false, r.next
174
+
175
+ end
176
+
177
+ def test_prepared_statement()
178
+ con = NuoDB::Connection.createSqlConnection @database, @schema, @username, @password
179
+ stmt = con.createStatement
180
+ assert_not_nil stmt
181
+ stmt.execute "drop table test_nuodb if exists"
182
+ stmt.execute <<EOS
183
+ create table test_nuodb (
184
+ i integer,
185
+ d double,
186
+ s string,
187
+ b boolean,
188
+ x integer generated always,
189
+ primary key (i))
190
+ EOS
191
+
192
+ insert = con.createPreparedStatement "insert into test_nuodb(i,d,s,b) values(?,?,?,?)"
193
+
194
+ insert.setInteger 1, 10
195
+ insert.setDouble 2, 1.1
196
+ insert.setString 3, 'one'
197
+ insert.setBoolean 4, true
198
+ insert.execute
199
+ k = insert.getGeneratedKeys
200
+ assert_not_nil k
201
+ assert k.next
202
+ assert k.getInteger(1) > 0
203
+ assert !k.next
204
+
205
+ #stmt.execute "insert into test_nuodb(i,d,s,b) values(10,1.1,'one',true)"
206
+ stmt.execute "insert into test_nuodb(i,d,s,b) values(20,2.2,'two',false)"
207
+
208
+ query = con.createPreparedStatement "select * from test_nuodb where i=?"
209
+ assert_not_nil query
210
+ assert_nil query.getGeneratedKeys
211
+ assert_equal(-1, query.getUpdateCount)
212
+
213
+ query.setInteger 1, 10
214
+ r = query.executeQuery
215
+ assert_nil query.getGeneratedKeys
216
+ assert_equal(-1, query.getUpdateCount)
217
+ assert_not_nil r
218
+ assert_equal true, r.next
219
+ assert_equal 10, r.getInteger(1)
220
+ assert_equal 1.1, r.getDouble(2)
221
+ assert_equal 'one', r.getString(3)
222
+ assert_equal true, r.getBoolean(4)
223
+
224
+ assert_equal false, r.next
225
+
226
+ query.setInteger 1, 20
227
+ r = query.executeQuery
228
+ assert_nil query.getGeneratedKeys
229
+ assert_not_nil r
230
+ assert_equal true, r.next
231
+ assert_equal 20, r.getInteger(1)
232
+ assert_equal 2.2, r.getDouble(2)
233
+ assert_equal 'two', r.getString(3)
234
+ assert_equal false, r.getBoolean(4)
235
+
236
+ assert_equal false, r.next
237
+
238
+ update = con.createPreparedStatement 'update test_nuodb set s=? where i=?'
239
+ assert_not_nil update
240
+ update.setString 1, 'change'
241
+
242
+ update.setInteger 2, 999
243
+ update.execute
244
+ assert_equal(-1, update.getUpdateCount)
245
+
246
+ update.setString 1, 'change'
247
+ update.setInteger 2, 20
248
+ update.execute
249
+ assert_equal 1, update.getUpdateCount
250
+
251
+ query.setInteger 1, 20
252
+ r = query.executeQuery
253
+ assert_not_nil r
254
+ assert_equal true, r.next
255
+ assert_equal 20, r.getInteger(1)
256
+ #assert_equal 'change', r.getString(3)
257
+ assert_equal -1, update.getUpdateCount
258
+
259
+ # todo rewrite these tests using rspec and clean up this mess
260
+ # also, just as i added to the AR side, have the rakefile set
261
+ # up the database for us, and have tables reset for each test
262
+ # and close connections.
263
+
264
+ end
265
+
266
+ end
267
+
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nuodb
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.rc.1
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - ! '''Robert'
9
+ - Buck'
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-11-13 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '0.9'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '0.9'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rdoc
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '3.10'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '3.10'
47
+ description: An easy to use database API for the NuoDB distributed database.
48
+ email:
49
+ - support@nuodb.com
50
+ executables: []
51
+ extensions:
52
+ - ext/nuodb/extconf.rb
53
+ extra_rdoc_files:
54
+ - README.rdoc
55
+ files:
56
+ - .gitignore
57
+ - AUTHORS
58
+ - COPYING
59
+ - Gemfile
60
+ - History.txt
61
+ - LICENSE
62
+ - Manifest.txt
63
+ - README.rdoc
64
+ - Rakefile
65
+ - ext/nuodb/extconf.rb
66
+ - ext/nuodb/nuodb.cpp
67
+ - lib/nuodb.rb
68
+ - lib/nuodb/error.rb
69
+ - lib/nuodb/version.rb
70
+ - nuodb.gemspec
71
+ - test/test_nuodb.rb
72
+ homepage: http://nuodb.github.com/ruby-nuodb/
73
+ licenses:
74
+ - BSD
75
+ post_install_message:
76
+ rdoc_options:
77
+ - --charset=UTF-8
78
+ require_paths:
79
+ - lib
80
+ - ext
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>'
91
+ - !ruby/object:Gem::Version
92
+ version: 1.3.1
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.24
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Native Ruby driver for NuoDB.
99
+ test_files:
100
+ - test/test_nuodb.rb