Skip to content

LOAD DATA executions not returning affected rows value #283

@NoProblemJack

Description

@NoProblemJack

Hi there,

I believe there is a bug in the returned 'affected rows' value that results after executing a LOAD DATA command. I am running on windows 10, and connecting to a cloud based MySQL database 5.7

Hopefully the following reprex is satisfactory. It uses a temporary table for reproducability, but the result is the same with permanent tables.

db_temp_table_name <- "temp_table123"
temp_file_name <- tempfile("temp123.csv")
temp_file_name <- stringr::str_replace_all(temp_file_name, "\\\\", "/")

local_temp_table <- data.frame(id = 1:10)
write.csv(local_temp_table, temp_file_name)

sql_create_table <-
  paste(
    "CREATE TEMPORARY TABLE ", db_temp_table_name, "
    (id INT)
   ENGINE=InnoDB"
  )

sql_load_data <-
  paste0(
    "LOAD DATA LOCAL INFILE '", temp_file_name, "'
    INTO TABLE ", db_temp_table_name, "
    FIELDS TERMINATED BY ',' ENCLOSED BY '\"' ESCAPED BY '\\\\'
    LINES TERMINATED BY '\\r\\n'
    IGNORE 1 LINES
    (`id`)"
  )

mariadb_con <-
  RMariaDB::dbConnect(
    RMariaDB::MariaDB(),
    host = ...,
    user = ...,
    password = ...,
    port = ...,
    dbname = ...,
    bigint = "numeric"
  )

RMariaDB::dbExecute(conn = mariadb_con, statement = sql_create_table)
RMariaDB::dbGetQuery(conn = mariadb_con, "select * from temp_table123")
affected_records <- RMariaDB::dbExecute(conn = mariadb_con, statement = sql_load_data)
affected_records ## has value 0, but should have value 10
RMariaDB::dbGetQuery(conn = mariadb_con, "select * from temp_table123") ## confirm that the insert did infact occur.
RMariaDB::dbDisconnect(mariadb_con)

For comparison reasons, it is worth noting that when using RMySQL the correct 'affected rows' value is returned, so the value is presumably being returned by the database. I am working on a project where confirmation that the correct number of inserts has occurred is necessary, and so this issue is preventing me from upgrading from RMySQL to RMariaDB.

Many thanks in advance. Appreciate the work you do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions