There are quite a few basic problems:
(1) #include '...' won't work/compile because a single-quote in C/C++ denotes a character and not a string (this is different in SQL)
(2) You have no DECLARE SECTION, so the precompiler cannot find any host variables.
(3) Use
Code:
EXEC SQL INCLUDE OG.h;
instead of #include "OG.h" so that the precompiler is aware of this.
(4) Don't use casts on the SQLCODE - use it directly to avoid potential problems arising from the casting. (As a general rule: if you need a cast, you typically have a design problem in your code.)
(5) You should treat positive SQL codes differently than negative ones because positive codes denote warnings only and are not error conditions.
(6) I always recommend to do this:
Code:
EXEC SQL INCLUDE SQLCA;
instead of #include <sqlca.h>
(7) I also recommend to do this:
Code:
EXEC SQL DECLARE SQLCA;
instead of "struct sqlca sqlca;" and place this inside each function or method that contains embedded SQL statements. Otherwise, you have a global variable and that impacts reentrancy most severely.
Regarding the segfaults, it would be usual debugging that can be applied to find the reason for this. But I think there are some basic problems with the code (see above), which suggests that other problems can be present in the pieces not shown here. Maybe it is something simple like trying to access a pointer that was not properly initialized? Hard to guess...