I'm trying to use R's DBI library to create a view on an Athena database, connected via JDBC. The dbSentStatement command, which is supposed to submit and execute arbitrary SQL without returning a result, throws an error when no result set is returned:
DBI::dbSendStatement(athena_con, my_query)
Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set", :
Unable to retrieve JDBC result set
JDBC ERROR: [Simba][JDBC](11300) A ResultSet was expected but not generated from query <query repeated here>
In addition, the view is not created.
I've tried other DBI commands that seemed promising (dbExecute, dbGetQuery, dbSentQuery), but they all throw the same error. (Actually, I expect them all to - dbSendStatement is the one that, from the manual, should work.)
Is there some other way to create a view using DBI, dbplyr, etc.? Or am I doing this right and its a limitation of RJDBC or the driver?
RJDBC pre-dates the more recent DBI specification and uses a different function to access this functionality: RJDBC::dbSendUpdate(con, query) .
DBI's dbSendStatement() doesn't work here yet. For best compatibility, RJDBC could implement this method and forward it to its dbSendUpdate() .
Without given more details of your query, I cannot promise this helps:
But for my case:
nrow <- dbExecute(con, paste0("CREATE VIEW ExampleView AS",
"Random statements"))
Would help you create a view on your backend.
Difference: I'm using SQLite.
Related
I have set up FTS5 (full-text search) with virtual tables in sqlite. MATCH queries are working except it always throws a syntax error on initial token queries.
For example: SELECT * FROM fts_article WHERE fts_article MATCH '^suo' throws
Error calling sqlite3_step (1: fts5: syntax error near "^") rs
I've tried all the syntax variations listed in the docs, getting the same error.
(In production code I will be using bound parameters, and I've tried it that way also.)
UPDATE: Some additional context: I am using the sqlite baked into libsqlcipher-ios.a from SQLCipher. And I am running my sql through FMDB. I have tried calling the sqlite api directly. In that case, the error seems to go away but I'm not seeing the results I expect. Still investigating ...
what is the difference between src_postgres and dbConnect function? Both can be used to connect R with postgres using the RPosgresql package. In my experiments I only could use src_postgres to read and dbConnect to write to the database.
When I tried it in different combinations I only received errors.
This seems fairly strange to me.
src_postgres is a function for creating a connection to a PostgreSQL database from the dplyr package. The RPostgreSQL package implements a method for the generic dbConnect from the DBI package. src_postgres calls dbConnect from RPostgreSQL (I assume).
The generic connection object returned by dbConnect is meant to be an open ended interface for sending SQL queries to the data base. This means you could feed it any select, update, insert, delete, etc. query that you like.
src_postgres is part of the higher level interface to working with data from databases that Hadley built in dplyr. The src_* functions connect to a db and then the tbl functions specify a more specific data source (table, view, arbitrary select query) to pull data from. There are some basic table manipulation functions in dplyr but I don't believe it is intended to be a tool for doing update or insert type things in the db. That's just not what that tool is for. Note that the "verbs" implemented in dplyr are all focused on pulling data out and summarising (select, filter, mutate, etc.).
If you need to alter data in a data base on a row level, you'll need to send SQL queries to a connection created by dbConnect. If all you're doing is pulling data from a db and analyzing it in R, that is what dplyr is for.
I'm trying to use a SQLite database a linked server in SSMS. I've managed to get the ODBC driver installed and a linked server created, but I can't seem to find a way to get queries to work. I think it's just a matter of not understanding the proper syntax for it. Here's what I've tried:
exec sp_tables_ex 'SQLITE'
This works as expected, showing all of the tables in the database.
select * from SQLITE.[default].dbo.TRANSLATION
Fails with this error message
Invalid use of schema or catalog for OLE DB provider "MSDASQL" for
linked server "SQLITE". A four-part name was supplied, but the
provider does not expose the necessary interfaces to use a catalog or
schema.
Taking a clue from that, I tried removing the schema:
select * from SQLITE.[default].TRANSLATION
But this gives me another error message:
Invalid object name 'SQLITE.default.TRANSLATION'.
Likewise, the following give the same error (with slight changes for the object name):
select * from SQLITE.[default].TRANSLATION
select * from SQLITE.dbo.TRANSLATION
select * from SQLITE.TRANSLATION
Any ideas? I'm not quite sure what to try from here.
In a brand new MS Access 2010 database, I linked to two tables from a SQLite database using an ODBC connection. I have the following union query:
SELECT Calibration_Header.Gage_ID FROM Calibration_Header
UNION SELECT CHArchive.Gage_ID FROM CHArchive;
If I execute this SQL against the same database using the sqlite3 command line application, it runs successfully and returns the proper data. When I run the query in the MS Access 2010 database, I get the following error message:
ODBC--call failed.
near "(": syntax error (1) (#1)
Other union queries against different tables get the same error message when run in MS Access. When run in the sqlite3 command line, they run successfully and return the proper data.
I suspect that a UNION SELECT is not in the standard Access vernacular. You can try implementing ANSI-92 in Access 2010 and then running your query as code, as described by Albert Kallal at http://www.utteraccess.com/forum/Create-View-Access-t1924479.html&p=1924500#entry1924500. I used these instructions to successfully create an Access "view".
I realise that this is a very old thread, but I have just had this problem and found a pretty simple solution, so thought it worth sharing in case anyone else has the problem. Although Access seems unable to run a UNION query on two linked tables, if you create a pass-through query and put the SQL for the UNION in there, it works ok. Presumably the SQL is then executed by SQLite and the results returned as a single resultset, rather than Access itself trying to apply the UNION to two separate resultsets.
I am unable to test in earlier versions, but it works in Access 2016.
I don't know that this is an RSQLite/RMySQL conflict, but that's my best guess so far.
I use RMySQL to get data from a MySQL database, then I close that connection with dbDisconnect(). Then I use these data to in a record linking process using the RLBigDataLinkage() function in the RecordLinkage package. This function uses an SQLite database and the RSQLite package because there are two many possible matches to keep all of them in memory. As far as I can tell from the documentation, there is no way to explicitly close the SQLite connection.
Then I use these matches to pull a larger dataset from my MySQL database, again with RMySQL. I can connect to the database, but when I query, I get the following error:
Error in mysqlExecStatement(conn, statement, ...) :
RS-DBI driver: (could not run statement: MySQL server has gone away)
This happens even with trivial queries.
> dbGetQuery(db, "SELECT * FROM ann_id_info LIMIT 5")
Error in mysqlExecStatement(conn, statement, ...) :
RS-DBI driver: (could not run statement: MySQL server has gone away)
I can still query from the MySQL command line, though.
Is there a way I can disconnect an "unknown" RSQLite connection? Thanks!