A
A
ArtemZA2020-01-01 19:45:41
Python
ArtemZA, 2020-01-01 19:45:41

What should be done to make Sqlite UPDATE work?

Hello.
I decided to write a small application in order to get information about the characters from the game server.
For data storage decided to use SQLite.
I managed to do what would:
The program received the data -> placed it in the database -> Showed
But:
When it comes time to update the information, the code does not work, although no errors pop up
Tell me what I'm doing wrong?
The function of searching for information about a player in the database

def search_nicknames(name):
    cursor = conn.cursor()
    sql = "SELECT * FROM user_info WHERE Nickname ==? "
    search_data_update = []
    print("search_nicknames ",name)
    
    
    
    cursor.execute(sql, (name,))  
    #print(name[i])
    
    result =   cursor.fetchall()
    cursor.close()
    #print("Fetachall: ", result)
    if result  == []:
        print("ISNERT")
        return insert_data(name)
         


    if result != []:

        print("Есть в БД", name,result[0][9])
       
        if (time.time() - result[0][9]) > 1800 or result[0][1] == "ERROR":

            print("Последний раз обновлялся ",time.ctime(result[0][9]) ," ", result[0][1],result[0][2])
            print(time.ctime(time.time()))
       
            return update_data(name)

        else:
            print("рановато " , name)
            
            return result[0]

Data update function
def update_data(name):
    cursor = conn.cursor()
    

    
    print("update_data " , name)
    req_data_user = user_req(name)
   

    print("UPDATE DATA",req_data_user[1],req_data_user[2],req_data_user[3],req_data_user[4],req_data_user[5],req_data_user[6],req_data_user[7],req_data_user[8],time.time(),name[0])
   
  
    cursor.execute("""UPDATE user_info set Corporation = ? ,Alliance = ?,Sec_status = ? ,Ship_Kill = ? ,Solo_Kill = ?,Ship_Lost = ?,Gang_Ratio = ? ,ZKillboard_inf = ?, time_update = ?  WHERE Nickname == ?""",(req_data_user[1],req_data_user[2],req_data_user[3],req_data_user[4],req_data_user[5],req_data_user[6],req_data_user[7],req_data_user[8],time.time(),name[0]))


    conn.commit()
    cursor.close()

    return req_data_user

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
o5a, 2020-01-02
@ArtemZA

In the UPDATE execution, user_info uses name[0] in the parameters , but should just be name .

X
xDimus, 2020-01-01
@xDimus

Change your request WHERE Nickname == ?toWHERE Nickname = ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question