Skip to content

Commit

Permalink
fix: call before_first for call next
Browse files Browse the repository at this point in the history
  • Loading branch information
cutsea110 committed Mar 31, 2024
1 parent 6199173 commit c93dbb0
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/embedded/execquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ fn print_result_set(mut results: EmbeddedResultSet) -> Result<i32> {
println!();
// scan record
let mut c = 0;
results.before_first()?;
while results.next() {
c += 1;
print_record(&mut results, &meta)?;
Expand Down
1 change: 1 addition & 0 deletions app/network/execquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async fn print_result_set(mut results: NetworkResultSet) -> Result<(i32, i32)> {
println!();
// scan record
let mut total_count = 0;
results.before_first().expect("before first");
loop {
let rows = results.get_rows(MAX_ROWS, &meta).await.expect("get rows");
let c = rows.len();
Expand Down
21 changes: 11 additions & 10 deletions capnp/remote.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,17 @@ interface DateBox {
interface RemoteResultSet {
# result set

next @0 () -> (val :BoolBox);
close @1 () -> (res :TxBox);
getMetadata @2 () -> (metadata :RemoteMetaData);
getInt16 @3 (fldname :Text) -> (val :Int16Box);
getInt32 @4 (fldname :Text) -> (val :Int32Box);
getString @5 (fldname :Text) -> (val :StringBox);
getBool @6 (fldname :Text) -> (val :BoolBox);
getDate @7 (fldname :Text) -> (val :DateBox);
getRow @8 () -> (row :Row); # get one record
getRows @9 (limit :UInt32) -> (count :UInt32, rows :List(Row)); # get records up to limit
beforeFirst @0 () -> (val :BoolBox);
next @1 () -> (val :BoolBox);
close @2 () -> (res :TxBox);
getMetadata @3 () -> (metadata :RemoteMetaData);
getInt16 @4 (fldname :Text) -> (val :Int16Box);
getInt32 @5 (fldname :Text) -> (val :Int32Box);
getString @6 (fldname :Text) -> (val :StringBox);
getBool @7 (fldname :Text) -> (val :BoolBox);
getDate @8 (fldname :Text) -> (val :DateBox);
getRow @9 () -> (row :Row); # get one record
getRows @10 (limit :UInt32) -> (count :UInt32, rows :List(Row)); # get records up to limit

struct Row {
# record
Expand Down
4 changes: 4 additions & 0 deletions src/rdbc/embedded/resultset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl<'a> EmbeddedResultSet<'a> {

impl<'a> ResultSetAdapter for EmbeddedResultSet<'a> {
type Meta = EmbeddedMetaData;
type Setuped = ();
type Next = bool;
type Int16Value = i16;
type Int32Value = i32;
Expand All @@ -40,6 +41,9 @@ impl<'a> ResultSetAdapter for EmbeddedResultSet<'a> {
type DateValue = NaiveDate;
type Res = ();

fn before_first(&self) -> Result<Self::Setuped> {
self.s.lock().unwrap().before_first()
}
fn next(&self) -> Self::Next {
self.s.lock().unwrap().next()
}
Expand Down
25 changes: 25 additions & 0 deletions src/rdbc/network/resultset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ use crate::{
remote_capnp::{bool_box, date_box, int16_box, int32_box, remote_result_set, string_box},
};

pub struct SetupedImpl {
client: bool_box::Client,
}
impl SetupedImpl {
pub fn new(client: bool_box::Client) -> Self {
Self { client }
}
pub async fn has_value(&self) -> Result<bool> {
let reply = self.client.read_request().send().promise.await?;
Ok(reply.get()?.get_val())
}
}

pub struct NextImpl {
client: bool_box::Client,
}
Expand Down Expand Up @@ -234,6 +247,7 @@ impl NetworkResultSet {

impl ResultSetAdapter for NetworkResultSet {
type Meta = NetworkResultSetMetaData;
type Setuped = SetupedImpl;
type Next = NextImpl;
type Int16Value = Int16ValueImpl;
type Int32Value = Int32ValueImpl;
Expand All @@ -242,6 +256,17 @@ impl ResultSetAdapter for NetworkResultSet {
type DateValue = DateValueImpl;
type Res = ResponseImpl;

fn before_first(&self) -> Result<Self::Setuped> {
let val = self
.resultset
.before_first_request()
.send()
.pipeline
.get_val();

Ok(Self::Setuped::new(val))
}

fn next(&self) -> Self::Next {
let exists = self.resultset.next_request().send().pipeline.get_val();

Expand Down
2 changes: 2 additions & 0 deletions src/rdbc/resultsetadapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl fmt::Display for ResultSetError {

pub trait ResultSetAdapter {
type Meta: ResultSetMetaDataAdapter;
type Setuped;
type Next;
type Int16Value;
type Int32Value;
Expand All @@ -41,6 +42,7 @@ pub trait ResultSetAdapter {
type DateValue;
type Res;

fn before_first(&self) -> Result<Self::Setuped>;
fn next(&self) -> Self::Next;
fn get_i16(&mut self, fldname: &str) -> Result<Self::Int16Value>;
fn get_i32(&mut self, fldname: &str) -> Result<Self::Int32Value>;
Expand Down

0 comments on commit c93dbb0

Please sign in to comment.