------------------------------------------------------------------------------
--                                                                          --
--                An Ada2005 binding to the Qt C++ framework                --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2009-2010 Vadim Godunko <vgodunko@gmail.com>                 --
--                                                                          --
-- QtAda is free software;  you can  redistribute it and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
-- sion. QtAda is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
-- for  more details.  You should have  received  a copy of the GNU General --
-- Public License distributed with QtAda;  see file COPYING.  If not, write --
-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
-- Boston, MA 02110-1301, USA.                                              --
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  does not  by itself cause  the resulting  executable  to  be --
-- covered  by the  GNU  General  Public  License.  This exception does not --
-- however invalidate  any other reasons why  the executable file  might be --
-- covered by the  GNU Public License.                                      --
--                                                                          --
------------------------------------------------------------------------------
--    This file has been generated automatically. Please don't edit it.     --
------------------------------------------------------------------------------
with System.Address_To_Access_Conversions;

package body Qt4.Sql_Errors is

   function initialize_QSqlError
    (Storage : System.Address)
      return Internals.QSqlError_Access;
   pragma Import (C, initialize_QSqlError, "__QtAda_inititialize_QSqlError");

   function initialize_QSqlError_QStringCR_QStringCR_ErrorType_int
    (Storage : System.Address;
     Driver_Text : Qt4.Strings.Internals.QString_Access;
     Database_Text : Qt4.Strings.Internals.QString_Access;
     The_Type : Sql_Error_Type;
     Number : Qt4.Q_Integer)
      return Internals.QSqlError_Access;
   pragma Import (C, initialize_QSqlError_QStringCR_QStringCR_ErrorType_int, "__QtAda_inititialize_QSqlError_QStringCR_QStringCR_ErrorType_int");

   function adjust_QSqlError
    (Storage : System.Address;
     From    : Internals.QSqlError_Access)
       return Internals.QSqlError_Access;
   pragma Import (C, adjust_QSqlError, "__QtAda_adjust_QSqlError");

   procedure finalize_QSqlError (Object : Internals.QSqlError_Access);
   pragma Import (C, finalize_QSqlError, "__QtAda_finalize_QSqlError");

   procedure QSqlError_databaseText
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Internals.QSqlError_Access);
   pragma Import (C, QSqlError_databaseText, "__QtAda_QSqlError_databaseText_Q");

   procedure QSqlError_driverText
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Internals.QSqlError_Access);
   pragma Import (C, QSqlError_driverText, "__QtAda_QSqlError_driverText_Q");

   function QSqlError_isValid
    (Self : Internals.QSqlError_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlError_isValid, "__QtAda_QSqlError_isValid_Q");

   function QSqlError_number
    (Self : Internals.QSqlError_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QSqlError_number, "__QtAda_QSqlError_number_Q");

   procedure QSqlError_setDatabaseText_QStringCR
    (Self : Internals.QSqlError_Access;
     Database_Text : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlError_setDatabaseText_QStringCR, "__QtAda_QSqlError_setDatabaseText_QStringCR");

   procedure QSqlError_setDriverText_QStringCR
    (Self : Internals.QSqlError_Access;
     Driver_Text : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlError_setDriverText_QStringCR, "__QtAda_QSqlError_setDriverText_QStringCR");

   procedure QSqlError_setNumber_int
    (Self : Internals.QSqlError_Access;
     Number : Qt4.Q_Integer);
   pragma Import (C, QSqlError_setNumber_int, "__QtAda_QSqlError_setNumber_int");

   procedure QSqlError_setType_ErrorType
    (Self : Internals.QSqlError_Access;
     The_Type : Sql_Error_Type);
   pragma Import (C, QSqlError_setType_ErrorType, "__QtAda_QSqlError_setType_ErrorType");

   procedure QSqlError_text
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Internals.QSqlError_Access);
   pragma Import (C, QSqlError_text, "__QtAda_QSqlError_text_Q");

   function QSqlError_type
    (Self : Internals.QSqlError_Access)
       return Sql_Error_Type;
   pragma Import (C, QSqlError_type, "__QtAda_QSqlError_type_Q");

   ------------
   -- Adjust --
   ------------

   overriding
   procedure Adjust (Self : in out Q_Sql_Error) is
   begin
      Self.Object := adjust_QSqlError (Self.Storage'Address, Self.Object);
      Self.Wrapper := False;
   end Adjust;

   --------------
   -- Finalize --
   --------------

   overriding
   procedure Finalize (Self : in out Q_Sql_Error) is
   begin
      if not Self.Wrapper then
         finalize_QSqlError (Self.Object);
      end if;
   end Finalize;

   ----------------
   -- Initialize --
   ----------------

   overriding
   procedure Initialize (Self : in out Q_Sql_Error) is
      use type Internals.QSqlError_Access;

   begin
      if Self.Object = null then
         Self.Object := initialize_QSqlError (Self.Storage'Address);
      end if;
   end Initialize;

   ------------
   -- Create --
   ------------

   function Create
    (Driver_Text : Qt4.Strings.Q_String'Class
       := Qt4.Strings.Create;
     Database_Text : Qt4.Strings.Q_String'Class
       := Qt4.Strings.Create;
     The_Type : Sql_Error_Type
       := No_Error;
     Number : Qt4.Q_Integer
       := -1)
       return Q_Sql_Error
   is
   begin
      return Self : Q_Sql_Error
        := (Ada.Finalization.Controlled with others => <>)
      do
         Self.Object := initialize_QSqlError_QStringCR_QStringCR_ErrorType_int (Self.Storage'Address, Qt4.Strings.Internals.QString_View (Driver_Text), Qt4.Strings.Internals.QString_View (Database_Text), The_Type, Number);
      end return;
   end Create;

   -------------------
   -- Database_Text --
   -------------------

   function Database_Text
    (Self : Q_Sql_Error'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QSqlError_databaseText (Qt4.Strings.Internals.QString_View (Returns), Self.Object);
      end return;
   end Database_Text;

   -----------------
   -- Driver_Text --
   -----------------

   function Driver_Text
    (Self : Q_Sql_Error'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QSqlError_driverText (Qt4.Strings.Internals.QString_View (Returns), Self.Object);
      end return;
   end Driver_Text;

   --------------
   -- Is_Valid --
   --------------

   function Is_Valid
    (Self : Q_Sql_Error'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlError_isValid (Self.Object), 0);
   end Is_Valid;

   ------------
   -- Number --
   ------------

   function Number
    (Self : Q_Sql_Error'Class)
       return Qt4.Q_Integer
   is
   begin
      return QSqlError_number (Self.Object);
   end Number;

   -----------------------
   -- Set_Database_Text --
   -----------------------

   procedure Set_Database_Text
    (Self : in out Q_Sql_Error'Class;
     Database_Text : Qt4.Strings.Q_String'Class)
   is
   begin
      QSqlError_setDatabaseText_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (Database_Text));
   end Set_Database_Text;

   ---------------------
   -- Set_Driver_Text --
   ---------------------

   procedure Set_Driver_Text
    (Self : in out Q_Sql_Error'Class;
     Driver_Text : Qt4.Strings.Q_String'Class)
   is
   begin
      QSqlError_setDriverText_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (Driver_Text));
   end Set_Driver_Text;

   ----------------
   -- Set_Number --
   ----------------

   procedure Set_Number
    (Self : in out Q_Sql_Error'Class;
     Number : Qt4.Q_Integer)
   is
   begin
      QSqlError_setNumber_int (Self.Object, Number);
   end Set_Number;

   --------------
   -- Set_Type --
   --------------

   procedure Set_Type
    (Self : in out Q_Sql_Error'Class;
     The_Type : Sql_Error_Type)
   is
   begin
      QSqlError_setType_ErrorType (Self.Object, The_Type);
   end Set_Type;

   ----------
   -- Text --
   ----------

   function Text
    (Self : Q_Sql_Error'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QSqlError_text (Qt4.Strings.Internals.QString_View (Returns), Self.Object);
      end return;
   end Text;

   ----------------
   -- Error_Type --
   ----------------

   function Error_Type
    (Self : Q_Sql_Error'Class)
       return Sql_Error_Type
   is
   begin
      return QSqlError_type (Self.Object);
   end Error_Type;

   ---------------
   -- Internals --
   ---------------

   package body Internals is

   --------------------
   -- QSqlError_View --
   --------------------

      function QSqlError_View
       (Item : Q_Sql_Error'Class)
          return QSqlError_Access
      is
      begin
         return Item.Object;
      end QSqlError_View;

      package QSqlError_Conversions is
        new System.Address_To_Access_Conversions
             (QSqlError);

   -------------------------
   -- QSqlErrorTo_Pointer --
   -------------------------

      function To_Pointer
       (Address : System.Address)
          return QSqlError_Access
      is
      begin
         return
           QSqlError_Access
            (QSqlError_Conversions.To_Pointer
            (Address));
      end To_Pointer;

   -------------------------
   -- QSqlErrorTo_Address --
   -------------------------

      function To_Address
       (Pointer : QSqlError_Access)
          return System.Address
      is
      begin
         return
           QSqlError_Conversions.To_Address
            (QSqlError_Conversions.Object_Pointer
              (Pointer));
      end To_Address;

   --------------------
   -- Create_Wrapper --
   --------------------

      function Create_Wrapper
       (Item : Internals.QSqlError_Access)
          return Q_Sql_Error
      is
      begin
         return Q_Sql_Error'
          (Ada.Finalization.Controlled with
             Object  => Item,
             Wrapper => True,
             others  => <>);
      end Create_Wrapper;

   end Internals;

end Qt4.Sql_Errors;
