Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Improve this question
I have around 100 rows in MS Access, each row includes an attachment. Using RODBC in R I can access the table but have no idea how to access attached files and download them in R
could you plz help me how to do it
Attachments in MS Access are special data types that actually involve nested tables for metadata (filename and filedata) information. Hence, you cannot access this data with DML SQL statements alone via RODBC but can using a COM interface, specifically connecting to the DAO SaveToFile() method.
Consider the following using the RDCOMClient package which allows interfacing to the Access Object Library. Do note: in order to run the below code, you must have MSAccess.exe (the MS Office GUI program) installed and not just the .accdb file. In the SQL query below, ColAttach is the name of the attachment field in your table and you must use those qualifiers .filedata and .filename. DAO recordset field numbers are zero based (hence the 0 and 1).
library(RDCOMClient)
# INITIALIZING OBJECTS
accApp <- COMCreate("Access.Application")
accApp$OpenCurrentDatabase("C:\\Path\\To\\Database.accdb")
docmd <- accApp[["DoCmd"]]
db <- accApp$CurrentDb()
rst <- db$OpenRecordset("SELECT ColAttach.filedata, ColAttach.filename FROM TblAttach")
while(rst$EOF() == FALSE){
rst$Fields(0)$SaveToFile(paste0("C:\\Path\\To\\Output_", rst$Fields(1)$Value()))
rst$MoveNext()
}
# CLOSING OBJECTS
rst$close()
docmd$CloseDatabase()
accApp$Quit()
# RELEASING RESOURCES
accApp <- db <- docmd <- rst <- NULL
rm(rst, db, accApp)
gc()
For multiple attachments, loop through the child recordset on each filename and filedata values (notice the different SQL). Be sure to check if file exists and destroy accordingly else you will receive a COM error:
rst <- db$OpenRecordset("SELECT ID, ColAttach FROM TblAttach")
while(rst$EOF() == FALSE){
childRS <- rst[['ColAttach']]$Value()
while(childRS$EOF() == FALSE){
if (file.exists(paste0("C:\\Path\\To\\Output_", childRS[["filename"]]$Value()))) {
unlink(paste0("C:\\Path\\To\\Output_", childRS[["filename"]]$Value()))
}
childRS[["filedata"]]$SaveToFile(paste0("C:\\Path\\To\\Output_",
childRS[["filename"]]$Value()))
childRS$MoveNext()
}
rst$MoveNext()
}
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 months ago.
Improve this question
I am using Insight.Database version 6.3.10 for SQL Server ORM, using C# as the client. I have a run into an issue where the mapping does not return a correct value for money column data type. I am using decimal in C# client. Below is the sample code:
DROP TABLE IF EXISTS dbo.MyTestTable;
CREATE TABLE dbo.MyTestTable
(
AmountToAllocate MONEY
)
GO
INSERT INTO dbo.MyTestTable VALUES(177279.73)
GO
CREATE OR ALTER PROC [dbo].[MyTestProc]
AS
BEGIN
SELECT TOP 1 m.AmountToAllocate FROM dbo.MyTestTable m
END
GO
I have an object in C# client:
public class MyTestResponse
{
public decimal AmountToAllocate { get; set; }
}
Now, if I execute the store proc with Insight.Database, the returned object has AmountToAllocate property, but its value is 0, instead of 177279.73.
I have no idea what went wrong, and why the mapping does not work properly.
Does anyone know how to resolve it? Thank you
Despite you solving your own problem, for reference for anyone else in the future, you can find all of the SQL Server data type mappings in C# in SQL Server Data Type Mappings.
Money maps to Decimal.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Hi I try to call some data using API but it shows error message of "invalid key". But In the function I didn't figure out where I can input my key. The code is shown below:
sahie_years <- getCensus(
name = "timeseries/healthins/sahie",
vars = c("NAME", "PCTUI_PT"),
region = "state:01",
time = "from 2006 to 2018")
head(sahie_years)
Can anybody have some ideas?
See documentation here for setting up your API key.
You need to sign up for an API key here.
Once you've done that you can either specify your API key by setting an environment variable using Sys.setenv(CENSUS_KEY="YOUR_CENSUS_KEY_GOES_HERE"), or
just set it directly in your getCensus call by adding the argument key = "YOUR_CENSUS_KEY_GOES_HERE".
For API keys in general, it is often easiest to set them in a .Renviron file, which will make them available in each session using Sys.getenv.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have a dictionary object in UFT (VBScript) where it contains items that is array. I want to know how to iterate thru every element in that array item that is refered by key.
Below is the example of my dictionary having items that is array
Set NodeValues = CreateObject("Scripting.Dictionary")
NodeValues.Add "Nodename", Array("EMS", "ACM")
NodeValues.Add "MSW", Array("0x31,0x32,0x33,0x34" , "0x25,0x25,0x12,0x12")
NodeValues.Add "SBL", Array("0x35,0x32,0x30,0x31" , "0x45,0x55,0x22,0x92")
NodeValues.Add "Data", Array(array("0x21,0x21,0x21", "0x11,0x11,0x22") , array("0x45,0x55,0x22,0x92","0x25,0x65,0x25"))
Since this dictionary is generated dynamically am not sure how many elements it will have in array. Now i need to loop thru all the elements in array to find my required elements
For example. How do I iterate thru all the elements in Array of Nodename ( key) untill i find EMS. I tried different ways to access but no success.
Please help me with solution.
To check if "EMS" is found in the array stored for the key Nodename, you can check the following code:
For Each element In NodeValues.Item("Nodename")
If StrComp(element, "EMS", 1) = 0 Then
MsgBox "found"
Exit For
End If
Next
To get the Index:
arrTemp = NodeValues.Item("Nodename")
blnFound = False
For i = 0 To UBound(arrTemp)
If StrComp(arrTemp(i), "EMS", 1) = 0 Then
blnFound = True
Exit For
End If
Next
If blnFound Then
MsgBox "Index: " & i
Else
MsgBox "Not found"
End If
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I'm trying to implement a RPC server in Go using Hprose. It worked fine but then after adding some more functions it didn't :/
Funny thing is that it doesn't work even on other http libraries such as fasthttp. The ListenAndServe() method just seems to be stuck somewhere during execution as it never returns. What might be causing this?
package main
import (
"net/http"
"fmt"
"github.com/hprose/hprose-golang/rpc"
log "logutil"
)
func main() {
log.InitializeLogger()
InitializeEthClient()
InitializeClients()
server := rpc.NewHTTPService()
// TxtStorage functions
server.AddFunction("DeployTxtStorage", DeployNewTxtStorage)
server.AddFunction("GetPackedData", GetPackedData)
server.AddFunction("GetReputation", GetReputation)
server.AddFunction("GetEventsForReputation", GetEventsForReputation)
server.AddFunction("GetEventsForData", GetEventsForData)
// Clients functions
server.AddFunction("RegisterClient", RegisterClient)
log.Info("Registered server functions!")
err := http.ListenAndServe(":8080", server)
fmt.Println(err)
log.Info("Waiting for incoming connections...")
log.WriteAway()
}
ListenAndServe is blocking, it won't return unless it hits an error. You seem to be expecting your final lines to print out
Waiting for incoming connections...
But that will never happen as the server is running. Are you sure it isn't just working as expected?
I have encountered an error when trying to insert thousands of rows with R/RJDBC and the dbSendUpdate command on an Oracle database.
Problem can be reproduced by creating a test table with
CREATE TABLE mytest (ID NUMBER(10) not null);
and then executing the following R script
library(RJDBC)
drv<-JDBC("oracle.jdbc.OracleDriver","ojdbc-11.1.0.7.0.jar") # place your JDBC driver here
conn <- dbConnect(drv, "jdbc:oracle:thin:#MYSERVICE", "myuser", "mypasswd") # place your connection details here
for (i in 1:10000) {
dbSendUpdate(conn,"INSERT INTO mytest VALUES (?)",i))
}
Searching the Internet provided the information, that one should close result cursors, which is obvious (e.g. see java.sql.SQLException: - ORA-01000: maximum open cursors exceeded or Unable to resolve error - java.sql.SQLException: ORA-01000: maximum open cursors exceeded).
But the help file for ??dbSendUpdate claims for not using result cursors at all:
.. that dbSendUpdate is used with DBML queries and thus doesn't return any result set.
Therefore this behavior doesn't make much sense to me :-(
Can anybody help?
Thanks, a lot!
PS: Found something interessting in the RJDBC documentation http://www.rforge.net/RJDBC/
Note that the life time of a connection, result set, driver etc. is determined by the lifetime of the corresponding R object. Once the R handle goes out of scope (or if removed explicitly by rm) and is garbage-collected in R, the corresponding connection or result set is closed and released. This is important for databases that have limited resources (like Oracle) - you may need to add gc() by hand to force garbage collection if there could be many open objects. The only exception are drivers which stay registered in the JDBC even after the corresponding R object is released as there is currently no way to unload a JDBC driver (in RJDBC).
But again, even inserting gc() within the loop will produce the same beahvoir.
Finally we realized this being a bug in package RJDBC. If you are willing to patch RJDBC you can use the patched sources available at https://github.com/Starfox899/RJDBC (as long as they are not imported into the package).