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