------------------------------------------------------------------------------
--                                                                          --
--                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 Qt4.Sql_Queries;
with Qt_Ada.Internals.Boolean_Conversions;
with System.Address_To_Access_Conversions;

package body Qt4.Sql_Databases is

   function initialize_QSqlDatabase
    (Storage : System.Address)
      return Internals.QSqlDatabase_Access;
   pragma Import (C, initialize_QSqlDatabase, "__QtAda_inititialize_QSqlDatabase");

   function adjust_QSqlDatabase
    (Storage : System.Address;
     From    : Internals.QSqlDatabase_Access)
       return Internals.QSqlDatabase_Access;
   pragma Import (C, adjust_QSqlDatabase, "__QtAda_adjust_QSqlDatabase");

   procedure finalize_QSqlDatabase (Object : Internals.QSqlDatabase_Access);
   pragma Import (C, finalize_QSqlDatabase, "__QtAda_finalize_QSqlDatabase");

   procedure QSqlDatabase_close
    (Self : Internals.QSqlDatabase_Access);
   pragma Import (C, QSqlDatabase_close, "__QtAda_QSqlDatabase_close");

   function QSqlDatabase_commit
    (Self : Internals.QSqlDatabase_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlDatabase_commit, "__QtAda_QSqlDatabase_commit");

   procedure QSqlDatabase_connectOptions
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Internals.QSqlDatabase_Access);
   pragma Import (C, QSqlDatabase_connectOptions, "__QtAda_QSqlDatabase_connectOptions_Q");

   procedure QSqlDatabase_connectionName
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Internals.QSqlDatabase_Access);
   pragma Import (C, QSqlDatabase_connectionName, "__QtAda_QSqlDatabase_connectionName_Q");

   procedure QSqlDatabase_databaseName
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Internals.QSqlDatabase_Access);
   pragma Import (C, QSqlDatabase_databaseName, "__QtAda_QSqlDatabase_databaseName_Q");

   procedure QSqlDatabase_driverName
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Internals.QSqlDatabase_Access);
   pragma Import (C, QSqlDatabase_driverName, "__QtAda_QSqlDatabase_driverName_Q");

   procedure QSqlDatabase_exec_QStringCR
    (Returns : Qt4.Sql_Queries.Internals.QSqlQuery_Access;
     Self : Internals.QSqlDatabase_Access;
     Query : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlDatabase_exec_QStringCR, "__QtAda_QSqlDatabase_exec_QStringCR_Q");

   procedure QSqlDatabase_hostName
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Internals.QSqlDatabase_Access);
   pragma Import (C, QSqlDatabase_hostName, "__QtAda_QSqlDatabase_hostName_Q");

   function QSqlDatabase_isOpen
    (Self : Internals.QSqlDatabase_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlDatabase_isOpen, "__QtAda_QSqlDatabase_isOpen_Q");

   function QSqlDatabase_isOpenError
    (Self : Internals.QSqlDatabase_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlDatabase_isOpenError, "__QtAda_QSqlDatabase_isOpenError_Q");

   function QSqlDatabase_isValid
    (Self : Internals.QSqlDatabase_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlDatabase_isValid, "__QtAda_QSqlDatabase_isValid_Q");

   procedure QSqlDatabase_lastError
    (Returns : Qt4.Sql_Errors.Internals.QSqlError_Access;
     Self : Internals.QSqlDatabase_Access);
   pragma Import (C, QSqlDatabase_lastError, "__QtAda_QSqlDatabase_lastError_Q");

   function QSqlDatabase_open
    (Self : Internals.QSqlDatabase_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlDatabase_open, "__QtAda_QSqlDatabase_open");

   function QSqlDatabase_open_QStringCR_QStringCR
    (Self : Internals.QSqlDatabase_Access;
     User : Qt4.Strings.Internals.QString_Access;
     Password : Qt4.Strings.Internals.QString_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlDatabase_open_QStringCR_QStringCR, "__QtAda_QSqlDatabase_open_QStringCR_QStringCR");

   procedure QSqlDatabase_password
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Internals.QSqlDatabase_Access);
   pragma Import (C, QSqlDatabase_password, "__QtAda_QSqlDatabase_password_Q");

   function QSqlDatabase_port
    (Self : Internals.QSqlDatabase_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QSqlDatabase_port, "__QtAda_QSqlDatabase_port_Q");

   procedure QSqlDatabase_primaryIndex_QStringCR
    (Returns : Qt4.Sql_Records.Internals.QSqlRecord_Access;
     Self : Internals.QSqlDatabase_Access;
     Tablename : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlDatabase_primaryIndex_QStringCR, "__QtAda_QSqlDatabase_primaryIndex_QStringCR_Q");

   procedure QSqlDatabase_record_QStringCR
    (Returns : Qt4.Sql_Records.Internals.QSqlRecord_Access;
     Self : Internals.QSqlDatabase_Access;
     Tablename : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlDatabase_record_QStringCR, "__QtAda_QSqlDatabase_record_QStringCR_Q");

   function QSqlDatabase_rollback
    (Self : Internals.QSqlDatabase_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlDatabase_rollback, "__QtAda_QSqlDatabase_rollback");

   procedure QSqlDatabase_setConnectOptions_QStringCR
    (Self : Internals.QSqlDatabase_Access;
     Options : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlDatabase_setConnectOptions_QStringCR, "__QtAda_QSqlDatabase_setConnectOptions_QStringCR");

   procedure QSqlDatabase_setDatabaseName_QStringCR
    (Self : Internals.QSqlDatabase_Access;
     Name : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlDatabase_setDatabaseName_QStringCR, "__QtAda_QSqlDatabase_setDatabaseName_QStringCR");

   procedure QSqlDatabase_setHostName_QStringCR
    (Self : Internals.QSqlDatabase_Access;
     Host : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlDatabase_setHostName_QStringCR, "__QtAda_QSqlDatabase_setHostName_QStringCR");

   procedure QSqlDatabase_setPassword_QStringCR
    (Self : Internals.QSqlDatabase_Access;
     Password : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlDatabase_setPassword_QStringCR, "__QtAda_QSqlDatabase_setPassword_QStringCR");

   procedure QSqlDatabase_setPort_int
    (Self : Internals.QSqlDatabase_Access;
     Port : Qt4.Q_Integer);
   pragma Import (C, QSqlDatabase_setPort_int, "__QtAda_QSqlDatabase_setPort_int");

   procedure QSqlDatabase_setUserName_QStringCR
    (Self : Internals.QSqlDatabase_Access;
     Name : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlDatabase_setUserName_QStringCR, "__QtAda_QSqlDatabase_setUserName_QStringCR");

   procedure QSqlDatabase_tables_TableType
    (Returns : Qt4.String_Lists.Internals.QStringList_Access;
     Self : Internals.QSqlDatabase_Access;
     The_Type : Qt4.Sql.Table_Type);
   pragma Import (C, QSqlDatabase_tables_TableType, "__QtAda_QSqlDatabase_tables_TableType_Q");

   function QSqlDatabase_transaction
    (Self : Internals.QSqlDatabase_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlDatabase_transaction, "__QtAda_QSqlDatabase_transaction");

   procedure QSqlDatabase_userName
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Internals.QSqlDatabase_Access);
   pragma Import (C, QSqlDatabase_userName, "__QtAda_QSqlDatabase_userName_Q");

   procedure QSqlDatabase_defaultConnection
    (Returns : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlDatabase_defaultConnection, "__QtAda_QSqlDatabase_defaultConnection_S");

   procedure QSqlDatabase_addDatabase_QStringCR_QStringCR
    (Returns : Internals.QSqlDatabase_Access;
     The_Type : Qt4.Strings.Internals.QString_Access;
     Connection_Name : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlDatabase_addDatabase_QStringCR_QStringCR, "__QtAda_QSqlDatabase_addDatabase_QStringCR_QStringCR_S");

   procedure QSqlDatabase_cloneDatabase_QSqlDatabaseCR_QStringCR
    (Other : Internals.QSqlDatabase_Access;
     Connection_Name : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlDatabase_cloneDatabase_QSqlDatabaseCR_QStringCR, "__QtAda_QSqlDatabase_cloneDatabase_QSqlDatabaseCR_QStringCR_S");

   procedure QSqlDatabase_connectionNames
    (Returns : Qt4.String_Lists.Internals.QStringList_Access);
   pragma Import (C, QSqlDatabase_connectionNames, "__QtAda_QSqlDatabase_connectionNames_S");

   function QSqlDatabase_contains_QStringCR
    (Connection_Name : Qt4.Strings.Internals.QString_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlDatabase_contains_QStringCR, "__QtAda_QSqlDatabase_contains_QStringCR_S");

   procedure QSqlDatabase_database_QStringCR_bool
    (Returns : Internals.QSqlDatabase_Access;
     Connection_Name : Qt4.Strings.Internals.QString_Access;
     Open : Interfaces.C.unsigned);
   pragma Import (C, QSqlDatabase_database_QStringCR_bool, "__QtAda_QSqlDatabase_database_QStringCR_bool_S");

   procedure QSqlDatabase_drivers
    (Returns : Qt4.String_Lists.Internals.QStringList_Access);
   pragma Import (C, QSqlDatabase_drivers, "__QtAda_QSqlDatabase_drivers_S");

   function QSqlDatabase_isDriverAvailable_QStringCR
    (Name : Qt4.Strings.Internals.QString_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlDatabase_isDriverAvailable_QStringCR, "__QtAda_QSqlDatabase_isDriverAvailable_QStringCR_S");

   procedure QSqlDatabase_removeDatabase_QStringCR
    (Connection_Name : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlDatabase_removeDatabase_QStringCR, "__QtAda_QSqlDatabase_removeDatabase_QStringCR_S");

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

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

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

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

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

   overriding
   procedure Initialize (Self : in out Q_Sql_Database) is
      use type Internals.QSqlDatabase_Access;

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

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

   function Create return Q_Sql_Database is
   begin
      return Self : Q_Sql_Database
        := (Ada.Finalization.Controlled with others => <>)
      do
         Self.Object := initialize_QSqlDatabase (Self.Storage'Address);
      end return;
   end Create;

   -----------
   -- Close --
   -----------

   procedure Close
    (Self : in out Q_Sql_Database'Class)
   is
   begin
      QSqlDatabase_close (Self.Object);
   end Close;

   ------------
   -- Commit --
   ------------

   function Commit
    (Self : not null access Q_Sql_Database'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlDatabase_commit (Self.Object), 0);
   end Commit;

   ---------------------
   -- Connect_Options --
   ---------------------

   function Connect_Options
    (Self : Q_Sql_Database'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QSqlDatabase_connectOptions (Qt4.Strings.Internals.QString_View (Returns), Self.Object);
      end return;
   end Connect_Options;

   ---------------------
   -- Connection_Name --
   ---------------------

   function Connection_Name
    (Self : Q_Sql_Database'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QSqlDatabase_connectionName (Qt4.Strings.Internals.QString_View (Returns), Self.Object);
      end return;
   end Connection_Name;

   -------------------
   -- Database_Name --
   -------------------

   function Database_Name
    (Self : Q_Sql_Database'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QSqlDatabase_databaseName (Qt4.Strings.Internals.QString_View (Returns), Self.Object);
      end return;
   end Database_Name;

   -----------------
   -- Driver_Name --
   -----------------

   function Driver_Name
    (Self : Q_Sql_Database'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QSqlDatabase_driverName (Qt4.Strings.Internals.QString_View (Returns), Self.Object);
      end return;
   end Driver_Name;

   ----------
   -- Exec --
   ----------

   function Exec
    (Self : Q_Sql_Database'Class;
     Query : Qt4.Strings.Q_String'Class
       := Qt4.Strings.Create)
       return Qt4.Sql_Queries.Q_Sql_Query
   is
   begin
      return Returns : Qt4.Sql_Queries.Q_Sql_Query do
         QSqlDatabase_exec_QStringCR (Qt4.Sql_Queries.Internals.QSqlQuery_View (Returns), Self.Object, Qt4.Strings.Internals.QString_View (Query));
      end return;
   end Exec;

   ---------------
   -- Host_Name --
   ---------------

   function Host_Name
    (Self : Q_Sql_Database'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QSqlDatabase_hostName (Qt4.Strings.Internals.QString_View (Returns), Self.Object);
      end return;
   end Host_Name;

   -------------
   -- Is_Open --
   -------------

   function Is_Open
    (Self : Q_Sql_Database'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlDatabase_isOpen (Self.Object), 0);
   end Is_Open;

   -------------------
   -- Is_Open_Error --
   -------------------

   function Is_Open_Error
    (Self : Q_Sql_Database'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlDatabase_isOpenError (Self.Object), 0);
   end Is_Open_Error;

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

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

   ----------------
   -- Last_Error --
   ----------------

   function Last_Error
    (Self : Q_Sql_Database'Class)
       return Qt4.Sql_Errors.Q_Sql_Error
   is
   begin
      return Returns : Qt4.Sql_Errors.Q_Sql_Error do
         QSqlDatabase_lastError (Qt4.Sql_Errors.Internals.QSqlError_View (Returns), Self.Object);
      end return;
   end Last_Error;

   ----------
   -- Open --
   ----------

   function Open
    (Self : not null access Q_Sql_Database'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlDatabase_open (Self.Object), 0);
   end Open;

   ----------
   -- Open --
   ----------

   function Open
    (Self : not null access Q_Sql_Database'Class;
     User : Qt4.Strings.Q_String'Class;
     Password : Qt4.Strings.Q_String'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlDatabase_open_QStringCR_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (User), Qt4.Strings.Internals.QString_View (Password)), 0);
   end Open;

   --------------
   -- Password --
   --------------

   function Password
    (Self : Q_Sql_Database'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QSqlDatabase_password (Qt4.Strings.Internals.QString_View (Returns), Self.Object);
      end return;
   end Password;

   ----------
   -- Port --
   ----------

   function Port
    (Self : Q_Sql_Database'Class)
       return Qt4.Q_Integer
   is
   begin
      return QSqlDatabase_port (Self.Object);
   end Port;

   -------------------
   -- Primary_Index --
   -------------------

   function Primary_Index
    (Self : Q_Sql_Database'Class;
     Tablename : Qt4.Strings.Q_String'Class)
       return Qt4.Sql_Indices.Q_Sql_Index
   is
   begin
      return Returns : Qt4.Sql_Indices.Q_Sql_Index do
         QSqlDatabase_primaryIndex_QStringCR (Qt4.Sql_Records.Internals.QSqlRecord_View (Returns), Self.Object, Qt4.Strings.Internals.QString_View (Tablename));
      end return;
   end Primary_Index;

   ------------------
   -- table_record --
   ------------------

   function table_record
    (Self : Q_Sql_Database'Class;
     Tablename : Qt4.Strings.Q_String'Class)
       return Qt4.Sql_Records.Q_Sql_Record
   is
   begin
      return Returns : Qt4.Sql_Records.Q_Sql_Record do
         QSqlDatabase_record_QStringCR (Qt4.Sql_Records.Internals.QSqlRecord_View (Returns), Self.Object, Qt4.Strings.Internals.QString_View (Tablename));
      end return;
   end table_record;

   --------------
   -- Rollback --
   --------------

   function Rollback
    (Self : not null access Q_Sql_Database'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlDatabase_rollback (Self.Object), 0);
   end Rollback;

   -------------------------
   -- Set_Connect_Options --
   -------------------------

   procedure Set_Connect_Options
    (Self : in out Q_Sql_Database'Class;
     Options : Qt4.Strings.Q_String'Class
       := Qt4.Strings.Create)
   is
   begin
      QSqlDatabase_setConnectOptions_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (Options));
   end Set_Connect_Options;

   -----------------------
   -- Set_Database_Name --
   -----------------------

   procedure Set_Database_Name
    (Self : in out Q_Sql_Database'Class;
     Name : Qt4.Strings.Q_String'Class)
   is
   begin
      QSqlDatabase_setDatabaseName_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (Name));
   end Set_Database_Name;

   -------------------
   -- Set_Host_Name --
   -------------------

   procedure Set_Host_Name
    (Self : in out Q_Sql_Database'Class;
     Host : Qt4.Strings.Q_String'Class)
   is
   begin
      QSqlDatabase_setHostName_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (Host));
   end Set_Host_Name;

   ------------------
   -- Set_Password --
   ------------------

   procedure Set_Password
    (Self : in out Q_Sql_Database'Class;
     Password : Qt4.Strings.Q_String'Class)
   is
   begin
      QSqlDatabase_setPassword_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (Password));
   end Set_Password;

   --------------
   -- Set_Port --
   --------------

   procedure Set_Port
    (Self : in out Q_Sql_Database'Class;
     Port : Qt4.Q_Integer)
   is
   begin
      QSqlDatabase_setPort_int (Self.Object, Port);
   end Set_Port;

   -------------------
   -- Set_User_Name --
   -------------------

   procedure Set_User_Name
    (Self : in out Q_Sql_Database'Class;
     Name : Qt4.Strings.Q_String'Class)
   is
   begin
      QSqlDatabase_setUserName_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (Name));
   end Set_User_Name;

   ------------
   -- Tables --
   ------------

   function Tables
    (Self : Q_Sql_Database'Class;
     The_Type : Qt4.Sql.Table_Type
       := Qt4.Sql.Tables)
       return Qt4.String_Lists.Q_String_List
   is
   begin
      return Returns : Qt4.String_Lists.Q_String_List do
         QSqlDatabase_tables_TableType (Qt4.String_Lists.Internals.QStringList_View (Returns), Self.Object, The_Type);
      end return;
   end Tables;

   -----------------
   -- Transaction --
   -----------------

   function Transaction
    (Self : not null access Q_Sql_Database'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlDatabase_transaction (Self.Object), 0);
   end Transaction;

   ---------------
   -- User_Name --
   ---------------

   function User_Name
    (Self : Q_Sql_Database'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QSqlDatabase_userName (Qt4.Strings.Internals.QString_View (Returns), Self.Object);
      end return;
   end User_Name;

   ------------------------
   -- Default_Connection --
   ------------------------

   function Default_Connection
     return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QSqlDatabase_defaultConnection (Qt4.Strings.Internals.QString_View (Returns));
      end return;
   end Default_Connection;

   ------------------
   -- Add_Database --
   ------------------

   function Add_Database
    (The_Type : Qt4.Strings.Q_String'Class;
     Connection_Name : Qt4.Strings.Q_String'Class
       := Default_Connection)
       return Q_Sql_Database
   is
   begin
      return Returns : Q_Sql_Database do
         QSqlDatabase_addDatabase_QStringCR_QStringCR (Returns.Object, Qt4.Strings.Internals.QString_View (The_Type), Qt4.Strings.Internals.QString_View (Connection_Name));
      end return;
   end Add_Database;

   --------------------
   -- Clone_Database --
   --------------------

   procedure Clone_Database
    (Other : Q_Sql_Database'Class;
     Connection_Name : Qt4.Strings.Q_String'Class)
   is
   begin
      QSqlDatabase_cloneDatabase_QSqlDatabaseCR_QStringCR (Other.Object, Qt4.Strings.Internals.QString_View (Connection_Name));
   end Clone_Database;

   ----------------------
   -- Connection_Names --
   ----------------------

   function Connection_Names
     return Qt4.String_Lists.Q_String_List
   is
   begin
      return Returns : Qt4.String_Lists.Q_String_List do
         QSqlDatabase_connectionNames (Qt4.String_Lists.Internals.QStringList_View (Returns));
      end return;
   end Connection_Names;

   --------------
   -- Contains --
   --------------

   function Contains
    (Connection_Name : Qt4.Strings.Q_String'Class
       := Default_Connection)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlDatabase_contains_QStringCR (Qt4.Strings.Internals.QString_View (Connection_Name)), 0);
   end Contains;

   --------------
   -- Database --
   --------------

   function Database
    (Connection_Name : Qt4.Strings.Q_String'Class
       := Default_Connection;
     Open : Boolean
       := True)
       return Q_Sql_Database
   is
   begin
      return Returns : Q_Sql_Database do
         QSqlDatabase_database_QStringCR_bool (Returns.Object, Qt4.Strings.Internals.QString_View (Connection_Name), Qt_Ada.Internals.Boolean_Conversions.To_unsigned (Open));
      end return;
   end Database;

   -------------
   -- Drivers --
   -------------

   function Drivers
     return Qt4.String_Lists.Q_String_List
   is
   begin
      return Returns : Qt4.String_Lists.Q_String_List do
         QSqlDatabase_drivers (Qt4.String_Lists.Internals.QStringList_View (Returns));
      end return;
   end Drivers;

   -------------------------
   -- Is_Driver_Available --
   -------------------------

   function Is_Driver_Available
    (Name : Qt4.Strings.Q_String'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlDatabase_isDriverAvailable_QStringCR (Qt4.Strings.Internals.QString_View (Name)), 0);
   end Is_Driver_Available;

   ---------------------
   -- Remove_Database --
   ---------------------

   procedure Remove_Database
    (Connection_Name : Qt4.Strings.Q_String'Class)
   is
   begin
      QSqlDatabase_removeDatabase_QStringCR (Qt4.Strings.Internals.QString_View (Connection_Name));
   end Remove_Database;

   function initialize_QSqlQuery
    (Storage : System.Address)
      return Internals.QSqlQuery_Access;
   pragma Import (C, initialize_QSqlQuery, "__QtAda_inititialize_QSqlQuery");

   function initialize_QSqlQuery_QStringCR_QSqlDatabaseCR
    (Storage : System.Address;
     Query : Qt4.Strings.Internals.QString_Access;
     Db : Qt4.Sql_Databases.Internals.QSqlDatabase_Access)
      return Internals.QSqlQuery_Access;
   pragma Import (C, initialize_QSqlQuery_QStringCR_QSqlDatabaseCR, "__QtAda_inititialize_QSqlQuery_QStringCR_QSqlDatabaseCR");

   function initialize_QSqlQuery_QSqlDatabaseCR
    (Storage : System.Address;
     Db : Qt4.Sql_Databases.Internals.QSqlDatabase_Access)
      return Internals.QSqlQuery_Access;
   pragma Import (C, initialize_QSqlQuery_QSqlDatabaseCR, "__QtAda_inititialize_QSqlQuery_QSqlDatabaseCR");

   function adjust_QSqlQuery
    (Storage : System.Address;
     From    : Internals.QSqlQuery_Access)
       return Internals.QSqlQuery_Access;
   pragma Import (C, adjust_QSqlQuery, "__QtAda_adjust_QSqlQuery");

   procedure finalize_QSqlQuery (Object : Internals.QSqlQuery_Access);
   pragma Import (C, finalize_QSqlQuery, "__QtAda_finalize_QSqlQuery");

   procedure QSqlQuery_addBindValue_QVariantCR_ParamTypeFlag
    (Self : Internals.QSqlQuery_Access;
     Val : Qt4.Variants.Internals.QVariant_Access;
     The_Type : Qt4.Sql.Param_Type_Flag);
   pragma Import (C, QSqlQuery_addBindValue_QVariantCR_ParamTypeFlag, "__QtAda_QSqlQuery_addBindValue_QVariantCR_ParamTypeFlag");

   function QSqlQuery_at
    (Self : Internals.QSqlQuery_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QSqlQuery_at, "__QtAda_QSqlQuery_at_Q");

   procedure QSqlQuery_bindValue_QStringCR_QVariantCR_ParamTypeFlag
    (Self : Internals.QSqlQuery_Access;
     Placeholder : Qt4.Strings.Internals.QString_Access;
     Val : Qt4.Variants.Internals.QVariant_Access;
     The_Type : Qt4.Sql.Param_Type_Flag);
   pragma Import (C, QSqlQuery_bindValue_QStringCR_QVariantCR_ParamTypeFlag, "__QtAda_QSqlQuery_bindValue_QStringCR_QVariantCR_ParamTypeFlag");

   procedure QSqlQuery_bindValue_int_QVariantCR_ParamTypeFlag
    (Self : Internals.QSqlQuery_Access;
     Pos : Qt4.Q_Integer;
     Val : Qt4.Variants.Internals.QVariant_Access;
     The_Type : Qt4.Sql.Param_Type_Flag);
   pragma Import (C, QSqlQuery_bindValue_int_QVariantCR_ParamTypeFlag, "__QtAda_QSqlQuery_bindValue_int_QVariantCR_ParamTypeFlag");

   procedure QSqlQuery_boundValue_QStringCR
    (Returns : Qt4.Variants.Internals.QVariant_Access;
     Self : Internals.QSqlQuery_Access;
     Placeholder : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlQuery_boundValue_QStringCR, "__QtAda_QSqlQuery_boundValue_QStringCR_Q");

   procedure QSqlQuery_boundValue_int
    (Returns : Qt4.Variants.Internals.QVariant_Access;
     Self : Internals.QSqlQuery_Access;
     Pos : Qt4.Q_Integer);
   pragma Import (C, QSqlQuery_boundValue_int, "__QtAda_QSqlQuery_boundValue_int_Q");

   procedure QSqlQuery_clear
    (Self : Internals.QSqlQuery_Access);
   pragma Import (C, QSqlQuery_clear, "__QtAda_QSqlQuery_clear");

   function QSqlQuery_exec_QStringCR
    (Self : Internals.QSqlQuery_Access;
     Query : Qt4.Strings.Internals.QString_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlQuery_exec_QStringCR, "__QtAda_QSqlQuery_exec_QStringCR");

   function QSqlQuery_exec
    (Self : Internals.QSqlQuery_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlQuery_exec, "__QtAda_QSqlQuery_exec");

   function QSqlQuery_execBatch_BatchExecutionMode
    (Self : Internals.QSqlQuery_Access;
     Mode : Batch_Execution_Mode)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlQuery_execBatch_BatchExecutionMode, "__QtAda_QSqlQuery_execBatch_BatchExecutionMode");

   procedure QSqlQuery_executedQuery
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Internals.QSqlQuery_Access);
   pragma Import (C, QSqlQuery_executedQuery, "__QtAda_QSqlQuery_executedQuery_Q");

   procedure QSqlQuery_finish
    (Self : Internals.QSqlQuery_Access);
   pragma Import (C, QSqlQuery_finish, "__QtAda_QSqlQuery_finish");

   function QSqlQuery_first
    (Self : Internals.QSqlQuery_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlQuery_first, "__QtAda_QSqlQuery_first");

   function QSqlQuery_isActive
    (Self : Internals.QSqlQuery_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlQuery_isActive, "__QtAda_QSqlQuery_isActive_Q");

   function QSqlQuery_isForwardOnly
    (Self : Internals.QSqlQuery_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlQuery_isForwardOnly, "__QtAda_QSqlQuery_isForwardOnly_Q");

   function QSqlQuery_isNull_int
    (Self : Internals.QSqlQuery_Access;
     Field : Qt4.Q_Integer)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlQuery_isNull_int, "__QtAda_QSqlQuery_isNull_int_Q");

   function QSqlQuery_isSelect
    (Self : Internals.QSqlQuery_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlQuery_isSelect, "__QtAda_QSqlQuery_isSelect_Q");

   function QSqlQuery_isValid
    (Self : Internals.QSqlQuery_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlQuery_isValid, "__QtAda_QSqlQuery_isValid_Q");

   function QSqlQuery_last
    (Self : Internals.QSqlQuery_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlQuery_last, "__QtAda_QSqlQuery_last");

   procedure QSqlQuery_lastError
    (Returns : Qt4.Sql_Errors.Internals.QSqlError_Access;
     Self : Internals.QSqlQuery_Access);
   pragma Import (C, QSqlQuery_lastError, "__QtAda_QSqlQuery_lastError_Q");

   procedure QSqlQuery_lastInsertId
    (Returns : Qt4.Variants.Internals.QVariant_Access;
     Self : Internals.QSqlQuery_Access);
   pragma Import (C, QSqlQuery_lastInsertId, "__QtAda_QSqlQuery_lastInsertId_Q");

   procedure QSqlQuery_lastQuery
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Internals.QSqlQuery_Access);
   pragma Import (C, QSqlQuery_lastQuery, "__QtAda_QSqlQuery_lastQuery_Q");

   function QSqlQuery_next
    (Self : Internals.QSqlQuery_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlQuery_next, "__QtAda_QSqlQuery_next");

   function QSqlQuery_nextResult
    (Self : Internals.QSqlQuery_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlQuery_nextResult, "__QtAda_QSqlQuery_nextResult");

   function QSqlQuery_numRowsAffected
    (Self : Internals.QSqlQuery_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QSqlQuery_numRowsAffected, "__QtAda_QSqlQuery_numRowsAffected_Q");

   function QSqlQuery_numericalPrecisionPolicy
    (Self : Internals.QSqlQuery_Access)
       return Qt4.Sql.Numerical_Precision_Policy;
   pragma Import (C, QSqlQuery_numericalPrecisionPolicy, "__QtAda_QSqlQuery_numericalPrecisionPolicy_Q");

   function QSqlQuery_prepare_QStringCR
    (Self : Internals.QSqlQuery_Access;
     Query : Qt4.Strings.Internals.QString_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlQuery_prepare_QStringCR, "__QtAda_QSqlQuery_prepare_QStringCR");

   function QSqlQuery_previous
    (Self : Internals.QSqlQuery_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlQuery_previous, "__QtAda_QSqlQuery_previous");

   procedure QSqlQuery_record
    (Returns : Qt4.Sql_Records.Internals.QSqlRecord_Access;
     Self : Internals.QSqlQuery_Access);
   pragma Import (C, QSqlQuery_record, "__QtAda_QSqlQuery_record_Q");

   function QSqlQuery_seek_int_bool
    (Self : Internals.QSqlQuery_Access;
     Index : Qt4.Q_Integer;
     Relative : Interfaces.C.unsigned)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlQuery_seek_int_bool, "__QtAda_QSqlQuery_seek_int_bool");

   procedure QSqlQuery_setForwardOnly_bool
    (Self : Internals.QSqlQuery_Access;
     Forward : Interfaces.C.unsigned);
   pragma Import (C, QSqlQuery_setForwardOnly_bool, "__QtAda_QSqlQuery_setForwardOnly_bool");

   procedure QSqlQuery_setNumericalPrecisionPolicy_NumericalPrecisionPolicy
    (Self : Internals.QSqlQuery_Access;
     Precision_Policy : Qt4.Sql.Numerical_Precision_Policy);
   pragma Import (C, QSqlQuery_setNumericalPrecisionPolicy_NumericalPrecisionPolicy, "__QtAda_QSqlQuery_setNumericalPrecisionPolicy_NumericalPrecisionPolicy");

   function QSqlQuery_size
    (Self : Internals.QSqlQuery_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QSqlQuery_size, "__QtAda_QSqlQuery_size");

   procedure QSqlQuery_value_int
    (Returns : Qt4.Variants.Internals.QVariant_Access;
     Self : Internals.QSqlQuery_Access;
     Index : Qt4.Q_Integer);
   pragma Import (C, QSqlQuery_value_int, "__QtAda_QSqlQuery_value_int");

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

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

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

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

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

   overriding
   procedure Initialize (Self : in out Q_Sql_Query) is
      use type Internals.QSqlQuery_Access;

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

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

   function Create
    (Query : Qt4.Strings.Q_String'Class
       := Qt4.Strings.Create;
     Db : Qt4.Sql_Databases.Q_Sql_Database'Class
       := Qt4.Sql_Databases.Create)
       return Q_Sql_Query
   is
   begin
      return Self : Q_Sql_Query
        := (Ada.Finalization.Controlled with others => <>)
      do
         Self.Object := initialize_QSqlQuery_QStringCR_QSqlDatabaseCR (Self.Storage'Address, Qt4.Strings.Internals.QString_View (Query), Qt4.Sql_Databases.Internals.QSqlDatabase_View (Db));
      end return;
   end Create;

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

   function Create
    (Db : Qt4.Sql_Databases.Q_Sql_Database'Class)
       return Q_Sql_Query
   is
   begin
      return Self : Q_Sql_Query
        := (Ada.Finalization.Controlled with others => <>)
      do
         Self.Object := initialize_QSqlQuery_QSqlDatabaseCR (Self.Storage'Address, Qt4.Sql_Databases.Internals.QSqlDatabase_View (Db));
      end return;
   end Create;

   --------------------
   -- Add_Bind_Value --
   --------------------

   procedure Add_Bind_Value
    (Self : in out Q_Sql_Query'Class;
     Val : Qt4.Variants.Q_Variant'Class;
     The_Type : Qt4.Sql.Param_Type_Flag
       := Qt4.Sql.In_Parameter)
   is
   begin
      QSqlQuery_addBindValue_QVariantCR_ParamTypeFlag (Self.Object, Qt4.Variants.Internals.QVariant_View (Val), The_Type);
   end Add_Bind_Value;

   -----------------
   -- At_Position --
   -----------------

   function At_Position
    (Self : Q_Sql_Query'Class)
       return Qt4.Q_Integer
   is
   begin
      return QSqlQuery_at (Self.Object);
   end At_Position;

   ----------------
   -- Bind_Value --
   ----------------

   procedure Bind_Value
    (Self : in out Q_Sql_Query'Class;
     Placeholder : Qt4.Strings.Q_String'Class;
     Val : Qt4.Variants.Q_Variant'Class;
     The_Type : Qt4.Sql.Param_Type_Flag
       := Qt4.Sql.In_Parameter)
   is
   begin
      QSqlQuery_bindValue_QStringCR_QVariantCR_ParamTypeFlag (Self.Object, Qt4.Strings.Internals.QString_View (Placeholder), Qt4.Variants.Internals.QVariant_View (Val), The_Type);
   end Bind_Value;

   ----------------
   -- Bind_Value --
   ----------------

   procedure Bind_Value
    (Self : in out Q_Sql_Query'Class;
     Pos : Qt4.Q_Integer;
     Val : Qt4.Variants.Q_Variant'Class;
     The_Type : Qt4.Sql.Param_Type_Flag
       := Qt4.Sql.In_Parameter)
   is
   begin
      QSqlQuery_bindValue_int_QVariantCR_ParamTypeFlag (Self.Object, Pos, Qt4.Variants.Internals.QVariant_View (Val), The_Type);
   end Bind_Value;

   -----------------
   -- Bound_Value --
   -----------------

   function Bound_Value
    (Self : Q_Sql_Query'Class;
     Placeholder : Qt4.Strings.Q_String'Class)
       return Qt4.Variants.Q_Variant
   is
   begin
      return Returns : Qt4.Variants.Q_Variant do
         QSqlQuery_boundValue_QStringCR (Qt4.Variants.Internals.QVariant_View (Returns), Self.Object, Qt4.Strings.Internals.QString_View (Placeholder));
      end return;
   end Bound_Value;

   -----------------
   -- Bound_Value --
   -----------------

   function Bound_Value
    (Self : Q_Sql_Query'Class;
     Pos : Qt4.Q_Integer)
       return Qt4.Variants.Q_Variant
   is
   begin
      return Returns : Qt4.Variants.Q_Variant do
         QSqlQuery_boundValue_int (Qt4.Variants.Internals.QVariant_View (Returns), Self.Object, Pos);
      end return;
   end Bound_Value;

   -----------
   -- Clear --
   -----------

   procedure Clear
    (Self : in out Q_Sql_Query'Class)
   is
   begin
      QSqlQuery_clear (Self.Object);
   end Clear;

   ----------
   -- Exec --
   ----------

   function Exec
    (Self : not null access Q_Sql_Query'Class;
     Query : Qt4.Strings.Q_String'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlQuery_exec_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (Query)), 0);
   end Exec;

   ----------
   -- Exec --
   ----------

   function Exec
    (Self : not null access Q_Sql_Query'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlQuery_exec (Self.Object), 0);
   end Exec;

   ----------------
   -- Exec_Batch --
   ----------------

   function Exec_Batch
    (Self : not null access Q_Sql_Query'Class;
     Mode : Batch_Execution_Mode
       := Values_As_Rows)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlQuery_execBatch_BatchExecutionMode (Self.Object, Mode), 0);
   end Exec_Batch;

   --------------------
   -- Executed_Query --
   --------------------

   function Executed_Query
    (Self : Q_Sql_Query'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QSqlQuery_executedQuery (Qt4.Strings.Internals.QString_View (Returns), Self.Object);
      end return;
   end Executed_Query;

   ------------
   -- Finish --
   ------------

   procedure Finish
    (Self : in out Q_Sql_Query'Class)
   is
   begin
      QSqlQuery_finish (Self.Object);
   end Finish;

   -----------
   -- First --
   -----------

   function First
    (Self : not null access Q_Sql_Query'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlQuery_first (Self.Object), 0);
   end First;

   ---------------
   -- Is_Active --
   ---------------

   function Is_Active
    (Self : Q_Sql_Query'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlQuery_isActive (Self.Object), 0);
   end Is_Active;

   ---------------------
   -- Is_Forward_Only --
   ---------------------

   function Is_Forward_Only
    (Self : Q_Sql_Query'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlQuery_isForwardOnly (Self.Object), 0);
   end Is_Forward_Only;

   -------------
   -- Is_Null --
   -------------

   function Is_Null
    (Self : Q_Sql_Query'Class;
     Field : Qt4.Q_Integer)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlQuery_isNull_int (Self.Object, Field), 0);
   end Is_Null;

   ---------------
   -- Is_Select --
   ---------------

   function Is_Select
    (Self : Q_Sql_Query'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlQuery_isSelect (Self.Object), 0);
   end Is_Select;

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

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

   ----------
   -- Last --
   ----------

   function Last
    (Self : not null access Q_Sql_Query'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlQuery_last (Self.Object), 0);
   end Last;

   ----------------
   -- Last_Error --
   ----------------

   function Last_Error
    (Self : Q_Sql_Query'Class)
       return Qt4.Sql_Errors.Q_Sql_Error
   is
   begin
      return Returns : Qt4.Sql_Errors.Q_Sql_Error do
         QSqlQuery_lastError (Qt4.Sql_Errors.Internals.QSqlError_View (Returns), Self.Object);
      end return;
   end Last_Error;

   --------------------
   -- Last_Insert_Id --
   --------------------

   function Last_Insert_Id
    (Self : Q_Sql_Query'Class)
       return Qt4.Variants.Q_Variant
   is
   begin
      return Returns : Qt4.Variants.Q_Variant do
         QSqlQuery_lastInsertId (Qt4.Variants.Internals.QVariant_View (Returns), Self.Object);
      end return;
   end Last_Insert_Id;

   ----------------
   -- Last_Query --
   ----------------

   function Last_Query
    (Self : Q_Sql_Query'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QSqlQuery_lastQuery (Qt4.Strings.Internals.QString_View (Returns), Self.Object);
      end return;
   end Last_Query;

   ----------
   -- Next --
   ----------

   function Next
    (Self : not null access Q_Sql_Query'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlQuery_next (Self.Object), 0);
   end Next;

   -----------------
   -- Next_Result --
   -----------------

   function Next_Result
    (Self : not null access Q_Sql_Query'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlQuery_nextResult (Self.Object), 0);
   end Next_Result;

   -----------------------
   -- Num_Rows_Affected --
   -----------------------

   function Num_Rows_Affected
    (Self : Q_Sql_Query'Class)
       return Qt4.Q_Integer
   is
   begin
      return QSqlQuery_numRowsAffected (Self.Object);
   end Num_Rows_Affected;

   --------------------------------
   -- Numerical_Precision_Policy --
   --------------------------------

   function Numerical_Precision_Policy
    (Self : Q_Sql_Query'Class)
       return Qt4.Sql.Numerical_Precision_Policy
   is
   begin
      return QSqlQuery_numericalPrecisionPolicy (Self.Object);
   end Numerical_Precision_Policy;

   -------------
   -- Prepare --
   -------------

   function Prepare
    (Self : not null access Q_Sql_Query'Class;
     Query : Qt4.Strings.Q_String'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlQuery_prepare_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (Query)), 0);
   end Prepare;

   --------------
   -- Previous --
   --------------

   function Previous
    (Self : not null access Q_Sql_Query'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlQuery_previous (Self.Object), 0);
   end Previous;

   ------------------
   -- Query_Record --
   ------------------

   function Query_Record
    (Self : Q_Sql_Query'Class)
       return Qt4.Sql_Records.Q_Sql_Record
   is
   begin
      return Returns : Qt4.Sql_Records.Q_Sql_Record do
         QSqlQuery_record (Qt4.Sql_Records.Internals.QSqlRecord_View (Returns), Self.Object);
      end return;
   end Query_Record;

   ----------
   -- Seek --
   ----------

   function Seek
    (Self : not null access Q_Sql_Query'Class;
     Index : Qt4.Q_Integer;
     Relative : Boolean
       := False)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlQuery_seek_int_bool (Self.Object, Index, Qt_Ada.Internals.Boolean_Conversions.To_unsigned (Relative)), 0);
   end Seek;

   ----------------------
   -- Set_Forward_Only --
   ----------------------

   procedure Set_Forward_Only
    (Self : in out Q_Sql_Query'Class;
     Forward : Boolean)
   is
   begin
      QSqlQuery_setForwardOnly_bool (Self.Object, Qt_Ada.Internals.Boolean_Conversions.To_unsigned (Forward));
   end Set_Forward_Only;

   ------------------------------------
   -- Set_Numerical_Precision_Policy --
   ------------------------------------

   procedure Set_Numerical_Precision_Policy
    (Self : in out Q_Sql_Query'Class;
     Precision_Policy : Qt4.Sql.Numerical_Precision_Policy)
   is
   begin
      QSqlQuery_setNumericalPrecisionPolicy_NumericalPrecisionPolicy (Self.Object, Precision_Policy);
   end Set_Numerical_Precision_Policy;

   ----------
   -- Size --
   ----------

   function Size
    (Self : not null access Q_Sql_Query'Class)
       return Qt4.Q_Integer
   is
   begin
      return QSqlQuery_size (Self.Object);
   end Size;

   -----------
   -- Value --
   -----------

   function Value
    (Self : not null access Q_Sql_Query'Class;
     Index : Qt4.Q_Integer)
       return Qt4.Variants.Q_Variant
   is
   begin
      return Returns : Qt4.Variants.Q_Variant do
         QSqlQuery_value_int (Qt4.Variants.Internals.QVariant_View (Returns), Self.Object, Index);
      end return;
   end Value;
   ---------------
   -- Internals --
   ---------------

   package body Internals is

   -----------------------
   -- QSqlDatabase_View --
   -----------------------

      function QSqlDatabase_View
       (Item : Q_Sql_Database'Class)
          return QSqlDatabase_Access
      is
      begin
         return Item.Object;
      end QSqlDatabase_View;

      package QSqlDatabase_Conversions is
        new System.Address_To_Access_Conversions
             (QSqlDatabase);

   ----------------------------
   -- QSqlDatabaseTo_Pointer --
   ----------------------------

      function To_Pointer
       (Address : System.Address)
          return QSqlDatabase_Access
      is
      begin
         return
           QSqlDatabase_Access
            (QSqlDatabase_Conversions.To_Pointer
            (Address));
      end To_Pointer;

   ----------------------------
   -- QSqlDatabaseTo_Address --
   ----------------------------

      function To_Address
       (Pointer : QSqlDatabase_Access)
          return System.Address
      is
      begin
         return
           QSqlDatabase_Conversions.To_Address
            (QSqlDatabase_Conversions.Object_Pointer
              (Pointer));
      end To_Address;

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

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

   --------------------
   -- QSqlQuery_View --
   --------------------

      function QSqlQuery_View
       (Item : Q_Sql_Query'Class)
          return QSqlQuery_Access
      is
      begin
         return Item.Object;
      end QSqlQuery_View;

      package QSqlQuery_Conversions is
        new System.Address_To_Access_Conversions
             (QSqlQuery);

   -------------------------
   -- QSqlQueryTo_Pointer --
   -------------------------

      function To_Pointer
       (Address : System.Address)
          return QSqlQuery_Access
      is
      begin
         return
           QSqlQuery_Access
            (QSqlQuery_Conversions.To_Pointer
            (Address));
      end To_Pointer;

   -------------------------
   -- QSqlQueryTo_Address --
   -------------------------

      function To_Address
       (Pointer : QSqlQuery_Access)
          return System.Address
      is
      begin
         return
           QSqlQuery_Conversions.To_Address
            (QSqlQuery_Conversions.Object_Pointer
              (Pointer));
      end To_Address;

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

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

   end Internals;

end Qt4.Sql_Databases;
