Closed
Description
I recently tried to use SQLite and ran into several issues.
The example in the doc that uses the Chinook DB is broken. it doesn't contain a "using DBInterface" line, and so the first use of DBInterface causes an error, i.e.,
DBInterface.execute(db, "SELECT FirstName, LastName FROM Employee WHERE LastName REGEXP 'e(?=a)'") |> DataFrame
doesn't work.
Using
SQLite.execute(db, sql)
as a query will succeed, i.e. will not cause an error, but seems to simply return an integer.
however,
DBInterface.execute(db, sql)
does work correctly.
It appears that DBInterface is the long term interface to SQLite. However it seems like some things, like the query, should use DBInterface, while others, like tables(), should use SQLite.
What I can offer is my very simple example test code to help people get started :-)
using SQLite
using DataFrames
using DBInterface
# DROP TABLE IF EXISTS Test1;
# CREATE TABLE Test1 (
# field1 TEXT,
# field2 INTEGER,
# field3 REAL
# );
# to create the DB
# cat test1.sql | sqlite3 test1.db
# quick and easy way to see what's in it
# echo "select * from Test1" | sqlite3 test1.db
function main()
dbname = "test1.db"
db = SQLite.DB(dbname)
x = rand(1:100)
y = randn()
sql = "insert into Test1 (field1, field2, field3) values (\"foo\", $(x), $(y))"
SQLite.execute(db, sql)
tables = SQLite.tables(db)
println(tables)
cols = SQLite.columns(db, "Test1")
println(cols)
println(cols.name)
println(cols.type)
sql = "select * from Test1"
# this isn't working. always returns 100 ...
# s = SQLite.execute(db, sql)
s = DBInterface.execute(db, sql)
for r in s
println(r)
end
s = DBInterface.execute(db, sql) |> DataFrame
println(s)
end
main()
Metadata
Metadata
Assignees
Labels
No labels