fernandobatels / rsfbclient

Rust Firebird Client
MIT License
76 stars 11 forks source link

Failed to map BIGINT using i64 #11

Closed silvioprog closed 4 years ago

silvioprog commented 4 years ago

Hi.

Consider the following table structure and its data:

CREATE TABLE test (
  id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL PRIMARY KEY,
  name VARCHAR(100) NOT NULL UNIQUE
);

INSERT INTO test (name) VALUES ('Fulano');
INSERT INTO test (name) VALUES ('Beltrano');
INSERT INTO test (name) VALUES ('Cicrano');

SELECT * FROM test;

-- ID   NAME
-- 1    Fulano
-- 2    Beltrano
-- 3    Cicrano

Now, consider the following example:

use rsfbclient::{Connection, FbError};

fn main() -> Result<(), FbError> {
    let conn = Connection::open("localhost", 3050, "test.fdb", "SYSDBA", "masterkey")?;
    let tr = conn.transaction()?;
    let rows = tr.prepare("SELECT * FROM test")?.query(())?.into_iter();
    println!("| ID | NAME |");
    println!("| -- | ---- |");
    for row in rows {
        let (id, name): (i64, String) = row?;
        println!("| {} | {} |", id, name);
    }
    Ok(())
}

It is returning the following result:

| ID | NAME |
| -- | ---- |
| 4294967297 | Fulano |  
| 8589934594 | Beltrano |
| 12884901891 | Cicrano |

but it should return:

| ID | NAME |
| -- | ---- |   
| 1 | Fulano |  
| 2 | Beltrano |
| 3 | Cicrano |

regards,

P.S.: Changing the column type from i64 to i32 it prints the values properly for short ones, however, it isn't managed to map a full bigint range (-2^63 .. 2^63-1).