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 6174175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:42:23+00:00 2026-05-23T23:42:23+00:00

I have a table created using Python + Sqlite3 c.execute(‘CREATE TABLE IF NOT EXISTS

  • 0

I have a table created using Python + Sqlite3

c.execute('CREATE TABLE IF NOT EXISTS reg(col1 TEXT PRIMARY KEY, col2 TEXT)')

I even wrote a record into it using val1 and val2 variables which have string values (URLs to be specific)

c.execute('INSERT INTO reg VALUES(?,?)', (val1, val2))

Now when I print the table using this code

c.execute('SELECT * FROM reg')
rows = c.fetchall()
print rows

It shows output as

[(u'http://www.someURL.com', u'http://www.someURL.com/someDIR/')]

Now, what is this u in front of my column values mean?

EDIT: My next doubt is in continuation to this question so I am updating this thread instead of creating a new one. I have updated the title too. Hope that’s OK.

From the above code, It is clear that my col1 is a Primary Key. So, when I tried to purposefully insert the same records for the second time it throws the exception

IntegrityError: column col1 is not unique

In order to handle this, I modified the code like this…

try:
    c.execute('INSERT INTO reg VALUES(?,?)', (val1, val2))
except sqlite3.IntegrityError:
    print val1+ " is already in the database"

Now executing this code caused me this exception

Traceback (most recent call last):
  File "C:\Documents and Settings\user\Desktop\dbUrl.py", line 47, in <module>
    c.execute('INSERT INTO reg VALUES(?,?)', (val1,val2))
OperationalError: database is locked

Any idea how do I resolve this? Infact, I don’t even understand what this OperationError mean and what made the DB to be locked?

  • 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-23T23:42:24+00:00Added an answer on May 23, 2026 at 11:42 pm

    The u means those are Unicode strings. They can be encoded to any character set you want:

    u'http://www.someURL.com'.encode('ascii') # or 'latin-1' or 'utf-8'
    

    You’ll get back the same string without the u because they’re all ASCII characters.

    See http://docs.python.org/howto/unicode.html.

    If the strings only contain ASCII characters (all the normal symbols on an English keyboard) then you don’t have to worry too much about this. If, however, you’re using an extended character set, you need to make sure you’re specifying the right encoding when saving strings or displaying them to the user.

    Edit: When I execute

    import sqlite3
    
    con = sqlite3.connect(":memory:")
    con.isolation_level = None
    c = con.cursor()
    
    val1, val2 = 'a', 'b'
    
    c.execute('CREATE TABLE IF NOT EXISTS reg(col1 TEXT PRIMARY KEY, col2 TEXT)')
    c.execute('INSERT INTO reg VALUES(?,?)', (val1, val2))
    try:
        c.execute('INSERT INTO reg VALUES(?,?)', (val1, val2))
    except sqlite3.IntegrityError:
        print val1, "is already in the database"
    

    I get a is already in the database. (Note the proper way to do that print statement, although yours is perfectly valid.) So your problem is somewhere else — locked means something else is writing to the database. Try this with an in memory database as I did, so you know for sure nothing else is accessing it. If this works, your problem is what the exception indicates — something else is accessing the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created one table using the below command: create table Table1( Id int
I have a table that's created like this: CREATE TABLE bin_test (id INTEGER PRIMARY
I have to create one table using XSLT and CSS. The table should look
I have the following database table created thus: CREATE TABLE AUCTIONS ( ARTICLE_NO VARCHAR(20),
I have a Sqlite 3 and/or MySQL table named clients.. Using python 2.6, How
I have created a MySQL database using MySQL Workbench. It has about 20 tables.
Apologies for the vague question. Here it is: I have a table object created
I have a table that is created in a DataList in ASP.Net. This table
I have a table where I created an INSTEAD OF trigger to enforce some
I have a table that I created within xcode so there is no nib

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.