------------------------------------------------------------------------------
--                                                                          --
--                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.     --
------------------------------------------------------------------------------
private with Ada.Finalization;
with Qt4.Sql;
with Qt4.Sql_Errors;
with Qt4.Sql_Indices;
with Qt4.Sql_Records;
with Qt4.String_Lists;
with Qt4.Strings;
with Qt4.Variants;
private with Qt_Ada.Internals.Value_Class_Sizes;
with System;

package Qt4.Sql_Databases is

   --  QSqlQuery::BatchExecutionMode

   type Batch_Execution_Mode is
    (Values_As_Rows,
     Values_As_Columns);
   pragma Convention (C, Batch_Execution_Mode);
   for Batch_Execution_Mode'Size use Interfaces.C.unsigned'Size;

   type Q_Sql_Database is tagged private;

   type Q_Sql_Query is tagged private;

   function Create return Q_Sql_Database;

   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;

   function Create
    (Db : Qt4.Sql_Databases.Q_Sql_Database'Class)
       return Q_Sql_Query;

   procedure Close
    (Self : in out Q_Sql_Database'Class);

   function Commit
    (Self : not null access Q_Sql_Database'Class)
       return Boolean;

   function Connect_Options
    (Self : Q_Sql_Database'Class)
       return Qt4.Strings.Q_String;

   function Connection_Name
    (Self : Q_Sql_Database'Class)
       return Qt4.Strings.Q_String;

   function Database_Name
    (Self : Q_Sql_Database'Class)
       return Qt4.Strings.Q_String;

   function Driver_Name
    (Self : Q_Sql_Database'Class)
       return Qt4.Strings.Q_String;

   function Exec
    (Self : Q_Sql_Database'Class;
     Query : Qt4.Strings.Q_String'Class
       := Qt4.Strings.Create)
       return Q_Sql_Query;

   function Host_Name
    (Self : Q_Sql_Database'Class)
       return Qt4.Strings.Q_String;

   function Is_Open
    (Self : Q_Sql_Database'Class)
       return Boolean;

   function Is_Open_Error
    (Self : Q_Sql_Database'Class)
       return Boolean;

   function Is_Valid
    (Self : Q_Sql_Database'Class)
       return Boolean;

   function Last_Error
    (Self : Q_Sql_Database'Class)
       return Qt4.Sql_Errors.Q_Sql_Error;

   function Open
    (Self : not null access Q_Sql_Database'Class)
       return Boolean;

   function Open
    (Self : not null access Q_Sql_Database'Class;
     User : Qt4.Strings.Q_String'Class;
     Password : Qt4.Strings.Q_String'Class)
       return Boolean;

   function Password
    (Self : Q_Sql_Database'Class)
       return Qt4.Strings.Q_String;

   function Port
    (Self : Q_Sql_Database'Class)
       return Qt4.Q_Integer;

   function Primary_Index
    (Self : Q_Sql_Database'Class;
     Tablename : Qt4.Strings.Q_String'Class)
       return Qt4.Sql_Indices.Q_Sql_Index;

   function table_record
    (Self : Q_Sql_Database'Class;
     Tablename : Qt4.Strings.Q_String'Class)
       return Qt4.Sql_Records.Q_Sql_Record;

   function Rollback
    (Self : not null access Q_Sql_Database'Class)
       return Boolean;

   procedure Set_Connect_Options
    (Self : in out Q_Sql_Database'Class;
     Options : Qt4.Strings.Q_String'Class
       := Qt4.Strings.Create);

   procedure Set_Database_Name
    (Self : in out Q_Sql_Database'Class;
     Name : Qt4.Strings.Q_String'Class);

   procedure Set_Host_Name
    (Self : in out Q_Sql_Database'Class;
     Host : Qt4.Strings.Q_String'Class);

   procedure Set_Password
    (Self : in out Q_Sql_Database'Class;
     Password : Qt4.Strings.Q_String'Class);

   procedure Set_Port
    (Self : in out Q_Sql_Database'Class;
     Port : Qt4.Q_Integer);

   procedure Set_User_Name
    (Self : in out Q_Sql_Database'Class;
     Name : Qt4.Strings.Q_String'Class);

   function Tables
    (Self : Q_Sql_Database'Class;
     The_Type : Qt4.Sql.Table_Type
       := Qt4.Sql.Tables)
       return Qt4.String_Lists.Q_String_List;

   function Transaction
    (Self : not null access Q_Sql_Database'Class)
       return Boolean;

   function User_Name
    (Self : Q_Sql_Database'Class)
       return Qt4.Strings.Q_String;

   function Default_Connection
     return Qt4.Strings.Q_String;

   function Add_Database
    (The_Type : Qt4.Strings.Q_String'Class;
     Connection_Name : Qt4.Strings.Q_String'Class
       := Default_Connection)
       return Q_Sql_Database;

   procedure Clone_Database
    (Other : Q_Sql_Database'Class;
     Connection_Name : Qt4.Strings.Q_String'Class);

   function Connection_Names
     return Qt4.String_Lists.Q_String_List;

   function Contains
    (Connection_Name : Qt4.Strings.Q_String'Class
       := Default_Connection)
       return Boolean;

   function Database
    (Connection_Name : Qt4.Strings.Q_String'Class
       := Default_Connection;
     Open : Boolean
       := True)
       return Q_Sql_Database;

   function Drivers
     return Qt4.String_Lists.Q_String_List;

   function Is_Driver_Available
    (Name : Qt4.Strings.Q_String'Class)
       return Boolean;

   procedure Remove_Database
    (Connection_Name : Qt4.Strings.Q_String'Class);

   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);

   function At_Position
    (Self : Q_Sql_Query'Class)
       return Qt4.Q_Integer;

   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);

   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);

   function Bound_Value
    (Self : Q_Sql_Query'Class;
     Placeholder : Qt4.Strings.Q_String'Class)
       return Qt4.Variants.Q_Variant;

   function Bound_Value
    (Self : Q_Sql_Query'Class;
     Pos : Qt4.Q_Integer)
       return Qt4.Variants.Q_Variant;

   procedure Clear
    (Self : in out Q_Sql_Query'Class);

   function Exec
    (Self : not null access Q_Sql_Query'Class;
     Query : Qt4.Strings.Q_String'Class)
       return Boolean;

   function Exec
    (Self : not null access Q_Sql_Query'Class)
       return Boolean;

   function Exec_Batch
    (Self : not null access Q_Sql_Query'Class;
     Mode : Batch_Execution_Mode
       := Values_As_Rows)
       return Boolean;

   function Executed_Query
    (Self : Q_Sql_Query'Class)
       return Qt4.Strings.Q_String;

   procedure Finish
    (Self : in out Q_Sql_Query'Class);

   function First
    (Self : not null access Q_Sql_Query'Class)
       return Boolean;

   function Is_Active
    (Self : Q_Sql_Query'Class)
       return Boolean;

   function Is_Forward_Only
    (Self : Q_Sql_Query'Class)
       return Boolean;

   function Is_Null
    (Self : Q_Sql_Query'Class;
     Field : Qt4.Q_Integer)
       return Boolean;

   function Is_Select
    (Self : Q_Sql_Query'Class)
       return Boolean;

   function Is_Valid
    (Self : Q_Sql_Query'Class)
       return Boolean;

   function Last
    (Self : not null access Q_Sql_Query'Class)
       return Boolean;

   function Last_Error
    (Self : Q_Sql_Query'Class)
       return Qt4.Sql_Errors.Q_Sql_Error;

   function Last_Insert_Id
    (Self : Q_Sql_Query'Class)
       return Qt4.Variants.Q_Variant;

   function Last_Query
    (Self : Q_Sql_Query'Class)
       return Qt4.Strings.Q_String;

   function Next
    (Self : not null access Q_Sql_Query'Class)
       return Boolean;

   function Next_Result
    (Self : not null access Q_Sql_Query'Class)
       return Boolean;

   function Num_Rows_Affected
    (Self : Q_Sql_Query'Class)
       return Qt4.Q_Integer;

   function Numerical_Precision_Policy
    (Self : Q_Sql_Query'Class)
       return Qt4.Sql.Numerical_Precision_Policy;

   function Prepare
    (Self : not null access Q_Sql_Query'Class;
     Query : Qt4.Strings.Q_String'Class)
       return Boolean;

   function Previous
    (Self : not null access Q_Sql_Query'Class)
       return Boolean;

   function Query_Record
    (Self : Q_Sql_Query'Class)
       return Qt4.Sql_Records.Q_Sql_Record;

   function Seek
    (Self : not null access Q_Sql_Query'Class;
     Index : Qt4.Q_Integer;
     Relative : Boolean
       := False)
       return Boolean;

   procedure Set_Forward_Only
    (Self : in out Q_Sql_Query'Class;
     Forward : Boolean);

   procedure Set_Numerical_Precision_Policy
    (Self : in out Q_Sql_Query'Class;
     Precision_Policy : Qt4.Sql.Numerical_Precision_Policy);

   function Size
    (Self : not null access Q_Sql_Query'Class)
       return Qt4.Q_Integer;

   function Value
    (Self : not null access Q_Sql_Query'Class;
     Index : Qt4.Q_Integer)
       return Qt4.Variants.Q_Variant;

   package Internals is

      type QSqlDatabase is private;

      type QSqlDatabase_Access is access all QSqlDatabase;
      pragma Convention (C, QSqlDatabase_Access);

      function QSqlDatabase_View
       (Item : Q_Sql_Database'Class)
          return QSqlDatabase_Access;
      pragma Inline (QSqlDatabase_View);

      function To_Pointer
       (Address : System.Address)
          return QSqlDatabase_Access;
      pragma Inline (To_Pointer);

      function To_Address
       (Pointer : QSqlDatabase_Access)
          return System.Address;
      pragma Inline (To_Address);

      function Create_Wrapper
       (Item : Internals.QSqlDatabase_Access)
          return Q_Sql_Database;

      type QSqlQuery is private;

      type QSqlQuery_Access is access all QSqlQuery;
      pragma Convention (C, QSqlQuery_Access);

      function QSqlQuery_View
       (Item : Q_Sql_Query'Class)
          return QSqlQuery_Access;
      pragma Inline (QSqlQuery_View);

      function To_Pointer
       (Address : System.Address)
          return QSqlQuery_Access;
      pragma Inline (To_Pointer);

      function To_Address
       (Pointer : QSqlQuery_Access)
          return System.Address;
      pragma Inline (To_Address);

      function Create_Wrapper
       (Item : Internals.QSqlQuery_Access)
          return Q_Sql_Query;

   private

      type QSqlDatabase is record
         Placeholder : Interfaces.C.char_array (1 .. Qt_Ada.Internals.Value_Class_Sizes.QSqlDatabase_C_Size_Of);
      end record;
      pragma Convention (C, QSqlDatabase);

      type QSqlQuery is record
         Placeholder : Interfaces.C.char_array (1 .. Qt_Ada.Internals.Value_Class_Sizes.QSqlQuery_C_Size_Of);
      end record;
      pragma Convention (C, QSqlQuery);

   end Internals;

private

   type Q_Sql_Database is new Ada.Finalization.Controlled with record
      Storage : aliased Internals.QSqlDatabase;
      Object  : Internals.QSqlDatabase_Access := null;
      Wrapper : Boolean := False;
   end record;

   overriding
   procedure Adjust (Self : in out Q_Sql_Database);

   overriding
   procedure Finalize (Self : in out Q_Sql_Database);

   overriding
   procedure Initialize (Self : in out Q_Sql_Database);

   type Q_Sql_Query is new Ada.Finalization.Controlled with record
      Storage : aliased Internals.QSqlQuery;
      Object  : Internals.QSqlQuery_Access := null;
      Wrapper : Boolean := False;
   end record;

   overriding
   procedure Adjust (Self : in out Q_Sql_Query);

   overriding
   procedure Finalize (Self : in out Q_Sql_Query);

   overriding
   procedure Initialize (Self : in out Q_Sql_Query);

end Qt4.Sql_Databases;
