Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error executing query with c-style comments #26

Closed
franconob opened this issue Jul 23, 2013 · 7 comments
Closed

Error executing query with c-style comments #26

franconob opened this issue Jul 23, 2013 · 7 comments

Comments

@franconob
Copy link

Hello, I'm trying to execute some queries that have comments wrapped by /* and */ and I'm getting:

"Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;/*!40101 SET @OLD_COL' at line 2"
connDb.query("/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;", function(err2, result) {
    if (err2) {
        throw err2;
    }
})

Are these comments supported?

Thanks.

@sidorares
Copy link
Owner

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

@sidorares
Copy link
Owner

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 } ]

@sidorares
Copy link
Owner

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

@franconob
Copy link
Author

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

@sidorares
Copy link
Owner

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

sidorares added a commit that referenced this issue Jul 29, 2013
@sidorares
Copy link
Owner

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

@mlucic
Copy link

mlucic commented Aug 2, 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants