MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / comdb2CreateTrigger

Function comdb2CreateTrigger

sqlite/src/comdb2lua.c:134–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134void comdb2CreateTrigger(Parse *parse, int consumer, int seq, Token *proc, Cdb2TrigTables *tbl)
135{
136 if (comdb2IsPrepareOnly(parse))
137 return;
138
139 if (comdb2IsDryrun(parse)) {
140 sqlite3ErrorMsg(parse, "DRYRUN not supported for this operation");
141 parse->rc = SQLITE_MISUSE;
142 return;
143 }
144#ifndef SQLITE_OMIT_AUTHORIZATION
145 {
146 if( sqlite3AuthCheck(parse, consumer ? SQLITE_CREATE_LUA_CONSUMER :
147 SQLITE_CREATE_LUA_TRIGGER, 0, 0, 0) ){
148 sqlite3ErrorMsg(parse, COMDB2_NOT_AUTHORIZED_ERRMSG);
149 parse->rc = SQLITE_AUTH;
150 return;
151 }
152 }
153#endif
154
155 if (!tbl) {
156 sqlite3ErrorMsg(parse, "invalid table name");
157 return;
158 }
159
160 if (comdb2AuthenticateUserOp(parse))
161 return;
162
163 char spname[MAX_SPNAME];
164
165 if (comdb2TokenToStr(proc, spname, sizeof(spname))) {
166 sqlite3ErrorMsg(parse, "procedure name is too long");
167 return;
168 }
169
170 Q4SP(qname, spname);
171 if (getqueuebyname(qname)) {
172 sqlite3ErrorMsg(parse, "%s:%s already exists", consumer ? "consumer" : "trigger", spname);
173 return;
174 }
175
176 if (consumer == COMDB2_DEFAULT_CONSUMER) {
177 if (tbl->next) {
178 sqlite3ErrorMsg(parse, "cannot create default consumer for multiple tables");
179 return;
180 }
181 } else if (!comdb2LocateSP(parse, spname)) {
182 sqlite3ErrorMsg(parse, "no such procedure: %s", spname);
183 return;
184 }
185
186 strbuf *s = strbuf_new();
187 while (tbl) {
188 Table *table = tbl->table;
189 Cdb2TrigEvents *events = tbl->events;
190 tbl = tbl->next;
191 ColumnEventList celist;

Callers

nothing calls this directly

Calls 15

comdb2IsPrepareOnlyFunction · 0.85
comdb2IsDryrunFunction · 0.85
sqlite3ErrorMsgFunction · 0.85
sqlite3AuthCheckFunction · 0.85
comdb2AuthenticateUserOpFunction · 0.85
comdb2TokenToStrFunction · 0.85
getqueuebynameFunction · 0.85
comdb2LocateSPFunction · 0.85
add_watched_colsFunction · 0.85
freeFunction · 0.85
new_schemachange_typeFunction · 0.85
mallocFunction · 0.85

Tested by

no test coverage detected