|
@ -100,36 +100,38 @@ def sourceTables(request, sourceId): |
|
|
json_data.append(table['fields']) |
|
|
json_data.append(table['fields']) |
|
|
|
|
|
|
|
|
except: |
|
|
except: |
|
|
|
|
|
print('no linked tables before') |
|
|
|
|
|
|
|
|
source = SourceDataBase.objects.get(source_id=sourceId) |
|
|
source = SourceDataBase.objects.get(source_id=sourceId) |
|
|
source = serializers.serialize('json', [source]) |
|
|
source = serializers.serialize('json', [source]) |
|
|
source = json.loads(source)[0]['fields'] |
|
|
source = json.loads(source)[0]['fields'] |
|
|
password = source['password'].encode(('utf-8')) |
|
|
password = source['password'].encode(('utf-8')) |
|
|
print(password) |
|
|
|
|
|
host = source['host'] |
|
|
host = source['host'] |
|
|
username = source['username'] |
|
|
username = source['username'] |
|
|
port = source['port'] |
|
|
port = source['port'] |
|
|
password = pc.decrypt(password) |
|
|
password = pc.decrypt(password) |
|
|
database = source['database'] |
|
|
database = source['database'] |
|
|
print(password) |
|
|
|
|
|
|
|
|
|
|
|
db=_mysql.connect( |
|
|
db=_mysql.connect( |
|
|
host=host, |
|
|
host=host, |
|
|
port=int(port), |
|
|
port=int(port), |
|
|
user=username, |
|
|
user=username, |
|
|
passwd=password, |
|
|
passwd=password, |
|
|
db=database, |
|
|
db=database |
|
|
charset='utf8' |
|
|
|
|
|
) |
|
|
) |
|
|
db.query('show tables;') |
|
|
db.query('show tables;') |
|
|
tables = db.store_result().fetch_row(maxrows=0, how=2) |
|
|
tables = db.store_result().fetch_row(maxrows=0, how=2) |
|
|
db.close() |
|
|
db.close() |
|
|
json_data = list(tables[0].values()) |
|
|
tables = list(tables) |
|
|
for i, table in enumerate(json_data): |
|
|
for i, table in enumerate(tables): |
|
|
json_data[i] = { |
|
|
tableName = list(table.values())[0].decode('utf-8') |
|
|
'table': table.decode('utf-8'), |
|
|
if next((x for x in json_data if x['table'] == tableName), None): |
|
|
|
|
|
print(tableName + ' linked') |
|
|
|
|
|
else: |
|
|
|
|
|
json_data.append({ |
|
|
|
|
|
'table': tableName, |
|
|
'status': 0 |
|
|
'status': 0 |
|
|
} |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return JsonResponse({'code': 20000, 'message': 'success', 'data': json_data }) |
|
|
return JsonResponse({'code': 20000, 'message': 'success', 'data': json_data }) |
|
|
|
|
|
|
|
|