comp.lang.ada
 help / color / mirror / Atom feed
From: "Björn Persson" <spam-away@nowhere.nil>
Subject: Re: ada and pl/sql
Date: Mon, 27 Mar 2006 21:07:22 GMT
Date: 2006-03-27T21:07:22+00:00	[thread overview]
Message-ID: <euYVf.50035$d5.206366@newsb.telia.net> (raw)
In-Reply-To: <122gh5o729tsfcf@corp.supernews.com>

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



  parent reply	other threads:[~2006-03-27 21:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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
replies disabled

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