I am creating a contact book using sqlite3 in python, but when I'm trying to insert my phone number as integer type, it appears that it will occur syntax error for octal integer, and when I'm putting the numbers into string type, the 0 is not printed. How can I input my phone number no matter in int or str?
import sqlite3
from math import ceil
conn = sqlite3.connect("contact_book.db")
c = conn.cursor()
c.execute("""CREATE TABLE contact_book(
name text,
address text,
phone_number integer,
email address text
)""")
conn.commit()
def insert_contact_details(name, address, phone_number, email_address=None):
with conn:
c.execute("INSERT INTO contact_book VALUES(:name, :address, :phone_number, :email_address)",
{'name': name, 'address': address, 'phone_number': str(phone_number), 'email_address': email_address})
Below is when I put phone number into int:
insert_contact_details("Durian", "Malaysia", 0123239588)
output:
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
Below is when I put phone number into str type:
insert_contact_details("Durian", "Malaysia", "0123239588")
output:
[(Durian, Malaysia, 123239588, None)]