-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlite_setup_create_table.py
More file actions
87 lines (65 loc) · 2.16 KB
/
sqlite_setup_create_table.py
File metadata and controls
87 lines (65 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import sqlite3
def create_new_table():
connection = sqlite3.connect('fundanew.db')
cursor = connection.cursor()
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS ads (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
status text,
link text,
thumbnail_link text,
name text,
address text,
price int,
living_space int,
plot_area int,
rooms int,
broker_name text,
broker_link text,
is_processed boolean DEFAULT FALSE,
added_on timestamp,
type text,
latitude text,
longitude text,
error_link text,
UNIQUE(link)
)"""
)
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS images (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
ad_id INTEGER NOT NULL,
image_link text,
type_of_image text,
is_processed boolean DEFAULT FALSE,
added_on timestamp DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (ad_id) REFERENCES ads(id),
UNIQUE (ad_id, image_link)
)"""
)
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS ad_details (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
ad_id INTEGER NOT NULL,
ad_body text,
is_processed boolean DEFAULT FALSE,
added_on timestamp DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (ad_id) REFERENCES ads(id),
UNIQUE (ad_id)
)"""
)
connection.close()
# PRAGMA foreign_keys;
# Code language: SQL (Structured Query Language) (sql)
# The command returns an integer value: 1: enable, 0: disabled. If the command returns nothing, it means that your SQLite version doesn’t support foreign key constraints.
# If the SQLite library is compiled with foreign key constraint support, the application can use the PRAGMA foreign_keys command to enable or disable foreign key constraints at runtime.
# To disable foreign key constraint:
# PRAGMA foreign_keys = OFF;
# Code language: SQL (Structured Query Language) (sql)
# To enable foreign key constraint:
# PRAGMA foreign_keys = ON;
if __name__ == "__main__":
create_new_table()