data-manipulation/dm.py

34 lines
1.1 KiB
Python
Raw Normal View History

2017-03-12 15:02:21 +03:00
# -*- coding: utf-8 -*-
2017-03-12 18:33:51 +03:00
import sys, json, sqlite3
2017-03-12 15:02:21 +03:00
table_list = open("tables.json", "r")
data = json.load(table_list)
2017-03-12 18:33:51 +03:00
tbl_list = data["tables"]
print(len(tbl_list))
i = 0
while i < len(tbl_list):
tbl_descr = data["tables"][i]["tableDescription"]
tbl_name = data["tables"][i]["tableName"]
field_list = data["tables"][i]["fieldList"][i].keys()
2017-03-12 15:02:21 +03:00
2017-03-12 18:33:51 +03:00
x = 0
# список всех полей таблицы
qwery_create = "CREATE TABLE " + tbl_name + " ("
qwery_select = "SELECT * FROM "
index = ""
while x < len(data["tables"][i]["fieldList"]):
if data["tables"][i]["fieldList"][x]["autoIncrement"] == "yes":
auto_increment = " AUTOINCREMENT, "
else:
auto_increment = ", "
qwery_create = qwery_create + data["tables"][i]["fieldList"][x]["fName"] + " " + data["tables"][i]["fieldList"][x]["fType"] + auto_increment
if data["tables"][i]["fieldList"][x]["index"] == "PRIMARY KEY":
index = "PRIMARY KEY(" + data["tables"][i]["fieldList"][x]["fName"] + ")"
x = x+1
qwery_create = qwery_create + index + ");"
print(qwery_create)
i = i+1