sqlpostgres 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.md +23 -0
- data/README.rdoc +59 -0
- data/Rakefile +32 -0
- data/VERSION +1 -0
- data/doc/BUGS +2 -0
- data/doc/examples/README +6 -0
- data/doc/examples/connection.rb +16 -0
- data/doc/examples/connection_auto.rb +22 -0
- data/doc/examples/connection_ctor.rb +18 -0
- data/doc/examples/connection_default.rb +15 -0
- data/doc/examples/connection_exec.rb +18 -0
- data/doc/examples/connection_manual.rb +12 -0
- data/doc/examples/connection_wrapped_new.rb +13 -0
- data/doc/examples/connection_wrapped_open.rb +13 -0
- data/doc/examples/cursor.rb +38 -0
- data/doc/examples/include_module.rb +9 -0
- data/doc/examples/include_module2.rb +12 -0
- data/doc/examples/insert.rb +30 -0
- data/doc/examples/insert2.rb +36 -0
- data/doc/examples/insert_bytea.rb +16 -0
- data/doc/examples/insert_bytea_array.rb +17 -0
- data/doc/examples/insert_default_values.rb +16 -0
- data/doc/examples/insert_insert.rb +16 -0
- data/doc/examples/insert_insert_default.rb +16 -0
- data/doc/examples/insert_insert_select.rb +20 -0
- data/doc/examples/insert_select.rb +20 -0
- data/doc/examples/interval.rb +17 -0
- data/doc/examples/savepoint.rb +38 -0
- data/doc/examples/select.rb +33 -0
- data/doc/examples/select2.rb +36 -0
- data/doc/examples/select_cross_join.rb +18 -0
- data/doc/examples/select_distinct.rb +18 -0
- data/doc/examples/select_distinct_on +19 -0
- data/doc/examples/select_for_update.rb +18 -0
- data/doc/examples/select_from.rb +17 -0
- data/doc/examples/select_from_subselect.rb +20 -0
- data/doc/examples/select_group_by.rb +19 -0
- data/doc/examples/select_having.rb +20 -0
- data/doc/examples/select_join_on.rb +18 -0
- data/doc/examples/select_join_using.rb +18 -0
- data/doc/examples/select_limit.rb +19 -0
- data/doc/examples/select_natural_join.rb +18 -0
- data/doc/examples/select_offset.rb +19 -0
- data/doc/examples/select_order_by.rb +20 -0
- data/doc/examples/select_select.rb +30 -0
- data/doc/examples/select_select_alias.rb +30 -0
- data/doc/examples/select_select_expression.rb +31 -0
- data/doc/examples/select_select_literal.rb +24 -0
- data/doc/examples/select_union.rb +21 -0
- data/doc/examples/select_where_array.rb +18 -0
- data/doc/examples/select_where_in.rb +18 -0
- data/doc/examples/select_where_string.rb +18 -0
- data/doc/examples/simple.rb +34 -0
- data/doc/examples/transaction.rb +30 -0
- data/doc/examples/transaction_abort.rb +30 -0
- data/doc/examples/transaction_commit.rb +34 -0
- data/doc/examples/translate_substitute_values.rb +17 -0
- data/doc/examples/update.rb +32 -0
- data/doc/examples/update2.rb +44 -0
- data/doc/examples/update_only.rb +17 -0
- data/doc/examples/update_set.rb +17 -0
- data/doc/examples/update_set_array.rb +16 -0
- data/doc/examples/update_set_bytea.rb +16 -0
- data/doc/examples/update_set_expression.rb +16 -0
- data/doc/examples/update_set_subselect.rb +20 -0
- data/doc/examples/update_where.rb +17 -0
- data/doc/examples/use_prefix.rb +8 -0
- data/doc/examples/use_prefix2.rb +11 -0
- data/doc/index.html +31 -0
- data/doc/insertexamples.rb +9 -0
- data/doc/makemanual +4 -0
- data/doc/makerdoc +5 -0
- data/doc/manual.dbk +622 -0
- data/lib/sqlpostgres/Connection.rb +198 -0
- data/lib/sqlpostgres/Cursor.rb +157 -0
- data/lib/sqlpostgres/Delete.rb +67 -0
- data/lib/sqlpostgres/Exceptions.rb +15 -0
- data/lib/sqlpostgres/Insert.rb +279 -0
- data/lib/sqlpostgres/NullConnection.rb +22 -0
- data/lib/sqlpostgres/PgBit.rb +73 -0
- data/lib/sqlpostgres/PgBox.rb +37 -0
- data/lib/sqlpostgres/PgCidr.rb +21 -0
- data/lib/sqlpostgres/PgCircle.rb +75 -0
- data/lib/sqlpostgres/PgInet.rb +21 -0
- data/lib/sqlpostgres/PgInterval.rb +208 -0
- data/lib/sqlpostgres/PgLineSegment.rb +37 -0
- data/lib/sqlpostgres/PgMacAddr.rb +21 -0
- data/lib/sqlpostgres/PgPath.rb +64 -0
- data/lib/sqlpostgres/PgPoint.rb +65 -0
- data/lib/sqlpostgres/PgPolygon.rb +56 -0
- data/lib/sqlpostgres/PgTime.rb +77 -0
- data/lib/sqlpostgres/PgTimeWithTimeZone.rb +98 -0
- data/lib/sqlpostgres/PgTimestamp.rb +93 -0
- data/lib/sqlpostgres/PgTwoPoints.rb +54 -0
- data/lib/sqlpostgres/PgType.rb +34 -0
- data/lib/sqlpostgres/PgWrapper.rb +41 -0
- data/lib/sqlpostgres/Savepoint.rb +98 -0
- data/lib/sqlpostgres/Select.rb +855 -0
- data/lib/sqlpostgres/Transaction.rb +120 -0
- data/lib/sqlpostgres/Translate.rb +436 -0
- data/lib/sqlpostgres/Update.rb +188 -0
- data/lib/sqlpostgres.rb +67 -0
- data/test/Assert.rb +72 -0
- data/test/Connection.test.rb +246 -0
- data/test/Cursor.test.rb +190 -0
- data/test/Delete.test.rb +68 -0
- data/test/Insert.test.rb +123 -0
- data/test/MockPGconn.rb +62 -0
- data/test/NullConnection.test.rb +32 -0
- data/test/PgBit.test.rb +98 -0
- data/test/PgBox.test.rb +108 -0
- data/test/PgCidr.test.rb +61 -0
- data/test/PgCircle.test.rb +107 -0
- data/test/PgInet.test.rb +61 -0
- data/test/PgInterval.test.rb +180 -0
- data/test/PgLineSegment.test.rb +108 -0
- data/test/PgMacAddr.test.rb +61 -0
- data/test/PgPath.test.rb +106 -0
- data/test/PgPoint.test.rb +100 -0
- data/test/PgPolygon.test.rb +95 -0
- data/test/PgTime.test.rb +120 -0
- data/test/PgTimeWithTimeZone.test.rb +117 -0
- data/test/PgTimestamp.test.rb +134 -0
- data/test/RandomThings.rb +25 -0
- data/test/Savepoint.test.rb +286 -0
- data/test/Select.test.rb +930 -0
- data/test/Test.rb +62 -0
- data/test/TestConfig.rb +21 -0
- data/test/TestSetup.rb +13 -0
- data/test/TestUtil.rb +92 -0
- data/test/Transaction.test.rb +275 -0
- data/test/Translate.test.rb +354 -0
- data/test/Update.test.rb +227 -0
- data/test/roundtrip.test.rb +565 -0
- data/test/test +34 -0
- data/tools/exampleinserter/ExampleInserter.rb +177 -0
- data/tools/rdoc/ChangeLog +796 -0
- data/tools/rdoc/EXAMPLE.rb +48 -0
- data/tools/rdoc/MANIFEST +58 -0
- data/tools/rdoc/Makefile +27 -0
- data/tools/rdoc/NEW_FEATURES +226 -0
- data/tools/rdoc/README +390 -0
- data/tools/rdoc/ToDo +6 -0
- data/tools/rdoc/contrib/Index +6 -0
- data/tools/rdoc/contrib/xslfo/ChangeLog +181 -0
- data/tools/rdoc/contrib/xslfo/README +106 -0
- data/tools/rdoc/contrib/xslfo/TODO +10 -0
- data/tools/rdoc/contrib/xslfo/convert.xsl +151 -0
- data/tools/rdoc/contrib/xslfo/demo/README +21 -0
- data/tools/rdoc/contrib/xslfo/demo/rdocfo +99 -0
- data/tools/rdoc/contrib/xslfo/fcm.xsl +54 -0
- data/tools/rdoc/contrib/xslfo/files.xsl +62 -0
- data/tools/rdoc/contrib/xslfo/labeled-lists.xsl +66 -0
- data/tools/rdoc/contrib/xslfo/lists.xsl +44 -0
- data/tools/rdoc/contrib/xslfo/modules.xsl +152 -0
- data/tools/rdoc/contrib/xslfo/rdoc.xsl +75 -0
- data/tools/rdoc/contrib/xslfo/source.xsl +66 -0
- data/tools/rdoc/contrib/xslfo/styles.xsl +69 -0
- data/tools/rdoc/contrib/xslfo/tables.xsl +67 -0
- data/tools/rdoc/contrib/xslfo/utils.xsl +21 -0
- data/tools/rdoc/debian/changelog +33 -0
- data/tools/rdoc/debian/compat +1 -0
- data/tools/rdoc/debian/control +20 -0
- data/tools/rdoc/debian/copyright +10 -0
- data/tools/rdoc/debian/dirs +2 -0
- data/tools/rdoc/debian/docs +2 -0
- data/tools/rdoc/debian/rdoc.1 +252 -0
- data/tools/rdoc/debian/rdoc.manpages +1 -0
- data/tools/rdoc/debian/rdoc.pod +149 -0
- data/tools/rdoc/debian/rules +9 -0
- data/tools/rdoc/dot/dot.rb +255 -0
- data/tools/rdoc/etc/rdoc.dtd +203 -0
- data/tools/rdoc/install.rb +137 -0
- data/tools/rdoc/markup/install.rb +43 -0
- data/tools/rdoc/markup/sample/sample.rb +42 -0
- data/tools/rdoc/markup/simple_markup/fragments.rb +323 -0
- data/tools/rdoc/markup/simple_markup/inline.rb +348 -0
- data/tools/rdoc/markup/simple_markup/lines.rb +147 -0
- data/tools/rdoc/markup/simple_markup/preprocess.rb +68 -0
- data/tools/rdoc/markup/simple_markup/to_html.rb +281 -0
- data/tools/rdoc/markup/simple_markup.rb +474 -0
- data/tools/rdoc/markup/test/AllTests.rb +2 -0
- data/tools/rdoc/markup/test/TestInline.rb +151 -0
- data/tools/rdoc/markup/test/TestParse.rb +411 -0
- data/tools/rdoc/rdoc/code_objects.rb +536 -0
- data/tools/rdoc/rdoc/diagram.rb +331 -0
- data/tools/rdoc/rdoc/generators/chm_generator.rb +112 -0
- data/tools/rdoc/rdoc/generators/html_generator.rb +1268 -0
- data/tools/rdoc/rdoc/generators/template/chm/chm.rb +86 -0
- data/tools/rdoc/rdoc/generators/template/html/html.rb +705 -0
- data/tools/rdoc/rdoc/generators/template/html/kilmer.rb +377 -0
- data/tools/rdoc/rdoc/generators/template/xml/rdf.rb +110 -0
- data/tools/rdoc/rdoc/generators/template/xml/xml.rb +110 -0
- data/tools/rdoc/rdoc/generators/xml_generator.rb +130 -0
- data/tools/rdoc/rdoc/options.rb +451 -0
- data/tools/rdoc/rdoc/parsers/parse_c.rb +287 -0
- data/tools/rdoc/rdoc/parsers/parse_f95.rb +118 -0
- data/tools/rdoc/rdoc/parsers/parse_rb.rb +2311 -0
- data/tools/rdoc/rdoc/parsers/parse_simple.rb +37 -0
- data/tools/rdoc/rdoc/parsers/parserfactory.rb +75 -0
- data/tools/rdoc/rdoc/rdoc.rb +219 -0
- data/tools/rdoc/rdoc/template.rb +234 -0
- data/tools/rdoc/rdoc/tokenstream.rb +25 -0
- data/tools/rdoc/rdoc.rb +9 -0
- metadata +291 -0
data/Gemfile
ADDED
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
data/doc/examples/README
ADDED
@@ -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,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,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
|