Bộ lồng nhau hay còn gọi là cây SQL Traversal Pre-order Tree Travers [MPTT] đã sửa đổi được triển khai bằng Python cho MySQL và SQLite. Sử dụng cả đánh dấu ngang [trái, phải] và danh sách phụ huynhId để linh hoạt hơn cho truy vấn đặc biệt
Cung cấp xác thực cấu trúc cây và “ghi nhớ” thông qua SQLite. kỉ niệm. để đọc nhanh
Thí dụ
Chúng tôi muốn đạt được cây sau. Nút được đại diện bởi tên id → parentId [l, r]. Để xuất một cây theo cách này fangorn. kiểm tra. chức năng trực quan hóa có thể được sử dụng
R 1 → None [1, 18]
└─A1 2 → 1 [2, 5]
└─B1 3 → 2 [3, 4]
└─A2 4 → 1 [6, 13]
└─B2 5 → 4 [7, 8]
└─B3 6 → 4 [9, 12]
└─C1 7 → 6 [10, 11]
└─A3 8 → 1 [14, 17]
└─B4 9 → 8 [15, 16]
Đầu tiên chúng ta cần một bảng để đại diện cho cây. Và chúng tôi muốn một nút cây có tên
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
Bây giờ chúng ta có thể tạo ví dụ cây. Lưu ý rằng DAO mà cây dựa vào dự kiến sẽ hỗ trợ kiểu tham số DB-API có tên [i. e. NƠI node_id =. nútId]. Ngoài ra, các phương pháp kiểm soát giao dịch được khuyến nghị để triển khai hỗ trợ giao dịch lồng nhau. Tuy nhiên, bộ thử nghiệm yêu cầu các giao dịch lồng nhau để chạy. Đối với MySQLdb và sqlite3, có các trình bao bọc tương thích dưới fangorn. tương thích
Ali 252
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
27 import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
28Ali 255
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
Ali 257
Ali 258_______29
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
Initial nested dictionary:- {'Dict2': {'name': 'Bob', 'age': 21}, 'Dict1': {'name': 'Ali', 'age': 19}} Deleting Dict2:- {'Dict1': {'name': 'Ali', 'age': 19}} Deleting Dict1:- {}1
Ali 258
Initial nested dictionary:- {'Dict2': {'name': 'Bob', 'age': 21}, 'Dict1': {'name': 'Ali', 'age': 19}} Deleting Dict2:- {'Dict1': {'name': 'Ali', 'age': 19}} Deleting Dict1:- {}3
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
29Initial nested dictionary:- {'Dict2': {'name': 'Bob', 'age': 21}, 'Dict1': {'name': 'Ali', 'age': 19}} Deleting Dict2:- {'Dict1': {'name': 'Ali', 'age': 19}} Deleting Dict1:- {}5
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
Initial nested dictionary:- {'Dict2': {'name': 'Bob', 'age': 21}, 'Dict1': {'name': 'Ali', 'age': 19}} Deleting Dict2:- {'Dict1': {'name': 'Ali', 'age': 19}} Deleting Dict1:- {}7
Ali 258
Initial nested dictionary:- {'Dict2': {'name': 'Bob', 'age': 21}, 'Dict1': {'name': 'Ali', 'age': 19}} Deleting Dict2:- {'Dict1': {'name': 'Ali', 'age': 19}} Deleting Dict1:- {}9
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
301Ali 258
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
303 Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
Ali 257
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}9
Tạo một từ điển lồng nhau
Trong Python, từ điển lồng nhau có thể được tạo bằng cách đặt các từ điển được phân tách bằng dấu phẩy trong dấu ngoặc nhọn.
Python3
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
307Ali 252
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
27 import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
28import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
271import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
272import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
273import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
274import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
275import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
276import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
277____25import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
279import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
280import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
276import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
282Ali 252
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
284
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
285Ali 252
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
27 import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
28import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
271import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
29import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
521Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
523Ali 258
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
525Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
527Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}2
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
273import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
274import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
29import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
521Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
294Ali 258
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
525Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
298Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}9
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
276import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
641Ali 259
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
279import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
280import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
276import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
282Ali 252
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
284
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
649Ali 252
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
27 import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
28import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
271import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
29Ali 255
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0_______407
Ali 258
Ali 259
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}11
Ali 258
Initial nested dictionary:- {'Dict2': {'name': 'Bob', 'age': 21}, 'Dict1': {'name': 'Ali', 'age': 19}} Deleting Dict2:- {'Dict1': {'name': 'Ali', 'age': 19}} Deleting Dict1:- {}3
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}07
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}2
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
273import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
274import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
29Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}20
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
Ali 257
Ali 258
Ali 255
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}25
Ali 255
Ali 258
Ali 259
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}29
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
276import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
641____93import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
279import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
280import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
276import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
282Ali 252
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
284Đầu ra.
Ali 251
Thêm các phần tử vào Từ điển lồng nhau
Việc thêm các phần tử vào Từ điển lồng nhau có thể được thực hiện theo nhiều cách. Một cách để thêm từ điển trong Nested dictionary là thêm các giá trị từng cái một, Nested_dict[dict][key] = ‘value’. Một cách khác là thêm toàn bộ từ điển trong một lần, Nested_dict[dict] = { ‘key’. 'giá trị'}.
Python3
Ali 252
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
27 Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}41
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
276Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}43
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
279import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
280import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
276import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
282Ali 252
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
284
Ali 252______451____1271
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}53
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
27 Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}55
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}56
Ali 252______451____1271
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}60
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
521Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}53
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
27 import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
294Ali 252______451____1271
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}60
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
525Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}53
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
27 Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}72
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
276Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}74
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
276import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
282Ali 252
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
284
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}79
Ali 252______451______1274
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}53
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
27 import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
28import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
521Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}88
Ali 258
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
525Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}92
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}93
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
276Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}74
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
276import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
282Ali 252
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
284Đầu ra.
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}
Truy cập các phần tử của Từ điển lồng nhau
Để truy cập giá trị của bất kỳ khóa nào trong từ điển lồng nhau, hãy sử dụng cú pháp lập chỉ mục [].
Python3
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
285Ali 252
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
27 import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
28import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
271import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
29import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
521Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
523Ali 258
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
525Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
527Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}2
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
273import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
274import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
29import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
521Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
294Ali 258
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
525Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
298Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}9
Ali 2525
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
276import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
282Ali 252____451
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
271Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}60
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
521Ali 2533
Ali 2534
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
276import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
282Ali 252
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}51
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
274Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}60
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
525Ali 2533
Đầu ra.
Ali 25
Xóa từ điển khỏi Từ điển lồng nhau
Việc xóa từ điển khỏi từ điển lồng nhau có thể được thực hiện bằng cách sử dụng từ khóa del hoặc bằng cách sử dụng hàm pop[].
Python3
Ali 252
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
27 import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
28import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
271import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
29import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
521Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
523Ali 258
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
525Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
Ali 2554
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}2
Ali 2556
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
274import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
29import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
521Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
294Ali 258
import MySQLdb as mysql
conn = mysql.connect[user = 'guest', db = 'test']
conn.query['''
CREATE TABLE `node` [
`node_id` int[10] unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int[10] unsigned DEFAULT NULL,
`l` int[10] unsigned NOT NULL,
`r` int[10] unsigned NOT NULL,
`name` varchar[8] NOT NULL,
PRIMARY KEY [`node_id`],
KEY `l` [`l`],
KEY `r` [`r`],
KEY `parent_id` [`parent_id`],
CONSTRAINT `node_has_node` FOREIGN KEY [`parent_id`]
REFERENCES `node` [`node_id`]
ON DELETE CASCADE
ON UPDATE CASCADE
] ENGINE=InnoDB;
''']
525Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}0
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}72
Initial nested dictionary:- {} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}} After adding dictionary Dict1 {'Dict1': {'age': 21, 'name': 'Bob'}, 'Dict2': {'age': 25, 'name': 'Cara'}}9