sqlpostgres 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
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
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'pg', '~> 0.13.2'
4
+
5
+ group :development do
6
+ gem 'jeweler', '~> 1.8.4'
7
+ gem 'rake', '~> 10.0.3'
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.8.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rdoc
10
+ json (1.7.6)
11
+ pg (0.13.2)
12
+ rake (10.0.3)
13
+ rdoc (3.12)
14
+ json (~> 1.4)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ jeweler (~> 1.8.4)
21
+ pg (~> 0.13.2)
22
+ rake (~> 10.0.3)
data/LICENSE.md ADDED
@@ -0,0 +1,23 @@
1
+ Copyright 2013 Wayne Conrad
2
+
3
+ This software is distributed under the [MIT License](http://opensource.org/licenses/MIT):
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
data/README.rdoc ADDED
@@ -0,0 +1,59 @@
1
+ = sqlpostgres
2
+
3
+ sqlpostgres is a mini-language for building and execting SQL
4
+ statements against a postgresql database.
5
+
6
+ This is a very old library, pre-dating active record and lacking many
7
+ of its refinements. New projects will probably not want to use this.
8
+
9
+ == INSTALL
10
+
11
+ $ gem install USPS-intelligent-barcode
12
+
13
+ == EXAMPLE
14
+
15
+ require "sqlpostgres"
16
+
17
+ include SqlPostgres
18
+
19
+ Connection.open do |connection|
20
+ connection.exec("create temporary table foo (t text)")
21
+
22
+ insert = Insert.new('foo', connection)
23
+ insert.insert('t', 'Smith')
24
+ insert.exec
25
+
26
+ insert = Insert.new('foo', connection)
27
+ insert.insert('t', 'Jones')
28
+ insert.exec
29
+
30
+ update = Update.new('foo', connection)
31
+ update.set('t', "O'Brien")
32
+ update.where(["t = %s", "Smith"])
33
+ update.exec
34
+
35
+ select = Select.new(connection)
36
+ select.select('t')
37
+ select.from('foo')
38
+ select.order_by('t')
39
+ p select.exec
40
+ # [{"t"=>"Jones"}, {"t"=>"O'Brien"}]
41
+
42
+ end
43
+
44
+ == RUBY VERSIONS
45
+
46
+ The tests are known to pass in MRI 1.8.7 and MRI 1.9.3
47
+
48
+ == POSTGRES VERSIONS
49
+
50
+ This library works with Postgres 1.8. It does not yet fully support
51
+ Postgres 1.9.
52
+
53
+ == ENCODINGS
54
+
55
+ This library only works properly with the SQL-ASCII encoding.
56
+
57
+ == WHOAMI
58
+
59
+ Wayne Conrad <wconrad@yagni.com>
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+
5
+ require 'bundler'
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts 'Run `bundle install` to install missing gems'
11
+ exit e.status_code
12
+ end
13
+ require 'rake'
14
+
15
+ require 'jeweler'
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see
18
+ # http://docs.rubygems.org/read/chapter/20 for more options
19
+ gem.name = 'sqlpostgres'
20
+ gem.homepage = 'http://github.com/wconrad/sqlpostgres'
21
+ gem.license = 'MIT'
22
+ gem.summary = %Q{library for postgresql queries}
23
+ gem.description =
24
+ ('A mini-language for building and executing SQL statements '\
25
+ 'against a postgresql database. This is a very old library, '\
26
+ 'pre-dating active record and lacking many of its refinments. '\
27
+ 'New projects will probably not want to use it.')
28
+ gem.email = 'wconrad@yagni.com'
29
+ gem.authors = ['Wayne Conrad']
30
+ # dependencies defined in Gemfile
31
+ end
32
+ Jeweler::RubygemsDotOrgTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.2.4
data/doc/BUGS ADDED
@@ -0,0 +1,2 @@
1
+ Is only tested and known to work properly if the database encoding is
2
+ SQL_ASCII.
@@ -0,0 +1,6 @@
1
+ These example programs are designed to run standalone, provided that
2
+ there is a database with the same name as your login name.
3
+
4
+ They are automatically inserted into the class (rdoc) documentation
5
+ and into the manual's docbook source. To do that, run the script
6
+ "insertexamples.rb"
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "../../test"))
4
+ $:.unshift(File.join(File.dirname(__FILE__), "../../lib/"))
5
+
6
+ require 'Assert'
7
+ require 'sqlpostgres'
8
+
9
+ include Assert
10
+ include SqlPostgres
11
+
12
+ # Example: ../manual.dbk
13
+ Connection.open do |connection|
14
+ # Use the connection
15
+ end
16
+ # End example
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), "../../lib/")
4
+
5
+ require 'sqlpostgres'
6
+ include SqlPostgres
7
+
8
+ dbName = "sqlpostgres_test"
9
+ Connection.open do |connection1|
10
+ connection1.exec("create database #{dbName}")
11
+ begin
12
+ # Example: ../manual.dbk
13
+ Connection.open('db_name'=>'sqlpostgres_test') do |connection|
14
+ # Use the connection
15
+ end
16
+ # End example
17
+ sleep(0.1) # I don't know why, but it seems to take some time
18
+ # for the connection to be closed
19
+ ensure
20
+ connection1.exec("drop database #{dbName}")
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), "../../lib/")
4
+
5
+ require 'sqlpostgres'
6
+ include SqlPostgres
7
+
8
+ Connection.open do |connection|
9
+
10
+ connection.exec("create temporary table person (name text)")
11
+
12
+ # Example: ../manual.dbk
13
+ insert = Insert.new('person', connection)
14
+ insert.insert('name', 'Fred')
15
+ insert.exec
16
+ # End example
17
+
18
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), "../../lib/")
4
+
5
+ require 'sqlpostgres'
6
+ include SqlPostgres
7
+
8
+ # Example: ../manual.dbk
9
+ Connection.open do |connection|
10
+ Connection.default = connection
11
+ select = Select.new
12
+ select.select_literal(1, 'i') # OUTPUT
13
+ p select.exec
14
+ end
15
+ # End example
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), "../../lib/")
4
+
5
+ require 'sqlpostgres'
6
+ include SqlPostgres
7
+
8
+ Connection.open do |connection|
9
+
10
+ connection.exec("create temporary table person (name text)")
11
+
12
+ # Example: ../manual.dbk
13
+ insert = Insert.new('person')
14
+ insert.insert('name', 'Fred')
15
+ insert.exec(connection)
16
+ # End example
17
+
18
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), "../../lib/")
4
+
5
+ require 'sqlpostgres'
6
+ include SqlPostgres
7
+
8
+ # Example: ../manual.dbk
9
+ connection = Connection.new
10
+ # use the connection
11
+ connection.close
12
+ # End example
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), "../../lib/")
4
+
5
+ require 'sqlpostgres'
6
+ include SqlPostgres
7
+
8
+ # Example: ../manual.dbk
9
+ pgconn = PGconn.connect('localhost', 5432, '', '', ENV['USER'])
10
+ connection = Connection.new('connection'=>pgconn)
11
+ # use the connection
12
+ connection.close # or, if you prefer, pgconn.close
13
+ # End example
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), "../../lib/")
4
+
5
+ require 'sqlpostgres'
6
+ include SqlPostgres
7
+
8
+ # Example: ../manual.dbk
9
+ pgconn = PGconn.connect('localhost', 5432, '', '', ENV['USER'])
10
+ connection = Connection.open('connection'=>pgconn) do |connection|
11
+ # use the connection
12
+ end
13
+ # End example
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "../../lib"))
4
+ $:.unshift(File.join(File.dirname(__FILE__), "../../test"))
5
+
6
+ require 'Assert'
7
+ require 'sqlpostgres'
8
+
9
+ include SqlPostgres
10
+ include Assert
11
+
12
+ Connection.open do |connection|
13
+
14
+ connection.exec("create temporary table foo (i int)")
15
+ 5.times do |i|
16
+ connection.exec("insert into foo (i) values (#{i})")
17
+ end
18
+
19
+ # Example: ../../lib/sqlpostgres/Cursor.rb
20
+ Transaction.new(connection) do
21
+ select = Select.new(connection)
22
+ select.select('i')
23
+ select.from('foo')
24
+ Cursor.new('my_cursor', select, {}, connection) do |cursor|
25
+ while !(rows = cursor.fetch).empty?
26
+ for row in rows
27
+ p row # OUTPUT
28
+ # OUTPUT
29
+ # OUTPUT
30
+ # OUTPUT
31
+ # OUTPUT
32
+ end
33
+ end
34
+ end
35
+ end
36
+ # End example
37
+
38
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), "../../lib/")
4
+
5
+ # Example: ../../lib/sqlpostgres.rb
6
+ require 'sqlpostgres'
7
+ include SqlPostgres
8
+ insert = Insert.new('foo')
9
+ # End example
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), "../../lib/")
4
+
5
+ # Example: ../manual.dbk
6
+ require 'sqlpostgres'
7
+ include SqlPostgres
8
+
9
+ Connection.open do |connection|
10
+ #...
11
+ end
12
+ # End example
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "../../lib"))
4
+ $:.unshift(File.join(File.dirname(__FILE__), "../../test"))
5
+
6
+ require 'Assert'
7
+ require 'sqlpostgres'
8
+
9
+ include SqlPostgres
10
+ include Assert
11
+
12
+ Connection.open do |connection|
13
+
14
+ connection.exec("create temporary table foo (i int, t text)")
15
+
16
+ # Example: ../../lib/sqlpostgres/Insert.rb
17
+ insert = Insert.new('foo', connection)
18
+ insert.insert('i', 1)
19
+ insert.insert('t', 'foo')
20
+ p insert.statement # OUTPUT
21
+ insert.exec
22
+ # End example
23
+
24
+ select = Select.new(connection)
25
+ select.select('i')
26
+ select.select('t')
27
+ select.from('foo')
28
+ assertEquals(select.exec, [{'i'=>1, 't'=>'foo'}])
29
+
30
+ end
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "../../lib"))
4
+ $:.unshift(File.join(File.dirname(__FILE__), "../../test"))
5
+
6
+ require 'Assert'
7
+ require 'sqlpostgres'
8
+
9
+ include SqlPostgres
10
+ include Assert
11
+
12
+ Connection.open do |connection|
13
+
14
+ connection.exec("create temporary table person (name text, "\
15
+ "date_of_birth date)")
16
+
17
+ # Example: ../manual.dbk
18
+ insert = Insert.new('person', connection)
19
+ insert.insert('name', "O'Reilly")
20
+ insert.insert('date_of_birth', Date.civil(1972, 1, 1))
21
+ p insert.statement # OUTPUT
22
+ insert.exec
23
+ # End example
24
+
25
+ select = Select.new(connection)
26
+ select.select('name')
27
+ select.select('date_of_birth')
28
+ select.from('person')
29
+ assertEquals(select.exec, [
30
+ {
31
+ 'name'=>"O'Reilly",
32
+ 'date_of_birth'=>Date.civil(1972, 1, 1)
33
+ }
34
+ ])
35
+
36
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "../../lib"))
4
+ $:.unshift(File.join(File.dirname(__FILE__), "../../test"))
5
+
6
+ require 'Assert'
7
+ require 'sqlpostgres'
8
+
9
+ include SqlPostgres
10
+ include Assert
11
+
12
+ # Example: ../../lib/sqlpostgres/Insert.rb
13
+ insert = Insert.new('foo')
14
+ insert.insert_bytea('t', "\000\001\002\003")
15
+ p insert.statement # OUTPUT
16
+ # End example
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "../../lib"))
4
+ $:.unshift(File.join(File.dirname(__FILE__), "../../test"))
5
+
6
+ require 'Assert'
7
+ require 'sqlpostgres'
8
+
9
+ include SqlPostgres
10
+ include Assert
11
+
12
+ # Example: ../../lib/sqlpostgres/Insert.rb
13
+ insert = Insert.new('foo')
14
+ insert.insert_bytea_array('t', ["foo", "\000bar\nbaz"])
15
+ p insert.statement # OUTPUT
16
+
17
+ # End example
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "../../lib"))
4
+ $:.unshift(File.join(File.dirname(__FILE__), "../../test"))
5
+
6
+ require 'Assert'
7
+ require 'sqlpostgres'
8
+
9
+ include SqlPostgres
10
+ include Assert
11
+
12
+ # Example: ../../lib/sqlpostgres/Insert.rb
13
+ insert = Insert.new('foo')
14
+ insert.default_values
15
+ p insert.statement # OUTPUT
16
+ # End example
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "../../lib"))
4
+ $:.unshift(File.join(File.dirname(__FILE__), "../../test"))
5
+
6
+ require 'Assert'
7
+ require 'sqlpostgres'
8
+
9
+ include SqlPostgres
10
+ include Assert
11
+
12
+ # Example: ../../lib/sqlpostgres/Insert.rb
13
+ insert = Insert.new('foo')
14
+ insert.insert('t', 'bar')
15
+ p insert.statement # OUTPUT
16
+ # End example
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "../../lib"))
4
+ $:.unshift(File.join(File.dirname(__FILE__), "../../test"))
5
+
6
+ require 'Assert'
7
+ require 'sqlpostgres'
8
+
9
+ include SqlPostgres
10
+ include Assert
11
+
12
+ # Example: ../../lib/sqlpostgres/Insert.rb
13
+ insert = Insert.new('foo')
14
+ insert.insert('i', :default)
15
+ p insert.statement # OUTPUT
16
+ # End example
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "../../lib"))
4
+ $:.unshift(File.join(File.dirname(__FILE__), "../../test"))
5
+
6
+ require 'Assert'
7
+ require 'sqlpostgres'
8
+
9
+ include SqlPostgres
10
+ include Assert
11
+
12
+ # Example: ../../lib/sqlpostgres/Insert.rb
13
+ select = Select.new
14
+ select.select('j')
15
+ select.from('bar')
16
+ select.limit(1)
17
+ insert = Insert.new('foo')
18
+ insert.insert('i', select)
19
+ p insert.statement # OUTPUT
20
+ # End example
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "../../lib"))
4
+ $:.unshift(File.join(File.dirname(__FILE__), "../../test"))
5
+
6
+ require 'Assert'
7
+ require 'sqlpostgres'
8
+
9
+ include SqlPostgres
10
+ include Assert
11
+
12
+ # Example: ../../lib/sqlpostgres/Insert.rb
13
+ select = Select.new
14
+ select.select('i')
15
+ select.from('bar')
16
+ insert = Insert.new('foo')
17
+ insert.insert('i')
18
+ insert.select(select)
19
+ p insert.statement # OUTPUT
20
+ # End example
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "../../test"))
4
+ $:.unshift(File.join(File.dirname(__FILE__), "../../lib/"))
5
+
6
+ require 'Assert'
7
+ require 'sqlpostgres'
8
+
9
+ include Assert
10
+ include SqlPostgres
11
+
12
+ # Example: ../../lib/sqlpostgres/PgInterval.rb
13
+ interval = PgInterval.new('hours'=>1, 'minutes'=>30)
14
+ p interval.hours # OUTPUT
15
+ p interval.minutes # OUTPUT
16
+ p interval.seconds # OUTPUT
17
+ # End example
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "../../lib"))
4
+ $:.unshift(File.join(File.dirname(__FILE__), "../../test"))
5
+
6
+ require 'Assert'
7
+ require 'sqlpostgres'
8
+
9
+ include SqlPostgres
10
+ include Assert
11
+
12
+ Connection.open do |connection|
13
+
14
+ connection.exec("create temporary table foo (i int)")
15
+
16
+ # Example: ../../lib/sqlpostgres/Savepoint.rb
17
+ Transaction.new(connection) do
18
+
19
+ insert = Insert.new('foo', connection)
20
+ insert.insert('i', 1)
21
+ insert.exec
22
+
23
+ Savepoint.new('bar', connection) do |sp|
24
+ insert = Insert.new('foo', connection)
25
+ insert.insert('i', 2)
26
+ sp.abort
27
+ end
28
+
29
+ insert = Insert.new('foo', connection)
30
+ insert.insert('i', 3)
31
+ insert.exec
32
+
33
+ end
34
+
35
+ p connection.query("select i from foo order by i") #OUTPUT
36
+ # End example
37
+
38
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "../../test"))
4
+ $:.unshift(File.join(File.dirname(__FILE__), "../../lib/"))
5
+
6
+ require 'Assert'
7
+ require 'sqlpostgres'
8
+
9
+ include Assert
10
+ include SqlPostgres
11
+
12
+ Connection.open do |connection|
13
+
14
+ connection.exec("create temporary table foo (i int)")
15
+
16
+ for i in [1, 2, nil]
17
+ insert = Insert.new('foo', connection)
18
+ insert.insert('i', i)
19
+ insert.exec
20
+ end
21
+
22
+ # Example: ../../lib/sqlpostgres/Select.rb
23
+ select = Select.new(connection)
24
+ select.select('i')
25
+ select.from('foo')
26
+ select.order_by('i')
27
+ p select.statement # OUTPUT
28
+ p select.exec # OUTPUT
29
+ # End example
30
+
31
+ assertEquals(select.exec, [{"i"=>1}, {"i"=>2}, {"i"=>nil}])
32
+
33
+ end