P
P
PRIYD2019-08-20 12:10:12
Python
PRIYD, 2019-08-20 12:10:12

Why is metadata displayed when querying a column?

I'm trying to request a column for output, but metadata is sent along with it:
5d5bb8c095897703417199.png

import telebot
import sqlite3 as sqlite
from sqlite3 import Error

bot = telebot.TeleBot("TOKEN")
conn = sqlite.connect("test.db", check_same_thread=False)
c = conn.cursor()
count = 0

try:
  c.execute('''CREATE TABLE messages (
    id PRIMARY KEY,
    message VARCRCHAR(500) UNIQUE NOT NULL)
    ''')
except sqlite.OperationalError as e:
  print('sqlite error:', e.args[0])  # table messages already exists


# On '/start':
@bot.message_handler(commands=['start'])
def on_start(message):
    bot.send_message(message.chat.id, 'Привет! Меня зовут Джемисон. Введи сообщение для хранения.')


@bot.message_handler(commands=['list'])
def on_list(message):
    c.execute('''SELECT message FROM messages''')
    list_of_elements = c.fetchall()
    bot.send_message(message.chat.id, list_of_elements)
    #print(list_of_elements)


# On any text:
@bot.message_handler(content_types=['text'])
def on_message(message):
    global count
    count += 1
    message_id = 'id' + str(count)
    data = {}
    data["message_id"] = message_id
    data['message'] = message

    c.execute('''INSERT INTO messages(id, message) VALUES(?,?)''', (str(data['message_id']), str(data['message'])) )


bot.polling()

PS the code is terrible, do not hit

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elvis, 2019-08-20
@PRIYD

when you receive the text, you enter the entire message into the database, and not the text , correct it, and then only the text will be entered into the database

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question