%%%------------------------------------------------------------------- %%% @author bsk %%% @copyright (C) 2018, %%% @doc %%% %%% @end %%% Created : 05. 十二月 2018 上午10:14 %%%------------------------------------------------------------------- -module(sys_o_tables_esql). -author("bsk"). %% API -compile(export_all). -include("esqltool.hrl"). %, del_SysTabInfo/1, findSysTableInfo/2]).%%del_sys_table/1, %% not used create_sys_table(Nodes, TableName) -> %% Conn = getESqlDBRef(), %% case Conn of %% {ok, Db} -> %% ok = esqlite3:exec("begin;", Db), %% %% ok = esqlite3:exec("commit;", Db), %% esqlite3:close(Db); %% {error, false} -> %% io:format("Conn is ~p ~n", [Conn]), %% RecSize = -1; %% _ -> %% io:format("Conn is ~p ~n", [Conn]), %% RecSize = -2 %% end, ok. %%% 创建同步表后应添加一条记录 add_sys_table(Uuid, CluId, TableName, TableDesc, TableType, BwType, StartTime, EndTime) -> if Uuid == " " -> ID = syncTool:getUUIDString(); Uuid == "" -> ID = syncTool:getUUIDString(); true -> ID = Uuid end, UpdateTime = syncTool:getTimeStr(), CreateUser = node(), StrUuid = syncTool:change2Str(ID), StrCluId = syncTool:change2Str(CluId), StrTableName = syncTool:change2Str(TableName), StrTableDesc = syncTool:change2Str(TableDesc), StrTableType = syncTool:change2Str(TableType), StrStartTime = syncTool:change2Str(StartTime), StrBwType = syncTool:change2Str(BwType), StrEndTime = syncTool:change2Str(EndTime), StrCreateUser = syncTool:change2Str(CreateUser), Sql = ["INSERT INTO sys_o_tables (uuid, Clusterid, tableName, tableDesc, tableType, bwType, startTime, endTime, update_time, create_by)VALUES ('", StrUuid, "', '", StrCluId, "', '", StrTableName, "', '", StrTableDesc, "', '", StrTableType, "', '", StrBwType, "', '", StrStartTime, "', '", StrEndTime, "', '", UpdateTime, "', '", StrCreateUser, "');"], Ret = executeSqlLocalyAndSaveToCacheAndSendSql(Sql), if Ret == {atomic, ok} -> Result = ID; true -> Result = "" end, Result. update_sys_tableRec(Uuid, TableType, TableName, SyncType, BwType, StartTime, EndTime) -> UpdateTime = syncTool:getTimeStr(), StrUuid = syncTool:change2Str(Uuid), StrTableType = syncTool:change2Str(TableType), StrTableName = syncTool:change2Str(TableName), StrSyncType = syncTool:change2Str(SyncType), StrBwType = syncTool:change2Str(BwType), StrStartTime = syncTool:change2Str(StartTime), StrEndTime = syncTool:change2Str(EndTime), Sql = ["UPDATE sys_o_tables SET bwType ='", StrBwType, "', startTime='", StrStartTime, "', endTime='", StrEndTime, "', update_time='", UpdateTime, "' WHERE uuid = '", StrUuid, "';"], executeSqlLocalyAndSaveToCacheAndSendSql(Sql). del_sys_table(Uuid, TableType) -> UpdateTime = syncTool:getTimeStr(), StrUuid = syncTool:change2Str(Uuid), StrTableType = syncTool:change2Str(TableType), Sql = ["UPDATE sys_o_tables SET del_flag ='1', update_time='", UpdateTime, "' WHERE uuid = '", StrUuid, "';DROP TABLE '", StrUuid, "';DROP TABLE '", StrUuid, "_fea';"], executeSqlLocalyAndSaveToCacheAndSendSql(Sql). searchUuidWithTabName(TableName) -> StrTableName = syncTool:change2Str(TableName), io:format("~p is ~p", [StrTableName, TableName]), Sql = ["SELECT uuid FROM sys_o_tables WHERE tableName = '", StrTableName, "' And del_flag=0;"], Maps = selectSomeInfoWithSql(Sql), if is_list(Maps) -> [Rec | Tmp] = Maps, [Tup | TmpTum] = Rec, Ret = element(2, Tup); is_tuple(Maps) -> Ret = "" end, Ret. tableIsExist(Uuid) -> StrUuid = syncTool:change2Str(Uuid), io:format("struuid is ~p ", [StrUuid]), Sql = ["SELECT uuid,tableName FROM sys_o_tables WHERE uuid = '", StrUuid, "' AND del_flag=0;"], Maps = selectSomeInfoWithSql(Sql), if is_list(Maps) -> if length(Maps) > 0 -> Ret = true; true -> Ret = false end; is_tuple(Maps) -> Ret = false; true -> Ret = error end, Ret. findAllSysTableInfo() -> Sql = ["SELECT * FROM sys_o_tables where del_flag=0;"], Maps = selectSomeInfoWithSql(Sql), if is_list(Maps) -> Ret = Maps; is_tuple(Maps) -> Ret = []; true -> Ret = [] end, io:format("Ret is ~p ", [Ret]), Ret.