comp.lang.ada
 help / color / mirror / Atom feed
* ada and pl/sql
@ 2006-03-27 20:05 Jason King
  2006-03-27 20:28 ` Georg Bauhaus
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Jason King @ 2006-03-27 20:05 UTC (permalink / raw)


I'm a long-term pl/sql developer who would like to have a general 
purpose programming language that works a lot like what I'm used to. 
Hence I've been looking at Ada.
There are (from the pl/sql perspective) three significant differences:
1)  Transparent shifting from pl/sql to sql
     FOR x IN (SELECT user_name FROM all_users ) LOOP
         -- do something
     END LOOP ; -- creates a cursor and x.user_name is valid inside the 

                --loop
2)  pl/sql is very forgiving about doing "automatic" conversions
     x number := "1" + 2; -- assigns 3 to x it doesn't raise an error.
3)  The most commonly used string type is varchar2 with usage examples 
   below:
    v varchar2(50);  -- declare a varchar2, max length 50
    v varchar2(50) := 'short string';  -- assign a value, literal <50
                                       -- does not raise an error.
    v varchar2(10) := '12345678901' ;  -- raises value_error
                                       -- literal > max
declare
    v1 varchar2(10) := 'Hello';
    v2 varchar2(10) := 'World';
    v3 varchar2(30);
begin
    v3 := v1 || ' ' || v2 ; -- || is string concat operator.
                            -- no error here since 'Hello World'
                            -- fits.
    dbms_output.put_line(v3) ; -- prints "Hello World"

Issue 1 is true for all languages so I can just deal with it.
Issue 2 I often code around on the pl/sql as its automatic conversions 
aren't always what I want.
Issue 3 is a killer.
Ada string doesn't work because it raises errors for assignments of 
shorter as well as longer strings.  ada.strings.bounded and 
ada.strings.unbounded are issues because assignment (:=) doesn't work 
for them and concatenation is method not an operator.  As far as I can 
tell I can't overload the assignment operator or the || operator.
Other than creating a new language is there some way to make a 
varchar2-like first-class datatype that has its own operators?





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ada and pl/sql
  2006-03-27 20:05 ada and pl/sql Jason King
@ 2006-03-27 20:28 ` Georg Bauhaus
  2006-03-27 21:07 ` Björn Persson
  2006-03-29 18:04 ` Kenneth Almquist
  2 siblings, 0 replies; 9+ messages in thread
From: Georg Bauhaus @ 2006-03-27 20:28 UTC (permalink / raw)


Jason King wrote:

> Ada string doesn't work because it raises errors for assignments of
> shorter as well as longer strings.  ada.strings.bounded and
> ada.strings.unbounded are issues because assignment (:=) doesn't work
> for them and concatenation is method not an operator.  As far as I can
> tell I can't overload the assignment operator or the || operator.
> Other than creating a new language is there some way to make a
> varchar2-like first-class datatype that has its own operators?
 
There seems to have been some misinformation somewhere, try
this:

with Ada.Strings.Unbounded;
with Ada.Text_IO;

procedure v is

   use Ada.Strings.Unbounded, Ada;

   x: Unbounded_String := Null_Unbounded_String;

begin
   x := x & "Hello";
   x := x & "World";
   Text_IO.put_line(to_string(x));
end v;





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ada and pl/sql
  2006-03-27 20:05 ada and pl/sql Jason King
  2006-03-27 20:28 ` Georg Bauhaus
@ 2006-03-27 21:07 ` Björn Persson
  2006-03-27 21:15   ` Martin Dowie
  2006-03-29 18:04 ` Kenneth Almquist
  2 siblings, 1 reply; 9+ messages in thread
From: Björn Persson @ 2006-03-27 21:07 UTC (permalink / raw)


Jason King wrote:
> declare
>    v1 varchar2(10) := 'Hello';
>    v2 varchar2(10) := 'World';
>    v3 varchar2(30);
> begin
>    v3 := v1 || ' ' || v2 ; -- || is string concat operator.
>                            -- no error here since 'Hello World'
>                            -- fits.
>    dbms_output.put_line(v3) ; -- prints "Hello World"
[...]
> ada.strings.bounded and 
> ada.strings.unbounded are issues because assignment (:=) doesn't work 
> for them and concatenation is method not an operator.

Assignment and concatenation work just fine. Here's your example in Ada:

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_IO;

procedure Unbounded_Demo is
    String_1 : Unbounded_String := To_Unbounded_String("Hello");
    String_2 : Unbounded_String := To_Unbounded_String("World");
    String_3 : Unbounded_String;
begin
    String_3 := String_1 & ' ' & String_2;
    Ada.Text_IO.Unbounded_IO.Put_Line(String_3);
end Unbounded_Demo;

(Ada.Text_IO.Unbounded_IO is new in Ada 2005, so it's only present in 
the newest libraries.)

> As far as I can 
> tell I can't overload the assignment operator or the || operator.

That's right. Instead of overloadable assignment, Ada has controlled 
types. "||" isn't an operator in Ada; the string concatenation operator 
is "&", and that one is overloadable.

> Other than creating a new language is there some way to make a 
> varchar2-like first-class datatype that has its own operators?

It's perfectly possible to create such a type in pure Ada, but you don't 
need to, because it's already there in the standard library. Bounded or 
unbounded strings are what you want.

I have actually written a string handling package of my own. I got sick 
of the endless character encoding bugs, so I created an unbounded string 
type where each string object keeps track of its own encoding. I call it 
EAstrings � encoding-aware strings.

-- 
Bj�rn Persson                              PGP key A88682FD
                    omb jor ers @sv ge.
                    r o.b n.p son eri nu



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ada and pl/sql
  2006-03-27 21:07 ` Björn Persson
@ 2006-03-27 21:15   ` Martin Dowie
  2006-03-27 23:28     ` Jason King
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Dowie @ 2006-03-27 21:15 UTC (permalink / raw)


Bj�rn Persson wrote:
> (Ada.Text_IO.Unbounded_IO is new in Ada 2005, so it's only present in 
> the newest libraries.)

<shameless_plug>
Or you can pick up the source and compile your own from 
http://www.martin.dowie.btinternet.co.uk/
</shameless_plug>

:-)

Cheers
-- Martin



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ada and pl/sql
  2006-03-27 21:15   ` Martin Dowie
@ 2006-03-27 23:28     ` Jason King
  2006-03-28  2:53       ` Jeffrey Creem
  2006-03-29 19:47       ` Martin Krischik
  0 siblings, 2 replies; 9+ messages in thread
From: Jason King @ 2006-03-27 23:28 UTC (permalink / raw)


Now don't laugh folks, but most of my work is done on Windows.  Is the 
gcc Ada usable and does it include Ada 2005?  I'd prefer something 
gnat-like as a cursory examination of add-on packages leads me to 
believe gnat has more contributions and extensions than all the other 
implementations combined.  If I understand correctly the current free 
GNAT builds are GPL'ed not LGPL'ed which would put a crimp in some of 
the things I want to develop.
Martin Dowie wrote:
> Bj�rn Persson wrote:
> 
>> (Ada.Text_IO.Unbounded_IO is new in Ada 2005, so it's only present in 
>> the newest libraries.)
> 
> 
> <shameless_plug>
> Or you can pick up the source and compile your own from 
> http://www.martin.dowie.btinternet.co.uk/
> </shameless_plug>
> 
> :-)
> 
> Cheers
> -- Martin



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ada and pl/sql
  2006-03-27 23:28     ` Jason King
@ 2006-03-28  2:53       ` Jeffrey Creem
  2006-03-29 19:51         ` Martin Krischik
  2006-03-29 19:47       ` Martin Krischik
  1 sibling, 1 reply; 9+ messages in thread
From: Jeffrey Creem @ 2006-03-28  2:53 UTC (permalink / raw)


Jason King wrote:
> Now don't laugh folks, but most of my work is done on Windows.  Is the 
> gcc Ada usable and does it include Ada 2005?  I'd prefer something 
> gnat-like as a cursory examination of add-on packages leads me to 
> believe gnat has more contributions and extensions than all the other 
> implementations combined.  If I understand correctly the current free 
> GNAT builds are GPL'ed not LGPL'ed which would put a crimp in some of 
> the things I want to develop.


More specifically, the GNAT GPL Edition has GPL runtime libraries 
instead of GPL + linking/generics exception (making it sort of act like 
what everyone assumes the LGPL says but which it does not). If you plan 
on distributing executables built with the GNAT GPL edition, you would 
need to do so under the terms of the GPL.

In any case, GCC is "gnat like" since it is the same compiler. What you 
loose is that a "GNAT" release from AdaCore gets more testing and is 
released when it is ready for Ada (v.s. GCC releases in which Ada status 
is not currently allowed to be a major driver in terms of the release).

The biggest problem right now is that we don't have a really good (or 
even bad) release installer for GNAT/GCC 4.1.0 under windows.

Normally, I'd just point you to www.mingw.org but they are a bit behind 
when it comes to the newer GCC releases and don't have an Ada focus 
(they never release GDB versions that are fully up to speed on Ada -- 
thought that has gotten better as the standard GDB has gotten better but 
there is still a ways to go).




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ada and pl/sql
  2006-03-27 20:05 ada and pl/sql Jason King
  2006-03-27 20:28 ` Georg Bauhaus
  2006-03-27 21:07 ` Björn Persson
@ 2006-03-29 18:04 ` Kenneth Almquist
  2 siblings, 0 replies; 9+ messages in thread
From: Kenneth Almquist @ 2006-03-29 18:04 UTC (permalink / raw)


Jason King wrote:
> declare
>    v1 varchar2(10) := 'Hello';
>    v2 varchar2(10) := 'World';
>    v3 varchar2(30);
> begin
>    v3 := v1 || ' ' || v2 ; -- || is string concat operator.
>                            -- no error here since 'Hello World'
>                            -- fits.
>    dbms_output.put_line(v3) ; -- prints "Hello World"

As others have said, Ada's unbounded_string type is probably what
you are looking for.  For this particular example, the Ada string
type will also work:

  declare
     v1 : constant string := "Hello";
     v2 : constant string := "World";
     v3 : constant string := v1 & ' ' & v2;   -- & is string concat operator.
  begin
     ada.text_io.put_line(v3);     -- prints "Hello World"
  end;




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ada and pl/sql
  2006-03-27 23:28     ` Jason King
  2006-03-28  2:53       ` Jeffrey Creem
@ 2006-03-29 19:47       ` Martin Krischik
  1 sibling, 0 replies; 9+ messages in thread
From: Martin Krischik @ 2006-03-29 19:47 UTC (permalink / raw)


Jason King wrote:

> Now don't laugh folks, but most of my work is done on Windows. Is the 
> gcc Ada usable and does it include Ada 2005? ï¿œI'd prefer something
> gnat-like as a cursory examination of add-on packages leads me to
> believe gnat has more contributions and extensions than all the other
> implementations combined. ï¿œIf I understand correctly the current free
> GNAT builds are GPL'ed not LGPL'ed which would put a crimp in some of
> the things I want to develop.

Not the 4.1.0 builds you get at gnuada.sf.net. Only the Windows compiles are
not ready yet - but we are working on it.

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: ada and pl/sql
  2006-03-28  2:53       ` Jeffrey Creem
@ 2006-03-29 19:51         ` Martin Krischik
  0 siblings, 0 replies; 9+ messages in thread
From: Martin Krischik @ 2006-03-29 19:51 UTC (permalink / raw)


Jeffrey Creem wrote:

> The biggest problem right now is that we don't have a really good (or
> even bad) release installer for GNAT/GCC 4.1.0 under windows.

I have found out that cygwin has rpm support. It's still in the making but
perhaps we are going to have a rpm build for cygwin soon. 

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2006-03-29 19:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-27 20:05 ada and pl/sql Jason King
2006-03-27 20:28 ` Georg Bauhaus
2006-03-27 21:07 ` Björn Persson
2006-03-27 21:15   ` Martin Dowie
2006-03-27 23:28     ` Jason King
2006-03-28  2:53       ` Jeffrey Creem
2006-03-29 19:51         ` Martin Krischik
2006-03-29 19:47       ` Martin Krischik
2006-03-29 18:04 ` Kenneth Almquist

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox