Domanda

Con funzionalità dal pacchetto RODBC, ho creato con successo un ODBC ma riceve i messaggi di errore quando provo a interrogare il database.Sto usando il driver informix 3.31 a 32 bit (versione 3.31.00.10287).

channel <- odbcConnect("exampleDSN")
unclass(channel)
[1] 3
attr(,"connection.string")
[1] "DSN=exampleDSN;UID=user;PWD=****;DB=exampleDB;HOST=exampleHOST;SRVR=exampleSRVR;SERV=exampleSERV;PRO=onsoctcp ... (more parameters)"
attr(,"handle_ptr")
<pointer: 0x0264c098>
attr(,"case")
[1] "nochange"
attr(,"id")
[1] 4182
attr(,"believeNRows")
[1] TRUE
attr(,"colQuote")
[1] "\""
attr(,"tabQuote")
[1] "\""
attr(,"interpretDot")
[1] TRUE
attr(,"encoding")
[1] ""
attr(,"rows_at_time")
[1] 100
attr(,"isMySQL")
[1] FALSE
attr(,"call")
odbcDriverConnect(connection = "DSN=exampleDSN")
.

Quando provo a interrogare e indagare sulla struttura dell'oggetto restituito, ricevo un messaggio di errore 'CHR [1: 2] "42000 -201 [INFICIX] [Driver Informix ODBC] [Informix] Si è verificato un errore di sintassi."... '

In particolare, ho scritto un'espressione da loop attraverso tutte le tabelle nel database, recuperare 10 righe e indagare sulla struttura dell'oggetto restituito.

for (i in 1:153){res <- sqlFetch(channel, sqlTables(channel, tableType="TABLE")$TABLE_NAME[i], max=10); str(res)}
.

Ogni iterazione restituisce lo stesso messaggio di errore.Qualche idea da dove iniziare?

Informazioni aggiuntive: quando restituisco l'oggetto 'res', ricevo il seguente -

> res
[1] "42000 -201 [Informix][Informix ODBC Driver][Informix]A syntax error has occurred."
[2] "[RODBC] ERROR: Could not SQLExecDirect 'SELECT * FROM \"exampleTABLE\"'"
.

È stato utile?

Soluzione

You can try using the sqlQuery() function in RODBC to retrieve your results. This is the function I use at work and have never had a problem with it:

sqlQuery(channel, "select top 10 * from exampleTABLE")

You should be able to put all of your queries into a list and iterate through them as you were before:

dat <- lapply(queries, function(x) sqlQuery(channel, x))

where queries is your list of queries and channel is your open ODBC connection. I guess I should also encourage you to close said connection when your done with odbcCloseAll()

Altri suggerimenti

The error message you quote is:

"[RODBC] ERROR: Could not SQLExecDirect 'SELECT * FROM \"exampleTABLE\"'"

Informix only recognizes table names enclosed in double quotes if the environment DELIMIDENT is set in the environment, either of the server or the client (or both). It doesn't much matter what it is set to; I use DELIMIDENT=1 when I want delimited identifiers.

How did you create the table in the Informix database? Unless you created the table with DELIMIDENT set, the table name will not be case sensitive; you do not need the quotes around the table name.

The fact that you're getting error -201 means you've got through the connection process; that is a good start, and simplifies what follows.

I'm not sure whether you're on a Unix machine or a Windows machine - it often helps to indicate that. On Windows, you might have to set the environment with SETNET32 (an Informix program), or there may be a way to specify the DELIMIDENT in the connect string. On Unix, you probably set it in your environment and the R software picks it up. However, there might be problems if you launch R via some sort of menu button or option in a GUI environment; the chances are that the profile is not executed before the R program is.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top