-------------------------------------------------------------------- */ msSDELayerGetRowIDColumn */ -------------------------------------------------------------------- */ A helper function to return unique row ID column for */ an opened SDE layer. The caller owns the string. */ ------------------------------------------------
| 170 | /* an opened SDE layer. The caller owns the string. */ |
| 171 | /* -------------------------------------------------------------------- */ |
| 172 | char *msSDELayerGetRowIDColumn(layerObj *layer) |
| 173 | { |
| 174 | #ifdef USE_SDE |
| 175 | long status, column_type; |
| 176 | char* column_name; |
| 177 | char* full_column_name; |
| 178 | char* proc_key; |
| 179 | |
| 180 | SE_REGINFO registration; |
| 181 | |
| 182 | msSDELayerInfo *sde=NULL; |
| 183 | sde = layer->layerinfo; |
| 184 | |
| 185 | if(!msSDELayerIsOpen(layer)) { |
| 186 | msSetError( MS_SDEERR, |
| 187 | "SDE layer has not been opened.", |
| 188 | "msSDELayerGetRowIDColumn()"); |
| 189 | return NULL; |
| 190 | } |
| 191 | |
| 192 | column_name = (char*) msSmallMalloc(SE_QUALIFIED_COLUMN_LEN+1); |
| 193 | column_name[0]='\0'; |
| 194 | |
| 195 | proc_key = msLayerGetProcessingKey(layer,"OBJECTID"); |
| 196 | if (proc_key) |
| 197 | strcpy(column_name,proc_key); |
| 198 | |
| 199 | if (proc_key) { |
| 200 | if (layer->debug) |
| 201 | msDebug("msSDELayerGetRowIDColumn(): Column was manually set to %s\n", column_name); |
| 202 | return column_name; |
| 203 | } |
| 204 | full_column_name = (char*) msSmallMalloc(SE_QUALIFIED_COLUMN_LEN+1); |
| 205 | full_column_name[0]='\0'; |
| 206 | |
| 207 | /* |
| 208 | ** if the state_id is the SE_DEFAULT_STATE_ID, we are |
| 209 | ** assuming no versioned queries are happening at all |
| 210 | ** and we are using the hardcoded row_id column. |
| 211 | */ |
| 212 | if (sde->state_id == SE_DEFAULT_STATE_ID) { |
| 213 | if(layer->debug) { |
| 214 | msDebug("msSDELayerGetRowIDColumn(): State ID was " |
| 215 | "SE_DEFAULT_STATE_ID, reverting to %s.\n", |
| 216 | MS_SDE_ROW_ID_COLUMN); |
| 217 | } |
| 218 | strcpy(column_name,MS_SDE_ROW_ID_COLUMN); |
| 219 | } |
| 220 | |
| 221 | /* |
| 222 | ** if the state_id was not set to SE_DEFAULT_STATE_ID, |
| 223 | ** check if the table is registered, and if so, use the |
| 224 | ** registration info to tell us what the row_id column is. |
| 225 | */ |
| 226 | status = SE_reginfo_create (®istration); |
| 227 | if(status != SE_SUCCESS) { |
| 228 | sde_error( status, |
| 229 | "msSDELayerGetRowIDColumn()", |
no test coverage detected