Skip to content

Queries fail when an empty array is passed #39

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

Closed
thanhnguyen2187 opened this issue Feb 11, 2024 · 1 comment
Closed

Queries fail when an empty array is passed #39

thanhnguyen2187 opened this issue Feb 11, 2024 · 1 comment

Comments

@thanhnguyen2187
Copy link
Contributor

thanhnguyen2187 commented Feb 11, 2024

Hi!

On testing #38, I found a subtle bug where ws4sqlite would not be able to process if an empty array is passed. In more details:

# start the server
ws4sqlite --db /tmp/crypta.db

# sending request
curl \
    -X POST \
    --header 'Content-Type: application/json' \
    --data @/tmp/data.json \
    --fail-with-body \
    127.0.0.1:12321/crypta \
| jq

Where /tmp/data's content is:

{
    "transaction": [
        {
            "query": "SELECT 1",
            "values": []
        }
    ]
}

The response is:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   257  100   156  100   101   420k   272k --:--:-- --:--:-- --:--:--  250k
curl: (22) The requested URL returned error: 400
{
  "reqIdx": -1,
  "error": "in parsing body: json: cannot unmarshal array into Go struct field requestItem.transaction.values of type map[string]json.RawMessage"
}

A workaround for this is to change from empty array [] to empty object/dictionary {}.

I'll see if I can help with this in another PR.

Thanks!


EDIT: this is expected. ws4sqlite differs from sqliterg in this regard 😅.

@thanhnguyen2187
Copy link
Contributor Author

thanhnguyen2187 commented Feb 11, 2024

If the query needs to be parametrized, named parameters can be defined in the statement using SQLite (e.g. :id or @id), and the proper values for them must be specified here. You can specify values that do not match a parameter; they'll be ignored.

https://germ.gitbook.io/ws4sqlite/documentation/requests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant