Permalink
Browse files

Load plruby-0.4.3 into trunk.

git-svn-id: file:///home/knu/repos/ts/plruby/trunk@53 1f148aff-833f-de11-9cfd-0015170b777a
  • Loading branch information...
1 parent 7673c8d commit c5b29485689f265ba47efe3d222206727abc382d ts committed Nov 22, 2004
Showing with 6,365 additions and 4,267 deletions.
  1. +9 −0 Changes
  2. +0 −69 MANIFEST
  3. +17 −30 README.en
  4. +100 −19 docs/plruby.rb
  5. +33 −0 ex_trans.sql
  6. +43 −87 extconf.rb
  7. +352 −292 plruby.html
  8. +89 −33 plruby.rd
  9. +1 −1 src/conversions.h
  10. +28 −23 src/conversions/bitstring/plruby_bitstring.c
  11. +13 −3 src/conversions/convcommon.h
  12. +11 −10 src/conversions/datetime/plruby_datetime.c
  13. +93 −76 src/conversions/geometry/plruby_geometry.c
  14. +71 −16 src/conversions/network/plruby_network.c
  15. +148 −183 src/plpl.c
  16. +80 −66 src/plplan.c
  17. +203 −226 src/plruby.c
  18. +74 −71 src/plruby.h
  19. +323 −0 src/pltrans.c
  20. +51 −0 test/conv_bitstring/b.rb
  21. +26 −0 test/conv_bitstring/runtest
  22. +148 −0 test/conv_bitstring/test.expected.73
  23. +148 −0 test/conv_bitstring/test.expected.74
  24. +148 −0 test/conv_bitstring/test.expected.80
  25. +148 −0 test/conv_bitstring/test.out
  26. +8 −0 test/conv_bitstring/test_mklang.sql
  27. +63 −0 test/conv_bitstring/test_queries.orig
  28. +63 −0 test/conv_bitstring/test_queries.sql
  29. +51 −0 test/conv_geometry/b.rb
  30. +26 −0 test/conv_geometry/runtest
  31. +265 −0 test/conv_geometry/test.expected.73
  32. +265 −0 test/conv_geometry/test.expected.74
  33. +265 −0 test/conv_geometry/test.expected.80
  34. +265 −0 test/conv_geometry/test.out
  35. +8 −0 test/conv_geometry/test_mklang.sql
  36. +194 −0 test/conv_geometry/test_queries.orig
  37. +194 −0 test/conv_geometry/test_queries.sql
  38. +51 −0 test/conv_network/b.rb
  39. +26 −0 test/conv_network/runtest
  40. +213 −0 test/conv_network/test.expected.73
  41. +237 −0 test/conv_network/test.expected.74
  42. +237 −0 test/conv_network/test.expected.80
  43. +237 −0 test/conv_network/test.out
  44. +8 −0 test/conv_network/test_mklang.sql
  45. +60 −0 test/conv_network/test_queries.orig
  46. +60 −0 test/conv_network/test_queries.sql
  47. +2 −10 test/plp/b.rb
  48. +0 −472 test/plp/test.expected.65
  49. +0 −472 test/plp/test.expected.70
  50. +2 −2 test/plp/{test.expected.72 → test.expected.75}
  51. +2 −2 test/plp/{test.expected.71 → test.expected.80}
  52. +1 −1 test/plp/test_mklang.sql
  53. +0 −930 test/plp/test_setup_new.sql
  54. +2 −19 test/plt/b.rb
  55. +1 −5 test/plt/runtest
  56. +0 −178 test/plt/test.expected.65
  57. +0 −178 test/plt/test.expected.70
  58. 0 test/plt/{test.expected.72 → test.expected.75}
  59. 0 test/plt/{test.expected.71 → test.expected.80}
  60. +1 −1 test/plt/test_mklang.sql
  61. +0 −262 test/plt/test_setup_new.sql
  62. +0 −262 test/plt/test_setup_new_trigger.sql
  63. +0 −248 test/plt/test_setup_old.sql
  64. +2 −9 test/range/b.rb
  65. +396 −0 test/range/test.expected.75
  66. +396 −0 test/range/test.expected.75.orig
  67. +396 −0 test/range/test.expected.80
  68. +10 −10 test/range/test.out
  69. +1 −1 test/range/test_mklang.sql
View
@@ -79,3 +79,12 @@
--- 0.4.1
add bitstring
+
+--- 0.4.2
+
+ by default convert arguments ( --disable-conversion to remove it)
+
+--- 0.4.3
+
+ IMPORTANT : work only with postgres >= 7.3
+ transaction and named arguments for 8.0
View
@@ -1,69 +0,0 @@
-Changes
-MANIFEST
-README.en
-docs/plruby.rb
-example.run
-extconf.rb
-plruby.html
-plruby.rd
-src/plruby.c
-src/plruby.h
-src/package.h
-src/conversions/geometry/plruby_geometry.c
-src/conversions/geometry/extconf.rb
-src/conversions/geometry/geometry.sql
-src/conversions/geometry/conversions.h
-src/conversions/network/plruby_network.c
-src/conversions/network/network.sql
-src/conversions/network/extconf.rb
-src/conversions/network/conversions.h
-src/conversions/basic/conversions.h
-src/conversions/basic/plruby_basic.c
-src/conversions/basic/extconf.rb
-src/conversions/bitstring/bitstring.sql
-src/conversions/bitstring/extconf.rb
-src/conversions/bitstring/conversions.h
-src/conversions/bitstring/plruby_bitstring.c
-src/conversions.h
-src/plplan.c
-src/plpl.c
-test/plp/b.rb
-test/plp/runtest
-test/plp/test.expected.65
-test/plp/test.expected.70
-test/plp/test.expected.71
-test/plp/test.expected.72
-test/plp/test.expected.73
-test/plp/test.out
-test/plp/test_mklang.sql
-test/plp/test_queries.sql
-test/plp/test_setup.sql
-test/plp/test_setup_new.sql
-test/plp/test_setup_new_trigger.sql
-test/plp/test.expected.74
-test/plt/b.rb
-test/plt/runtest
-test/plt/test.expected.65
-test/plt/test.expected.70
-test/plt/test.expected.71
-test/plt/test.expected.72
-test/plt/test.expected.73
-test/plt/test.out
-test/plt/test_mklang.sql
-test/plt/test_queries.sql
-test/plt/test_setup.sql
-test/plt/test_setup_new.sql
-test/plt/test_setup_new_trigger.sql
-test/plt/test_setup_old.sql
-test/plt/test.expected.74
-test/plt/test_setup_new_trigger_array.sql
-test/range/b.rb
-test/range/runtest
-test/range/test_queries.sql
-test/range/test.out
-test/range/test.expected.73
-test/range/test_mklang.sql
-test/range/test.expected.74
-test/range/test_queries.orig
-test/range/test.expected.73.orig
-test/range/test.expected.74.orig
View
@@ -7,11 +7,11 @@ procedures
* Prerequisite
- ruby >= 1.4.4
- source of postgresql (for some include files).
+ ruby >= 1.6
+ postgresql >= 7.3
- For PostgreSQL 7.2 the source is not required if all headers was installed.
- Command (see INSTALL in the directory postgresql-7.2)
+ All PostgreSQL headers need to be installed. Command (see INSTALL in the
+ directory postgresql-7.x.y)
make install-all-headers
@@ -29,19 +29,14 @@ procedures
--with-pgsql-lib=<library dir for PostgreSQL>
- --with-pgsql-srcinc=<include file *from* the source of PostgreSQL>
- pgsql-srcinc must contains, for example, the file catalog/pg_proc.h
- (not needed if `make install-all-headers' was executed)
-
- --with-pgsql-version=<release number for PostgreSQL, actually 65, 70, 71
- or 72 i.e. major and minor number>
+ --with-pgsql-version=<release number for PostgreSQL, actually 73,
+ or 74 i.e. major and minor number>
--disable-conversion
by default plruby try to convert a postgres type to a ruby class
- (for PostgreSQL >= 72). This option give the possibility to disable
- all conversions
+ This option give the possibility to disable all conversions
- --with_suffix=<suffix to add>
+ --with-suffix=<suffix to add>
For example
@@ -53,13 +48,12 @@ procedures
Example :
ruby extconf.rb --with-pgsql-include=/usr/include/postgresql \
- --with-pgsql-lib=/usr/lib \
- --with-pgsql-srcinc=/var/postgres/postgresl-6.5/src/include
+ --with-pgsql-lib=/usr/lib
* Test (and examples)
- WARNING : if plruby was compiled with --enable-conversion
+ WARNING : if plruby was compiled without --disable-conversion
you must *FIRST* run `make install' before `make test'
make test
@@ -82,23 +76,16 @@ procedures
The commands to create the new language are:
- create function plruby_call_handler () returns opaque
- as 'path-to-plruby-shared-lib'
- language 'C';
-
- create trusted procedural language 'plruby'
- handler plruby_call_handler
- lancompiler 'PL/Ruby';
-
+ create function plruby_call_handler () returns language_handler
+ as 'path-to-plruby-shared-lib'
+ language 'C';
- *** WARNING for PostgreSQL > 7.0.2 ***
- for the new interface to fmgr, the language must be specified
- as 'newC' rather than 'C'
+ create trusted language 'plruby'
+ handler plruby_call_handler
+ lancompiler 'PL/Ruby';
- *** WARNING for PostgreSQL >= 7.1.rc4 ***
- the language must be specified as 'C' rather than 'newC'
- The trusted keyword on create procedural language tells PostgreSQL,
+ The 'trusted' keyword on 'create language' tells PostgreSQL,
that all users (not only those with superuser privilege) are
permitted to create functions with LANGUAGE 'plruby'. This is
absolutely safe, because there is nothing a normal user can do
View
@@ -55,6 +55,8 @@
#
# * PLRuby::PL::Cursor
#
+# * PLRuby::PL::Transaction
+#
# * PLRuby::BitString
#
# * PLRuby::Tinterval
@@ -81,6 +83,14 @@
#
#
module PLRuby
+ #
+ # Create a new transaction and yield an object <em>PL::Transaction</em>
+ #
+ # Only available with PostgreSQL >= 8.0
+ def transaction()
+ yield txn
+ end
+
# Ruby interface to PostgreSQL elog()
#
# Possible value for <tt>level</tt> are <tt>NOTICE</tt>,
@@ -129,12 +139,12 @@ module PLRuby::Description
#
# ' LANGUAGE 'plruby';
#
-# when calling the function in a query, the arguments are given <b>as
-# string values</b> in the array <em>args</em>. To create a little max
+# when calling the function in a query, the arguments are given
+# in the array <em>args</em>. To create a little max
# function returning the higher of two int4 values write :
#
# CREATE FUNCTION ruby_max(int4, int4) RETURNS int4 AS '
-# if args[0].to_i > args[1].to_i
+# if args[0] > args[1]
# return args[0]
# else
# return args[1]
@@ -147,10 +157,11 @@ module PLRuby::Description
# in PLRuby.
#
# CREATE FUNCTION overpaid_2 (EMP) RETURNS bool AS '
-# args[0]["salary"].to_f > 200000 ||
-# (args[0]["salary"].to_f > 100000 && args[0]["age"].to_i < 30)
+# args[0]["salary"] > 200000 ||
+# (args[0]["salary"] > 100000 && args[0]["age"] < 30)
# ' LANGUAGE 'plruby';
#
+#
# === Warning : with PostgreSQL >= 7.4 "array" are given as a ruby Array
#
# For example to define a function (int4[], int4) and return int4[],
@@ -159,8 +170,8 @@ module PLRuby::Description
# CREATE FUNCTION ruby_int4_accum(_int4, int4) RETURNS _int4 AS '
# if /\\{(\\d+),(\\d+)\\}/ =~ args[0]
# a, b = $1, $2
-# newsum = a.to_i + args[1].to_i
-# newcnt = b.to_i + 1
+# newsum = a + args[1]
+# newcnt = b + 1
# else
# raise "unexpected value #{args[0]}"
# end
@@ -171,9 +182,73 @@ module PLRuby::Description
#
# CREATE FUNCTION ruby_int4_accum(_int4, int4) RETURNS _int4 AS '
# a = args[0]
-# [a[0].to_i + args[1].to_i, a[1].to_i + 1]
+# [a[0] + args[1], a[1] + 1]
# ' LANGUAGE 'plruby';
#
+# === Release PostgreSQL 8.0
+#
+# With this version, plruby can have named arguments and the previous functions
+# can be written
+#
+# CREATE FUNCTION ruby_max(a int4, b int4) RETURNS int4 AS '
+# if a > b
+# a
+# else
+# b
+# end
+# ' LANGUAGE 'plruby';
+#
+#
+# CREATE FUNCTION overpaid_2 (emp EMP) RETURNS bool AS '
+# emp["salary"] > 200000 ||
+# (emp["salary"] > 100000 && emp["age"] < 30)
+# ' LANGUAGE 'plruby';
+#
+# With this version, you can also use transaction. For example
+#
+# plruby_test=# create table tu (a int, b int);
+# CREATE TABLE
+# plruby_test=# create or replace function tt(abort bool) returns bool as '
+# plruby_test'# transaction do |txn|
+# plruby_test'# PL.exec("insert into tu values (1, 2)")
+# plruby_test'# transaction do |txn1|
+# plruby_test'# PL.exec("insert into tu values (3, 4)")
+# plruby_test'# txn1.abort
+# plruby_test'# end
+# plruby_test'# PL.exec("insert into tu values (5, 6)")
+# plruby_test'# txn.abort if abort
+# plruby_test'# end
+# plruby_test'# abort
+# plruby_test'# ' language 'plruby';
+# CREATE FUNCTION
+# plruby_test=#
+# plruby_test=# select tt(true);
+# tt
+# ----
+# t
+# (1 row)
+#
+# plruby_test=# select * from tu;
+# a | b
+# ---+---
+# (0 rows)
+#
+# plruby_test=# select tt(false);
+# tt
+# ----
+# f
+# (1 row)
+#
+# plruby_test=# select * from tu;
+# a | b
+# ---+---
+# 1 | 2
+# 5 | 6
+# (2 rows)
+#
+# plruby_test=#
+#
+#
module PLRuby::Description::Function
end
#
@@ -242,7 +317,7 @@ class PLRuby::Description::Function::SFRM
#
# plruby_test=# create or replace function vv(int) returns setof int as '
# plruby_test'# i = PL.context || 0
-# plruby_test'# if i >= args[0].to_i
+# plruby_test'# if i >= args[0]
# plruby_test'# nil
# plruby_test'# else
# plruby_test'# PL.context = i + 1
@@ -343,7 +418,7 @@ class PLRuby::Description::Function::ExprMultiResult
# when PL::INSERT
# new[args[0]] = 0
# when PL::UPDATE
-# new[args[0]] = old[args[0]].to_i + 1
+# new[args[0]] = old[args[0]] + 1
# else
# return PL::OK
# end
@@ -549,15 +624,6 @@ class PLRuby::Description::Singleton_method
#
class PLRuby::Description::Conversion
end
-#
-#Ruby interface to PostgreSQL elog()
-#
-#Possible value for <em>level</em> are <em>NOTICE</em>, <em>DEBUG</em> and <em>NOIND</em>
-#
-#Use <em>raise()</em> if you want to simulate <em>elog(ERROR, "...")</em>
-#
- def warn [level], message
- end
#
# general module
#
@@ -932,6 +998,21 @@ def reverse_each
end
#
+# A transaction is created with the global function #transaction
+#
+# Only available with PostgreSQL >= 8.0
+#
+class PLRuby::PL::Transaction
+
+ # abort the transaction
+ def abort
+ end
+
+ # commit the transaction
+ def commit
+ end
+end
+#
# The class PLRuby::BitString implement the PostgreSQL type <em>bit</em>
# and <em>bit varying</em>
#
View
@@ -0,0 +1,33 @@
+create table tu (a int, b int);
+
+create or replace function uu(abort bool) returns bool as '
+ transaction do |txn|
+ PL.exec("insert into tu values (1, 2)")
+ transaction do |txn1|
+ PL.exec("insert into tu values (3, 4)")
+ txn1.abort
+ end
+ PL.exec("insert into tu values (5, 6)")
+ txn.abort if abort
+ end
+ abort
+' language 'plruby';
+
+
+create or replace function uu() returns bool as '
+ transaction do |txn1|
+ PL.exec("insert into tu values (3, 4)")
+ txn1.abort
+ end
+ true
+' language 'plruby';
+
+create or replace function tt(abort bool) returns bool as '
+ transaction do |txn|
+ PL.exec("insert into tu values (1, 2)")
+ PL.exec("select uu()")
+ PL.exec("insert into tu values (5, 6)")
+ txn.abort if abort
+ end
+ abort
+' language 'plruby';
Oops, something went wrong.

0 comments on commit c5b2948

Please sign in to comment.