Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example shows 0s, instead of the inserted data #13

Closed
spytheman opened this issue Jul 27, 2021 · 4 comments · Fixed by #14
Closed

example shows 0s, instead of the inserted data #13

spytheman opened this issue Jul 27, 2021 · 4 comments · Fixed by #14
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@spytheman
Copy link
Contributor

Running the example produces 0, instead of the inserted values:
image

import elliotchance.vsql.vsql

fn main() {
	mut db := vsql.open('/tmp/test.vsql') ?

	// All SQL commands use query():
	db.query('CREATE TABLE foo (a FLOAT)') ?
	db.query('INSERT INTO foo (a) VALUES (1.23)') ?
	db.query('INSERT INTO foo (a) VALUES (4.56)') ?

	// Iterate through a result:
	result := db.query('SELECT * FROM foo') ?
	for row in result {
		println(row.get_f64('a'))
	}

	// See SQLSTATE (Errors) below for more examples.
}

The values are inside the /tmp/test.vsql as validated by running the vsql-cli.v later.

@spytheman
Copy link
Contributor Author

If I change the loop to do println(row), I get:

elliotchance.vsql.vsql.Row{
    offset: 58
    data: {'A': elliotchance.vsql.vsql.Value{
        typ: FLOAT
        f64_value: 1.23
        string_value: ''
    }}
}
elliotchance.vsql.vsql.Row{
    offset: 78
    data: {'A': elliotchance.vsql.vsql.Value{
        typ: FLOAT
        f64_value: 4.56
        string_value: ''
    }}
}

so the data is there, but perhaps .get_f64() can not access it 🤔

@spytheman
Copy link
Contributor Author

println(row.get_f64('A')) shows the values

@elliotchance
Copy link
Owner

Ah yes, sorry. In a recent update (v0.2.4 - #6) to conform to the SQL standard, all regular (non-delimited) identifiers are represented in upper case. I forgot to update the example to be row.get_f64('A').

That Row actually needs some love. It should return an error with a helpful message instead of returning a misleading value:

println(row.get_f64('Foo') ?)
// no such column Foo, did you mean FOO?

Alternatively, CREATE TABLE foo ("a" FLOAT) would allow you to use row.get_f64('a').

@elliotchance elliotchance added bug Something isn't working good first issue Good for newcomers labels Jul 27, 2021
@spytheman
Copy link
Contributor Author

imho returning a helpful error is better - code is written just once, and the error will be caught in development; forcing get_f64 functions to upcase their arguments will happen in production too

elliotchance added a commit that referenced this issue Jul 28, 2021
- The `Row` now has new functions for `get_bool`, `get_null` and
`get_unknown` for respective value types.
- The get methods are sensitive to returning only on the correct types
(ie. `get_f64` can only be used on numeric values).
- An error is returned from any get method if the column does not exist.
- Should a column not exist but there is a column with a different
case, a more helpful message is returned like
"no such column foo, did you mean FOO?"

Fixes #13
elliotchance added a commit that referenced this issue Jul 28, 2021
- The `Row` now has new functions for `get_bool`, `get_null` and
`get_unknown` for respective value types.
- The get methods are sensitive to returning only on the correct types
(ie. `get_f64` can only be used on numeric values).
- An error is returned from any get method if the column does not exist.
- Should a column not exist but there is a column with a different
case, a more helpful message is returned like
"no such column foo, did you mean FOO?"

Fixes #13
elliotchance added a commit that referenced this issue Jul 28, 2021
- The `Row` now has new functions for `get_bool`, `get_null` and
`get_unknown` for respective value types.
- The get methods are sensitive to returning only on the correct types
(ie. `get_f64` can only be used on numeric values).
- An error is returned from any get method if the column does not exist.
- Should a column not exist but there is a column with a different
case, a more helpful message is returned like
"no such column foo, did you mean FOO?"

Fixes #13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants