fluiddb 0.1.10 → 0.1.13

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/FluidDb.rb CHANGED
@@ -132,7 +132,7 @@ module FluidDb
132
132
  end
133
133
 
134
134
  # Return a single row from the database, given the sql parameter.
135
- # Throwa an error for no data.
135
+ # Throws an error for no data.
136
136
  # Throws an error for more than 1 row
137
137
  #
138
138
  # @param [String] sql The SELECT statement to run
@@ -142,7 +142,7 @@ module FluidDb
142
142
  end
143
143
 
144
144
  # Return a single value is returned from a single row from the database, given the sql parameter.
145
- # Throwa an error for no data.
145
+ # Throws an error for no data.
146
146
  # Throws an error for more than 1 row
147
147
  #
148
148
  # @param [String] sql The SELECT statement to run
data/lib/FluidDb/Mock.rb CHANGED
@@ -4,10 +4,11 @@ module FluidDb
4
4
 
5
5
  #A constant way of enabling testing for FluidDb
6
6
  class Mock<Base
7
+ attr_reader :hash
7
8
 
8
9
  @verbose = false
9
10
 
10
- def initialize
11
+ def initialize(uri)
11
12
  @hash = Hash.new
12
13
 
13
14
  end
data/lib/FluidDb/Pgsql.rb CHANGED
@@ -17,23 +17,23 @@ module FluidDb
17
17
  hash["port"] = uri.port unless uri.port.nil?
18
18
  hash["user"] = uri.user unless uri.user.nil?
19
19
  hash["password"] = uri.password unless uri.password.nil?
20
-
20
+
21
21
  @connection = PG.connect( hash )
22
22
  end
23
-
23
+
24
24
  def close
25
25
  @connection.close
26
26
  end
27
-
27
+
28
28
  def queryForArray( sql, params=[] )
29
29
  sql = self.format_to_sql( sql, params )
30
30
  results = @connection.exec(sql)
31
-
31
+
32
32
  # if ( $result === false ) then
33
33
  # $message = pg_last_error( $this->connection );
34
34
  # throw new Fluid_ConnectionException( $message );
35
35
  #end
36
-
36
+
37
37
  case results.num_tuples
38
38
  when -1
39
39
  raise FluidDb::ConnectionError.new
@@ -98,19 +98,19 @@ module FluidDb
98
98
 
99
99
  self.verboseLog( "#{self.class.name}.execute. #{sql}" )
100
100
  r = @connection.exec(sql)
101
-
101
+
102
102
  if !expected_affected_rows.nil? and
103
103
  r.cmd_tuples != expected_affected_rows then
104
104
  raise ExpectedAffectedRowsError.new( "Expected affected rows, #{expected_affected_rows}, Actual affected rows, #{r.cmd_tuples}")
105
105
  end
106
106
  rescue PG::Error => e
107
- raise DuplicateKeyError.new( e.message ) unless e.message.index( "duplicate key value violates unique constraint" ).nil?
107
+ raise DuplicateKeyError.new( e.message ) unless e.message.index( "duplicate key value violates unique constraint" ).nil?
108
108
 
109
- raise e
109
+ raise e
110
110
  end
111
111
 
112
112
  def exec_params( sql, params=[], expected_affected_rows=nil )
113
- parts = sql.split( "?" )
113
+ parts = sql.split( "?" )
114
114
  sql = ""
115
115
  parts.each_with_index do |p,idx|
116
116
  sql = sql + p;
@@ -128,6 +128,21 @@ module FluidDb
128
128
  raise e
129
129
  end
130
130
 
131
+ # Transaction Semantics
132
+ def Begin
133
+ @connection.exec( "BEGIN", [] )
134
+ end
135
+
136
+ # Transaction Semantics
137
+ def Commit
138
+ @connection.exec( "COMMIT", [] )
139
+ end
140
+
141
+ # Transaction Semantics
142
+ def Rollback
143
+ @connection.exec( "ROLLBACK", [] )
144
+ end
145
+
131
146
  def insert( sql, params )
132
147
  raise "Pgsql uses SEQUENCES, so possibly easier to use 2 executes"
133
148
  # self.execute( sql, params )
@@ -11,7 +11,7 @@ module FluidDb
11
11
  # @param [String] uri a location for the resource to which we will attach, eg tinytds://<user>:<pass>@<dataserver>/<database>
12
12
  def connect()
13
13
  uri = @uri
14
-
14
+
15
15
  dataserver = uri.host
16
16
  database = uri.path.sub( "/", "" )
17
17
  username = URI.unescape( uri.user )
@@ -30,16 +30,34 @@ module FluidDb
30
30
  end
31
31
 
32
32
  hash = Hash[:username, username, :password, password, :database, database, :dataserver, dataserver]
33
+ failOverDataServer = nil
33
34
  if !uri.query.nil? then
34
35
  cgi = CGI.parse( uri.query )
35
36
  hash[:timeout] = cgi["timeout"][0].to_i if cgi.has_key?( "timeout" )
37
+
38
+ failOverDataServer = cgi["failoverdataserver"][0] if cgi.has_key?( "failoverdataserver" )
36
39
  end
37
40
 
38
- @connection = ::TinyTds::Client.new( hash )
41
+ begin
42
+ @connection = ::TinyTds::Client.new( hash )
43
+ rescue ::TinyTds::Error=>e
44
+ #Message for an incorrect password,
45
+ #Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.
46
+ #Message for unavailable db
47
+ #Cannot open user default database. Login failed.
48
+ if e.message == "Cannot open user default database. Login failed." &&
49
+ !failOverDataServer.nil? then
50
+ hash[:dataserver] = failOverDataServer
51
+ @connection = ::TinyTds::Client.new( hash )
52
+ else
53
+ raise e
54
+ end
55
+ end
39
56
 
40
57
  if !@connection.active? then
41
58
  raise "Unable to connect to the database"
42
59
  end
60
+
43
61
  end
44
62
 
45
63
  def close
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.1.10
4
+ version: 0.1.13
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-11-12 00:00:00.000000000 Z
12
+ date: 2014-02-11 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A semantic layer for db interaction
15
15
  email: guy@guyirvine.com