Created
September 8, 2012 22:52
-
-
Save killerswan/3680618 to your computer and use it in GitHub Desktop.
sqlite3 Rust bindings, subtle problem with `&const <T>`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ git rebase -i to_rust4~4 | |
| Successfully rebased and updated refs/heads/to_rust4. | |
| kunix:rustsqlite $ rustc --test sqlite.rc | |
| sqlite.rs:605:31: 605:42 error: mismatched types: expected `&const <V88>` but found `sqlite_bind_arg` (expected &-ptr but found enum sqlite_bind_arg) | |
| sqlite.rs:605 assert x.get(~"id") == integer(2); | |
| ^~~~~~~~~~~ | |
| sqlite.rs:606:31: 606:42 error: mismatched types: expected `&const <V179>` but found `sqlite_bind_arg` (expected &-ptr but found enum sqlite_bind_arg) | |
| sqlite.rs:606 assert x.get(~"k") == text(~"e"); | |
| ^~~~~~~~~~~ | |
| sqlite.rs:607:31: 607:44 error: mismatched types: expected `&const <V270>` but found `sqlite_bind_arg` (expected &-ptr but found enum sqlite_bind_arg) | |
| sqlite.rs:607 assert x.get(~"v") == number(2.17); | |
| ^~~~~~~~~~~~~ | |
| sqlite.rs:605:15: 605:42 error: cannot determine a type for this bounded type parameter: unconstrained type | |
| sqlite.rs:605 assert x.get(~"id") == integer(2); | |
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| enum sqlite_bind_arg { | |
| text(~str), | |
| number(float), | |
| integer(int), | |
| blob(~[u8]), | |
| null(), | |
| } | |
| ... | |
| #[test] | |
| fn step_row_basics() { | |
| let dbh = checked_open(); | |
| checked_exec(dbh, | |
| ~" | |
| BEGIN; | |
| CREATE TABLE IF NOT EXISTS test (id INTEGER, k TEXT, v REAL); | |
| INSERT OR IGNORE INTO test (id, k, v) VALUES(1, 'pi', 3.1415); | |
| INSERT OR IGNORE INTO test (id, k, v) VALUES(2, 'e', 2.17); | |
| INSERT OR IGNORE INTO test (id, k, v) VALUES(3, 'o', 1.618); | |
| COMMIT; | |
| " | |
| ); | |
| let sth = checked_prepare(dbh, ~"SELECT * FROM test WHERE id=2"); | |
| let r: sqlite_result<sqlite_row_result> = sth.step_row(); | |
| let possible_row: sqlite_row_result = result::get(r); | |
| match possible_row { | |
| row(x) => { | |
| // x is a map::hashmap<~str, sqlite_bind_arg> | |
| assert x.get(~"id") == integer(2); | |
| assert x.get(~"k") == text(~"e"); | |
| assert x.get(~"v") == number(2.17); | |
| } | |
| done => { | |
| fail(~"didnt get even one row back."); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment