theBrain 10.0
Loading...
Searching...
No Matches
abrain.c
Go to the documentation of this file.
1
10/* LABEL-START */
11
12#define META_FILE_NAME "abrain.c"
13
14/* LABEL-END */
15
16#include <stdlib.h>
17#include <stdbool.h>
18#include <stdint.h>
19#include <string.h>
20#include <ctype.h>
21
22#include "sqlite3.h"
23#include "msgque_mq.h"
24#include "debug_mq.h"
25
27static MK_TYP BrainTT = NULL;
28#define BrainT ((typeof(MqContextST)) BrainTT)
29#define BRAINCTX ((struct BrainCtxS*const)mqctx)
30#define MQCTX ((MQ_CTX*const)brain)
31#define META_CONTEXT_S mqctx
32#define SETUP_brain struct BrainCtxS*const brain = BRAINCTX
33#define SETUP_db sqlite3*const db = brain->db
34#define SETUP_W(sh) \
35 SETUP_brain; \
36 MK_I64 key; \
37 register sqlite3_stmt *hdl= brain->sh
38#define SETUP_C(sh) \
39 SETUP_brain; \
40 MK_STRN key; MK_SIZE klen; \
41 register sqlite3_stmt *hdl= brain->sh
42#define DbErrorCheck(f) \
43 if (unlikely((f) != SQLITE_OK)) { \
44 MkErrorSetC_4M (mqctx, sqlite3_errmsg(brain->db), __func__, sqlite3_extended_errcode(brain->db)); \
45 goto error; \
46 }
47#define CHECK_ARGS(s) \
48 if (MqReadGetNumItems(mqctx)) { \
49 return MkErrorSetV_4M (mqctx, __func__, SQLITE_ERROR, "usage: %s (%s)\n", __func__, s); \
50 }
51#define check_sqlite(E) \
52 if (unlikely((E) != SQLITE_OK))
53#define check_NULL(E) \
54 if (unlikely((E) == NULL))
55
56#define DB_PREPARE_MAX 100
57
71
72/*****************************************************************************/
73/* */
74/* Request Handler */
75/* */
76/*****************************************************************************/
77
80static void __attribute__ ((noreturn))
81BrainHelp (const char * base)
82{
83 fprintf (stderr, "usage: %s [OPTION]... [ARGUMENT]...\n", base);
84 fputs ("\n", stderr);
85 fputs (" This tool is the database server of NHI1.\n", stderr);
86 fputs (" main: https://theBrain.nhi1.de\n", stderr);
87 fputs (" tool: https://thebrain.nhi1.de/theBrain.htm\n", stderr);
88 fputs ("\n", stderr);
89 fprintf (stderr, " %s [ARGUMENT]... syntax:\n", base);
90 fprintf (stderr, " aclient [OPTION]... %c %s [OPTION]... [ARGUMENT]\n", MK_ALFA, base);
91 fputs ("\n", stderr);
92 fputs (MqHelp (NULL), stderr);
93 fputs ("\n", stderr);
94 fprintf (stderr," %s [OPTION]:\n", base);
95 fputs (" -h, --help print this help\n", stderr);
96 fputs ("\n", stderr);
97
98 exit(EXIT_SUCCESS);
99}
100
101#define READ_C(n) MK_STRN n; MkErrorCheck(MqReadSTR(mqctx,&n))
102
103/*****************************************************************************/
104/* */
105/* Helper */
106/* */
107/*****************************************************************************/
108
109static enum MkErrorE IdxGet_RT ( MK_RT_ARGS MQ_CTX const mqctx, MK_I32 *pidx ) {
110 MkErrorCheck (MqReadI32 (mqctx, pidx));
111 if (*pidx < 0 || *pidx > DB_PREPARE_MAX-1) {
112 MkErrorSetV_4M (mqctx, __func__, SQLITE_ERROR, "prepare index out of range: 0 <= idx <= %i", DB_PREPARE_MAX-1);
113 goto error;
114 }
115 return MK_OK;
116error:
117 return MkErrorStack_1X(mqctx);
118}
119
120#define IdxGet(...) IdxGet_RT(MK_RT_CALL __VA_ARGS__)
121
122inline static enum MkErrorE IdxFinalize_RT ( MK_RT_ARGS MQ_CTX const mqctx, MK_I32 idx ) {
124 if (brain->prepStmt[idx] != NULL) {
125 DbErrorCheck(sqlite3_finalize(brain->prepStmt[idx]));
126 brain->prepStmt[idx] = NULL;
127 MkSysFree(brain->inType[idx]);
128 brain->inEnd[idx] = NULL;
129 MkSysFree(brain->outType[idx]);
130 brain->outEnd[idx] = NULL;
131 }
132 return MK_OK;
133error:
134 return MkErrorStack_1X(mqctx);
135}
136
137#define IdxFinalize(...) IdxFinalize_RT(MK_RT_CALL __VA_ARGS__)
138
139inline static enum MkErrorE HdlGet_RT (
141 MQ_CTX const mqctx,
142 sqlite3_stmt **phdl,
143 MK_STRN *pInType,
144 MK_STRN *pInEnd,
145 MK_STRN *pOutType,
146 MK_STRN *pOutEnd
147) {
149 MK_I32 idx;
150 MkErrorCheck (IdxGet (mqctx, &idx));
151 check_NULL(*phdl = brain->prepStmt[idx]) {
152 MkErrorSetV_4M (mqctx, __func__, SQLITE_ERROR, "the prepare-index '%i' was NOT defined", idx);
153 goto error;
154 }
155 *pInType = brain->inType[idx];
156 *pInEnd = brain->inEnd[idx];
157 *pOutType = brain->outType[idx];
158 *pOutEnd = brain->outEnd[idx];
159 return MK_OK;
160error:
161 return MkErrorStack_1X(mqctx);
162}
163
164#define HdlGet(...) HdlGet_RT(MK_RT_CALL __VA_ARGS__)
165
166static enum MkErrorE ctxCleanup_RT ( MK_RT_ARGS MQ_CTX const mqctx ) {
168 MkSysFree (brain->storage);
169 if (brain->db != NULL) {
170 for (MK_I32 idx=0; idx<brain->prepare_start; idx++) {
171 MkErrorCheck (IdxFinalize (mqctx, idx));
172 }
173 brain->prepare_start=0;
174 DbErrorCheck(sqlite3_close(brain->db))
175 brain->db=NULL;
176 }
177 return MK_OK;
178error:
179 brain->db = NULL;
180 return MkErrorStack_1X(mqctx);
181}
182
183#define ctxCleanup(...) ctxCleanup_RT(MK_RT_CALL __VA_ARGS__)
184
185/*****************************************************************************/
186/* */
187/* Service Handler */
188/* */
189/*****************************************************************************/
190
191inline static enum MkTypeE GetTypeE ( MK_STRB t ) {
192 switch (t) {
193 case 'C': return MK_STRT;
194 case 'I': return MK_I32T;
195 case 'D': return MK_DBLT;
196 case 'W': return MK_I64T;
197 case 'B': return MK_BINT;
198 case 'Y': return MK_I8T;
199 case 'O': return MK_BOLT;
200 case 'S': return MK_I16T;
201 case 'F': return MK_FLTT;
202 case 'L': return MK_LSTT;
203 }
204 return MK_STRT;
205}
206
207inline static MK_STRB GetTypeS ( enum MkTypeE const ntype ) {
208 switch (ntype) {
209 case MK_STRT: return 'C';
210 case MK_I32T: return 'I';
211 case MK_DBLT: return 'D';
212 case MK_I64T: return 'W';
213 case MK_BINT: return 'B';
214 case MK_I8T: return 'Y';
215 case MK_BOLT: return 'O';
216 case MK_I16T: return 'S';
217 case MK_FLTT: return 'F';
218 case MK_LSTT: return 'L';
219 }
220 return '*';
221}
222
223inline static enum MkTypeE GetTypeD ( sqlite3_stmt *hdl, MK_I32 idx ) {
224 switch (sqlite3_column_type(hdl,idx)) {
225 case SQLITE_INTEGER:
226 switch (sqlite3_column_bytes(hdl,idx)) {
227 case 1: return MK_I8T;
228 case 2: return MK_I16T;
229 case 3:
230 case 4: return MK_I32T;
231 case 6:
232 case 8: return MK_I64T;
233 }
234 break;
235 case SQLITE_FLOAT: return MK_DBLT;
236 case SQLITE_BLOB: return MK_BINT;
237 case SQLITE_TEXT: return MK_STRT;
238 case SQLITE_NULL: return MK_BINT;
239 }
240 return MK_BINT;
241}
242
243#define case1(t,f,c) \
244 case t##T: { \
245 t dat; \
246 MkErrorCheck(MkBufferGet ## c(buf,&dat)); \
247 DbErrorCheck(f(hdl,idx,dat)); \
248 break; \
249 }
250
251inline static enum MkErrorE GetFromDBnat_RT (
253 MQ_CTX const mqctx,
254 enum MkTypeE ntype,
255 sqlite3_stmt *hdl,
256 MK_I32 idx
257) {
258 switch (ntype) {
259 case MK_STRT: return MqSendSTR(mqctx,(MK_STRN)sqlite3_column_text(hdl,idx));
260 case MK_I32T: return MqSendI32(mqctx,(MK_I32)sqlite3_column_int(hdl,idx));
261 case MK_I16T: return MqSendI16(mqctx,(MK_I16)sqlite3_column_int(hdl,idx));
262 case MK_I8T: return MqSendI8(mqctx,(MK_I8)sqlite3_column_int(hdl,idx));
263 case MK_BOLT: return MqSendBOL(mqctx,(MK_BOL)sqlite3_column_int(hdl,idx));
264 case MK_I64T: return MqSendI64(mqctx,(MK_I64)sqlite3_column_int64(hdl,idx));
265 case MK_DBLT: return MqSendDBL(mqctx,(MK_DBL)sqlite3_column_double(hdl,idx));
266 case MK_FLTT: return MqSendFLT(mqctx,(MK_FLT)sqlite3_column_double(hdl,idx));
267 case MK_BINT: return MqSendBIN(mqctx,MkBinaryCreate(sqlite3_column_bytes(hdl,idx),sqlite3_column_blob(hdl,idx)));
268 case MK_LSTT:
269 return MkErrorSetV_4M (mqctx, __func__, SQLITE_ERROR, "invalid protocoll item '%c'", GetTypeS(ntype));
270 }
271 return MK_BINT;
272}
273
274#define GetFromDBnat(...) GetFromDBnat_RT(MK_RT_CALL __VA_ARGS__)
275
276inline static enum MkErrorE GetFromDBary_RT (
278 MQ_CTX const mqctx,
279 enum MkTypeE ntype,
280 sqlite3_stmt *hdl,
281 MK_I32 idx
282) {
283 switch (ntype) {
284 case MK_BINT:
285 MqSendBIN_E(mqctx,MkBinaryCreate(sqlite3_column_bytes(hdl,idx),sqlite3_column_blob(hdl,idx)));
286 break;
287 case MK_STRT:
288 MqSendSTR_E(mqctx,(MK_STRN)sqlite3_column_text(hdl,idx));
289 break;
290 default:
291 MkBufferCastTo_E( MkBufferSetSTR(BRAINCTX->buf, (MK_STRN)sqlite3_column_text(hdl, idx)), ntype);
292 MqSendBUF_E(mqctx, BRAINCTX->buf);
293 break;
294 }
295 return MK_OK;
296error:
297 return MkErrorStack_1X(mqctx);
298}
299
300#define GetFromDBary(...) GetFromDBary_RT(MK_RT_CALL __VA_ARGS__)
301
304 MK_I32 idx=0;
305 MK_BUF buf;
306 sqlite3_stmt *hdl=NULL;
307 MK_STRN inType=NULL, inEnd=NULL;
308 MK_STRN outType=NULL, outEnd=NULL;
309 enum MkTypeE ntype;
310
311 MkErrorCheck(HdlGet(mqctx, &hdl, &inType, &inEnd, &outType, &outEnd));
312 DbErrorCheck(sqlite3_reset(hdl));
313
314 MqSendSTART(mqctx);
315 while (MqReadItemExists(mqctx)) {
316 idx+=1;
317 MkErrorCheck(MqReadBUF(mqctx,&buf));
318 if (inType && inType < inEnd) {
319 ntype = GetTypeE(*inType);
320 if (buf->var.type != ntype && buf->var.type != MK_STRT) {
321 MkErrorSetV_4M(mqctx,__func__,SQLITE_ERROR,
322 "the buffer type '%c' does not match database type '%c'",
323 MkBufferGetType1(buf), *inType);
324 goto error;
325 }
326 inType++;
327 } else {
328 ntype = buf->var.type;
329 }
330 switch (buf->var.type) {
331 case MK_I8T: DbErrorCheck(sqlite3_bind_int(hdl,idx,buf->storage.first.A->I8)); break;
332 case MK_BOLT: DbErrorCheck(sqlite3_bind_int(hdl,idx,buf->storage.first.A->BOL)); break;
333 case MK_I16T: DbErrorCheck(sqlite3_bind_int(hdl,idx,buf->storage.first.A->I16)); break;
334 case MK_I32T: DbErrorCheck(sqlite3_bind_int(hdl,idx,buf->storage.first.A->I32)); break;
335 case MK_I64T: DbErrorCheck(sqlite3_bind_int64(hdl,idx,buf->storage.first.A->I64)); break;
336 case MK_FLTT: DbErrorCheck(sqlite3_bind_double(hdl,idx,buf->storage.first.A->FLT)); break;
337 case MK_DBLT: DbErrorCheck(sqlite3_bind_double(hdl,idx,buf->storage.first.A->DBL)); break;
338 case MK_STRT:
339 switch (ntype) {
340 case1(MK_I8,sqlite3_bind_int,I8)
341 case1(MK_BOL,sqlite3_bind_int,BOL)
342 case1(MK_I16,sqlite3_bind_int,I16)
343 case1(MK_I32,sqlite3_bind_int,I32)
344 case1(MK_I64,sqlite3_bind_int64,I64)
345 case1(MK_FLT,sqlite3_bind_double,FLT)
346 case1(MK_DBL,sqlite3_bind_double,DBL)
347 case MK_STRT:
348 DbErrorCheck(sqlite3_bind_text (hdl,idx,buf->storage.first.C,(int)buf->storage.size,SQLITE_TRANSIENT));
349 break;
350 case MK_BINT:
351 if (buf->storage.size == 0) {
352 DbErrorCheck (sqlite3_bind_null (hdl,idx));
353 } else {
354 DbErrorCheck (sqlite3_bind_blob (hdl,idx,buf->storage.first.B,(int)buf->storage.size,SQLITE_TRANSIENT));
355 }
356 break;
357 case MK_LSTT:
358 MkErrorSetV_4M (mqctx, __func__, SQLITE_ERROR, "invalid protocoll item '%c'", GetTypeS(ntype));
359 }
360 break;
361 case MK_BINT:
362 if (buf->storage.size == 0) {
363 DbErrorCheck (sqlite3_bind_null (hdl,idx));
364 } else {
365 DbErrorCheck (sqlite3_bind_blob (hdl,idx,buf->storage.first.B,(int)buf->storage.size,SQLITE_TRANSIENT));
366 }
367 break;
368 case MK_LSTT:
369 MkErrorSetV_4M (mqctx, __func__, SQLITE_ERROR, "invalid protocoll item '%c'", GetTypeS(ntype));
370 break;
371 }
372 }
373
374 MK_STRN pos;
375 MqSendSTART(mqctx);
376 while (true) {
377 switch (sqlite3_step(hdl)) {
378 case SQLITE_ROW: {
379 MqSendL_START(mqctx);
380 for (idx=0,pos=outType; idx<sqlite3_column_count(hdl); idx++,pos++) {
381 ntype = pos && pos < outEnd ? GetTypeE(*pos) : GetTypeD(hdl,idx);
382 switch (sqlite3_column_type(hdl,idx)) {
383 case SQLITE_INTEGER:
384 case SQLITE_FLOAT:
385 case SQLITE_NULL:
386 MkErrorCheck(GetFromDBnat(mqctx, ntype, hdl, idx));
387 break;
388 case SQLITE_BLOB:
389 case SQLITE_TEXT:
390 MkErrorCheck(GetFromDBary(mqctx, ntype, hdl, idx));
391 break;
392 }
393 }
394 MqSendL_END(mqctx);
395 continue;
396 break;
397 }
398 case SQLITE_DONE:
399 goto error;
400 case SQLITE_LOCKED:
401 case SQLITE_BUSY:
402 continue;
403 default:
404 MkErrorSetC_4M (mqctx, sqlite3_errmsg(brain->db), __func__, sqlite3_extended_errcode(brain->db));
405 DbErrorCheck(sqlite3_reset(hdl));
406 goto error;
407 }
408 }
409
410error:
411 sqlite3_reset(hdl);
412 return MqSendRETURN(mqctx);
413}
414
417 MK_STRN sql;
418 MkErrorCheck(MqReadSTR(mqctx,&sql));
419 DbErrorCheck(sqlite3_exec(brain->db,sql, NULL, NULL, NULL));
420
421error:
422 return MqSendRETURN(mqctx);
423}
424
427 MK_STRN sql,end,type,start;
428 MK_I32 idx;
429 MK_BUF buf;
430
431 // parse prefix
432 MkErrorCheck(MqReadBUF(mqctx,&buf));
433 if (buf->var.type == MK_I32T) {
434 MkErrorCheck(MkBufferGetI32(buf,&idx));
435 MkErrorCheck(IdxFinalize(mqctx, idx));
436 MkErrorCheck(MqReadBUF(mqctx,&buf));
437 } else {
438 idx = brain->prepare_start;
439 }
440 MkErrorCheck(MkBufferGetSTR(buf,&sql));
441 end = sql + buf->storage.size;
442
443 // process values
444 MqSendSTART(mqctx);
445 while (sql != NULL && *sql != '\0') {
446 // get the index
447 for (; idx<DB_PREPARE_MAX && brain->prepStmt[idx]!=NULL; idx++);
448 if (idx >= DB_PREPARE_MAX) {
449 MkErrorSetV_4M (mqctx, __func__, SQLITE_ERROR, "unable to find a free prepare entry - only '%i' entries are allowed.", DB_PREPARE_MAX);
450 goto error;
451 }
452 // find 'in:???' prefix
453 brain->inType[idx] = NULL;
454 brain->inEnd[idx] = NULL;
455 brain->outType[idx] = NULL;
456 brain->outEnd[idx] = NULL;
457 // 1. search for '/' as beginn of comment
458 for (start=sql; start<end && *start != '/' && *start != ';'; start++);
459 // 2. '/*' as 2cnd char
460 if (start == end || *start++ != '/' || *start++ != '*') goto update;
461
462 // find 'in:???' prefix
463 // in1. 'WS' before "TYPE:???"
464 for (; start<end && isspace(*start); start++);
465 // in2. 'in:' the prefix
466 if (start >= end-3 || strncmp(start, "in:", 3)) goto out;
467 start+=3;
468 // in3. 'ASCII' as beginn of comment
469 for (type=start; start<end && isupper(*start); start++);
470 if (start == end) goto out;
471 // in4. we have everything
472 brain->inType[idx] = MkSysStrNDup(MkOBJ(mqctx), type, (start-type));
473 brain->inEnd[idx] = brain->inType[idx] + (start-type);
474 *brain->inEnd[idx] = '\0';
475
476out:
477 // find 'out:???' prefix
478 // out1. 'WS' before "TYPE:???"
479 for (; start<end && isspace(*start); start++);
480 // out2. 'out:' the prefix
481 if (start >= end-4 || strncmp(start, "out:", 4)) goto update;
482 start+=4;
483 // out3. 'ASCII' as beginn of comment
484 for (type=start; start<end && isupper(*start); start++);
485 if (start == end) goto update;
486 // out4. we have everything
487 brain->outType[idx] = MkSysStrNDup(MkOBJ(mqctx), type, (start-type));
488 brain->outEnd[idx] = brain->outType[idx] + (start-type);
489 *brain->outEnd[idx] = '\0';
490
491update:
492 // update the database
493 brain->prepare_start=idx+1;
494 DbErrorCheck(sqlite3_prepare_v2(brain->db, sql, -1, &brain->prepStmt[idx], &sql));
495 MqSendI32(mqctx, idx);
496 }
497error:
498/*
499printLC(brain->inType[idx])
500printLC(brain->inEnd[idx])
501printLC(brain->outType[idx])
502printLC(brain->outEnd[idx])
503*/
504 return MqSendRETURN(mqctx);
505}
506
508 MK_I32 idx;
509 MkErrorCheck(IdxGet(mqctx, &idx));
510 MkErrorCheck(IdxFinalize(mqctx, idx));
511error:
512 return MqSendRETURN(mqctx);
513}
514
515static enum MkErrorE OPEN ( MQ_SERVICE_CALL_ARGS );
516
518 MkErrorCheck (ctxCleanup(mqctx));
519 MkErrorCheck (MqServiceDelete (mqctx, "-ALL"));
520 MkErrorCheck (MqServiceCreate (mqctx, "OPEN", OPEN, NULL, NULL, NULL));
521
522error:
523 return MqSendRETURN(mqctx);
524}
525
528
529 // open storage
530 {
531 MK_STRN dbstorage;
532 MkErrorCheck(MqReadSTR(mqctx,&dbstorage));
533
534 if (dbstorage == NULL) {
535 return MkErrorSetC_4M (mqctx, "storage-file is empty or invalid", __func__, SQLITE_ERROR);
536 }
537
538 MkDLogV(mqctx,5,"try to open database '%s'\n", dbstorage);
539
540 // open the database
541 DbErrorCheck (sqlite3_open(dbstorage, &brain->db));
542 }
543
544 // add/remove services
545 MkErrorCheck (MqServiceDelete (mqctx, "OPEN"));
546
547 MkErrorCheck (MqServiceCreate (mqctx, "CLOS", CLOS, NULL, NULL, NULL));
548 MkErrorCheck (MqServiceCreate (mqctx, "EXEC", EXEC, NULL, NULL, NULL));
549 MkErrorCheck (MqServiceCreate (mqctx, "PREP", PREP, NULL, NULL, NULL));
550 MkErrorCheck (MqServiceCreate (mqctx, "FINA", FINA, NULL, NULL, NULL));
551 MkErrorCheck (MqServiceCreate (mqctx, "STEP", STEP, NULL, NULL, NULL));
552
553 MqSendSTART(mqctx);
554error:
555 return MqSendRETURN(mqctx);
556}
557
558/*****************************************************************************/
559/* */
560/* context_init */
561/* */
562/*****************************************************************************/
563
564static enum MkErrorE
566{
568 MkBufferDelete(brain->buf);
569 MkErrorCheck(ctxCleanup(mqctx));
570
571 return MK_OK;
572error:
573 return MkErrorStack_1X(mqctx);
574}
575
576static enum MkErrorE
578{
580 brain->prepare_start=0;
581 brain->buf = MkBufferCreate(MkBuffer1024STT,10);
582 MkErrorCheck (MqServiceCreate (mqctx, "OPEN", OPEN, NULL, NULL, NULL));
583
584 return MK_OK;
585error:
586 return MkErrorStack_1X(mqctx);
587}
588
589/*****************************************************************************/
590/* */
591/* main */
592/* */
593/*****************************************************************************/
594
595static enum MkErrorE
597{
598 MQ_CTX const mqctx = *contextP = MqContextCreate(BrainTT,tmpl);
599
600 mqctx->setup.isServer = true;
603
604 return MK_OK;
605}
606
607
612int
614 const int argc,
615 MK_STRN argv[]
616)
617{
618 MqSetup();
620
621 // define the new type
622 BrainTT = MkTypeDup2(MqContextSTT, "BrainTT");
623 BrainTT->objsize = sizeof(struct BrainCtxS);
624 BrainT->fHelp = BrainHelp;
625
626 // parse the command-line
627 MK_BFL args = MkBufferListCreateVC (argc, argv);
628 MQ_CTX mqctx = NULL;
629
630 // call Factory
631 MQ_FCT fct = MqFactoryAdd_2(BrainFactory, "abrain");
632 MqFactoryNew_E (fct, NULL, &mqctx);
633
634 // create the ServerCtxS
635 MqLinkCreate_E (mqctx, args);
636
637 // start event-loop and wait forever
639
640 // finish and exit
641error:
642 MkBufferListDelete(args);
643 MqExit_1 (mqctx);
644}
645
#define GetFromDBary(...)
Definition abrain.c:300
#define IdxGet(...)
Definition abrain.c:120
#define DbErrorCheck(f)
Definition abrain.c:42
static enum MkErrorE BrainCleanup(MQ_SERVICE_CALL_ARGS)
Definition abrain.c:565
static enum MkErrorE HdlGet_RT(MK_RT mkrt, MQ_CTX const mqctx, sqlite3_stmt **phdl, MK_STRN *pInType, MK_STRN *pInEnd, MK_STRN *pOutType, MK_STRN *pOutEnd)
Definition abrain.c:139
static enum MkErrorE FINA(MQ_SERVICE_CALL_ARGS)
Definition abrain.c:507
#define IdxFinalize(...)
Definition abrain.c:137
int main(const int argc, MK_STRN argv[])
main entry-point for the tool
Definition abrain.c:613
static enum MkErrorE OPEN(MQ_SERVICE_CALL_ARGS)
Definition abrain.c:526
#define DB_PREPARE_MAX
Definition abrain.c:56
static enum MkErrorE STEP(MQ_SERVICE_CALL_ARGS)
Definition abrain.c:302
static enum MkErrorE GetFromDBary_RT(MK_RT mkrt, MQ_CTX const mqctx, enum MkTypeE ntype, sqlite3_stmt *hdl, MK_I32 idx)
Definition abrain.c:276
static enum MkErrorE BrainFactory(MQ_CALLBACK_FACTORY_CTOR_ARGS)
Definition abrain.c:596
static enum MkErrorE IdxGet_RT(MK_RT mkrt, MQ_CTX const mqctx, MK_I32 *pidx)
Definition abrain.c:109
static enum MkTypeE GetTypeE(MK_STRB t)
Definition abrain.c:191
static MK_TYP BrainTT
link to the MqErrorS object
Definition abrain.c:27
static enum MkErrorE BrainSetup(MQ_SERVICE_CALL_ARGS)
Definition abrain.c:577
#define SETUP_brain
Definition abrain.c:32
static enum MkErrorE EXEC(MQ_SERVICE_CALL_ARGS)
Definition abrain.c:415
static enum MkTypeE GetTypeD(sqlite3_stmt *hdl, MK_I32 idx)
Definition abrain.c:223
static void BrainHelp(const char *base)
display help using -h or --help command-line option
Definition abrain.c:81
#define BRAINCTX
Definition abrain.c:29
#define ctxCleanup(...)
Definition abrain.c:183
#define check_NULL(E)
Definition abrain.c:53
#define GetFromDBnat(...)
Definition abrain.c:274
#define HdlGet(...)
Definition abrain.c:164
static MK_STRB GetTypeS(enum MkTypeE const ntype)
Definition abrain.c:207
static enum MkErrorE IdxFinalize_RT(MK_RT mkrt, MQ_CTX const mqctx, MK_I32 idx)
Definition abrain.c:122
static enum MkErrorE ctxCleanup_RT(MK_RT mkrt, MQ_CTX const mqctx)
Definition abrain.c:166
static enum MkErrorE PREP(MQ_SERVICE_CALL_ARGS)
Definition abrain.c:425
static enum MkErrorE GetFromDBnat_RT(MK_RT mkrt, MQ_CTX const mqctx, enum MkTypeE ntype, sqlite3_stmt *hdl, MK_I32 idx)
Definition abrain.c:251
#define BrainT
Definition abrain.c:28
static enum MkErrorE CLOS(MQ_SERVICE_CALL_ARGS)
Definition abrain.c:517
#define case1(t, f, c)
Definition abrain.c:243
#define MkBuffer1024STT
#define MkBufferGetSTR(...)
#define MkBufferGetI32(...)
#define MkBufferGetType1(...)
#define MkBufferCastTo_E(...)
#define MkBufferSetSTR(...)
#define MkBufferCreate(...)
#define MkBufferDelete(x)
#define MkBufferListCreateVC(...)
#define MkBufferListDelete(x)
#define MkErrorStack_1X(...)
#define MkErrorSetV_4M(m,...)
#define MkErrorSetC_4M(m,...)
static MkBinaryR MkBinaryCreate(MK_SIZE size, MK_BINN data)
MkErrorE
MkTypeE
MK_TIMEOUT_DEFAULT
MK_OK
MK_I8T
MK_I64T
MK_FLTT
MK_BINT
MK_I16T
MK_BOLT
MK_DBLT
MK_I32T
MK_STRT
MK_LSTT
float MK_FLT
const MK_STRB * MK_STRN
char MK_STRB
signed char MK_I8
signed long long MK_I64
MK_STRB * MK_STR
unsigned char MK_BOL
#define MK_ALFA
signed short int MK_I16
double MK_DBL
signed int MK_I32
#define MkOBJ(x)
#define MkDLogV(x, _debug, printfmt,...)
MK_STR MkSysStrNDup(MK_OBJN fmtobj, MK_STRN const str, MK_SIZE const len)
#define MkSysFree(pointer)
#define AllRtSetup_NULL
#define MK_RT_ARGS
#define MkTypeDup2(...)
#define MqContextSTT
#define MQ_SERVICE_CALL_ARGS
#define MqExit_1(ctx)
#define MqProcessEvent_E(...)
#define MqReadSTR(...)
#define MqReadBUF(...)
#define MqReadI32(...)
bool MqReadItemExists(MQ_CTX const ctx)
#define MqSendBIN(...)
#define MqSendI8(...)
#define MqSendBOL(...)
#define MqSendI64(...)
#define MqSendBUF_E(...)
#define MqSendSTR_E(...)
#define MqSendI32(...)
#define MqSendI16(...)
#define MqSendSTR(...)
#define MqSendBIN_E(...)
#define MqSendFLT(...)
#define MqSendDBL(...)
#define MqSendSTART(...)
#define MqSendL_START(...)
#define MqSendL_END(...)
#define MqSendRETURN(...)
#define MqServiceCreate(...)
#define MqServiceDelete(...)
#define MqContextCreate(...)
#define MQ_CALLBACK_FACTORY_CTOR_ARGS
#define MqFactoryNew_E(...)
#define MqFactoryAdd_2(fct, ident)
MQ_WAIT_FOREVER
MK_STR MqHelp(MK_STRN tool)
void MqSetup(void)
the local context of the server tool
Definition abrain.c:59
sqlite3 * db
database handle
Definition abrain.c:62
MK_STR inEnd[DB_PREPARE_MAX]
array prepared statement input types end pointer
Definition abrain.c:65
MK_STR outType[DB_PREPARE_MAX]
array prepared statement output types string
Definition abrain.c:66
MK_STRN storage
storage file
Definition abrain.c:61
sqlite3_stmt * prepStmt[DB_PREPARE_MAX]
array prepared statement pointer
Definition abrain.c:63
MK_STR outEnd[DB_PREPARE_MAX]
array prepared statement output types end pointer
Definition abrain.c:67
MK_STR inType[DB_PREPARE_MAX]
array prepared statement input types string
Definition abrain.c:64
MK_I32 prepare_start
point to the next empty prepare empty
Definition abrain.c:68
MQ_CTXR mqctx
the LibMqMsgque context object
Definition abrain.c:60
MK_BUF buf
context local storage
Definition abrain.c:69
union MkBufferU first
struct MkBufferS::@5 storage
MK_NUM size
struct MkBufferS::@4 var
enum MkTypeE type
size_t objsize
MqTokenF fCall
struct MqSetupS setup
struct MqCallbackS ServerCleanup
struct MqCallbackS ServerSetup
bool isServer
MK_STRN C
MK_ATO * A
MK_BIN B