| 976 | } |
| 977 | |
| 978 | static SE_SQL_CONSTRUCT* getSDESQLConstructInfo(layerObj *layer, long* id) |
| 979 | { |
| 980 | SE_SQL_CONSTRUCT* sql; |
| 981 | |
| 982 | char *full_filter=NULL; |
| 983 | char *pszId=NULL; |
| 984 | long status; |
| 985 | |
| 986 | msSDELayerInfo *sde=NULL; |
| 987 | full_filter = (char*) msSmallMalloc((1000+1)*sizeof (char)); |
| 988 | full_filter[0] = '\0'; |
| 989 | if(!msSDELayerIsOpen(layer)) { |
| 990 | msSetError( MS_SDEERR, |
| 991 | "SDE layer has not been opened.", |
| 992 | "getSDESQLConstructInfo()"); |
| 993 | return(NULL); |
| 994 | } |
| 995 | |
| 996 | sde = layer->layerinfo; |
| 997 | |
| 998 | if (!sde->join_table) { |
| 999 | msSetError( MS_SDEERR, |
| 1000 | "Join table is null, we should be using QueryInfo.", |
| 1001 | "getSDESQLConstructInfo()"); |
| 1002 | return(NULL); |
| 1003 | } |
| 1004 | |
| 1005 | status = SE_sql_construct_alloc( 2, &sql); |
| 1006 | if(status != SE_SUCCESS) { |
| 1007 | sde_error( status, |
| 1008 | "getSDESQLConstructInfo()", |
| 1009 | "SE_sql_construct_alloc()"); |
| 1010 | return(NULL); |
| 1011 | } |
| 1012 | |
| 1013 | strcpy(sql->tables[0], sde->table); /* main table */ |
| 1014 | strcpy(sql->tables[1], sde->join_table); /* join table */ |
| 1015 | |
| 1016 | /* If we were given an ID *and* we have a join, we need to |
| 1017 | set our FILTER statement to reflect this. */ |
| 1018 | if ((sde->join_table) && (id != NULL)) { |
| 1019 | pszId = msLongToString(*id); |
| 1020 | strcat(full_filter, layer->filter.string); |
| 1021 | strcat(full_filter, " AND "); |
| 1022 | strcat(full_filter, sde->row_id_column); |
| 1023 | strcat(full_filter, "="); |
| 1024 | strcat(full_filter, pszId); |
| 1025 | msFree(pszId); |
| 1026 | sql->where = msStrdup(full_filter); |
| 1027 | |
| 1028 | |
| 1029 | } else { |
| 1030 | sql->where = layer->filter.string; |
| 1031 | } |
| 1032 | |
| 1033 | msFree(full_filter); |
| 1034 | |
| 1035 | if (layer->debug) msDebug("WHERE statement: %s\n", sql->where); |
no test coverage detected