fluiddb 0.0.29 → 0.0.31

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/FluidDb.rb +3 -2
  2. data/lib/FluidDb/Pgsql.rb +17 -6
  3. metadata +2 -2
data/lib/FluidDb.rb CHANGED
@@ -24,6 +24,7 @@ module FluidDb
24
24
  class Base
25
25
 
26
26
  attr_writer :verbose
27
+ attr_reader :connection
27
28
 
28
29
  @connection;
29
30
  @uri
@@ -34,14 +35,14 @@ module FluidDb
34
35
  # @param [String] uri a location for the resource to which we will attach, eg mysql://user:pass@127.0.0.1/foo
35
36
  def initialize(uri)
36
37
  if uri.kind_of? String then
37
- @uri = Uri.parse( uri )
38
+ @uri = URI.parse( uri )
38
39
  else
39
40
  @uri = uri
40
41
  end
41
42
 
42
43
  self.connect
43
44
  end
44
-
45
+
45
46
  def splice_sql( sql, params )
46
47
 
47
48
  if params.length != sql.count( "?" ) then
data/lib/FluidDb/Pgsql.rb CHANGED
@@ -94,25 +94,36 @@ module FluidDb
94
94
 
95
95
 
96
96
  def execute( sql, params, expected_affected_rows=nil )
97
- # sql = self.format_to_sql( sql, params )
97
+ sql = self.format_to_sql( sql, params )
98
+ r = @connection.exec(sql)
98
99
 
99
- parts = sql.split( "?" )
100
+ if !expected_affected_rows.nil? and
101
+ r.cmd_tuples != expected_affected_rows then
102
+ raise ExpectedAffectedRowsError.new( "Expected affected rows, #{expected_affected_rows}, Actual affected rows, #{r.cmd_tuples}")
103
+ end
104
+ rescue PG::Error => e
105
+ raise DuplicateKeyError.new( e.message ) unless e.message.index( "duplicate key value violates unique constraint" ).nil?
106
+
107
+ raise e
108
+ end
109
+
110
+ def exec_params( sql, params, expected_affected_rows=nil )
111
+ parts = sql.split( "?" )
100
112
  sql = ""
101
113
  parts.each_with_index do |p,idx|
102
114
  sql = sql + p;
103
115
  sql = sql + "$#{idx+1}" if idx < parts.length - 1
104
116
  end
105
-
106
117
  r = @connection.exec_params( sql, params );
107
-
118
+
108
119
  if !expected_affected_rows.nil? and
109
120
  r.cmd_tuples != expected_affected_rows then
110
121
  raise ExpectedAffectedRowsError.new( "Expected affected rows, #{expected_affected_rows}, Actual affected rows, #{r.cmd_tuples}")
111
122
  end
112
123
  rescue PG::Error => e
113
- raise DuplicateKeyError.new( e.message ) unless e.message.index( "duplicate key value violates unique constraint" ).nil?
124
+ raise DuplicateKeyError.new( e.message ) unless e.message.index( "duplicate key value violates unique constraint" ).nil?
114
125
 
115
- raise e
126
+ raise e
116
127
  end
117
128
 
118
129
  def insert( sql, params )
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluiddb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.29
4
+ version: 0.0.31
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-13 00:00:00.000000000 Z
12
+ date: 2013-04-30 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A semantic layer for db interaction
15
15
  email: guy@guyirvine.com