activerecord-ingres-adapter 3.0.2

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/ext/Unicode.h ADDED
@@ -0,0 +1,56 @@
1
+ /*
2
+ ** Copyright (c) 2009 Ingres Corporation
3
+ **
4
+ ** This program is free software; you can redistribute it and/or modify
5
+ ** it under the terms of the GNU General Public License version 2 as
6
+ ** published by the Free Software Foundation.
7
+ **
8
+ ** This program is distributed in the hope that it will be useful,
9
+ ** but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ ** GNU General Public License for more details.
12
+ **
13
+ ** You should have received a copy of the GNU General Public License along
14
+ ** with this program; if not, write to the Free Software Foundation, Inc.,
15
+ ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
+ */
17
+
18
+ /* static char Sccsid[] = "$Id$"; */
19
+
20
+ /*
21
+ ** UNCIODE.H
22
+ **
23
+ ** History
24
+ ** 24-Aug-2009 (Grant.Croker@ingres.com)
25
+ ** Created
26
+ */
27
+
28
+ #include <stdlib.h>
29
+
30
+ typedef unsigned short ucs2;
31
+ typedef unsigned long ucs4;
32
+ typedef unsigned char utf8;
33
+
34
+ typedef short i2;
35
+ typedef long i4;
36
+ typedef unsigned short u_i2;
37
+ #ifndef _WIN32
38
+ typedef long long __int64;
39
+ #endif
40
+
41
+ #ifndef FALSE
42
+ #define FALSE 0
43
+ #endif
44
+ #ifndef TRUE
45
+ #define TRUE 0
46
+ #endif
47
+
48
+ #define UTF8 utf8
49
+ #define UCS2 ucs2
50
+ #define UCS4 ucs4
51
+
52
+ int utf8_to_utf16 (UTF8 * sourceStart, const UTF8 * sourceEnd, UCS2 * targetStart, const UCS2 * targetEnd, long *reslen);
53
+ int utf16_to_utf8 (UCS2 * sourceStart, const UCS2 * sourceEnd, UTF8 * targetStart, const UTF8 * targetEnd, long *reslen);
54
+ /*
55
+ vim: ts=2 sw=2 expandtab
56
+ */
@@ -0,0 +1 @@
1
+ ruby -r mkmf extconf.rb --with-ingres-include="%II_SYSTEM%\ingres\files" --with-ingres-lib="%II_SYSTEM%\ingres\lib"
data/ext/extconf.rb ADDED
@@ -0,0 +1,85 @@
1
+ # UNIX/Linux/OS X
2
+ # ruby -r mkmf extconf.rb --with-ingres-include="${II_SYSTEM}/ingres/files/" --with-ingres-lib="${II_SYSTEM}/ingres/lib/"
3
+ # Windows
4
+ # ruby -r mkmf extconf.rb --with-ingres-include="%II_SYSTEM%\ingres\files\" --with-ingres-lib="%II_SYSTEM%\ingres\lib\"
5
+ #
6
+ # If mkmf is not found on your system, install something like ruby1.8-dev
7
+ #
8
+ require 'mkmf'
9
+ puts "Start extconf.rb"
10
+
11
+ #Get the supplied library/header directory (if any)
12
+ ingres_dirs=dir_config('ingres')
13
+
14
+ #Sanity checks, --with-ingres-xxx override system set II_SYSTEM
15
+ if ingres_dirs[0] =~ /files/ and ingres_dirs[1] =~ /lib/
16
+ puts "Using supplied directories:"
17
+ puts "Headers - #{ingres_dirs[0]}"
18
+ puts "Libraries - #{ingres_dirs[1]}"
19
+
20
+ elsif ENV["II_SYSTEM"] # fallback
21
+ puts "Using II_SYSTEM=#{ENV['II_SYSTEM']}"
22
+ $CFLAGS += " -I#{ENV["II_SYSTEM"]}/ingres/files"
23
+ if RUBY_PLATFORM !~ /mswin32/
24
+ libdir = ENV["II_SYSTEM"] + "/ingres/lib"
25
+ $LDFLAGS += " -L#{libdir}"
26
+ $LDFLAGS += " -lq.1 -lcompat.1 -lframe.1 -liiapi.1"
27
+ if RUBY_PLATFORM =~ /solaris/
28
+ $LDFLAGS += " -lsocket"
29
+ end
30
+ if RUBY_PLATFORM =~ /linux/
31
+ $LDFLAGS += " -lrt"
32
+ end
33
+ else
34
+ libdir = "#{ENV["II_SYSTEM"]}\\ingres\\lib"
35
+ $LIBPATH.push("-libpath:\"#{libdir}\"")
36
+ end
37
+ else
38
+ puts "Unable to proceed without the environment variable II_SYSTEM or the flags --with-ingres-files/--with-ingres-lib pointing to a valid Ingres installation"
39
+ exit(1)
40
+ end
41
+
42
+ if have_header('iiapi.h')
43
+ if RUBY_PLATFORM =~ /mswin32/
44
+ if have_library('oiapi','IIapi_initialize') # Check for Ingres 2.6
45
+ have_library('ingres')
46
+ puts "Found Ingres 2.6 or earlier.\n"
47
+ elsif have_library('iilibapi','IIapi_initialize')
48
+ have_library('libingres')
49
+ puts "Found Ingres 2006/9.0.4 or later.\n"
50
+ else
51
+ puts "\n\nI couldn't find the Ingres libraries so I didn't create your Makefile.\n"
52
+ puts "Do you have Ingres installed?\n"
53
+ puts "Be sure to use the '--with-ingres-include' and '--with-ingres-lib' options.\n"
54
+ puts "See the first line of extconf.rb for an example.\n\n"
55
+ puts "BUILD FAILED\n\n"
56
+ exit
57
+ end
58
+ else
59
+
60
+ if have_library('iiapi')
61
+ else
62
+ puts "\n\nI couldn't find the Ingres libraries so I didn't create your Makefile.\n"
63
+ puts "Do you have Ingres installed?\n"
64
+ puts "Be sure to use the '--with-ingres-include' and '--with-ingres-lib' options.\n"
65
+ puts "See the first line of extconf.rb for an example.\n\n"
66
+ puts "BUILD FAILED\n\n"
67
+ exit
68
+ end
69
+
70
+ if ENV["INGRES_RUBY_DEBUG"] == "Y"
71
+ $CFLAGS += " -g "
72
+ end
73
+ end
74
+ $OBJS=['Unicode.o','Ingres.c']
75
+
76
+ if RUBY_VERSION.to_f >= 1.9
77
+ $CFLAGS << ' -DRUBY_19_COMPATIBILITY'
78
+ end
79
+
80
+ create_makefile('Ingres')
81
+ else
82
+ puts "Unable to find iiapi.h, please verify your setup"
83
+ end
84
+ #do not remove the following line
85
+ #vim: ts=4 sw=4 expandtabs
@@ -0,0 +1,11 @@
1
+ # Database and connection information for the tests
2
+ # Use a vnode for Windows as the build box only has a
3
+ # client installation
4
+ if RUBY_PLATFORM =~ /mswin32/
5
+ @@database = "ruby::demodb"
6
+ else
7
+ @@database = "demodb"
8
+ end
9
+ @@username = "ruby"
10
+ @@password = "ruby"
11
+
@@ -0,0 +1,12 @@
1
+ require 'Ingres'
2
+ require 'test/unit'
3
+ require 'ext/tests/config.rb'
4
+
5
+ class TestIngresConnection < Test::Unit::TestCase
6
+
7
+ def test_connect
8
+ ing = Ingres.new()
9
+ assert_kind_of(Ingres, ing.connect(@@database), "conn is not an Ingres object")
10
+ end
11
+
12
+ end
@@ -0,0 +1,31 @@
1
+ require 'Ingres'
2
+ require 'test/unit'
3
+ require 'ext/tests/config.rb'
4
+
5
+ class TestIngresConnectionHash < Test::Unit::TestCase
6
+
7
+ def test_connect_hash
8
+ ing = Ingres.new()
9
+ assert_kind_of(Ingres, ing.connect(:database => @@database), "conn is not an Ingres object")
10
+ end
11
+
12
+ def test_connect_hash_no_database
13
+ ing = Ingres.new()
14
+ assert_raise ArgumentError do
15
+ ing.connect()
16
+ end
17
+ end
18
+
19
+ def test_connect_hash_with_login_password
20
+ ing = Ingres.new()
21
+ assert_kind_of(Ingres, ing.connect_with_credentials(:database => @@database, :username => @@username, :password => @@password), "conn is not an Ingres object")
22
+ end
23
+
24
+ def test_connect_hash_with_login_only
25
+ ing = Ingres.new()
26
+ assert_raise ArgumentError do
27
+ ing.connect_with_credentials(:database => @@database, :username => @@username)
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,14 @@
1
+ require 'Ingres'
2
+ require 'test/unit'
3
+ require 'ext/tests/config.rb'
4
+
5
+ class TestIngresConnection < Test::Unit::TestCase
6
+
7
+ def test_connect_with_login_only
8
+ ing = Ingres.new()
9
+ assert_raise ArgumentError do
10
+ ing.connect_with_credentials(@@database,@@username)
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,12 @@
1
+ require 'Ingres'
2
+ require 'test/unit'
3
+ require 'ext/tests/config.rb'
4
+
5
+ class TestIngresConnection < Test::Unit::TestCase
6
+
7
+ def test_connect_with_login_password
8
+ ing = Ingres.new()
9
+ assert_kind_of(Ingres, ing.connect_with_credentials(@@database,@@username,@@password), "conn is not an Ingres object")
10
+ end
11
+
12
+ end
@@ -0,0 +1,14 @@
1
+ require 'Ingres'
2
+ require 'test/unit'
3
+ require 'ext/tests/config.rb'
4
+
5
+ class TestIngresDualConnections < Test::Unit::TestCase
6
+
7
+ def test_dual_connections
8
+ ing = Ingres.new()
9
+ assert_kind_of(Ingres, ing.connect(@@database), "conn is not an Ingres object")
10
+ ing2 = Ingres.new()
11
+ assert_kind_of(Ingres, ing2.connect(@@database), "conn is not an Ingres object")
12
+ end
13
+
14
+ end
@@ -0,0 +1,47 @@
1
+ require 'Ingres'
2
+ require 'test/unit'
3
+ require 'ext/tests/config.rb'
4
+
5
+ class TestIngresEnvionmentDateFormat < Test::Unit::TestCase
6
+
7
+ def test_connect_env_date_iso4
8
+ @@ing = Ingres.new()
9
+ @@ing.connect(:database => @@database, :date_format => Ingres::DATE_FORMAT_ISO4)
10
+ assert_equal "20091109 15:14:00", @@ing.execute("select date('20091109 15:14:00')").flatten[0]
11
+ end
12
+
13
+ def test_connect_env_date_finland
14
+ @@ing = Ingres.new()
15
+ @@ing.connect(:database => @@database, :date_format => Ingres::DATE_FORMAT_FINLAND)
16
+ assert_equal "2009-11-09 15:14:00", @@ing.execute("select date('2009-11-09 15:14:00')").flatten[0]
17
+ end
18
+
19
+ def test_connect_env_date_multinational4
20
+ @@ing = Ingres.new()
21
+ @@ing.connect(:database => @@database, :date_format => Ingres::DATE_FORMAT_MULTINATIONAL4)
22
+ assert_equal "09/11/2009 15:14:00", @@ing.execute("select date('09/11/2009 15:14:00')").flatten[0]
23
+ end
24
+
25
+ # Same as above but using Ingres.set_environment()
26
+ def test_set_env_date_iso4
27
+ @@ing = Ingres.new()
28
+ @@ing.connect(:database => @@database)
29
+ @@ing.set_environment(:date_format => Ingres::DATE_FORMAT_ISO4)
30
+ assert_equal "20061012 01:09:00", @@ing.execute("select rt_arrive_at, rt_depart_at from route where rt_depart_from = 'VLL' and rt_arrive_to = 'LHR'")[0][0]
31
+ end
32
+
33
+ def test_set_env_date_finland
34
+ @@ing = Ingres.new()
35
+ @@ing.connect(:database => @@database)
36
+ @@ing.set_environment(:date_format => Ingres::DATE_FORMAT_FINLAND)
37
+ assert_equal "2006-10-11 20:26:00", @@ing.execute("select rt_arrive_at, rt_depart_at from route where rt_depart_from = 'VLL' and rt_arrive_to = 'LHR'")[0][1]
38
+ end
39
+
40
+ def test_set_env_date_multinational4
41
+ @@ing = Ingres.new()
42
+ @@ing.connect(:database => @@database)
43
+ @@ing.set_environment(:date_format => Ingres::DATE_FORMAT_MULTINATIONAL4)
44
+ assert_equal "11/10/2006 23:40:00", @@ing.execute("select rt_arrive_at, rt_depart_at from route where rt_depart_from = 'VLL' and rt_arrive_to = 'LHR'")[1][0]
45
+ end
46
+
47
+ end
@@ -0,0 +1,29 @@
1
+ require 'Ingres'
2
+ require 'test/unit'
3
+ require 'ext/tests/config.rb'
4
+
5
+ class TestIngresQuerySimple < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @@ing = Ingres.new()
9
+ assert_kind_of(Ingres, @@ing.connect(@@database, @@username, @@password), "conn is not an Ingres object")
10
+ end
11
+
12
+ def teardown
13
+ @@ing.disconnect
14
+ end
15
+
16
+ def test_query_username
17
+ # ing.execute returns and array so we want the first and only element
18
+ assert_equal @@username, @@ing.execute("select dbmsinfo('session_user')").flatten[0]
19
+ end
20
+
21
+ def test_tables
22
+ if @@database == "demodb"
23
+ assert_not_nil @@ing.tables.include? "airport"
24
+ assert_not_nil @@ing.tables.include? "country"
25
+ assert_not_nil @@ing.tables.include? "user_profile"
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,22 @@
1
+ require 'Ingres'
2
+ require 'test/unit'
3
+ require 'ext/tests/config.rb'
4
+
5
+ class TestIngresQueryUsername < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @ing = Ingres.new()
9
+ @ing.connect(@@database, @@username, @@password)
10
+ end
11
+
12
+ def test_query_username
13
+ # ing.execute returns and array so we want the first and only element
14
+ assert_equal @@username, @ing.execute("select dbmsinfo('username')")[0][0]
15
+ end
16
+
17
+ def test_tables
18
+ # ing.execute returns and array so we want the first and only element
19
+ assert_not_nil @ing.tables.include? "airport"
20
+ end
21
+
22
+ end
@@ -0,0 +1,109 @@
1
+ require 'Ingres'
2
+ require 'test/unit'
3
+ require 'ext/tests/config.rb'
4
+
5
+ class TestIngresTransactionSavePoints < Test::Unit::TestCase
6
+
7
+ # Data set used for inserting
8
+ @@data = [[1, "one"], [2, "two"], [3, "three"], [4, "four"], [5, "five"], [6, "six"], [7, "seven"], [8, "eight"], [9, "nine"], [10, "ten"]]
9
+ # Some savepoint => rollback values in the form of at savepoint x rollback to (=>) y
10
+ @@rollback_points = { 5 => 3, 7 => 6 }
11
+
12
+ def setup
13
+ @@ing = Ingres.new()
14
+ #@@ing.set_debug_flag("GLOBAL_DEBUG","TRUE")
15
+ assert_kind_of(Ingres, @@ing.connect(@@database, @@username, @@password), "conn is not an Ingres object")
16
+ end
17
+
18
+ def teardown
19
+ # drop the savepoint_tests table if it happens to be around still
20
+ if @@ing.tables.include? "savepoint_tests"
21
+ @@ing.execute "drop table savepoint_tests"
22
+ end
23
+ @@ing.disconnect
24
+ end
25
+
26
+ # A simple test to create a savepoint, if this fails then the rest of this unit test
27
+ # has no chance
28
+ def test_savepoint_single
29
+ @@ing.execute "start transaction"
30
+ @@ing.execute "create table savepoint_tests (id integer not null, txt varchar(100))"
31
+ @@ing.savepoint "savepoint_1"
32
+ @@ing.execute "insert into savepoint_tests values (1, 'one')"
33
+ @@ing.rollback
34
+ end
35
+
36
+ # Generate a savepoint for each insert into the table and rollback them all at the end
37
+ def test_savepoint_multiple
38
+ @@ing.execute "start transaction"
39
+ @@ing.execute "create table savepoint_tests (id integer not null, txt varchar(100))"
40
+ @@data.each { |element|
41
+ @@ing.execute("insert into savepoint_tests values (#{element[0]}, '#{element[1]}')")
42
+ @@ing.savepoint "savepoint_#{element[0]}"
43
+ }
44
+ @@ing.rollback
45
+ end
46
+
47
+ # Generate a savepoint for each insert then rollback to specified savepoints verifying
48
+ # we have actually rolled back
49
+ def test_savepoint_named_rollback
50
+ @@ing.execute "start transaction"
51
+ @@ing.execute "create table savepoint_tests (id integer not null, txt varchar(100))"
52
+ @@data.each { |element|
53
+ @@ing.execute("insert into savepoint_tests values (#{element[0]}, '#{element[1]}')")
54
+ @@ing.savepoint "savepoint_#{element[0]}"
55
+ }
56
+ @@ing.rollback "savepoint_8"
57
+ assert_equal 8, @@ing.execute("select max(id) from savepoint_tests").flatten[0]
58
+ @@ing.rollback "savepoint_5"
59
+ assert_equal 5, @@ing.execute("select max(id) from savepoint_tests").flatten[0]
60
+ @@ing.rollback "savepoint_3"
61
+ assert_equal 3, @@ing.execute("select max(id) from savepoint_tests").flatten[0]
62
+ @@ing.rollback
63
+ end
64
+
65
+ # Test the ability to carry on working after a rollback has been issued against a named savepoint.
66
+ # Then carry on inserting then rollback again.
67
+ def test_savepoint_nested_transactions
68
+ @@ing.execute "start transaction"
69
+ @@ing.execute "create table savepoint_tests (id integer not null, txt varchar(100))"
70
+ @@data.each { |data_set|
71
+ @@ing.execute("insert into savepoint_tests values (#{data_set[0]}, '#{data_set[1]}')")
72
+ @@ing.savepoint "savepoint_#{data_set[0]}"
73
+ if @@rollback_points.has_key?(data_set[0])
74
+ @savepoint_no = @@rollback_points.values_at(data_set[0])
75
+ @@ing.rollback "savepoint_#{@savepoint_no}"
76
+ assert_equal @savepoint_no, @@ing.execute("select max(id) from savepoint_tests").flatten
77
+ end
78
+ }
79
+ @@ing.rollback
80
+ end
81
+
82
+ # Verify the driver raises a RuntimeError exception when rolling back to a non-existant
83
+ # savepoint
84
+ def test_savepoint_rollback_non_existent
85
+ @@ing.execute "start transaction"
86
+ @@ing.execute "create table savepoint_tests (id integer not null, txt varchar(100))"
87
+ @@data.each { |data_set|
88
+ @@ing.execute("insert into savepoint_tests values (#{data_set[0]}, '#{data_set[1]}')")
89
+ @@ing.savepoint "savepoint_#{data_set[0]}"
90
+ if (data_set[0]) == 5
91
+ @@ing.rollback "savepoint_3"
92
+ assert_equal 3, @@ing.execute("select max(id) from savepoint_tests").flatten[0]
93
+ end
94
+ }
95
+ assert_raise RuntimeError do
96
+ @@ing.rollback "savepoint_5"
97
+ end
98
+ end
99
+
100
+ # Ingres requires that a transaction has been started using "start transaction" before
101
+ # a savepoint can be created
102
+ def test_savepoint_no_transaction
103
+ # Cannot start a savepoint with no active transaction
104
+ assert_raise RuntimeError do
105
+ @@ing.savepoint "savepoint_1"
106
+ end
107
+ end
108
+
109
+ end