使用定义为的结构:
EXEC SQL BEGIN DECLARE SECTION;
typedef struct U_DataInfo{
char Cfg_Name[51];
int ID;
// Others elements
double X;
double Y;
} U_DataInfo;
EXEC SQL END DECLARE SECTION;
使用查询很简单:
SELECT DISTINCT CFG_NAME, ID, /* some columns */, X, Y
FROM table vi
LEFT JOIN other_table ON other_table.other_id = vi.id
LEFT JOIN /* other joins */
/* where conditions */
结果是,X和Y可以为NULL。
然后将光标用作:
U_DataInfo VL_Elem;
// Declare a dynamic cursor
EXEC SQL DECLARE SQL_DataCursor STATEMENT;
EXEC SQL PREPARE SQL_DataCursor FROM :SelectQuery;
EXEC SQL DECLARE DataCursor CURSOR FOR SQL_DataCursor;
// Open the cursor
EXEC SQL OPEN DataCursor;
// Some stuff and while...
EXEC SQL FETCH DataCursor
INTO :VL_Elem.Cfg_Name,
:VL_Elem.ID,
// Some Stuff
:VL_Elem.X,
:VL_Elem.Y;
// Some stuff
EXEC SQL CLOSE DataCursor;
每当SQL查询返回X和Y的NULL值时,它们在U_DataInfo中的变量都将0.000作为值。
我们可以使它们为-nan以便稍后在代码中进行检查吗?