momomoto 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/momomoto/database.rb +7 -2
- data/lib/momomoto/information_schema/key_column_usage.rb +0 -10
- data/lib/momomoto/information_schema/routines.rb +1 -1
- data/lib/momomoto/information_schema/table_constraints.rb +0 -10
- data/lib/momomoto/procedure.rb +1 -0
- data/test/test_functions.sql +11 -0
- data/test/test_procedure.rb +17 -0
- metadata +2 -2
data/lib/momomoto/database.rb
CHANGED
@@ -108,7 +108,7 @@ module Momomoto
|
|
108
108
|
conditions = { :table_name => table_name }
|
109
109
|
conditions[:table_schema] = schema_name if schema_name
|
110
110
|
cols = Momomoto::Information_schema::Columns.select( conditions )
|
111
|
-
raise CriticalError, "Table without columns" if cols.length < 1
|
111
|
+
raise CriticalError, "Table without columns (#{table_name})" if cols.length < 1
|
112
112
|
cols.each do | col |
|
113
113
|
columns[col.column_name.to_sym] = Momomoto::Datatype.const_get(col.data_type.gsub(' ','_').capitalize).new( col )
|
114
114
|
end
|
@@ -123,6 +123,12 @@ module Momomoto
|
|
123
123
|
params.each do | param |
|
124
124
|
p << { param.parameter_name.to_sym => Momomoto::Datatype.const_get(param.data_type.gsub(' ','_').capitalize).new }
|
125
125
|
end
|
126
|
+
# mark parameters of strict procedures as not null
|
127
|
+
if Information_schema::Routines.select_single(:routine_name=>procedure_name).is_null_call == 'YES'
|
128
|
+
p.each do | param |
|
129
|
+
param[param.keys.first].instance_variable_set(:@not_null,true)
|
130
|
+
end
|
131
|
+
end
|
126
132
|
p
|
127
133
|
end
|
128
134
|
|
@@ -137,7 +143,6 @@ module Momomoto
|
|
137
143
|
c
|
138
144
|
end
|
139
145
|
|
140
|
-
|
141
146
|
# begin a transaction
|
142
147
|
def begin
|
143
148
|
execute( "BEGIN;" )
|
@@ -2,17 +2,7 @@
|
|
2
2
|
module Momomoto
|
3
3
|
module Information_schema
|
4
4
|
class Key_column_usage < Momomoto::Table
|
5
|
-
primary_keys( [] )
|
6
5
|
schema_name( "information_schema" )
|
7
|
-
columns( { :constraint_catalog => Momomoto::Datatype::Character_varying.new,
|
8
|
-
:constraint_schema => Momomoto::Datatype::Character_varying.new,
|
9
|
-
:constraint_name => Momomoto::Datatype::Character_varying.new,
|
10
|
-
:table_catalog => Momomoto::Datatype::Character_varying.new,
|
11
|
-
:table_schema => Momomoto::Datatype::Character_varying.new,
|
12
|
-
:table_name => Momomoto::Datatype::Character_varying.new,
|
13
|
-
:column_name => Momomoto::Datatype::Character_varying.new,
|
14
|
-
:ordinal_position => Momomoto::Datatype::Integer.new
|
15
|
-
} )
|
16
6
|
end
|
17
7
|
end
|
18
8
|
end
|
@@ -4,16 +4,6 @@ module Momomoto
|
|
4
4
|
class Table_constraints < Momomoto::Table
|
5
5
|
primary_keys( [] )
|
6
6
|
schema_name( "information_schema" )
|
7
|
-
columns( { :constraint_catalog => Momomoto::Datatype::Text.new,
|
8
|
-
:constraint_schema => Momomoto::Datatype::Text.new,
|
9
|
-
:constraint_name => Momomoto::Datatype::Text.new,
|
10
|
-
:table_catalog => Momomoto::Datatype::Text.new,
|
11
|
-
:table_schema => Momomoto::Datatype::Text.new,
|
12
|
-
:table_name => Momomoto::Datatype::Text.new,
|
13
|
-
:constraint_type => Momomoto::Datatype::Text.new,
|
14
|
-
:is_deferrable => Momomoto::Datatype::Text.new,
|
15
|
-
:initially_deferred => Momomoto::Datatype::Text.new
|
16
|
-
} )
|
17
7
|
end
|
18
8
|
end
|
19
9
|
end
|
data/lib/momomoto/procedure.rb
CHANGED
@@ -77,6 +77,7 @@ module Momomoto
|
|
77
77
|
parameters.each do | parameter |
|
78
78
|
field_name, datatype = parameter.to_a.first
|
79
79
|
raise Error, "parameter #{field_name} not specified" if not params.member?( field_name )
|
80
|
+
raise Error, "Not null fields(#{field_name}) need to be set" if !params[field_name] && datatype.not_null?
|
80
81
|
args << datatype.escape( params[field_name] )
|
81
82
|
end
|
82
83
|
args.join(',')
|
data/test/test_functions.sql
CHANGED
@@ -3,6 +3,10 @@ CREATE OR REPLACE FUNCTION test_parameter_sql( param1 INTEGER ) RETURNS INTEGER
|
|
3
3
|
SELECT $1;
|
4
4
|
$$ LANGUAGE sql;
|
5
5
|
|
6
|
+
CREATE OR REPLACE FUNCTION test_parameter_sql_strict( param1 INTEGER ) RETURNS INTEGER AS $$
|
7
|
+
SELECT $1;
|
8
|
+
$$ LANGUAGE sql STRICT;
|
9
|
+
|
6
10
|
CREATE OR REPLACE FUNCTION test_parameter_plpgsql( param1 INTEGER, param2 TEXT ) RETURNS INTEGER AS $$
|
7
11
|
DECLARE
|
8
12
|
BEGIN
|
@@ -10,6 +14,13 @@ CREATE OR REPLACE FUNCTION test_parameter_plpgsql( param1 INTEGER, param2 TEXT )
|
|
10
14
|
END;
|
11
15
|
$$ LANGUAGE plpgsql;
|
12
16
|
|
17
|
+
CREATE OR REPLACE FUNCTION test_parameter_plpgsql_strict( param1 INTEGER, param2 TEXT ) RETURNS INTEGER AS $$
|
18
|
+
DECLARE
|
19
|
+
BEGIN
|
20
|
+
RETURN param1;
|
21
|
+
END;
|
22
|
+
$$ LANGUAGE plpgsql STRICT;
|
23
|
+
|
13
24
|
CREATE OR REPLACE FUNCTION test_set_returning( person_id INTEGER ) RETURNS SETOF person AS $$
|
14
25
|
DECLARE
|
15
26
|
result RECORD;
|
data/test/test_procedure.rb
CHANGED
@@ -71,5 +71,22 @@ class TestProcedure < Test::Unit::TestCase
|
|
71
71
|
Test_set_returning.call({:person_id => 5},{:person_id => 5},{:order=>:person_id,:limit=>10} )
|
72
72
|
end
|
73
73
|
|
74
|
+
def test_call_strict
|
75
|
+
a = Class.new(Momomoto::Procedure)
|
76
|
+
a.procedure_name("test_parameter_sql")
|
77
|
+
assert_equal( false, a.parameters[0][:param1].not_null? )
|
78
|
+
assert_raise( Momomoto::Error ) { a.call }
|
79
|
+
assert_nothing_raised { a.call({:param1=>nil})}
|
80
|
+
assert_nothing_raised { a.call({:param1=>1})}
|
81
|
+
|
82
|
+
b = Class.new(Momomoto::Procedure)
|
83
|
+
b.procedure_name("test_parameter_sql_strict")
|
84
|
+
assert_equal( true, b.parameters[0][:param1].not_null? )
|
85
|
+
assert_raise( Momomoto::Error ) { b.call }
|
86
|
+
assert_raise( Momomoto::Error ) { b.call({:param1=>nil})}
|
87
|
+
assert_nothing_raised { b.call({:param1=>1})}
|
88
|
+
|
89
|
+
end
|
90
|
+
|
74
91
|
end
|
75
92
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: momomoto
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.1.7
|
7
|
+
date: 2007-10-07 00:00:00 +02:00
|
8
8
|
summary: Momomoto is an object relational mapper for PostgreSQL.
|
9
9
|
require_paths:
|
10
10
|
- lib
|