How to run multiple sql queries through a single call in the Mysql2 Gem in IRB?

I play with mysql2 (and mysql 5), and the results and results are Enumerable.

I can run queries like

results = client.query("select now()")

And I can also run queries like

results = client.query("select version()")

But what I want to do is keep him busy. In real life, I assume that people run multiple queries. So, how can I make sure that I can get the version and time in one shot.

-

Things I tried that don't work :

results = client.query("select version(); select now()")

The error I get is:

Mysql2::Error: You have an error in your SQL Syntax; check the manual that corresponds to your Mysql Version for the right syntax to use near 'select now()' at line1

Now I understand that I can run the following queries in the Mysql Console and return the results, as if to do the same in the Mysql2 Gem:

select version();select now()

Gem Mysql2 ( ). , , , .

+3
2

, MySQL:

Mysql2::Client.default_query_options[:connect_flags] |= Mysql2::Client::MULTI_STATEMENTS

+7

a, :

SELECT VERSION(), NOW();

, :

SELECT CONCAT(VERSION(), NOW());
+1

Source: https://habr.com/ru/post/1789103/


All Articles