fluiddb 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/lib/FluidDb/Mock.rb CHANGED
@@ -5,8 +5,16 @@ module FluidDb
5
5
  #A constant way of enabling testing for FluidDb
6
6
  class Mock<Base
7
7
 
8
+ @verbose = false
9
+
8
10
  def initialize
9
11
  @hash = Hash.new
12
+
13
+ end
14
+
15
+ def verbose()
16
+ @verbose = true
17
+ return self
10
18
  end
11
19
 
12
20
  def connect()
@@ -17,21 +25,46 @@ module FluidDb
17
25
 
18
26
  def queryForArray( sql, params )
19
27
  sql = self.format_to_sql( sql, params )
20
- return @hash[sql]
28
+ puts "FluidDb::Mock.queryForArray. sql: #{sql}" if @verbose == true
29
+
30
+ results = @hash[sql]
31
+ case results.length
32
+ when 0
33
+ raise FluidDb::NoDataFoundError.new
34
+ when 1
35
+ return results.first
36
+ return r
37
+ else
38
+ raise FluidDb::TooManyRowsError.new
39
+ end
40
+
21
41
  end
22
42
 
23
43
  def queryForValue( sql, params )
24
44
  sql = self.format_to_sql( sql, params )
45
+ puts "FluidDb::Mock.queryForValue. sql: #{sql}" if @verbose == true
46
+
47
+ results = @hash[sql]
48
+ case results.length
49
+ when 0
50
+ raise FluidDb::NoDataFoundError.new
51
+ when 1
52
+ return results.first.first[1]
53
+ else
54
+ raise FluidDb::TooManyRowsError.new
55
+ end
25
56
  return @hash[sql]
26
57
  end
27
58
 
28
59
  def queryForResultset( sql, params )
29
60
  sql = self.format_to_sql( sql, params )
61
+ puts "FluidDb::Mock.queryForResultset. sql: #{sql}" if @verbose == true
30
62
  return @hash[sql]
31
63
  end
32
64
 
33
65
  def execute( sql, params, expected_affected_rows=nil )
34
66
  sql = self.format_to_sql( sql, params )
67
+ puts "FluidDb::Mock.execute. sql: #{sql}" if @verbose == true
35
68
  return @hash[sql]
36
69
  end
37
70
 
@@ -40,9 +73,13 @@ module FluidDb
40
73
  end
41
74
 
42
75
  def addSql( sql, result )
76
+ if !result.is_a? Array then
77
+ raise TypeError.new( "Expecting an Array of Hashes, eg [{'field1'=>1, 'field2'=>2}]. Note, the Array may be empty" )
78
+ end
79
+
43
80
  @hash[sql] = result;
44
81
  end
45
-
82
+
46
83
  def addSqlWithParams( sql, params, result )
47
84
  sql = self.format_to_sql( sql, params )
48
85
 
data/lib/FluidDb/Pgsql.rb CHANGED
@@ -28,7 +28,7 @@ module FluidDb
28
28
  # $message = pg_last_error( $this->connection );
29
29
  # throw new Fluid_ConnectionException( $message );
30
30
  #end
31
-
31
+
32
32
  case results.num_tuples
33
33
  when -1
34
34
  raise FluidDb::ConnectionError.new
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.10
4
+ version: 0.0.11
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: 2012-10-07 00:00:00.000000000 Z
12
+ date: 2012-10-26 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A semantic layer for db interaction
15
15
  email: guy@guyirvine.com