MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / SyncGetDatabases

Method SyncGetDatabases

class/databaseModel/pgsqlModel.py:952–982  ·  view source on GitHub ↗

@name 从服务器获取数据库 @param sid 0为本地数据库 1为远程数据库

(self, get)

Source from the content-addressed store, hash-verified

950 return 1
951
952 def SyncGetDatabases(self, get):
953 """
954 @name 从服务器获取数据库
955 @param sid 0为本地数据库 1为远程数据库
956 """
957 n = 0
958 s = 0
959 db_type = 0
960 sid = get.get('sid/d', 0)
961 if sid: db_type = 2
962
963 pgsql_obj = self.get_sql_obj_by_sid(sid)
964 status, err_msg = pgsql_obj.connect()
965 if status is False:
966 return public.returnMsg(False, "连接数据库失败!")
967
968 data = pgsql_obj.query('SELECT datname FROM pg_database;') # select * from pg_database order by datname
969 isError = self.IsSqlError(data)
970 if isError != None: return isError
971 if type(data) == str: return public.returnMsg(False, data)
972
973 sql = public.M('databases')
974 nameArr = ['information_schema', 'postgres', 'template1', 'template0', 'performance_schema', 'mysql', 'sys', 'master', 'model', 'msdb', 'tempdb', 'ReportServerTempDB', 'YueMiao', 'ReportServer']
975 for item in data:
976 dbname = item[0]
977 if dbname in nameArr: continue
978
979 if sql.where("name=? AND LOWER(type)=LOWER('PgSql')", (dbname,)).count(): continue
980 if public.M('databases').add('name,username,password,accept,ps,addtime,type,sid,db_type', (dbname, dbname, "", "", public.getMsg('INPUT_PS'), time.strftime('%Y-%m-%d %X', time.localtime()), 'PgSql', sid, db_type)): n += 1
981
982 return public.returnMsg(True, 'DATABASE_GET_SUCCESS', (str(n),))
983
984 def ResDatabasePassword(self, args):
985 """

Callers

nothing calls this directly

Calls 10

get_sql_obj_by_sidMethod · 0.95
returnMsgMethod · 0.80
getMethod · 0.45
connectMethod · 0.45
queryMethod · 0.45
IsSqlErrorMethod · 0.45
MMethod · 0.45
countMethod · 0.45
whereMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected