add CREATE TABLE
This commit is contained in:
parent
1e95f40c8b
commit
87b8237201
BIN
database.db
Normal file
BIN
database.db
Normal file
Binary file not shown.
39
dm.py
39
dm.py
|
@ -1,17 +1,34 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import sys, json, locale
|
import sys, json, sqlite3
|
||||||
reload(sys)
|
|
||||||
sys.setdefaultencoding('UTF-8')
|
|
||||||
sys.setdefaultencoding(locale.getpreferredencoding())
|
|
||||||
#locale.setlocale(locale.LC_ALL, 'ru_RU.UTF-8')
|
|
||||||
|
|
||||||
table_list = open("tables.json", "r")
|
table_list = open("tables.json", "r")
|
||||||
data = json.load(table_list)
|
data = json.load(table_list)
|
||||||
|
|
||||||
tDescr = data["tables"][0]["tableDescription"]
|
tbl_list = data["tables"]
|
||||||
tName = data["tables"][0]["tableName"]
|
print(len(tbl_list))
|
||||||
fList = data["tables"][0]["fList"]
|
i = 0
|
||||||
print(tName)
|
while i < len(tbl_list):
|
||||||
print(tDescr)
|
tbl_descr = data["tables"][i]["tableDescription"]
|
||||||
print(fList)
|
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
|
12
tables.json
12
tables.json
|
@ -3,7 +3,7 @@
|
||||||
{
|
{
|
||||||
"tableName": "users",
|
"tableName": "users",
|
||||||
"tableDescription": "Список пользователей",
|
"tableDescription": "Список пользователей",
|
||||||
"fList": [
|
"fieldList": [
|
||||||
{
|
{
|
||||||
"fName": "id",
|
"fName": "id",
|
||||||
"fDescr": "Номер п.п.",
|
"fDescr": "Номер п.п.",
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
"autoIncrement": "yes"
|
"autoIncrement": "yes"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fName": "username",
|
"fName": "login",
|
||||||
"fDescr": "Логин",
|
"fDescr": "Логин",
|
||||||
"fType": "char(20)",
|
"fType": "char(20)",
|
||||||
"index": "yes",
|
"index": "yes",
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
"autoIncrement": "no"
|
"autoIncrement": "no"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fName": "lastname",
|
"fName": "last_name",
|
||||||
"fDescr": "Фамилия",
|
"fDescr": "Фамилия",
|
||||||
"fType": "char(20)",
|
"fType": "char(20)",
|
||||||
"index": "no",
|
"index": "no",
|
||||||
|
@ -40,18 +40,18 @@
|
||||||
"autoIncrement": "no"
|
"autoIncrement": "no"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fName": "middlename",
|
"fName": "middle_name",
|
||||||
"fDescr": "Отчество",
|
"fDescr": "Отчество",
|
||||||
"fType": "char(20)",
|
"fType": "char(20)",
|
||||||
"index": "no",
|
"index": "no",
|
||||||
"autoIncr": "no"
|
"autoIncrement": "no"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tableName": "docs",
|
"tableName": "docs",
|
||||||
"tableDescription": "Список документов",
|
"tableDescription": "Список документов",
|
||||||
"fList": [
|
"fieldList": [
|
||||||
{
|
{
|
||||||
"fName": "id",
|
"fName": "id",
|
||||||
"fDescr": "Номер п.п.",
|
"fDescr": "Номер п.п.",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user