-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import sqlite3 | ||
|
||
conn = sqlite3.connect(":memory:") | ||
crs = conn.cursor() | ||
|
||
# use the database here | ||
|
||
conn.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,34 @@ | ||
import sqlite3 | ||
|
||
conn = sqlite3.connect("companies.db") | ||
crs = conn.cursor() | ||
|
||
sql = ''' | ||
CREATE TABLE companies ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
name VARCRCHAR(100) UNIQUE NOT NULL, | ||
established INTEGER NOT NULL, | ||
employees INTEGER DEFAULT 0 | ||
) | ||
''' | ||
def create_table(conn): | ||
crs = conn.cursor() | ||
|
||
try: | ||
crs.execute(sql) | ||
except sqlite3.OperationalError as err: | ||
print(f'sqlite error: {err.args[0]}') # table companies already exists | ||
print(f'remove companies.db to show how it works') | ||
sql = ''' | ||
CREATE TABLE companies ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
name VARCRCHAR(100) UNIQUE NOT NULL, | ||
established INTEGER NOT NULL, | ||
employees INTEGER DEFAULT 0 | ||
) | ||
''' | ||
|
||
conn.commit() | ||
try: | ||
crs.execute(sql) | ||
except sqlite3.OperationalError as err: | ||
print(f'sqlite error: {err.args[0]}') # table companies already exists | ||
print(f'remove companies.db to show how it works') | ||
|
||
conn.close() | ||
conn.commit() | ||
|
||
print('done') | ||
def main(): | ||
conn = sqlite3.connect("companies.db") | ||
|
||
create_table(conn) | ||
|
||
conn.close() | ||
|
||
print('done') | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters