1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
| %%%-------------------------------------------------------------------
| %%% @author bsk
| %%% @copyright (C) 2018, <COMPANY>
| %%% @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.
|
|