开发者

R ODBC SQL Query with a filepath name (Eg for INSERT INTO ... IN ...)

开发者 https://www.devze.com 2023-03-15 09:54 出处:网络
Using R 2.13.0 with Window XP 32b, I am struglling with defining properly a query that I\'d like to build in R and send to sqlQuery from the RODBC package.

Using R 2.13.0 with Window XP 32b,

I am struglling with defining properly a query that I'd like to build in R and send to sqlQuery from the RODBC package.

I have a problem with adding a filepath to the query.

following advices on how to deal with backslash in strings, here is the query that I can write but that lead to an error.

The following is running well in Access :

    SELECT Tamis_Lavage.* 
    FROM  Tamis_Lavage
    IN  "d:\Mes Documents\Pascal\03 - BiomFix\99 - Suivi Etude\01 - Donnees\Données STH\Test_Import\Copie de 20110623Acquisition.mdb"

is working fine in access.

its translation :

>   MyQuery <- paste(" 
+    SELECT Tamis_Lavage.* 
+    FROM Tamis_Lavage
+    IN \"d:\\Mes Documents\\Pascal\\03 - BiomFix\\99 - Suivi Etude\\01 - Donnees\\Données STH\\Test_Import\\Copie de 20110623Acquisition.mdb\" "
+     , sep="")
>   
>   tmp <- sqlQuery(con, query=MyQuery)
>   tmp       
[1] "42000 -1002 [Microsoft][Pilote ODBC Microsoft Access] Le moteur de base de données ne peut pas trouver '[d:\\Mes Documents\\Pascal\\03 - BiomFix\\99 - Suivi Etude\\01 - Donnees\\Données STH\\Test_Import\\Copie de 20110623Acquisition.mdb]'. Assurez-vous que le nom de paramètre ou d'alias est valide, qu'il ne comprend pas de caractère ou de ponctuation incorrect et qu'il n'est pas trop long."
[2] "[RODBC] ERROR: Could not SQLExecDirect ' SELECT Tamis_Lavage.* \n   FROM Tamis_Lavage\n   IN \"d:\\Mes Documents\\Pascal\\03 - BiomFix\\99 - Suivi Etude\\01 - Donnees\\Données STH\\Test_Import\\Copie de 20110623Acquisition.mdb\" '"                                                                                                                                                                  
>   MyQuery 
[1] " \n SELECT Tamis_Lav开发者_JS百科age.* \n   FROM Tamis_Lavage\n   IN \"d:\\Mes Documents\\Pascal\\03 - BiomFix\\99 - Suivi Etude\\01 - Donnees\\Données STH\\Test_Import\\Copie de 20110623Acquisition.mdb\" "

leads to an error.

Could you help in the translation process ?

Best regards Pascal


Your MyQuery could be problematic because of the newlines \n that you introduced.

Try the following:

MyQuery <- paste(
    "SELECT Tamis_Lavage.*", 
    "FROM Tamis_Lavage",
    "IN 'd:\\Mes Documents\\Pascal\\03 - BiomFix\\99 - Suivi Etude\\01 - Donnees\\Données STH\\Test_Import\\Copie de 20110623Acquisition.mdb'")

What is different?

  • None of the parameters to paste contains a \n.
  • I find it easier to use single quotes ' when working embedding quotes in strings. (This also has the benefit that you don't have to escape the quotes.)
0

精彩评论

暂无评论...
验证码 换一张
取 消