Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6105055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:54:48+00:00 2026-05-23T13:54:48+00:00

I’m try to insert values into my sqlite table using a python script. It

  • 0

I’m try to insert values into my sqlite table using a python script.

It was working perfectly until I tried to add another column called ‘information’ – it then threw the following error:

You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings

So I added:

conn.text_factory = str

Then I got this error:

Incorrect number of bindings supplied. The current statement uses 7, and there are 3 supplied.

I think the problem is that this new ‘information’ column contains a few lines of text so I may be specifying it incorrectly as ‘text’. My python script code:

import sqlite3;
from datetime import datetime, date;
import time
conn = sqlite3.connect('mynewtable.sqlite3')
conn.text_factory = str
c = conn.cursor()
c.execute('drop table if exists mynewtable')
c.execute('create table mynewtable(id integer primary key autoincrement, rank integer, placename text, information text, nooftimes integer, visit text, fav integer, year integer)')

def mysplit (string):
quote = False
retval = []
current = ""
for char in string:
    if char == '"':
        quote = not quote
    elif char == ',' and not quote:
        retval.append(current)
        current = ""
    else:
        current += char
retval.append(current)
return retval

# Read lines from file, skipping first line
data = open("mynewtable.csv", "r").readlines()[1:]
for entry in data:
# Parse values
vals = mysplit(entry.strip())

# Insert the row!
print "Inserting %s..." % (vals[0])
sql = "insert into mynewtable values(NULL, ?, ?, ?, ?, ?, ?, ?)"
c.execute(sql, vals)

# Done!
conn.commit()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:54:49+00:00Added an answer on May 23, 2026 at 1:54 pm

    It seems you are trying to re-invent the wheel a bit here 🙂

    Try using python’s csv module; I’ve used it extensively and it works very well:
    http://docs.python.org/library/csv.html

    It works perfectly well with properly formed csv files that have multi-line texts.

    EDIT:

    For example, you can use the csv rows (which are lists) directly in your execute function:

    import csv
    for row in csv.reader(open('allnamesallyearsn.csv')):
        c.execute(sql, row)
    

    2nd EDIT:

    As per my last comment, here is the code you posted making use of the csv module:

    import sqlite3, csv, time
    from datetime import datetime, date
    
    conn = sqlite3.connect('mynewtable.sqlite3')
    conn.text_factory = str
    c = conn.cursor()
    c.execute('drop table if exists mynewtable')
    c.execute('create table mynewtable('
              'id integer primary key autoincrement, '
              'rank integer, '
              'placename text, '
              'information text, '
              'nooftimes integer, '
              'visit text, '
              'fav integer, '
              'year integer)')
    
    sql_insert = "insert into mynewtable values(NULL, ?, ?, ?, ?, ?, ?, ?)"
    csv_reader = csv.reader(open('mynewtable.csv', 'rb'))
    csv_reader.next() # skip headers
    for csv_row in csv_reader:
        print "Inserting %s..." % (csv_row)
        c.execute(sql_insert, csv_row)
    
    conn.commit()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.