MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / main

Function main

examples/interfaces/08.events.cpp:130–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128}
129
130int main()
131{
132 int rc = 0;
133
134 // set default password if none specified in environment
135 setenv("ISC_USER", "sysdba", 0);
136 setenv("ISC_PASSWORD", "masterkey", 0);
137
138 // With ThrowStatusWrapper passed as status interface FbException will be thrown on error
139 ThrowStatusWrapper status(master->getStatus());
140
141 // Declare pointers to required interfaces
142 IProvider* prov = master->getDispatcher();
143 IAttachment* att = NULL;
144 ITransaction* tra = NULL;
145 Event* event = NULL;
146
147 try
148 {
149 // attach database
150 att = prov->attachDatabase(&status, "employee", 0, NULL);
151
152 // register an event
153 event = new Event(att, "EVENT1");
154 event->addRef();
155
156 const char cmdBlock[] = "execute block as begin post_event 'EVENT1'; end";
157
158 for (int i = 0; i < 3; ++i)
159 {
160#ifndef WIN32
161 sleep(1); // sec
162#else
163 Sleep(1000); // msec
164#endif
165 event->process(i);
166
167 tra = att->startTransaction(&status, 0, NULL);
168 att->execute(&status, tra, 0, cmdBlock, SAMPLES_DIALECT,
169 NULL, NULL, NULL, NULL);
170 tra->commit(&status);
171 tra = NULL;
172 }
173
174 // cleanup
175 event->release();
176 event = NULL;
177 att->detach(&status);
178 att = NULL;
179 }
180 catch (const FbException& error)
181 {
182 // handle error
183 rc = 1;
184
185 char buf[256];
186 master->getUtilInterface()->formatStatus(buf, sizeof(buf), error.getStatus());
187 fprintf(stderr, "%s\n", buf);

Callers

nothing calls this directly

Calls 15

setenvFunction · 0.85
sleepFunction · 0.50
getStatusMethod · 0.45
getDispatcherMethod · 0.45
attachDatabaseMethod · 0.45
addRefMethod · 0.45
processMethod · 0.45
startTransactionMethod · 0.45
executeMethod · 0.45
commitMethod · 0.45
releaseMethod · 0.45
detachMethod · 0.45

Tested by

no test coverage detected