package AdaBase.Results.Sets is type Datarow is tagged private; Empty_Datarow : constant Datarow; end AdaBase.Results.Sets;
AdaBase.Results.Sets.Datarow function
AdaBase.Statement.Base.[STMT].fetch_next ()
This function attempts to fetch the next row of data from a query's result set. If there is not another row of data available, the Empty_Datarow constant is returned, and the row's data_exhausted method returns False. If more data are available, the function returns a populated Datarow while the client library advances the cursor.
with AdaBase; with Connect; with CommonText; with Ada.Text_IO; with AdaBase.Results.Sets; procedure DS_Fetch is package CON renames Connect; package TIO renames Ada.Text_IO; package ARS renames AdaBase.Results.Sets; package CT renames CommonText; begin CON.DR.set_trait_character_set (""); -- Native charset (Latin1), not UTF-8 CON.connect_database; declare sql : constant String := "SELECT * FROM fruits WHERE color = 'orange'"; stmt : CON.Stmt_Type := CON.DR.query (sql); row : ARS.Datarow; begin TIO.Put_Line (" Query successful: " & stmt.successful'Img); TIO.Put_Line (" Data Discarded: " & stmt.data_discarded'Img); TIO.Put_Line ("Number of columns:" & stmt.column_count'Img); TIO.Put_Line (" Number of rows:" & stmt.rows_returned'Img); TIO.Put_Line (""); for c in Natural range 1 .. stmt.column_count loop TIO.Put_Line ("Column" & c'Img & ":"); TIO.Put_Line (" TABLE: " & stmt.column_table (c)); TIO.Put_Line (" NAME: " & stmt.column_name (c)); TIO.Put_Line (" TYPE: " & stmt.column_native_type (c)'Img); end loop; TIO.Put_Line (""); loop row := stmt.fetch_next; exit when row.data_exhausted; TIO.Put (CT.zeropad (Natural (row.column (1).as_byte2), 2) & " "); declare fruit : String := row.column ("fruit").as_string; frlen : Natural := fruit'Length; rest : String (1 .. 12 - frlen) := (others => ' '); begin TIO.Put (rest & fruit); end; TIO.Put (" (" & row.column ("color").as_string & ") calories ="); TIO.Put_Line (row.column (4).as_byte2'Img); end loop; end; CON.DR.disconnect; end DS_Fetch;
Query successful: TRUE Data Discarded: FALSE Number of columns: 4 Number of rows: 7 Column 1: TABLE: fruits NAME: id TYPE: FT_BYTE4 Column 2: TABLE: fruits NAME: fruit TYPE: FT_TEXTUAL Column 3: TABLE: fruits NAME: color TYPE: FT_TEXTUAL Column 4: TABLE: fruits NAME: calories TYPE: FT_NBYTE2 02 apricot (orange) calories = 30 07 clementine (orange) calories = 24 13 mango (orange) calories = 40 15 cantaloupe (orange) calories = 25 16 nectarine (orange) calories = 25 18 orange (orange) calories = 65 27 tangerine (orange) calories = 26
Query successful: TRUE Data Discarded: FALSE Number of columns: 4 Number of rows: 0 Column 1: TABLE: fruits NAME: id TYPE: FT_BYTE8 Column 2: TABLE: fruits NAME: fruit TYPE: FT_UTF8 Column 3: TABLE: fruits NAME: color TYPE: FT_UTF8 Column 4: TABLE: fruits NAME: calories TYPE: FT_BYTE8 02 apricot (orange) calories = 30 07 clementine (orange) calories = 24 13 mango (orange) calories = 40 15 cantaloupe (orange) calories = 25 16 nectarine (orange) calories = 25 18 orange (orange) calories = 65 27 tangerine (orange) calories = 26
Query successful: TRUE Data Discarded: FALSE Number of columns: 4 Number of rows: 7 Column 1: TABLE: fruits NAME: id TYPE: FT_BYTE4 Column 2: TABLE: fruits NAME: fruit TYPE: FT_UTF8 Column 3: TABLE: fruits NAME: color TYPE: FT_UTF8 Column 4: TABLE: fruits NAME: calories TYPE: FT_BYTE4 02 apricot (orange) calories = 30 07 clementine (orange) calories = 24 13 mango (orange) calories = 40 15 cantaloupe (orange) calories = 25 16 nectarine (orange) calories = 25 18 orange (orange) calories = 65 27 tangerine (orange) calories = 26
[STMT] is "MySQL.MySQL_statement", "PostgreSQL.PostgreSQL_statement", or "SQLite.SQLite_statement"