From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e8edf581e3a868a1 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Nick Roberts Newsgroups: comp.lang.ada Subject: Re: [ANN] Data Source Name parser (ODBC etc.) Date: Sat, 15 Jan 2005 18:42:06 +0000 Message-ID: References: <41E7682D.8040306@futureapps.de> Content-Type: text/plain; charset=us-ascii X-Trace: individual.net jfFBhURBXTu68Rn9CwbWIAHf4KoJTM/jmAyc7+l0QcGuhGhpQ= X-Orig-Path: not-for-mail User-Agent: Gemini/1.45d (Qt/3.3.2) (Windows-XP) Xref: g2news1.google.com comp.lang.ada:7825 Date: 2005-01-15T18:42:06+00:00 List-Id: Georg Bauhaus wrote: > some time ago when discussion APQ or Ada and databases, Brian May > suggested URL-like strings describing database connections. A parser > library for such strings (data source names) is now available at > http://home.arcor.de/bauhaus/Ada/dsn.html > ... > I have tried to make the interface simple, any comments as to whether it > is usable or whether it should go down the drain will affect following > versions. I like the idea. I think the syntax you propose is great (it needs to be completed). I'd like the query syntax to be defined and parsed, using the familiar field=value form and & for conjunction. I like the good error diagnostics, but I feel the Messages interface is too elaborate. Surely an enumerated type is not required, but just a message string? And surely instantiating a generic is too elaborate, as well? Surely only one derivation needs to be returned (if there is a legal derivation)? I think you only need a simple function, e.g.: package Database_IO.DSN is type Data_Source_Descriptor is private; function Parse (Name: in String) return Data_Source_Descriptor; function Server_Name (Descriptor: in Data_Source_Descriptor) return String; function User_Name (Descriptor: in Data_Source_Descriptor) return String; function User_Password (Descriptor: in Data_Source_Descriptor) return String; ... Syntax_Error: exception; type Parsing_Diagnosis (Max: Positive) is private; function Diagnose (Name: in String) return Parsing_Diagnosis; function Error_Count (Diagnosis: in Parsing_Diagnosis) return Natural; function Error_Message (Diagnosis: in Parsing_Diagnosis; Number: in Positive) return String; ... Use_Error: exception renames IO_Exceptions.Use_Error; private ... end; The function Parse either successfully parses the given DSN (in Name) and returns a broken down composite value (type Data_Source_Descriptor), or it raises the exception Syntax_Error. The function Diagnose parses the given DSN (in Name) and returns any errors in a composite value (type Parsing_Diagnosis). Functions allow the interrogation of the composite values. The discriminant Max sets a maximum on the number of different errors to be stored in diagnosis. The idea is that typical user code will have a nice, easy declaration like this: Source: constant Data_Source_Descriptor := Parse(...); followed by interrogation of Source to open up the appropriate database, log on, open a schema, table, etc. For quick and dirty applications, this enough. If the parsing fails, an exception is raised. For proper applications, the exception can be caught and handled, something like this: exception when Syntax_Error => declare Errors: constant Parsing_Diagnosis(20) := Diagnose(...); begin for i in Error_Count(Errors) loop Put_Line( Standard_Error, Error_Message(Errors,i) ); end loop; end; ... The exception Use_Error is raised if anything else goes wrong. I'm interested in participating in the development of some kind of open Database I/O interface package. -- Nick Roberts