accessing specific values in a table in sqlite3 of python 3 and then updating it









up vote
0
down vote

favorite












I have created a database table which is basically a simple atm database which has records of some people with their pin as the primary key. Now I need to create another file where a user can enter their pin and then it checks if the pin exists in the database and if it does it shows how much money he has and on entering the amount to withdraw, the database gets updated with a new value of amount in that person's record. The table I created is as such:



import sqlite3
conn = sqlite3.connect('pin.db')
print("opened successfully")

conn.execute('''CREATE TABLE CUSTOMERS
(ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
AMOUNT INT);''')

print("table created")


conn.execute("INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,AMOUNT)
VALUES (1234, 'Paul', 32, 'California', 20000.00 )");

conn.execute("INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,AMOUNT)
VALUES (2345, 'Allen', 25, 'Texas', 15000.00 )");

conn.execute("INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,AMOUNT)
VALUES (3456, 'Teddy', 23, 'Norway', 20000.00 )");

conn.execute("INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,AMOUNT)
VALUES (4567, 'Mark', 25, 'Rich-Mond ', 65000.00 )");

conn.commit()
print ("Records created successfully")

conn.close()


The other file will be something like this I guess:



import sqlite3

conn = sqlite3.connect('pin.db')
print ("Opened database successfully")

pin=int(input("enter the 4 digit pin: "))
conn.row_factory = lambda cursor, row: row[0]
c = conn.cursor()
ids = c.execute('SELECT id FROM CUSTOMERS').fetchall()
if pin in ids:
query= f"SELECT AMOUNT FROM CUSTOMERS WHERE ID=?"
c.execute(query,(pin))
print(c.fetchone())
else:
print("no")


The problem is that I'm getting a Value Error as such: ValueError: parameters are of unsupported type, I know the solution might be something very simple and basic but the thing is I'm completely new to this sqlite3 thing and so not good with it. Explanation will be of great help for me to learn.










share|improve this question



























    up vote
    0
    down vote

    favorite












    I have created a database table which is basically a simple atm database which has records of some people with their pin as the primary key. Now I need to create another file where a user can enter their pin and then it checks if the pin exists in the database and if it does it shows how much money he has and on entering the amount to withdraw, the database gets updated with a new value of amount in that person's record. The table I created is as such:



    import sqlite3
    conn = sqlite3.connect('pin.db')
    print("opened successfully")

    conn.execute('''CREATE TABLE CUSTOMERS
    (ID INT PRIMARY KEY NOT NULL,
    NAME TEXT NOT NULL,
    AGE INT NOT NULL,
    ADDRESS CHAR(50),
    AMOUNT INT);''')

    print("table created")


    conn.execute("INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,AMOUNT)
    VALUES (1234, 'Paul', 32, 'California', 20000.00 )");

    conn.execute("INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,AMOUNT)
    VALUES (2345, 'Allen', 25, 'Texas', 15000.00 )");

    conn.execute("INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,AMOUNT)
    VALUES (3456, 'Teddy', 23, 'Norway', 20000.00 )");

    conn.execute("INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,AMOUNT)
    VALUES (4567, 'Mark', 25, 'Rich-Mond ', 65000.00 )");

    conn.commit()
    print ("Records created successfully")

    conn.close()


    The other file will be something like this I guess:



    import sqlite3

    conn = sqlite3.connect('pin.db')
    print ("Opened database successfully")

    pin=int(input("enter the 4 digit pin: "))
    conn.row_factory = lambda cursor, row: row[0]
    c = conn.cursor()
    ids = c.execute('SELECT id FROM CUSTOMERS').fetchall()
    if pin in ids:
    query= f"SELECT AMOUNT FROM CUSTOMERS WHERE ID=?"
    c.execute(query,(pin))
    print(c.fetchone())
    else:
    print("no")


    The problem is that I'm getting a Value Error as such: ValueError: parameters are of unsupported type, I know the solution might be something very simple and basic but the thing is I'm completely new to this sqlite3 thing and so not good with it. Explanation will be of great help for me to learn.










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have created a database table which is basically a simple atm database which has records of some people with their pin as the primary key. Now I need to create another file where a user can enter their pin and then it checks if the pin exists in the database and if it does it shows how much money he has and on entering the amount to withdraw, the database gets updated with a new value of amount in that person's record. The table I created is as such:



      import sqlite3
      conn = sqlite3.connect('pin.db')
      print("opened successfully")

      conn.execute('''CREATE TABLE CUSTOMERS
      (ID INT PRIMARY KEY NOT NULL,
      NAME TEXT NOT NULL,
      AGE INT NOT NULL,
      ADDRESS CHAR(50),
      AMOUNT INT);''')

      print("table created")


      conn.execute("INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,AMOUNT)
      VALUES (1234, 'Paul', 32, 'California', 20000.00 )");

      conn.execute("INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,AMOUNT)
      VALUES (2345, 'Allen', 25, 'Texas', 15000.00 )");

      conn.execute("INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,AMOUNT)
      VALUES (3456, 'Teddy', 23, 'Norway', 20000.00 )");

      conn.execute("INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,AMOUNT)
      VALUES (4567, 'Mark', 25, 'Rich-Mond ', 65000.00 )");

      conn.commit()
      print ("Records created successfully")

      conn.close()


      The other file will be something like this I guess:



      import sqlite3

      conn = sqlite3.connect('pin.db')
      print ("Opened database successfully")

      pin=int(input("enter the 4 digit pin: "))
      conn.row_factory = lambda cursor, row: row[0]
      c = conn.cursor()
      ids = c.execute('SELECT id FROM CUSTOMERS').fetchall()
      if pin in ids:
      query= f"SELECT AMOUNT FROM CUSTOMERS WHERE ID=?"
      c.execute(query,(pin))
      print(c.fetchone())
      else:
      print("no")


      The problem is that I'm getting a Value Error as such: ValueError: parameters are of unsupported type, I know the solution might be something very simple and basic but the thing is I'm completely new to this sqlite3 thing and so not good with it. Explanation will be of great help for me to learn.










      share|improve this question















      I have created a database table which is basically a simple atm database which has records of some people with their pin as the primary key. Now I need to create another file where a user can enter their pin and then it checks if the pin exists in the database and if it does it shows how much money he has and on entering the amount to withdraw, the database gets updated with a new value of amount in that person's record. The table I created is as such:



      import sqlite3
      conn = sqlite3.connect('pin.db')
      print("opened successfully")

      conn.execute('''CREATE TABLE CUSTOMERS
      (ID INT PRIMARY KEY NOT NULL,
      NAME TEXT NOT NULL,
      AGE INT NOT NULL,
      ADDRESS CHAR(50),
      AMOUNT INT);''')

      print("table created")


      conn.execute("INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,AMOUNT)
      VALUES (1234, 'Paul', 32, 'California', 20000.00 )");

      conn.execute("INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,AMOUNT)
      VALUES (2345, 'Allen', 25, 'Texas', 15000.00 )");

      conn.execute("INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,AMOUNT)
      VALUES (3456, 'Teddy', 23, 'Norway', 20000.00 )");

      conn.execute("INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,AMOUNT)
      VALUES (4567, 'Mark', 25, 'Rich-Mond ', 65000.00 )");

      conn.commit()
      print ("Records created successfully")

      conn.close()


      The other file will be something like this I guess:



      import sqlite3

      conn = sqlite3.connect('pin.db')
      print ("Opened database successfully")

      pin=int(input("enter the 4 digit pin: "))
      conn.row_factory = lambda cursor, row: row[0]
      c = conn.cursor()
      ids = c.execute('SELECT id FROM CUSTOMERS').fetchall()
      if pin in ids:
      query= f"SELECT AMOUNT FROM CUSTOMERS WHERE ID=?"
      c.execute(query,(pin))
      print(c.fetchone())
      else:
      print("no")


      The problem is that I'm getting a Value Error as such: ValueError: parameters are of unsupported type, I know the solution might be something very simple and basic but the thing is I'm completely new to this sqlite3 thing and so not good with it. Explanation will be of great help for me to learn.







      sqlite3 python-3.7






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 15:03

























      asked Nov 8 at 17:39









      H4rd_C0d3

      54




      54



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53213326%2faccessing-specific-values-in-a-table-in-sqlite3-of-python-3-and-then-updating-it%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53213326%2faccessing-specific-values-in-a-table-in-sqlite3-of-python-3-and-then-updating-it%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Barbados

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3