wiki:SQL

Version 3 (modified by vadim.godunko, 10 years ago) ( diff )

--

This module will be available in Matreshka 0.0.7

SQL Database Access

SQL Database Access module provides simple generic API to access to SQL databases. Currently supported databases:

Example

This example creates database, creates table in the database, fills it and retrieve values from it.

with Ada.Wide_Wide_Text_IO;

with League.Strings;
with League.Values.Strings;
with SQL.Databases;
with SQL.Queries;

procedure Example is

   function "+"
    (Item : Wide_Wide_String) return League.Strings.Universal_String
       renames League.Strings.To_Universal_String;

   D : SQL.Databases.SQL_Database;

begin
   D.Open;

   --  Create table

   declare
      Q : SQL.Queries.SQL_Query := SQL.Queries.Create (D);

   begin
      Q.Prepare
       (+"CREATE TABLE point (x CHARACTER VARYING, y CHARACTER VARYING)");
      Q.Execute;
   end;

   --  Fill data

   declare
      Q : SQL.Queries.SQL_Query := SQL.Queries.Create (D);

   begin
      Q.Prepare (+"INSERT INTO point (x, y) VALUES ('a', 'b')");
      Q.Execute;
   end;

   --  Retrieve data from table

   declare
      Q : aliased SQL.Queries.SQL_Query := SQL.Queries.Create (D);

   begin
      Q.Prepare (+"SELECT x, y FROM point");
      Q.Execute;

      while Q.Next loop
         Ada.Wide_Wide_Text_IO.Put_Line
          (League.Values.Strings.To_Universal_String
            (Q.Value (1)).To_Wide_Wide_String
             & ":"
             & League.Values.Strings.To_Universal_String
                (Q.Value (2)).To_Wide_Wide_String);
      end loop;
   end;
end Example;
Note: See TracWiki for help on using the wiki.