/*
 * Copyright (c) 2015, 2025, Oracle and/or its affiliates.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, version 2.0,
 * as published by the Free Software Foundation.
 *
 * This program is designed to work with certain software (including
 * but not limited to OpenSSL) that is licensed under separate terms,
 * as designated in a particular file or component or in included license
 * documentation.  The authors of MySQL hereby grant you an additional
 * permission to link the program and your derivative works with the
 * separately licensed software that they have either included with
 * the program or referenced in the documentation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License, version 2.0, for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 */

syntax = "proto2";

// ifdef PROTOBUF_LITE: option optimize_for = LITE_RUNTIME;

/**
@namespace Mysqlx::Cursor
@brief Handling of Cursors
*/

package Mysqlx.Cursor;
option java_package = "com.mysql.cj.x.protobuf";

import "mysqlx.proto"; // comment_out_if PROTOBUF_LITE
import "mysqlx_prepare.proto";


/**
Open a cursor

@startuml
client -> server: Open
alt Success
    ... none or partial Resultsets or full Resultsets ...
    client <- server: StmtExecuteOk
else Failure
    client <- server: Error
end alt
@enduml

@returns @ref Mysqlx::Ok
*/
message Open {
  /** client-side assigned cursor ID; the ID is going to represent
      the new cursor and assigned to it the statement */
  required uint32 cursor_id = 1;

  message OneOfMessage {
    enum Type {
      PREPARE_EXECUTE = 0;
    }
    required Type type = 1;

    optional Mysqlx.Prepare.Execute prepare_execute = 2;
  }
  /** statement for which the resultset is going to be iterated through by the cursor */
  required OneOfMessage stmt = 4;

  /** number of rows that should be retrieved from sequential cursor */
  optional uint64 fetch_rows = 5;

  option (client_message_id) = CURSOR_OPEN; // comment_out_if PROTOBUF_LITE
}


/**
Fetch next portion of data from a cursor

@startuml
client -> server: Fetch
alt Success
  ... none or partial Resultsets or full Resultsets ...
  client <- server: StmtExecuteOk
else
 client <- server: Error
end
@enduml
*/
message Fetch {
  /** client-side assigned cursor ID; must be already open */
  required uint32 cursor_id = 1;

  /** number of rows that should be retrieved from sequential cursor */
  optional uint64 fetch_rows = 5;

  option (client_message_id) = CURSOR_FETCH; // comment_out_if PROTOBUF_LITE
}


/**
Close cursor

@startuml
client -> server: Close
alt Success
  client <- server: Ok
else Failure
  client <- server: Error
end
@enduml

@returns @ref Mysqlx::Ok or @ref Mysqlx::Error
*/
message Close {
  /** client-side assigned cursor ID; must be allocated/open */
  required uint32 cursor_id = 1;

  option (client_message_id) = CURSOR_CLOSE; // comment_out_if PROTOBUF_LITE
}
