fluiddb 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  require 'date'
2
+ require 'uri'
2
3
 
3
4
  module FluidDb
4
5
 
@@ -23,7 +23,6 @@ module FluidDb
23
23
  # throw new Fluid_ConnectionException( $message );
24
24
  #end
25
25
 
26
- results.count == 0
27
26
  case results.count
28
27
  when -1
29
28
  raise FluidDb::ConnectionError.new
@@ -40,7 +39,7 @@ module FluidDb
40
39
  end
41
40
 
42
41
  end
43
-
42
+
44
43
  def queryForValue( sql, params )
45
44
  sql = self.format_to_sql( sql, params )
46
45
  results = @connection.query(sql, :as => :array)
@@ -50,7 +49,6 @@ module FluidDb
50
49
  # throw new Fluid_ConnectionException( $message );
51
50
  #end
52
51
 
53
- results.count == 0
54
52
  case results.count
55
53
  when -1
56
54
  raise FluidDb::ConnectionError.new
@@ -78,7 +76,6 @@ module FluidDb
78
76
  # throw new Fluid_ConnectionException( $message );
79
77
  #end
80
78
 
81
- results.count == 0
82
79
  case results.count
83
80
  when -1
84
81
  raise FluidDb::ConnectionError.new
@@ -0,0 +1,105 @@
1
+ require "FluidDb"
2
+ require "pg"
3
+
4
+ module FluidDb
5
+
6
+ class Pgsql<Base
7
+
8
+ def initialize(uri)
9
+ host = uri.host
10
+ database = uri.path.sub( "/", "" )
11
+
12
+ @connection = PG.connect( dbname:uri.path.sub( "/", "" ) )
13
+ end
14
+
15
+ def convertTupleToHash( fields, tuple, j )
16
+ hash = Hash.new
17
+ 0.upto( fields.length-1 ).each do |i|
18
+ hash[fields[i].to_s] = tuple.getvalue(j, i)
19
+ end
20
+
21
+ return hash
22
+ end
23
+
24
+ def queryForArray( sql, params )
25
+ sql = self.format_to_sql( sql, params )
26
+ results = @connection.exec(sql)
27
+
28
+ # if ( $result === false ) then
29
+ # $message = pg_last_error( $this->connection );
30
+ # throw new Fluid_ConnectionException( $message );
31
+ #end
32
+
33
+ case results.num_tuples
34
+ when -1
35
+ raise FluidDb::ConnectionError.new
36
+ when 0
37
+ raise FluidDb::NoDataFoundError.new
38
+ when 1
39
+ return self.convertTupleToHash(results.fields, results, 0)
40
+ else
41
+ raise FluidDb::TooManyRowsError.new
42
+ end
43
+ end
44
+
45
+ def queryForValue( sql, params )
46
+ sql = self.format_to_sql( sql, params )
47
+ results = @connection.query(sql, :as => :array)
48
+
49
+ # if ( $result === false ) then
50
+ # $message = pg_last_error( $this->connection );
51
+ # throw new Fluid_ConnectionException( $message );
52
+ #end
53
+
54
+ case results.num_tuples
55
+ when -1
56
+ raise FluidDb::ConnectionError.new
57
+ when 0
58
+ raise FluidDb::NoDataFoundError.new
59
+ when 1
60
+ return results.getvalue(0,0)
61
+ else
62
+ raise FluidDb::TooManyRowsError.new
63
+ end
64
+
65
+ end
66
+
67
+
68
+ def queryForResultset( sql, params )
69
+ sql = self.format_to_sql( sql, params )
70
+ results = @connection.query(sql)
71
+
72
+ # if ( $result === false ) then
73
+ # $message = pg_last_error( $this->connection );
74
+ # throw new Fluid_ConnectionException( $message );
75
+ #end
76
+
77
+ case results.num_tuples
78
+ when -1
79
+ raise FluidDb::ConnectionError.new
80
+ else
81
+ list = Array.new
82
+ fields = results.fields
83
+ 0.upto( results.num_tuples -1 ) do |nbr|
84
+ list.push self.convertTupleToHash(fields, results, nbr)
85
+ end
86
+
87
+ return list
88
+ end
89
+ end
90
+
91
+
92
+ # def execute( sql, params, expected_affected_rows )
93
+ def execute( sql, params )
94
+ sql = self.format_to_sql( sql, params )
95
+ @connection.query( sql );
96
+ end
97
+
98
+ def insert( sql, params )
99
+ self.execute( sql, params )
100
+ return @connection.last_id
101
+ end
102
+
103
+ end
104
+
105
+ end
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.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -18,6 +18,7 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - lib/FluidDb/Mysql.rb
21
+ - lib/FluidDb/Pgsql.rb
21
22
  - lib/FluidDb.rb
22
23
  - README.md
23
24
  homepage: http://rubygems.org/gems/fluiddb