Хранимая процедура вызывает ошибку 1366, "Incorrect string value:... Если в передаваемых параметрах присутствует кириллица.
Сама процедура:
CREATE DEFINER=`root`@`%` PROCEDURE `InsertNewMessage`(
IN `in_from_userid` BIGINT,
IN `in_message_id` INT(11),
IN `in_user_select_lang` VARCHAR(2),
IN `in_lang_detect` VARCHAR(2),
IN `in_voice_text` TEXT,
IN `in_voice_translate` TEXT,
IN `in_voice_file` MEDIUMBLOB
)
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
INSERT INTO traductor.message (
message.from_userid,
message.message_id,
message.user_select_lang,
message.lang_detect,
message.user_select_dialect,
message.voice_text,
message.voice_translate,
message.voice_file
)
VALUES (
in_from_userid,
in_message_id,
in_user_select_lang,
in_lang_detect,
in_voice_text,
in_voice_translate,
in_voice_file
);
END
Вызывается процедура так:
async def InsertNewMessage(self, user_id: int,
message_id: int,
user_select_lang: str = None,
lang_detect: str = None,
voice_text: str = None,
voice_translate: str = '',
voice_file: bytes = None):
global call_proc, data
try:
call_proc = 'InsertNewMessage'
data = (user_id,
message_id,
user_select_lang,
lang_detect,
voice_text,
voice_translate,
voice_file,)
self.cursor.callproc(call_proc, data)
self.connection.commit()
except Error as e:
config.log.exception(f'{__name__} {call_proc} data={data} | {e}', exc_info=False)
Подключение к базе данных осуществляется так:
async def __aenter__(self):
self.connection = connect(
charset='utf8mb4',
host=self.config.db_host,
user=self.config.db_user,
password=self.config.db_password,
database=self.config.db_database)
self.cursor = self.connection.cursor()
return self
Кодировка базы данных
utf8mb4_general_ci
Но при этом если использовать прямой sql запрс, так:
async def InsertNewMessage(self, user_id: int,
message_id: int,
user_select_lang: str = None,
lang_detect: str = None,
user_select_dialect: str = None,
voice_text: str = None,
voice_translate: str = '',
voice_file: bytes = None):
global call_proc, data
try:
sql = """
INSERT INTO `message` (
`from_userid`,
`message_id`,
`user_select_lang`,
`lang_detect`,
`voice_text`,
`voice_translate`,
`voice_file`
)
VALUES (%s, %s, %s, %s, %s, %s, %s)
"""
data = (user_id,
message_id,
user_select_lang,
lang_detect,
voice_text,
voice_translate,
voice_file)
self.cursor.execute(sql, data)
self.connection.commit()
except Error as e:
config.log.exception(f'{__name__} {call_proc} data={data} | {e}', exc_info=False)
То всё прекрасно работает. В чем проблема с хранимой процедурой InsertNewMessage или проблема в другом?
p.s. использую библиотеку PyMySQL