add CREATE TABLE

master
svk 2017-03-12 18:33:51 +03:00
parent 1e95f40c8b
commit 87b8237201
3 changed files with 34 additions and 17 deletions

BIN
database.db 100644

Binary file not shown.

39
dm.py
View File

@ -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

View File

@ -3,7 +3,7 @@
{
"tableName": "users",
"tableDescription": "Список пользователей",
"fList": [
"fieldList": [
{
"fName": "id",
"fDescr": "Номер п.п.",
@ -12,7 +12,7 @@
"autoIncrement": "yes"
},
{
"fName": "username",
"fName": "login",
"fDescr": "Логин",
"fType": "char(20)",
"index": "yes",
@ -26,7 +26,7 @@
"autoIncrement": "no"
},
{
"fName": "lastname",
"fName": "last_name",
"fDescr": "Фамилия",
"fType": "char(20)",
"index": "no",
@ -40,18 +40,18 @@
"autoIncrement": "no"
},
{
"fName": "middlename",
"fName": "middle_name",
"fDescr": "Отчество",
"fType": "char(20)",
"index": "no",
"autoIncr": "no"
"autoIncrement": "no"
}
]
},
{
"tableName": "docs",
"tableDescription": "Список документов",
"fList": [
"fieldList": [
{
"fName": "id",
"fDescr": "Номер п.п.",