Skip to content

Commit

Permalink
Merge pull request #262 from libsql/fix_query
Browse files Browse the repository at this point in the history
Fix query
  • Loading branch information
penberg authored Aug 9, 2023
2 parents dbc4fd9 + a8492a5 commit 301d81e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 6 additions & 0 deletions crates/bindings/go/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
14 changes: 10 additions & 4 deletions crates/bindings/go/libsql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,17 @@ func TestQueryWithEmptyResult(t *testing.T) {
t.Fatal(err)
}
defer rows.Close()
if columns, err := rows.Columns(); len(columns) > 0 || err != nil {
t.Fatal("columns should be nil")
columns, err := rows.Columns()
if err != nil {
t.Fatal(err)
}
assert.DeepEqual(t, columns, []string{"NULL", "id", "name", "gpa", "cv"})
types, err := rows.ColumnTypes()
if err != nil {
t.Fatal(err)
}
if columnTypes, err := rows.ColumnTypes(); len(columnTypes) > 0 || err != nil {
t.Fatal("column types should be nil")
if len(types) != 5 {
t.Fatal("types should be 5")
}
for rows.Next() {
t.Fatal("there should be no rows")
Expand Down
8 changes: 6 additions & 2 deletions crates/core/src/statement.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::rows::{MappedRows, Row};
use crate::{errors, Connection, Error, Params, Result, Rows, ValueRef};

use std::cell::RefCell;
use std::ffi::c_int;
use std::sync::Arc;

Expand Down Expand Up @@ -42,8 +43,11 @@ impl Statement {

pub fn query(&self, params: &Params) -> Result<Rows> {
self.bind(params);

Ok(Rows::new(self.inner.clone()))
let err = self.inner.step();
Ok(Rows {
stmt: self.inner.clone(),
err: RefCell::new(Some(err)),
})
}

pub fn query_row(&self, params: &Params) -> Result<Row> {
Expand Down

0 comments on commit 301d81e

Please sign in to comment.