0

I am trying to insert a row in mysql from node using mysql2 driver, and I am getting the following error:

running query \"INSERT INTO outgo (name, monthIdMonth, type, distribution, recurrent, amount) VALUES ('Penalizări', (select MAX(idMonth) from `month`), '3', '1', '1', '0');\"
failed: Error: Incorrect string value: '\\xC4\\x83ri' for column 'name' at row 1

The outgo table is created like this:

CREATE TABLE IF NOT EXISTS `outgo` (
  `idOutgo` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(50) NOT NULL,
  `apartmentsGroupIdApartmentsGroup` INT UNSIGNED NULL,
  `outgoColumnInfoIdOutgoColumn` INT UNSIGNED NULL,
  `metering` ENUM('NONE','COLD_WATER','HOT_WATER','OTHER') NULL,
  `distribution` ENUM('MANUAL','PERSON','APARTMENT','SURFACE','CONSUMPTION', 'AUTOMATED','HEAT_SURFACE') NULL,
  `amount` DOUBLE(14,2) NULL,
  `cAmount` DOUBLE(14,2) NULL,
  `costPerUnit` DOUBLE(15,3) NULL,
  `unit` VARCHAR(5) NULL,
  `quantity` DOUBLE(14,2) NULL,
  `diffs` DOUBLE(14,4) NULL,
  `recurrent` TINYINT(1) NOT NULL DEFAULT 0,
  `monthIdMonth` INT UNSIGNED NOT NULL,
  `type` ENUM('GENERAL','REMAINING','PENALITY') NOT NULL DEFAULT 'GENERAL',
  `billIdBill` INT UNSIGNED NULL,
ENGINE = InnoDB;

Any idea what the problem is? The string it is complaining about is: "Penalizări". Schema encoding is utf8....

Petru
  • 904
  • 1
  • 12
  • 18
  • Show the `SHOW CREATE TABLE` for the `outgo`. And what is the connection encoding? – zerkms Jun 20 '15 at 07:01
  • I do not specify a connection encoding. How could I find out? Is it what "locale" command return on linux? – Petru Jun 20 '15 at 07:15
  • can you show the code used to insert row? – Andrey Sidorov Jun 22 '15 at 03:30
  • possible duplicate of [How to fix "Incorrect string value" errors?](http://stackoverflow.com/questions/1168036/how-to-fix-incorrect-string-value-errors) – Sumurai8 Jun 22 '15 at 08:46
  • 1
    Are you trying to use `ă`? Its utf8 hex is C483. A guess: You have not specified [utf8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through/279279#279279) – Rick James Jun 24 '15 at 20:46

1 Answers1

4

So, in the end, I found the solution: I added a charset parameter to the node connection:

var pool  = mysql.createPool({
    host     : config.get.mysql.host,
    port     : config.get.mysql.port,
    user     : config.get.mysql.username,
    password : config.get.mysql.password,
    database : 'general',
    connectionLimit : 50,
    queueLimit : 5000,
    charset: "utf8_general_ci"
});
Petru
  • 904
  • 1
  • 12
  • 18