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

Database#execute does not return a ResultSet #561

Closed
rickhull opened this issue Sep 16, 2024 · 1 comment
Closed

Database#execute does not return a ResultSet #561

rickhull opened this issue Sep 16, 2024 · 1 comment

Comments

@rickhull
Copy link
Contributor

rickhull commented Sep 16, 2024

See the FAQ here: https:/sparklemotion/sqlite3-ruby/blob/main/FAQ.md#how-do-i-discover-metadata-about-a-query

rows = db.execute( "select * from table" )
p rows[0].fields
p rows[0].types

This doesn't actually work. Database#execute returns an Array of Arrays.

require 'sqlite3'

db = SQLite3::Database.new('tmp.db')
rows = db.execute "select true"

p rows[0].fields #=> undefined method `fields' for an instance of Array (NoMethodError)

The FAQ seems to imply ResultSet behavior, but AFAICT, you only get a ResultSet from Statement#execute but not Database#execute. I lean towards unifying the behavior.

@flavorjones
Copy link
Member

@rickhull Thanks for pointing this out.

The behavior you're seeing (Database#execute returning an array) has not changed at least since 2005. The FAQ (which was written in 3e5a784 circa 2014) is in error. If you'd be willing to correct the FAQ in a PR that would be very valuable and you would have my thanks!

Changing what that method returns now would break many applications, unfortunately.

rickhull added a commit to rickhull/sqlite3-ruby that referenced this issue Sep 17, 2024
Updated several inaccuracies, per Issue sparklemotion#561
@rickhull rickhull mentioned this issue Sep 17, 2024
flavorjones pushed a commit that referenced this issue Sep 18, 2024
* Update FAQ.md

Updated several inaccuracies, per Issue #561

* fix typo
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

2 participants