Coder Social home page Coder Social logo

Comments (7)

sidorares avatar sidorares commented on August 25, 2024

Thanks, I'll try to check. You have whole query commented here - is that what you want? Uncommented part is ;;

from node-mysql2.

sidorares avatar sidorares commented on August 25, 2024

Can't reproduce. This works for me (5.6.10 MySQL Community Server (GPL)):

db.query("select 1+1 v /* this is comment */", function(err, rows, fields) {
      console.log(err, rows, fields);
});

result:

null [ { v: '2' } ] [ { catalog: 'def',
    schema: '',
    table: '',
    orgTable: '',
    name: 'v',
    orgName: '',
    characterSet: 63,
    columnLength: 3,
    columnType: 8,
    flags: 129,
    decimals: 0 } ]
db.execute("select 1+1 v /* this is comment */", function(err, rows, fields) {
      console.log(err, rows, fields);
});

result:

null [ { v: '2' } ] [ { catalog: 'def',
    schema: '',
    table: '',
    orgTable: '',
    name: 'v',
    orgName: '',
    characterSet: 63,
    columnLength: 3,
    columnType: 8,
    flags: 129,
    decimals: 0 } ]

from node-mysql2.

sidorares avatar sidorares commented on August 25, 2024

It looks mysql does not like /*! comment beginning. If you remove ! error disappear.

from node-mysql2.

franconob avatar franconob commented on August 25, 2024

But comments beginning with /*! are valid in mysql. It's a conditional execution.

from node-mysql2.

sidorares avatar sidorares commented on August 25, 2024

I wasn't aware about conditional comments. Just for the record: http://dev.mysql.com/doc/refman/5.5/en/comments.html

The problem here is likely with multiple queries in one command. I'll check if this is the case

from node-mysql2.

sidorares avatar sidorares commented on August 25, 2024

Should work now - could you try with v0.8.19?

from node-mysql2.

mlucic avatar mlucic commented on August 25, 2024

@sidorares I'm still getting this exact error on version 3.9.7, trying to execute a dump I pulled from a running MySQL instance.

e.g.

import mysql from "mysql2";

const schema = `
-- 
-- MySQL dump 10.13  Distrib 8.0.33, for Linux (x86_64)
--
-- Host: localhost    Database: blue
-- ------------------------------------------------------
-- Server version	8.0.33

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES UTF8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table \`myTable\`
--

/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE \`myTable\` (
  \`id\` int NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (\`id\`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table \`myTable\`
--

LOCK TABLES \`myTable\` WRITE;
/*!40000 ALTER TABLE \`myTable\` DISABLE KEYS */;
/*!40000 ALTER TABLE \`myTable\` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2024-08-02 14:32:21
`;

async function initSchema(): Promise<void> {
  const connection = mysql.createConnection({
    user: "username",
    password: "password",
    host: "host",
    port: "port",
  });

  await new Promise<void>((resolve, reject) => {
    connection.connect((err: Error | null | undefined) => {
      if (err) {
        reject(err);
      } else {
        resolve();
      }
    });
  });

  await new Promise<void>((resolve, reject) => {
    connection.query(schema, (err) => {
      if (err) {
        reject(err);
      } else {
        resolve();
      }
    });
  });

  await new Promise<void>((resolve, reject) => {
    connection.end((err: Error | null | undefined) => {
      if (err) {
        reject(err);
      } else {
        resolve();
      }
    });
  });
}

Results in:
ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COL' at line 9

from node-mysql2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.