Reputation: 1563
I am sending this query to a MySQL database using following function:
loadDataBudget <- function(korisnik, razinaLabel) {
lapply( dbListConnections( dbDriver( drv = "MySQL")), dbDisconnect)
# Connect to the database
db <- dbConnect(MySQL(), dbname = databaseBudget, host = options()$mysql$host,
port = options()$mysql$port, user = options()$mysql$user,
password = options()$mysql$password, encoding = "utf8")
# Construct the fetching query
query <- sprintf("SELECT positions, x201501, x201502, x201503, x201504, x201505, x201506, x201507, x201508, x201509,
x201510, x201511, x201512 FROM %s WHERE naziv = '%s' AND razina = '%d'",
tableBudget,
korisnik,
razinaLabel)
# Submit the fetch query and disconnect
data <- dbGetQuery(db, query)
dbDisconnect(db)
data
}
Function works well if the character argument korisnik
contain non UTF-8 characters. But if it contains Croatian UTF-8 characters it returns empty table. I have tried with two collations in MySQL database: utf8_general_ci and utf8_croatian_ci .
I have also tried to set names utf-8 before query but it didn't help.
Upvotes: 0
Views: 1506
Reputation: 142278
The text is truncated where there should be an accented Croatian letter?
If this does not suffice, see the "truncate" and debuging hints in
Trouble with UTF-8 characters; what I see is not what I stored
R
may need:
Tool -> Global Options -> Code -> Saving and put UTF-8
rs <- dbSendQuery(con, 'set character set "utf8"')
rs <- dbSendQuery(con, 'SET NAMES utf8')
Upvotes: 1