Add dictionary or list to Sqlite3 - Gives error operation parameter must be strSQLite3 Integer Max Valuehow can I insert a row in my database from 'adb shell'Sqlite3 gives “Error : Constraint failed” - interfacing to AM1808Python/SQlite3 'str' object is not callableSqlite3: How to check date inputUnsupported type error in sqlite3 using pythonHow to compute a hash of a sqlite database file without causing harmHow do I execute sqlite3 file into a database in mac terminal?how to insert values from csv into sqlite3 using pythonAdding column to sqlite database and distribute rows based on primary key

My professor has told me he will be the corresponding author. Will it hurt my future career?

How do I talk to my wife about unrealistic expectations?

What exactly is a "murder hobo"?

Was it ever illegal to name a pig "Napoleon" in France?

Why SQL does not use the indexed view?

How do ballistic trajectories work in a ring world?

Define functions in a tikzcd diagram

Can a USB hub be used to access a drive from two devices?

How to reclaim personal item I've lent to the office without burning bridges?

Does the Wild Magic sorcerer's Tides of Chaos feature grant advantage on all attacks, or just the first one?

Why are co-factors 4 and 8 so popular when co-factor is more than one?

When is one 'Ready' to make Original Contributions to Mathematics?

What's the difference between a type and a kind?

Why do airports remove/realign runways?

Taking my Ph.D. advisor out for dinner after graduation

How to evaluate the performance of open source solver?

Sense of humor in your sci-fi stories

How do I explain that I don't want to maintain old projects?

Does anyone have a method of differentiating informative comments from commented out code?

Movie featuring a De Lorean - NOT Back to the Future

Examples of fluid (including air) being used to transmit digital data?

Possibility to correct pitch from digital versions of records with the hole not centered

Computer name naming convention for security

Intern not wearing safety equipment; how could I have handled this differently?



Add dictionary or list to Sqlite3 - Gives error operation parameter must be str


SQLite3 Integer Max Valuehow can I insert a row in my database from 'adb shell'Sqlite3 gives “Error : Constraint failed” - interfacing to AM1808Python/SQlite3 'str' object is not callableSqlite3: How to check date inputUnsupported type error in sqlite3 using pythonHow to compute a hash of a sqlite database file without causing harmHow do I execute sqlite3 file into a database in mac terminal?how to insert values from csv into sqlite3 using pythonAdding column to sqlite database and distribute rows based on primary key






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Ok I am new to sqlite and python in general so please be nice =)
I have a simple dictionary -



time = data[0]['timestamp']
price = data[0]['price']

myprice = 'Date':time,'price':price


myprice looks like this (time is a timestamp) -



'Date': 1553549093, 'price': 1.7686


I now want to add the data to sqlite3 database...so I created this -



#Create database if not exist...

db_filename = 'mydb_test.db'
connection = sqlite3.connect(db_filename)

#Get a SQL cursor to be able to execute SQL commands...

cursor = connection.cursor()

#Create table

sql = '''CREATE TABLE IF NOT EXISTS TEST
(PID INTEGER PRIMARY KEY AUTOINCREMENT,
DATE TIMESTAMP,
PRICE FLOAT)'''

#Now lets execute the above SQL

cursor.execute(sql)


#Insert data in sql

sql2 = ("INSERT INTO GBPCAD VALUES (?,?)", [(myprice['Date'],myprice['price'])])

cursor.execute(sql2)
cursor.commit()
connection.close()


But when executing this code I get ValueError: operation parameter must be str



What am I doing wrong?










share|improve this question




























    0















    Ok I am new to sqlite and python in general so please be nice =)
    I have a simple dictionary -



    time = data[0]['timestamp']
    price = data[0]['price']

    myprice = 'Date':time,'price':price


    myprice looks like this (time is a timestamp) -



    'Date': 1553549093, 'price': 1.7686


    I now want to add the data to sqlite3 database...so I created this -



    #Create database if not exist...

    db_filename = 'mydb_test.db'
    connection = sqlite3.connect(db_filename)

    #Get a SQL cursor to be able to execute SQL commands...

    cursor = connection.cursor()

    #Create table

    sql = '''CREATE TABLE IF NOT EXISTS TEST
    (PID INTEGER PRIMARY KEY AUTOINCREMENT,
    DATE TIMESTAMP,
    PRICE FLOAT)'''

    #Now lets execute the above SQL

    cursor.execute(sql)


    #Insert data in sql

    sql2 = ("INSERT INTO GBPCAD VALUES (?,?)", [(myprice['Date'],myprice['price'])])

    cursor.execute(sql2)
    cursor.commit()
    connection.close()


    But when executing this code I get ValueError: operation parameter must be str



    What am I doing wrong?










    share|improve this question
























      0












      0








      0








      Ok I am new to sqlite and python in general so please be nice =)
      I have a simple dictionary -



      time = data[0]['timestamp']
      price = data[0]['price']

      myprice = 'Date':time,'price':price


      myprice looks like this (time is a timestamp) -



      'Date': 1553549093, 'price': 1.7686


      I now want to add the data to sqlite3 database...so I created this -



      #Create database if not exist...

      db_filename = 'mydb_test.db'
      connection = sqlite3.connect(db_filename)

      #Get a SQL cursor to be able to execute SQL commands...

      cursor = connection.cursor()

      #Create table

      sql = '''CREATE TABLE IF NOT EXISTS TEST
      (PID INTEGER PRIMARY KEY AUTOINCREMENT,
      DATE TIMESTAMP,
      PRICE FLOAT)'''

      #Now lets execute the above SQL

      cursor.execute(sql)


      #Insert data in sql

      sql2 = ("INSERT INTO GBPCAD VALUES (?,?)", [(myprice['Date'],myprice['price'])])

      cursor.execute(sql2)
      cursor.commit()
      connection.close()


      But when executing this code I get ValueError: operation parameter must be str



      What am I doing wrong?










      share|improve this question














      Ok I am new to sqlite and python in general so please be nice =)
      I have a simple dictionary -



      time = data[0]['timestamp']
      price = data[0]['price']

      myprice = 'Date':time,'price':price


      myprice looks like this (time is a timestamp) -



      'Date': 1553549093, 'price': 1.7686


      I now want to add the data to sqlite3 database...so I created this -



      #Create database if not exist...

      db_filename = 'mydb_test.db'
      connection = sqlite3.connect(db_filename)

      #Get a SQL cursor to be able to execute SQL commands...

      cursor = connection.cursor()

      #Create table

      sql = '''CREATE TABLE IF NOT EXISTS TEST
      (PID INTEGER PRIMARY KEY AUTOINCREMENT,
      DATE TIMESTAMP,
      PRICE FLOAT)'''

      #Now lets execute the above SQL

      cursor.execute(sql)


      #Insert data in sql

      sql2 = ("INSERT INTO GBPCAD VALUES (?,?)", [(myprice['Date'],myprice['price'])])

      cursor.execute(sql2)
      cursor.commit()
      connection.close()


      But when executing this code I get ValueError: operation parameter must be str



      What am I doing wrong?







      sqlite python-3.6






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 25 at 21:40









      Slavia888Slavia888

      527 bronze badges




      527 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Pass the arguments of the insert statement in execute():



          sql2 = "INSERT INTO GBPCAD (DATE, PRICE) VALUES (?,?)"
          cursor.execute(sql2, (myprice['Date'], myprice['price']))


          Also include in the insert statement the names of the columns.






          share|improve this answer























          • Thanks for taking time to answer. Error message gone but no data is added to db. Have to check somehow where problem is.

            – Slavia888
            Mar 26 at 22:28











          • The create statement in your code creates a table named TEST but the insert statement adds a row to a table GBPCAD. Why?

            – forpas
            Mar 26 at 22:38











          • Forpas you are fast =) I solved it. It was my bad using gbpcad as table-name in example. What was the problem was - connection.commit() and not cursor.commit() Everything works like a champion! And so are you! Many thanks!

            – Slavia888
            Mar 26 at 22:47












          • Fine if it is solved.

            – forpas
            Mar 26 at 22:49










          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',
          autoActivateHeartbeat: false,
          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%2f55346827%2fadd-dictionary-or-list-to-sqlite3-gives-error-operation-parameter-must-be-str%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Pass the arguments of the insert statement in execute():



          sql2 = "INSERT INTO GBPCAD (DATE, PRICE) VALUES (?,?)"
          cursor.execute(sql2, (myprice['Date'], myprice['price']))


          Also include in the insert statement the names of the columns.






          share|improve this answer























          • Thanks for taking time to answer. Error message gone but no data is added to db. Have to check somehow where problem is.

            – Slavia888
            Mar 26 at 22:28











          • The create statement in your code creates a table named TEST but the insert statement adds a row to a table GBPCAD. Why?

            – forpas
            Mar 26 at 22:38











          • Forpas you are fast =) I solved it. It was my bad using gbpcad as table-name in example. What was the problem was - connection.commit() and not cursor.commit() Everything works like a champion! And so are you! Many thanks!

            – Slavia888
            Mar 26 at 22:47












          • Fine if it is solved.

            – forpas
            Mar 26 at 22:49















          1














          Pass the arguments of the insert statement in execute():



          sql2 = "INSERT INTO GBPCAD (DATE, PRICE) VALUES (?,?)"
          cursor.execute(sql2, (myprice['Date'], myprice['price']))


          Also include in the insert statement the names of the columns.






          share|improve this answer























          • Thanks for taking time to answer. Error message gone but no data is added to db. Have to check somehow where problem is.

            – Slavia888
            Mar 26 at 22:28











          • The create statement in your code creates a table named TEST but the insert statement adds a row to a table GBPCAD. Why?

            – forpas
            Mar 26 at 22:38











          • Forpas you are fast =) I solved it. It was my bad using gbpcad as table-name in example. What was the problem was - connection.commit() and not cursor.commit() Everything works like a champion! And so are you! Many thanks!

            – Slavia888
            Mar 26 at 22:47












          • Fine if it is solved.

            – forpas
            Mar 26 at 22:49













          1












          1








          1







          Pass the arguments of the insert statement in execute():



          sql2 = "INSERT INTO GBPCAD (DATE, PRICE) VALUES (?,?)"
          cursor.execute(sql2, (myprice['Date'], myprice['price']))


          Also include in the insert statement the names of the columns.






          share|improve this answer













          Pass the arguments of the insert statement in execute():



          sql2 = "INSERT INTO GBPCAD (DATE, PRICE) VALUES (?,?)"
          cursor.execute(sql2, (myprice['Date'], myprice['price']))


          Also include in the insert statement the names of the columns.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 25 at 22:10









          forpasforpas

          32.1k5 gold badges11 silver badges30 bronze badges




          32.1k5 gold badges11 silver badges30 bronze badges












          • Thanks for taking time to answer. Error message gone but no data is added to db. Have to check somehow where problem is.

            – Slavia888
            Mar 26 at 22:28











          • The create statement in your code creates a table named TEST but the insert statement adds a row to a table GBPCAD. Why?

            – forpas
            Mar 26 at 22:38











          • Forpas you are fast =) I solved it. It was my bad using gbpcad as table-name in example. What was the problem was - connection.commit() and not cursor.commit() Everything works like a champion! And so are you! Many thanks!

            – Slavia888
            Mar 26 at 22:47












          • Fine if it is solved.

            – forpas
            Mar 26 at 22:49

















          • Thanks for taking time to answer. Error message gone but no data is added to db. Have to check somehow where problem is.

            – Slavia888
            Mar 26 at 22:28











          • The create statement in your code creates a table named TEST but the insert statement adds a row to a table GBPCAD. Why?

            – forpas
            Mar 26 at 22:38











          • Forpas you are fast =) I solved it. It was my bad using gbpcad as table-name in example. What was the problem was - connection.commit() and not cursor.commit() Everything works like a champion! And so are you! Many thanks!

            – Slavia888
            Mar 26 at 22:47












          • Fine if it is solved.

            – forpas
            Mar 26 at 22:49
















          Thanks for taking time to answer. Error message gone but no data is added to db. Have to check somehow where problem is.

          – Slavia888
          Mar 26 at 22:28





          Thanks for taking time to answer. Error message gone but no data is added to db. Have to check somehow where problem is.

          – Slavia888
          Mar 26 at 22:28













          The create statement in your code creates a table named TEST but the insert statement adds a row to a table GBPCAD. Why?

          – forpas
          Mar 26 at 22:38





          The create statement in your code creates a table named TEST but the insert statement adds a row to a table GBPCAD. Why?

          – forpas
          Mar 26 at 22:38













          Forpas you are fast =) I solved it. It was my bad using gbpcad as table-name in example. What was the problem was - connection.commit() and not cursor.commit() Everything works like a champion! And so are you! Many thanks!

          – Slavia888
          Mar 26 at 22:47






          Forpas you are fast =) I solved it. It was my bad using gbpcad as table-name in example. What was the problem was - connection.commit() and not cursor.commit() Everything works like a champion! And so are you! Many thanks!

          – Slavia888
          Mar 26 at 22:47














          Fine if it is solved.

          – forpas
          Mar 26 at 22:49





          Fine if it is solved.

          – forpas
          Mar 26 at 22:49








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid …


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346827%2fadd-dictionary-or-list-to-sqlite3-gives-error-operation-parameter-must-be-str%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







          Popular posts from this blog

          How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

          Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?