sqlpostgres 1.2.4

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.
Files changed (207) hide show
  1. data/Gemfile +8 -0
  2. data/Gemfile.lock +22 -0
  3. data/LICENSE.md +23 -0
  4. data/README.rdoc +59 -0
  5. data/Rakefile +32 -0
  6. data/VERSION +1 -0
  7. data/doc/BUGS +2 -0
  8. data/doc/examples/README +6 -0
  9. data/doc/examples/connection.rb +16 -0
  10. data/doc/examples/connection_auto.rb +22 -0
  11. data/doc/examples/connection_ctor.rb +18 -0
  12. data/doc/examples/connection_default.rb +15 -0
  13. data/doc/examples/connection_exec.rb +18 -0
  14. data/doc/examples/connection_manual.rb +12 -0
  15. data/doc/examples/connection_wrapped_new.rb +13 -0
  16. data/doc/examples/connection_wrapped_open.rb +13 -0
  17. data/doc/examples/cursor.rb +38 -0
  18. data/doc/examples/include_module.rb +9 -0
  19. data/doc/examples/include_module2.rb +12 -0
  20. data/doc/examples/insert.rb +30 -0
  21. data/doc/examples/insert2.rb +36 -0
  22. data/doc/examples/insert_bytea.rb +16 -0
  23. data/doc/examples/insert_bytea_array.rb +17 -0
  24. data/doc/examples/insert_default_values.rb +16 -0
  25. data/doc/examples/insert_insert.rb +16 -0
  26. data/doc/examples/insert_insert_default.rb +16 -0
  27. data/doc/examples/insert_insert_select.rb +20 -0
  28. data/doc/examples/insert_select.rb +20 -0
  29. data/doc/examples/interval.rb +17 -0
  30. data/doc/examples/savepoint.rb +38 -0
  31. data/doc/examples/select.rb +33 -0
  32. data/doc/examples/select2.rb +36 -0
  33. data/doc/examples/select_cross_join.rb +18 -0
  34. data/doc/examples/select_distinct.rb +18 -0
  35. data/doc/examples/select_distinct_on +19 -0
  36. data/doc/examples/select_for_update.rb +18 -0
  37. data/doc/examples/select_from.rb +17 -0
  38. data/doc/examples/select_from_subselect.rb +20 -0
  39. data/doc/examples/select_group_by.rb +19 -0
  40. data/doc/examples/select_having.rb +20 -0
  41. data/doc/examples/select_join_on.rb +18 -0
  42. data/doc/examples/select_join_using.rb +18 -0
  43. data/doc/examples/select_limit.rb +19 -0
  44. data/doc/examples/select_natural_join.rb +18 -0
  45. data/doc/examples/select_offset.rb +19 -0
  46. data/doc/examples/select_order_by.rb +20 -0
  47. data/doc/examples/select_select.rb +30 -0
  48. data/doc/examples/select_select_alias.rb +30 -0
  49. data/doc/examples/select_select_expression.rb +31 -0
  50. data/doc/examples/select_select_literal.rb +24 -0
  51. data/doc/examples/select_union.rb +21 -0
  52. data/doc/examples/select_where_array.rb +18 -0
  53. data/doc/examples/select_where_in.rb +18 -0
  54. data/doc/examples/select_where_string.rb +18 -0
  55. data/doc/examples/simple.rb +34 -0
  56. data/doc/examples/transaction.rb +30 -0
  57. data/doc/examples/transaction_abort.rb +30 -0
  58. data/doc/examples/transaction_commit.rb +34 -0
  59. data/doc/examples/translate_substitute_values.rb +17 -0
  60. data/doc/examples/update.rb +32 -0
  61. data/doc/examples/update2.rb +44 -0
  62. data/doc/examples/update_only.rb +17 -0
  63. data/doc/examples/update_set.rb +17 -0
  64. data/doc/examples/update_set_array.rb +16 -0
  65. data/doc/examples/update_set_bytea.rb +16 -0
  66. data/doc/examples/update_set_expression.rb +16 -0
  67. data/doc/examples/update_set_subselect.rb +20 -0
  68. data/doc/examples/update_where.rb +17 -0
  69. data/doc/examples/use_prefix.rb +8 -0
  70. data/doc/examples/use_prefix2.rb +11 -0
  71. data/doc/index.html +31 -0
  72. data/doc/insertexamples.rb +9 -0
  73. data/doc/makemanual +4 -0
  74. data/doc/makerdoc +5 -0
  75. data/doc/manual.dbk +622 -0
  76. data/lib/sqlpostgres/Connection.rb +198 -0
  77. data/lib/sqlpostgres/Cursor.rb +157 -0
  78. data/lib/sqlpostgres/Delete.rb +67 -0
  79. data/lib/sqlpostgres/Exceptions.rb +15 -0
  80. data/lib/sqlpostgres/Insert.rb +279 -0
  81. data/lib/sqlpostgres/NullConnection.rb +22 -0
  82. data/lib/sqlpostgres/PgBit.rb +73 -0
  83. data/lib/sqlpostgres/PgBox.rb +37 -0
  84. data/lib/sqlpostgres/PgCidr.rb +21 -0
  85. data/lib/sqlpostgres/PgCircle.rb +75 -0
  86. data/lib/sqlpostgres/PgInet.rb +21 -0
  87. data/lib/sqlpostgres/PgInterval.rb +208 -0
  88. data/lib/sqlpostgres/PgLineSegment.rb +37 -0
  89. data/lib/sqlpostgres/PgMacAddr.rb +21 -0
  90. data/lib/sqlpostgres/PgPath.rb +64 -0
  91. data/lib/sqlpostgres/PgPoint.rb +65 -0
  92. data/lib/sqlpostgres/PgPolygon.rb +56 -0
  93. data/lib/sqlpostgres/PgTime.rb +77 -0
  94. data/lib/sqlpostgres/PgTimeWithTimeZone.rb +98 -0
  95. data/lib/sqlpostgres/PgTimestamp.rb +93 -0
  96. data/lib/sqlpostgres/PgTwoPoints.rb +54 -0
  97. data/lib/sqlpostgres/PgType.rb +34 -0
  98. data/lib/sqlpostgres/PgWrapper.rb +41 -0
  99. data/lib/sqlpostgres/Savepoint.rb +98 -0
  100. data/lib/sqlpostgres/Select.rb +855 -0
  101. data/lib/sqlpostgres/Transaction.rb +120 -0
  102. data/lib/sqlpostgres/Translate.rb +436 -0
  103. data/lib/sqlpostgres/Update.rb +188 -0
  104. data/lib/sqlpostgres.rb +67 -0
  105. data/test/Assert.rb +72 -0
  106. data/test/Connection.test.rb +246 -0
  107. data/test/Cursor.test.rb +190 -0
  108. data/test/Delete.test.rb +68 -0
  109. data/test/Insert.test.rb +123 -0
  110. data/test/MockPGconn.rb +62 -0
  111. data/test/NullConnection.test.rb +32 -0
  112. data/test/PgBit.test.rb +98 -0
  113. data/test/PgBox.test.rb +108 -0
  114. data/test/PgCidr.test.rb +61 -0
  115. data/test/PgCircle.test.rb +107 -0
  116. data/test/PgInet.test.rb +61 -0
  117. data/test/PgInterval.test.rb +180 -0
  118. data/test/PgLineSegment.test.rb +108 -0
  119. data/test/PgMacAddr.test.rb +61 -0
  120. data/test/PgPath.test.rb +106 -0
  121. data/test/PgPoint.test.rb +100 -0
  122. data/test/PgPolygon.test.rb +95 -0
  123. data/test/PgTime.test.rb +120 -0
  124. data/test/PgTimeWithTimeZone.test.rb +117 -0
  125. data/test/PgTimestamp.test.rb +134 -0
  126. data/test/RandomThings.rb +25 -0
  127. data/test/Savepoint.test.rb +286 -0
  128. data/test/Select.test.rb +930 -0
  129. data/test/Test.rb +62 -0
  130. data/test/TestConfig.rb +21 -0
  131. data/test/TestSetup.rb +13 -0
  132. data/test/TestUtil.rb +92 -0
  133. data/test/Transaction.test.rb +275 -0
  134. data/test/Translate.test.rb +354 -0
  135. data/test/Update.test.rb +227 -0
  136. data/test/roundtrip.test.rb +565 -0
  137. data/test/test +34 -0
  138. data/tools/exampleinserter/ExampleInserter.rb +177 -0
  139. data/tools/rdoc/ChangeLog +796 -0
  140. data/tools/rdoc/EXAMPLE.rb +48 -0
  141. data/tools/rdoc/MANIFEST +58 -0
  142. data/tools/rdoc/Makefile +27 -0
  143. data/tools/rdoc/NEW_FEATURES +226 -0
  144. data/tools/rdoc/README +390 -0
  145. data/tools/rdoc/ToDo +6 -0
  146. data/tools/rdoc/contrib/Index +6 -0
  147. data/tools/rdoc/contrib/xslfo/ChangeLog +181 -0
  148. data/tools/rdoc/contrib/xslfo/README +106 -0
  149. data/tools/rdoc/contrib/xslfo/TODO +10 -0
  150. data/tools/rdoc/contrib/xslfo/convert.xsl +151 -0
  151. data/tools/rdoc/contrib/xslfo/demo/README +21 -0
  152. data/tools/rdoc/contrib/xslfo/demo/rdocfo +99 -0
  153. data/tools/rdoc/contrib/xslfo/fcm.xsl +54 -0
  154. data/tools/rdoc/contrib/xslfo/files.xsl +62 -0
  155. data/tools/rdoc/contrib/xslfo/labeled-lists.xsl +66 -0
  156. data/tools/rdoc/contrib/xslfo/lists.xsl +44 -0
  157. data/tools/rdoc/contrib/xslfo/modules.xsl +152 -0
  158. data/tools/rdoc/contrib/xslfo/rdoc.xsl +75 -0
  159. data/tools/rdoc/contrib/xslfo/source.xsl +66 -0
  160. data/tools/rdoc/contrib/xslfo/styles.xsl +69 -0
  161. data/tools/rdoc/contrib/xslfo/tables.xsl +67 -0
  162. data/tools/rdoc/contrib/xslfo/utils.xsl +21 -0
  163. data/tools/rdoc/debian/changelog +33 -0
  164. data/tools/rdoc/debian/compat +1 -0
  165. data/tools/rdoc/debian/control +20 -0
  166. data/tools/rdoc/debian/copyright +10 -0
  167. data/tools/rdoc/debian/dirs +2 -0
  168. data/tools/rdoc/debian/docs +2 -0
  169. data/tools/rdoc/debian/rdoc.1 +252 -0
  170. data/tools/rdoc/debian/rdoc.manpages +1 -0
  171. data/tools/rdoc/debian/rdoc.pod +149 -0
  172. data/tools/rdoc/debian/rules +9 -0
  173. data/tools/rdoc/dot/dot.rb +255 -0
  174. data/tools/rdoc/etc/rdoc.dtd +203 -0
  175. data/tools/rdoc/install.rb +137 -0
  176. data/tools/rdoc/markup/install.rb +43 -0
  177. data/tools/rdoc/markup/sample/sample.rb +42 -0
  178. data/tools/rdoc/markup/simple_markup/fragments.rb +323 -0
  179. data/tools/rdoc/markup/simple_markup/inline.rb +348 -0
  180. data/tools/rdoc/markup/simple_markup/lines.rb +147 -0
  181. data/tools/rdoc/markup/simple_markup/preprocess.rb +68 -0
  182. data/tools/rdoc/markup/simple_markup/to_html.rb +281 -0
  183. data/tools/rdoc/markup/simple_markup.rb +474 -0
  184. data/tools/rdoc/markup/test/AllTests.rb +2 -0
  185. data/tools/rdoc/markup/test/TestInline.rb +151 -0
  186. data/tools/rdoc/markup/test/TestParse.rb +411 -0
  187. data/tools/rdoc/rdoc/code_objects.rb +536 -0
  188. data/tools/rdoc/rdoc/diagram.rb +331 -0
  189. data/tools/rdoc/rdoc/generators/chm_generator.rb +112 -0
  190. data/tools/rdoc/rdoc/generators/html_generator.rb +1268 -0
  191. data/tools/rdoc/rdoc/generators/template/chm/chm.rb +86 -0
  192. data/tools/rdoc/rdoc/generators/template/html/html.rb +705 -0
  193. data/tools/rdoc/rdoc/generators/template/html/kilmer.rb +377 -0
  194. data/tools/rdoc/rdoc/generators/template/xml/rdf.rb +110 -0
  195. data/tools/rdoc/rdoc/generators/template/xml/xml.rb +110 -0
  196. data/tools/rdoc/rdoc/generators/xml_generator.rb +130 -0
  197. data/tools/rdoc/rdoc/options.rb +451 -0
  198. data/tools/rdoc/rdoc/parsers/parse_c.rb +287 -0
  199. data/tools/rdoc/rdoc/parsers/parse_f95.rb +118 -0
  200. data/tools/rdoc/rdoc/parsers/parse_rb.rb +2311 -0
  201. data/tools/rdoc/rdoc/parsers/parse_simple.rb +37 -0
  202. data/tools/rdoc/rdoc/parsers/parserfactory.rb +75 -0
  203. data/tools/rdoc/rdoc/rdoc.rb +219 -0
  204. data/tools/rdoc/rdoc/template.rb +234 -0
  205. data/tools/rdoc/rdoc/tokenstream.rb +25 -0
  206. data/tools/rdoc/rdoc.rb +9 -0
  207. metadata +291 -0
@@ -0,0 +1,22 @@
1
+ module SqlPostgres
2
+
3
+ # This is a special connection that is used when there isn't a real
4
+ # one. Any attempt to use it causes a NoConnection exception.
5
+
6
+ class NullConnection
7
+
8
+ # Raises NoConnection
9
+
10
+ def method_missing(method, *args)
11
+ raise NoConnection
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+
18
+ # Local Variables:
19
+ # tab-width: 2
20
+ # ruby-indent-level: 2
21
+ # indent-tabs-mode: nil
22
+ # End:
@@ -0,0 +1,73 @@
1
+ require 'sqlpostgres/PgType'
2
+
3
+ module SqlPostgres
4
+
5
+ # This class holds the value of a "bit" column.
6
+
7
+ class PgBit < PgType
8
+
9
+ # Return an array of 0's and 1's with the bits.
10
+
11
+ attr_reader :bits
12
+
13
+ class << self
14
+
15
+ # Create a PgBit from a string in Postgres format (ie
16
+ # "(1,2)").
17
+
18
+ def from_sql(s)
19
+ if s =~ /^[01]*$/
20
+ PgBit.new(s)
21
+ else
22
+ raise ArgumentError, "Invalid bit: #{s.inspect}"
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ # Constructor. Takes either an array of bits, a bunch of bits, or
29
+ # a string. These are all equivalent:
30
+ # PgBit.new([0, 1, 0, 1])
31
+ # PgBit.new(0, 1, 0, 1)
32
+ # PgBit.new("0101")
33
+
34
+ def initialize(*args)
35
+ args = args.flatten
36
+ if args.size == 1 && args[0].is_a?(String)
37
+ @bits = bits_from_sql(args[0])
38
+ else
39
+ @bits = args
40
+ end
41
+ end
42
+
43
+ # Return a string representation (ie "01011").
44
+
45
+ def to_s
46
+ bits.join
47
+ end
48
+
49
+ protected
50
+
51
+ def parts
52
+ [bits]
53
+ end
54
+
55
+ private
56
+
57
+ def column_type
58
+ 'bit'
59
+ end
60
+
61
+ def bits_from_sql(s)
62
+ s.scan(/./).collect do |d| d.to_i end
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
69
+ # Local Variables:
70
+ # tab-width: 2
71
+ # ruby-indent-level: 2
72
+ # indent-tabs-mode: nil
73
+ # End:
@@ -0,0 +1,37 @@
1
+ require 'sqlpostgres/PgTwoPoints'
2
+
3
+ module SqlPostgres
4
+
5
+ # This class holds the value of a "point" column.
6
+
7
+ class PgBox < PgTwoPoints
8
+
9
+ class << self
10
+
11
+ # Create a PgBox from a string in Postgres format
12
+
13
+ def from_sql(s)
14
+ if s =~ /^(\(.*\)),(\(.*\))$/
15
+ PgBox.new(PgPoint.from_sql($1), PgPoint.from_sql($2))
16
+ else
17
+ raise ArgumentError, "Invalid box: #{s.inspect}"
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+ private
24
+
25
+ def column_type
26
+ 'box'
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
33
+ # Local Variables:
34
+ # tab-width: 2
35
+ # ruby-indent-level: 2
36
+ # indent-tabs-mode: nil
37
+ # End:
@@ -0,0 +1,21 @@
1
+ require 'sqlpostgres/PgWrapper'
2
+
3
+ module SqlPostgres
4
+
5
+ # This class holds the value of an "cidr" column.
6
+
7
+ class PgCidr < PgWrapper
8
+
9
+ def column_type
10
+ 'cidr'
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+
17
+ # Local Variables:
18
+ # tab-width: 2
19
+ # ruby-indent-level: 2
20
+ # indent-tabs-mode: nil
21
+ # End:
@@ -0,0 +1,75 @@
1
+ require 'sqlpostgres/PgType'
2
+
3
+ module SqlPostgres
4
+
5
+ # This class holds the value of a "circle" column.
6
+
7
+ class PgCircle < PgType
8
+
9
+ # Return the center (PgPoint)
10
+
11
+ attr_reader :center
12
+
13
+ # Return the radius
14
+
15
+ attr_reader :radius
16
+
17
+ class << self
18
+
19
+ # Create a PgCircle from a string in Postgres format
20
+
21
+ def from_sql(s)
22
+ if s =~ /^<(.*),(.*)>$/
23
+ PgCircle.new(PgPoint.from_sql($1), $2.to_f)
24
+ else
25
+ raise ArgumentError, "Invalid circle: #{s.inspect}"
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ # Constructor
32
+
33
+ def initialize(*args)
34
+ case args.size
35
+ when 0
36
+ @center = PgPoint.new
37
+ @radius = 0
38
+ when 2
39
+ @center = args[0]
40
+ @radius = args[1]
41
+ when 3
42
+ @center = PgPoint.new(*args[0..1])
43
+ @radius = args[2]
44
+ else
45
+ raise ArgumentError, "Incorrect number of arguments: #{args.size}"
46
+ end
47
+ end
48
+
49
+ # Return a string representation (ie "<(1, 2), 3>").
50
+
51
+ def to_s
52
+ "<%s, %g>" % parts
53
+ end
54
+
55
+ protected
56
+
57
+ def parts
58
+ [center, radius]
59
+ end
60
+
61
+ private
62
+
63
+ def column_type
64
+ 'circle'
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+
71
+ # Local Variables:
72
+ # tab-width: 2
73
+ # ruby-indent-level: 2
74
+ # indent-tabs-mode: nil
75
+ # End:
@@ -0,0 +1,21 @@
1
+ require 'sqlpostgres/PgWrapper'
2
+
3
+ module SqlPostgres
4
+
5
+ # This class holds the value of an "inet" column.
6
+
7
+ class PgInet < PgWrapper
8
+
9
+ def column_type
10
+ 'inet'
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+
17
+ # Local Variables:
18
+ # tab-width: 2
19
+ # ruby-indent-level: 2
20
+ # indent-tabs-mode: nil
21
+ # End:
@@ -0,0 +1,208 @@
1
+ require 'sqlpostgres/PgType'
2
+
3
+ module SqlPostgres
4
+
5
+ # This class holds the value of an "interval" column. Instances are
6
+ # immutable.
7
+ #
8
+ # The fields of a PgInterval are:
9
+ # * millennia (integer, default 0)
10
+ # * centuries (integer, default 0)
11
+ # * decades (integer, default 0)
12
+ # * years (integer, default 0)
13
+ # * months (integer, default 0)
14
+ # * weeks (integer, default 0)
15
+ # * days (integer, default 0)
16
+ # * hours (integer, default 0)
17
+ # * minutes (integer, default 0)
18
+ # * seconds (integer or float, default 0)
19
+ # * ago (boolean, default false)
20
+ #
21
+ # These fields are set by passing has args to the constructor and can
22
+ # be retrieved using simple accessors:
23
+ #
24
+ #** Example: interval
25
+ # interval = PgInterval.new('hours'=>1, 'minutes'=>30)
26
+ # p interval.hours # 1
27
+ # p interval.minutes # 30
28
+ # p interval.seconds # 0
29
+ #**
30
+
31
+ class PgInterval < PgType
32
+
33
+ private
34
+
35
+ DATE_FIELDS = [
36
+ "millennia", "centuries", "decades",
37
+ "years", "months", "weeks", "days",
38
+ ]
39
+
40
+ TIME_FIELDS = ["hours", "minutes", "seconds"]
41
+
42
+ FIELDS = DATE_FIELDS + TIME_FIELDS + ["ago"]
43
+
44
+ public
45
+
46
+ for field in FIELDS
47
+ eval <<-EOS
48
+ def #{field}
49
+ @values["#{field}"]
50
+ end
51
+ EOS
52
+ end
53
+
54
+ class << self
55
+
56
+ # Convert a Postgres string (ie "2 days 12:00:00") to a
57
+ # PgInterval instance.
58
+
59
+ def from_sql(s)
60
+ begin
61
+ args = {}
62
+ words = s.split
63
+ raise ArgumentError if words.empty?
64
+ while !words.empty?
65
+ word = words.shift
66
+ case word
67
+ when /(-)?(\d{2}):(\d{2})(?::(\d{2}(\.\d+)?))?/
68
+ sign = if $1 then -1 else +1 end
69
+ args['hours'] = sign * $2.to_i
70
+ args['minutes'] = sign * $3.to_i
71
+ args['seconds'] = sign * $4.to_f
72
+ when /\d+/
73
+ n = word.to_i
74
+ units = words.shift
75
+ case units
76
+ when 'day', 'days'
77
+ args['days'] = n
78
+ when 'mon', 'mons'
79
+ args['months'] = n
80
+ when 'year', 'years'
81
+ args['years'] = n
82
+ else
83
+ raise ArgumentError
84
+ end
85
+ else
86
+ raise ArgumentError
87
+ end
88
+ end
89
+ rescue ArgumentError
90
+ raise ArgumentError, "Syntax error in interval: #{s.inspect}"
91
+ end
92
+ PgInterval.new(args)
93
+ end
94
+
95
+ end
96
+
97
+ # Constructor.
98
+ #
99
+ # [args]
100
+ # The values of the days, minutes, and so on, as a hash.
101
+ # Each value is an Integer except for ago, which is a boolean.
102
+ #
103
+ # The keys are:
104
+ # * millennia
105
+ # * centuries
106
+ # * decades
107
+ # * years
108
+ # * months
109
+ # * weeks
110
+ # * days
111
+ # * hours
112
+ # * minutes
113
+ # * seconds
114
+ #
115
+ # Any integer not specified defaults to 0; any boolean not specified
116
+ # defaults to false.
117
+
118
+ def initialize(args = {})
119
+ args = args.dup
120
+ @values = Hash[*FIELDS.collect do |field|
121
+ [field, args.delete(field) || default(field)]
122
+ end.flatten]
123
+ raise ArgumentError, args.inspect unless args.empty?
124
+ end
125
+
126
+ # Convert to Postgres format (ie "1 day 12:00:00")
127
+
128
+ def to_s
129
+ s = (to_s_pieces(DATE_FIELDS) + [to_s_time_piece]).compact.join(' ')
130
+ if s == ""
131
+ "0 days"
132
+ else
133
+ s
134
+ end + (ago ? " ago" : "")
135
+ end
136
+
137
+ protected
138
+
139
+ def parts
140
+ @values.values
141
+ end
142
+
143
+ private
144
+
145
+ def column_type
146
+ 'interval'
147
+ end
148
+
149
+ def singularize(units)
150
+ units.gsub(/ia$/, 'ium').gsub(/ies$/, 'y').gsub(/s$/, '')
151
+ end
152
+
153
+ def default(field)
154
+ if field == 'ago'
155
+ false
156
+ else
157
+ 0
158
+ end
159
+ end
160
+
161
+ def to_s_pieces(fields)
162
+ fields.collect do |field|
163
+ value = @values[field]
164
+ if value == 0
165
+ nil
166
+ else
167
+ if value == 1
168
+ "#{value} #{singularize(field)}"
169
+ else
170
+ "#{value} #{field}"
171
+ end
172
+ end
173
+ end
174
+ end
175
+
176
+ def to_s_time_piece
177
+ h, m, s = hours, minutes, seconds
178
+ if hours == 0 && minutes == 0 && seconds == 0
179
+ nil
180
+ else
181
+ allNegative = hours <= 0 && minutes <= 0 && seconds <= 0
182
+ allPositive = hours >= 0 && minutes >= 0 && seconds >= 0
183
+ if allNegative || allPositive
184
+ format = "%s%02d:%02d"
185
+ sign = if allNegative then "-" else "" end
186
+ if s != 0
187
+ if s.is_a?(Float)
188
+ format << ":%09.6f"
189
+ else
190
+ format << ":%02d"
191
+ end
192
+ end
193
+ format % [sign, hours.abs, minutes.abs, seconds.abs]
194
+ else
195
+ to_s_pieces(TIME_FIELDS)
196
+ end
197
+ end
198
+ end
199
+
200
+ end
201
+
202
+ end
203
+
204
+ # Local Variables:
205
+ # tab-width: 2
206
+ # ruby-indent-level: 2
207
+ # indent-tabs-mode: nil
208
+ # End:
@@ -0,0 +1,37 @@
1
+ require 'sqlpostgres/PgTwoPoints'
2
+
3
+ module SqlPostgres
4
+
5
+ # This class holds the value of a "line segment" column.
6
+
7
+ class PgLineSegment < PgTwoPoints
8
+
9
+ class << self
10
+
11
+ # Create a PgLineSegment from a string in Postgres format
12
+
13
+ def from_sql(s)
14
+ if s =~ /^\[(\(.*\)),(\(.*\))\]$/
15
+ PgLineSegment.new(PgPoint.from_sql($1), PgPoint.from_sql($2))
16
+ else
17
+ raise ArgumentError, "Invalid lseg: #{s.inspect}"
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+ private
24
+
25
+ def column_type
26
+ 'lseg'
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
33
+ # Local Variables:
34
+ # tab-width: 2
35
+ # ruby-indent-level: 2
36
+ # indent-tabs-mode: nil
37
+ # End:
@@ -0,0 +1,21 @@
1
+ require 'sqlpostgres/PgWrapper'
2
+
3
+ module SqlPostgres
4
+
5
+ # This class holds the value of an "macaddr" column.
6
+
7
+ class PgMacAddr < PgWrapper
8
+
9
+ def column_type
10
+ 'macaddr'
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+
17
+ # Local Variables:
18
+ # tab-width: 2
19
+ # ruby-indent-level: 2
20
+ # indent-tabs-mode: nil
21
+ # End:
@@ -0,0 +1,64 @@
1
+ require 'sqlpostgres/PgType'
2
+
3
+ module SqlPostgres
4
+
5
+ # This class holds the value of a "path" column.
6
+
7
+ class PgPath < PgType
8
+
9
+ attr_reader :points
10
+ attr_reader :closed
11
+
12
+ class << self
13
+
14
+ # Create a PgPath from a string in Postgres format
15
+
16
+ def from_sql(s)
17
+ if s =~ /^(\[)\(.*\)(,\(.*\))?\]$/ || s =~ /^(\()\(.*\)(,\(.*\))?\)$/
18
+ closed = $1 == "("
19
+ points = s.scan(/\([^(]*?\)/).collect do |t|
20
+ PgPoint.from_sql(t)
21
+ end
22
+ PgPath.new(closed, *points)
23
+ else
24
+ raise ArgumentError, "Invalid path: #{s.inspect}"
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ def initialize(closed = true, *points)
31
+ @points = points
32
+ @closed = closed
33
+ end
34
+
35
+ def to_s
36
+ s = points.join(", ")
37
+ if closed
38
+ "(#{s})"
39
+ else
40
+ "[#{s}]"
41
+ end
42
+ end
43
+
44
+ protected
45
+
46
+ def parts
47
+ [closed, points]
48
+ end
49
+
50
+ private
51
+
52
+ def column_type
53
+ 'path'
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+
60
+ # Local Variables:
61
+ # tab-width: 2
62
+ # ruby-indent-level: 2
63
+ # indent-tabs-mode: nil
64
+ # End:
@@ -0,0 +1,65 @@
1
+ require 'sqlpostgres/PgType'
2
+
3
+ module SqlPostgres
4
+
5
+ # This class holds the value of a "point" column.
6
+
7
+ class PgPoint < PgType
8
+
9
+ # Return the x coordinate
10
+
11
+ attr_reader :x
12
+
13
+ # Return the y coordinate
14
+
15
+ attr_reader :y
16
+
17
+ class << self
18
+
19
+ # Create a PgPoint from a string in Postgres format (ie
20
+ # "(1,2)").
21
+
22
+ def from_sql(s)
23
+ if s =~ /^\((.*?),(.*\))$/
24
+ PgPoint.new($1.to_f, $2.to_f)
25
+ else
26
+ raise ArgumentError, "Invalid point: #{s.inspect}"
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ # Constructor taking the x and y coordinate
33
+
34
+ def initialize(x = 0, y = 0)
35
+ @x = x
36
+ @y = y
37
+ end
38
+
39
+ # Return a string representation (ie "(1, 2)").
40
+
41
+ def to_s
42
+ "(%g, %g)" % parts
43
+ end
44
+
45
+ protected
46
+
47
+ def parts
48
+ [x, y]
49
+ end
50
+
51
+ private
52
+
53
+ def column_type
54
+ 'point'
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+
61
+ # Local Variables:
62
+ # tab-width: 2
63
+ # ruby-indent-level: 2
64
+ # indent-tabs-mode: nil
65
+ # End:
@@ -0,0 +1,56 @@
1
+ require File.join(File.dirname(__FILE__), "PgType")
2
+
3
+ module SqlPostgres
4
+
5
+ # This class holds the value of a "point" column.
6
+
7
+ class PgPolygon < PgType
8
+
9
+ attr_reader :points
10
+
11
+ class << self
12
+
13
+ # Create a PgPolygon from a string in Postgres format
14
+
15
+ def from_sql(s)
16
+ if s =~ /^(\()\(.*\)(,\(.*\))?\)$/
17
+ points = s.scan(/\([^(]*?\)/).collect do |t|
18
+ PgPoint.from_sql(t)
19
+ end
20
+ PgPolygon.new(*points)
21
+ else
22
+ raise ArgumentError, "Invalid polygon: #{s.inspect}"
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ def initialize(*points)
29
+ @points = points
30
+ end
31
+
32
+ def to_s
33
+ "(#{points.join(", ")})"
34
+ end
35
+
36
+ protected
37
+
38
+ def parts
39
+ points
40
+ end
41
+
42
+ private
43
+
44
+ def column_type
45
+ 'polygon'
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+
52
+ # Local Variables:
53
+ # tab-width: 2
54
+ # ruby-indent-level: 2
55
+ # indent-tabs-mode: nil
56
+ # End: