D
D
dmitriyprog2018-01-17 22:22:19
Python
dmitriyprog, 2018-01-17 22:22:19

I don’t understand why the photo id is not saved in the sqlite3 database?

Look, I save the photo id in the database. To check, I display the contents of the record on the screen (1 output) Everything is saved,
Then I add the following photo to another column and display the contents again:
First (13 actual) column none
Second (14 actual) - contains the desired value
I display the contents of the column again (on the photo is not shown) - everything is empty
5a5f9f2c234f1295785051.png
Code for saving the first, second photo
Beginning:

@bot.message_handler(content_types= ["photo"])
def verifyUser(message):
    core.make_order(message, True)

.....
def make_order(self, message, with_photo=False):
        db = DB()
        if db.get_next_step(message) == 1:
            self.bot.send_message(message.chat.id,
                                  "Введи, пожалуйста, свои фамилию, имя, отчество и отправь как обычное сообщение"
                                  " или прикрепи первую, вторую страницы паспорта")
            db.to_next_step(message)
        else:
            if with_photo or db.get_next_step(message) > 20:
                if db.get_next_step(message) < 20:
                     db.to_step(message, 20)
                self.make_order_with_photo(message)
            else:
                self.make_order_manual(message)

def make_order_with_photo(self, message):
        db = DB()
        if db.get_next_step(message) == 20:
            db.to_next_step(message)
            db.set_passphoto_one(message)
            db.set_passphoto_one(message)
            self.bot.send_message(message.chat.id, "И вторая страница")
            return
        elif db.get_next_step(message) == 21:
            db.to_next_step(message)
            db.set_passphoto_two(message)
            self.choise_number_message(message)
            return

....
class DB :

    def __init__(self):
        self.con = sqlite3.connect('users.db')
        self.cur = self.con.cursor()

........
def set_passphoto_one(self, message):
        query = "UPDATE users SET p='{im}' WHERE id={id}"
       # query = 'INSERT INTO users(id, p) VALUES('+str(message.chat.id)+', "' +  str(message.photo[1].file_id) + '") '
        print(query)
        self.cur.execute(query.format(im=str(message.photo[1].file_id), id=message.chat.id) )
        self.get_from_db(message)

    def set_passphoto_two(self, message):
        data = str(message.photo[1].file_id)
        query = "UPDATE users SET ph='{im}' WHERE id={id}"
        print(query)
        self.cur.execute(query.format(im=str(message.photo[1].file_id), id=message.chat.id))

Thank you. PS. I know that calling a database connection in each method is not good, but I still can’t figure it out - an error is thrown

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question