add CREATE TABLE
This commit is contained in:
39
dm.py
39
dm.py
@@ -1,17 +1,34 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import sys, json, locale
|
||||
reload(sys)
|
||||
sys.setdefaultencoding('UTF-8')
|
||||
sys.setdefaultencoding(locale.getpreferredencoding())
|
||||
#locale.setlocale(locale.LC_ALL, 'ru_RU.UTF-8')
|
||||
import sys, json, sqlite3
|
||||
|
||||
table_list = open("tables.json", "r")
|
||||
data = json.load(table_list)
|
||||
|
||||
tDescr = data["tables"][0]["tableDescription"]
|
||||
tName = data["tables"][0]["tableName"]
|
||||
fList = data["tables"][0]["fList"]
|
||||
print(tName)
|
||||
print(tDescr)
|
||||
print(fList)
|
||||
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()
|
||||
|
||||
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
|
Reference in New Issue
Block a user