Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
how to check if my DBA is open
-
- ***I am a very very beginner programmer and you will see it soon. I just started to create my app as part of a personal goal in Python.
I read about SQLite3 and start to code with and example of creating a , everything goes fine until I run again my code and got an error showing me up that my dba is already created.
My question is: There is a code or instruction that permit me to verify whether my dba file is open or not.
code example:
c = conn.cursor()
Create table
c.execute('''CREATE TABLE stocks
(date text, trans text, symbol text, qty real, price real)''')Insert a row of data
c.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)")
Save (commit) the changes
conn.commit()
We can also close the connection if we are done with it.
Just be sure any changes have been committed or they will be lost.
conn.close()
Thanks.
-
@sendog3c First of all: welcome here...
For the future, if you want to post your code in this forum, use the button </> above,
it will help you to insert your code between two lines of three back quotes
c = conn.cursor() # Create table c.execute('''CREATE TABLE IF NOT EXISTS stocks (date text, trans text, symbol text, qty real, price real)''') #c.execute('''CREATE TABLE stocks (date text, trans text, symbol text, qty real, price real)''') # Insert a row of data c.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)") # Save (commit) the changes conn.commit() # We can also close the connection if we are done with it. # Just be sure any changes have been committed or they will be lost. conn.close()
Now, for your problem, use CREATE TABLE IF NOT EXISTS
-
CVP:
Thank you. Let me try your answer.
-
CVP:
Thank you again. This works.