fluiddb 0.0.32 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/FluidDb/Db.rb CHANGED
@@ -15,6 +15,9 @@ module FluidDb
15
15
  when "pgsql"
16
16
  require "FluidDb/Pgsql"
17
17
  return FluidDb::Pgsql.new( uri )
18
+ when "fb"
19
+ require "FluidDb/Firebird"
20
+ return FluidDb::Firebird.new( uri )
18
21
  when "mock"
19
22
  require "FluidDb/Mock"
20
23
  return FluidDb::Mock.new( uri )
@@ -0,0 +1,141 @@
1
+ require "FluidDb"
2
+ require "fb"
3
+ include Fb
4
+
5
+ module FluidDb
6
+
7
+ class Firebird<Base
8
+
9
+ # Connect to Db.
10
+ #
11
+ # @param [String] uri a location for the resource to which we will attach, eg mysql://user:pass@127.0.0.1/foo
12
+ def connect()
13
+ uri = @uri
14
+
15
+ user = uri.user || "sysdba"
16
+ password = uri.password || "masterkey"
17
+
18
+
19
+ # The Database class acts as a factory for Connections.
20
+ # It can also create and drop databases.
21
+ db = Database.new(
22
+ :database => "#{uri.host}:#{uri.path}",
23
+ :username => user,
24
+ :password => password)
25
+ # :database is the only parameter without a default.
26
+ # Let's connect to the database, creating it if it doesn't already exist.
27
+ @connection = db.connect rescue db.create.connect
28
+
29
+ end
30
+
31
+ def close
32
+ @connection.close
33
+ end
34
+
35
+ def queryForArray( sql, params )
36
+ sql = self.format_to_sql( sql, params )
37
+ list = @connection.query(:hash, sql)
38
+
39
+ # if ( $result === false ) then
40
+ # $message = pg_last_error( $this->connection );
41
+ # throw new Fluid_ConnectionException( $message );
42
+ #end
43
+
44
+ case list.length
45
+ when -1
46
+ raise FluidDb::ConnectionError.new
47
+ when 0
48
+ raise FluidDb::NoDataFoundError.new
49
+ when 1
50
+ return list[0]
51
+ else
52
+ raise FluidDb::TooManyRowsError.new
53
+ end
54
+ end
55
+
56
+ def queryForValue( sql, params )
57
+ sql = self.format_to_sql( sql, params )
58
+ results = @connection.query(sql)
59
+
60
+ # if ( $result === false ) then
61
+ # $message = pg_last_error( $this->connection );
62
+ # throw new Fluid_ConnectionException( $message );
63
+ #end
64
+ case results.length
65
+ when -1
66
+ raise FluidDb::ConnectionError.new
67
+ when 0
68
+ raise FluidDb::NoDataFoundError.new
69
+ when 1
70
+ return results[0][0]
71
+ # return results.getvalue(0,0)
72
+ else
73
+ raise FluidDb::TooManyRowsError.new
74
+ end
75
+
76
+ end
77
+
78
+
79
+ def queryForResultset( sql, params )
80
+ sql = self.format_to_sql( sql, params )
81
+ list = @connection.query(:hash, sql)
82
+
83
+ # if ( $result === false ) then
84
+ # $message = pg_last_error( $this->connection );
85
+ # throw new Fluid_ConnectionException( $message );
86
+ #end
87
+
88
+ case list.length
89
+ when -1
90
+ raise FluidDb::ConnectionError.new
91
+ else
92
+
93
+ return list
94
+ end
95
+ end
96
+
97
+
98
+ def execute( sql, params, expected_affected_rows=nil )
99
+ sql = self.format_to_sql( sql, params )
100
+
101
+ self.verboseLog( "#{self.class.name}.execute. #{sql}" )
102
+ affected_rows = @connection.execute(sql)
103
+
104
+ if !expected_affected_rows.nil? and
105
+ affected_rows != expected_affected_rows then
106
+ raise ExpectedAffectedRowsError.new( "Expected affected rows, #{expected_affected_rows}, Actual affected rows, #{affected_rows}")
107
+ end
108
+ rescue PG::Error => e
109
+ raise DuplicateKeyError.new( e.message ) unless e.message.index( "duplicate key value violates unique constraint" ).nil?
110
+
111
+ raise e
112
+ end
113
+
114
+ def exec_params( sql, params, expected_affected_rows=nil )
115
+ parts = sql.split( "?" )
116
+ sql = ""
117
+ parts.each_with_index do |p,idx|
118
+ sql = sql + p;
119
+ sql = sql + "$#{idx+1}" if idx < parts.length - 1
120
+ end
121
+ affected_rows = @connection.exec_params( sql, params );
122
+
123
+ if !expected_affected_rows.nil? and
124
+ affected_rows != expected_affected_rows then
125
+ raise ExpectedAffectedRowsError.new( "Expected affected rows, #{expected_affected_rows}, Actual affected rows, #{affected_rows}")
126
+ end
127
+ rescue PG::Error => e
128
+ raise DuplicateKeyError.new( e.message ) unless e.message.index( "duplicate key value violates unique constraint" ).nil?
129
+
130
+ raise e
131
+ end
132
+
133
+ def insert( sql, params )
134
+ raise "Pgsql uses SEQUENCES, so possibly easier to use 2 executes"
135
+ # self.execute( sql, params )
136
+ #return @connection.last_id
137
+ end
138
+
139
+ end
140
+
141
+ end
@@ -85,7 +85,7 @@ module FluidDb
85
85
  def queryForResultset( sql, params )
86
86
  sql = self.format_to_sql( sql, params )
87
87
  results = @connection.execute(sql)
88
-
88
+
89
89
  list = Array.new
90
90
  results.each do |row|
91
91
  list << row
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.32
4
+ version: 0.1.0
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-30 00:00:00.000000000 Z
12
+ date: 2013-08-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A semantic layer for db interaction
15
15
  email: guy@guyirvine.com
@@ -18,6 +18,7 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - lib/FluidDb/Db.rb
21
+ - lib/FluidDb/Firebird.rb
21
22
  - lib/FluidDb/Mock.rb
22
23
  - lib/FluidDb/Mysql.rb
23
24
  - lib/FluidDb/Mysql2.rb