do_postgres 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +2 -2
  2. data/lib/do_postgres.rb +53 -3
  3. metadata +4 -4
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake/gempackagetask'
3
3
 
4
4
  PLUGIN = "do_postgres"
5
5
  NAME = "do_postgres"
6
- VERSION = "0.2.3"
6
+ VERSION = "0.2.4"
7
7
  AUTHOR = "Yehuda Katz"
8
8
  EMAIL = "wycats@gmail.com"
9
9
  HOMEPAGE = "http://dataobjects.devjavu.com"
@@ -20,7 +20,7 @@ spec = Gem::Specification.new do |s|
20
20
  s.author = AUTHOR
21
21
  s.email = EMAIL
22
22
  s.homepage = HOMEPAGE
23
- s.add_dependency('data_objects')
23
+ s.add_dependency('data_objects', ["<=0.2.0"])
24
24
  s.require_path = 'lib'
25
25
  s.autorequire = PLUGIN
26
26
  s.extensions = ["ext/extconf.rb"]
data/lib/do_postgres.rb CHANGED
@@ -34,6 +34,47 @@ module DataObject
34
34
  Command.new(self, text)
35
35
  end
36
36
 
37
+ def begin_transaction
38
+ Transaction.new(self)
39
+ end
40
+
41
+ end
42
+
43
+ class Transaction < Connection
44
+
45
+ attr_reader :connection
46
+
47
+ def initialize(conn)
48
+ @connection = conn
49
+ exec_sql("BEGIN")
50
+ end
51
+
52
+ # Commits the transaction
53
+ def commit
54
+ exec_sql("COMMIT")
55
+ end
56
+
57
+ # Rolls back the transaction
58
+ def rollback(savepoint = nil)
59
+ exec_sql("ROLLBACK#{savepoint ? " TO " + savepoint : ""}")
60
+ end
61
+
62
+ # Creates a savepoint for rolling back later (not commonly supported)
63
+ def save(name)
64
+ exec_sql("SAVEPOINT #{name}")
65
+ end
66
+
67
+ def create_command(*args)
68
+ @connection.create_command(*args)
69
+ end
70
+
71
+ protected
72
+
73
+ def exec_sql(sql)
74
+ @connection.logger.debug(sql)
75
+ Postgres_c.PQexec(@connection.db, "COMMIT")
76
+ end
77
+
37
78
  end
38
79
 
39
80
  class Reader < DataObject::Reader
@@ -115,12 +156,12 @@ module DataObject
115
156
  end
116
157
 
117
158
  def typecast(val, field_type)
118
- return nil if val.nil?
159
+ return nil if val.nil? || val == "NULL"
119
160
  case TYPES[field_type]
120
161
  when "BOOL"
121
162
  val == "t"
122
163
  when "INT2", "INT4", "OID", "TID", "XID", "CID", "INT8"
123
- val.to_i
164
+ val == '' ? nil : val.to_i
124
165
  when "FLOAT4", "FLOAT8", "NUMERIC", "CASH"
125
166
  val.to_f
126
167
  when "TIMESTAMP", "TIMETZ", "TIMESTAMPTZ"
@@ -190,7 +231,16 @@ module DataObject
190
231
  ResultData.new(@connection, rows_affected)
191
232
  end
192
233
 
234
+ def quote_string(value)
235
+ if value =~ /[\x00-\x80]/
236
+ raise "String cannot contain $Text$ in the body" if value.include?("$Text$")
237
+ "$Text$#{value}$Text$"
238
+ else
239
+ super
240
+ end
241
+ end
242
+
193
243
  end
194
244
 
195
245
  end
196
- end
246
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: do_postgres
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.3
7
- date: 2008-01-01 00:00:00 -08:00
6
+ version: 0.2.4
7
+ date: 2008-04-17 00:00:00 -07:00
8
8
  summary: A DataObject.rb driver for postgres
9
9
  require_paths:
10
10
  - lib
@@ -57,7 +57,7 @@ dependencies:
57
57
  version_requirement:
58
58
  version_requirements: !ruby/object:Gem::Version::Requirement
59
59
  requirements:
60
- - - ">"
60
+ - - <=
61
61
  - !ruby/object:Gem::Version
62
- version: 0.0.0
62
+ version: 0.2.0
63
63
  version: