How to receive a success message from Teradata to R? - r

first time poster here. I’m using R to ‘automate’ some Teradata (TD) SQL scripts. The ones that return data are working great. But I have an UPDATE SQL statement that only returns a message in TD like ‘xxx rows updated’. I’m using the RODBC package in R for my connection. When I use ‘sqlQuery’ and send the ‘update’ SQL statement to TD from R, I get nothing back, whether successful or not. I know only data returning is normal here, but what I want is to get that message back from TD to R. Then I can continue to ‘automate’ things based on the message. Is there a way, either in putting something in the SQL code at the end, or afterwards with R, to get this ‘successful’ message back?
Package RODBC has “odbcGetErrMsg”, but it doesn’t work on the success message. The only workaround I can think of is to do a count() before the update, then send the update statement, then count() after to get a number of rows changed. This may work, but I’d like to get the message instead. I’ve searched SO & Googled this with no luck. Any ideas of how to get a successful TD message from an update statement sent from R returned back in R please?

Related

Error linking RShiny forms to SQLite database

I'm trying to link data entered into a Shiny form to SQLite. The Shiny part works just fine as I've tried saving the data to an excel file. When I try to write the data to SQLite, I keep getting this error "Near "delete": syntax error" -- any ideas on what it could possible be? I've also tried this with just three input variables and it writes it just fine to SQLite but with ~20 variables, I keep getting this error.
Your variables should be quoted when sending statements to SQLite. If your variable of interest is generated by an input you can quote it like this paste0('"',input$variable,'"')

what is the reason for my syntax error in stored procedure mariadb?

DELIMITER //
CREATE PROCEDURE dbo.CleanupBackupRepositories ()
MODIFIES SQL DATA
DELETE HISTORY
FROM BackupRepositories
BEFORE SYSTEM_TIME DATE_ADD(CURRENT_DATE,INTERVAL 1YEAR);
//
DELIMITER;
i am trying to delete old history from this table but i get an syntax error on the line :
BEFORE SYSTEM_TIME DATE_ADD(CURRENT_DATE,INTERVAL 1YEAR);
every example i have checked tells me to do it like this? thanks for your time and effort!
There is a missing space between 1YEAR.
You also might want to use DATE_SUB as DATE_ADD results in 2022-08-12, not 2020-08-12. The way it is now, it would effectively wipe out all the history.

SQLite report on conflict

I'm using INSERT OR IGNORE and INSERT OR REPLACE , I'm trying to get SQLite to report whenever the OR IGNORE or OR REPLACE condition occurred.
I looked into using TRIGGER but wasn't able to get it to work as expected.
The desired behaviour is to raise a warning when the OR condition was true.
It would be possible to combine AFTER INSERT/DELETE triggers with user-defined functions to report whether some rows got inserted/deleted or not.
However, these statements are intended to be used when you do not care about which case actually happened.
The easiest way to detect if the same value already exists in the table is to run a SELECT.

Is there some limitation of query length in RODBC sqlQuery() function?

I wonder if there is query length limitation for sqlQuery function from RODBC package? I can't find any information in documentation but that's my hypothesis.
The thing is that when I use Hive editor to write a query I get correct output for my queries (including the long one). But when I connect through the sqlQuery() the long query (~250) doesn't work. I get error:
[RODBC] ERROR: Could not SQLExecDirect 'my long query here'
I can't think about different reason why the query works in Hive editor and does not work with sqlQuery().
I know 250 lines is a lot for SQL query but unfortunately I don't have permission to create temporary table in database I work with, so I do it in my code and that's why the code is so long. There's no way I can shorten the code.
Any help appreciated.

XOJO delete a record from SQLite database

I am using Xojo 2013 Version 1. I am trying to delete a record from a SQLite database. But I am failing miserably. Instead of deleting the record, it duplicates it for some reason.
Here is the code that I use:
command = "DELETE * from names where ID = 10"
namesDB.SQLExecute(command)
I am dynamically generating command. but however I change it it always does the same. Same result with or without quotes.
Any ideas?
The very first thing I would do is check to see if there is an error being generated.
if namesDB.Error then
dim s as string = namesDB.errorMessage
msgbox s
return
end
It will tell you if there's a database error and what the error is. If there's no error then the problem lies elsewhere.
FWIW, always, always, always check the error bit after every db operation. Unlike other languages, Xojo does NOT generate/throw an exception if there's a database error so it's up to you to check it.
Try calling Commit().
I just made a sample SQLite database with a "names" table, and this code worked fine:
db.SQLExecute("Delete from names where ID=2")
db.Commit
I have done a lot of work with XOJO and SQLite, and they work well together. I have never seen a record duplicated erroneously as you report. That is very weird. If this doesn't help, post more of your code. For example, I assume your "command" variable is a String, but maybe it's a Variant, etc.
I think on SQLite you don't need the * between the DELETE and the FROM.

Resources