table definition export as JSON complete
This commit is contained in:
parent
d1a4894cc1
commit
53628d6531
|
@ -62,7 +62,10 @@ class DBSchema:
|
||||||
def writeFingerprint(self):
|
def writeFingerprint(self):
|
||||||
keys = self.tables.keys()
|
keys = self.tables.keys()
|
||||||
for key in keys:
|
for key in keys:
|
||||||
|
print "[[ TABLE: <" + key + "> ]]"
|
||||||
tableDef = self.tables[key]
|
tableDef = self.tables[key]
|
||||||
|
# hehehe = tableDef.SQLstr()
|
||||||
|
print str(tableDef.SQLstr())
|
||||||
tableDef.toJSON()
|
tableDef.toJSON()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -101,7 +104,7 @@ class TableDefinition:
|
||||||
if results:
|
if results:
|
||||||
colstr = results.group(1)
|
colstr = results.group(1)
|
||||||
print "[[ TABLE: <" + tableName + "> ]]"
|
print "[[ TABLE: <" + tableName + "> ]]"
|
||||||
print "FIELDS: " + colstr
|
# print "FIELDS: " + colstr
|
||||||
columns = colstr.split(',')
|
columns = colstr.split(',')
|
||||||
for col in columns:
|
for col in columns:
|
||||||
newField = self.__parseCreateStr(col.strip())
|
newField = self.__parseCreateStr(col.strip())
|
||||||
|
@ -159,20 +162,20 @@ class TableDefinition:
|
||||||
newField['datatype'] = results.group(2)
|
newField['datatype'] = results.group(2)
|
||||||
newField['notnull'] = True
|
newField['notnull'] = True
|
||||||
return newField
|
return newField
|
||||||
|
# PRIMARY KEY (field_name,
|
||||||
|
results = re.match(r'PRIMARY KEY \((\w+)\,?', sqltext)
|
||||||
|
if results:
|
||||||
|
field = self.fields[results.group(1)]
|
||||||
|
field['primarykey'] = True
|
||||||
|
return False
|
||||||
# custom_ringtone TEXT
|
# custom_ringtone TEXT
|
||||||
results = re.match(r'(\w+)\s+(\w+)', sqltext)
|
results = re.match(r'(\w+)\s+(\w+)', sqltext)
|
||||||
if results:
|
if results:
|
||||||
newField['name'] = results.group(1)
|
newField['name'] = results.group(1)
|
||||||
newField['datatype'] = results.group(2)
|
newField['datatype'] = results.group(2)
|
||||||
return newField
|
return newField
|
||||||
# PRIMARY KEY (field_name,
|
|
||||||
results = re.match(r'PRIMARY KEY \((\w+)\,', sqltext)
|
|
||||||
if results:
|
|
||||||
field = self.fields[results.group(1)]
|
|
||||||
field['primarykey'] = True
|
|
||||||
return False
|
|
||||||
# field_name)
|
# field_name)
|
||||||
results = re.match(r'(\w+)\)', sqltext)
|
results = re.match(r'\,?(\w+)\)', sqltext)
|
||||||
if results:
|
if results:
|
||||||
field = self.fields[results.group(1)]
|
field = self.fields[results.group(1)]
|
||||||
field['primarykey'] = True
|
field['primarykey'] = True
|
||||||
|
@ -207,10 +210,7 @@ class TableDefinition:
|
||||||
return self.tableName
|
return self.tableName
|
||||||
|
|
||||||
|
|
||||||
|
def SQLstr(self):
|
||||||
class TableField:
|
return self.sqlStr
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
|
|
1
main.py
1
main.py
|
@ -15,6 +15,7 @@ def main():
|
||||||
retVal = db.scanDBFile(filein)
|
retVal = db.scanDBFile(filein)
|
||||||
|
|
||||||
if (retVal > 0):
|
if (retVal > 0):
|
||||||
|
print "\n\n"
|
||||||
db.writeFingerprint()
|
db.writeFingerprint()
|
||||||
else:
|
else:
|
||||||
print db.getErrorString(retVal)
|
print db.getErrorString(retVal)
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
|
||||||
|
{
|
||||||
|
"tables": {
|
||||||
|
"table_def_1": {
|
||||||
|
|
||||||
|
},
|
||||||
|
"table_def_2": {
|
||||||
|
|
||||||
|
},
|
||||||
|
"table_def_3": {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue