请帮帮我。我写与写数据到数据库mysql的CDR AVAYA日志分析器。解析器本身工作正常,但它并没有写入到数据库中。该程序本身是写在python 3.7和被划分成2个文件。该cdr.py解析器本身和db.py DB记录文件。它产生这样的错误:

pymysql.err.ProgrammingError: (1064, "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 '-dur, in-trk-code, in-crt-id, code-used, out-crt-id, clg-num-in-tag, dialed-num,' at line 1")

表中的所有字段的类型INT与写NULL的能力。

cdr.py

import socket
import db 

# Задаем адрес сервера
SERVER_ADDRESS = ('', 5100)

# Настраиваем сокет
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(SERVER_ADDRESS)
server_socket.listen(5)
print('server is running, please, press ctrl+c to stop')

# Слушаем запросы
while True:
    connection, address = server_socket.accept()

    data = connection.recv(1024)
    if not(b'\x00\x00\x00' in data):
        str = data.decode("utf-8")
        item=(str[0:6],str[7:11],str[12:17],str[18:22],str[23:26],str[27:30],str[31:34],str[35:50],str[51:74],str[75:76],str[77:90],str[91:92])
        print(item)
        db.write_db(item)

    connection.close()

db.py

import pymysql.cursors

def write_db(item, *agrs):
    connection = pymysql.connect(host='localhost',
                                 user='acdr',
                                 password='it8ejokd',
                                 db='avaya_cdr',
                                 charset='utf8mb4',
                                 cursorclass=pymysql.cursors.DictCursor)
    DBTBL = "cdr102019"
    DBFLD = "Date, Time, Sec-dur, in-trk-code, in-crt-id, code-used, out-crt-id, clg-num-in-tag, dialed-num, cond-code, vdn, frl"


    try:
        with connection.cursor() as cursor:
            sql = "INSERT INTO "+DBTBL+" ("+DBFLD+") VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
            cursor.execute(sql, (item))
        connection.commit()
    finally:
        connection.close()
分析解答

你需要把周围包含-列名反引号。

DBFLD = "Date, Time, `Sec-dur`, `in-trk-code`, `in-crt-id`, `code-used`, `out-crt-id`, `clg-num-in-tag`, `dialed-num`, `cond-code`, vdn, frl"

有关详细信息,请参阅当使用单引号,双引号,并且在MySQL反引号