2

I'm trying to insert data into my already created sqlite3 database. The data is able to be inputted. However, when trying to connect to my database and save I receive an error saying " AttributeError: 'function' object has no attribute 'connect'" My code fragment is listed below:

def data_entry():
    option_choice=0
    call("clear")
    print"\t","\n"*4
    print"\t","-"*45
    print"\t","\t-- Data Entry --"

    ID = raw_input("what is your user ID?")
    Name = raw_input("What is your name?")
    Age = raw_input("how old are you?")
    incidents = raw_input("How many incidents have you been involved in?")
    physical_ability = raw_input("what is your physical driving state?")
    Address = raw_input("what is your address?")
    Tel = raw_input("what is your phone number?")
    datestamp = raw_input("What is today's date?")
    keyword = raw_input("What is the make of your vehicle?")
    monthly_salary = raw_input("How much do you earn each month?")

    conn = db.connect('Insurance_Shark.db') 
    cursor = conn.cursor()
    cursor.execute("INSERT INTO customerdatabase VALUES(?, ?, ?, ?, ?, ?)",
        (ID, Name, Age, incidents, physical_ability, Address, Tel, datestamp, keyword, monthly_salary))
1
  • show you import line and what db in db.connect is. Commented Jan 10, 2016 at 18:16

1 Answer 1

1

You haven't shown how the db variable is defined, but it looks like it is a function, because:

>>> def db():
...     pass
... 
>>> db.connect()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute 'connect'

The connect() function is available directly from the sqlite3 module:

>>> import sqlite3 
>>> sqlite3.connect("test.db")
<sqlite3.Connection object at 0x10d922a28>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.