Used by NextShape() to access a shape in the query set */
| 1239 | |
| 1240 | /* Used by NextShape() to access a shape in the query set */ |
| 1241 | int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *record) |
| 1242 | { |
| 1243 | msMSSQL2008LayerInfo *layerinfo; |
| 1244 | int result; |
| 1245 | SQLINTEGER needLen = 0; |
| 1246 | SQLINTEGER retLen = 0; |
| 1247 | char dummyBuffer[1]; |
| 1248 | char *wkbBuffer; |
| 1249 | char *valueBuffer; |
| 1250 | char oidBuffer[ 16 ]; /* assuming the OID will always be a long this should be enough */ |
| 1251 | long record_oid; |
| 1252 | int t; |
| 1253 | |
| 1254 | /* for coercing single types into geometry collections */ |
| 1255 | char *wkbTemp; |
| 1256 | int geomType; |
| 1257 | |
| 1258 | layerinfo = getMSSQL2008LayerInfo(layer); |
| 1259 | |
| 1260 | if(!layerinfo) |
| 1261 | { |
| 1262 | msSetError(MS_QUERYERR, "GetShape called with layerinfo = NULL", "msMSSQL2008LayerGetShape()"); |
| 1263 | return MS_FAILURE; |
| 1264 | } |
| 1265 | |
| 1266 | if(!layerinfo->conn) |
| 1267 | { |
| 1268 | msSetError(MS_QUERYERR, "NextShape called on MSSQL2008 layer with no connection to DB.", "msMSSQL2008LayerGetShape()"); |
| 1269 | return MS_FAILURE; |
| 1270 | } |
| 1271 | |
| 1272 | shape->type = MS_SHAPE_NULL; |
| 1273 | |
| 1274 | while(shape->type == MS_SHAPE_NULL) |
| 1275 | { |
| 1276 | /* SQLRETURN rc = SQLFetchScroll(layerinfo->conn->hstmt, SQL_FETCH_ABSOLUTE, (SQLINTEGER) (*record) + 1); */ |
| 1277 | |
| 1278 | /* We only do forward fetches. the parameter 'record' is ignored, but is incremented */ |
| 1279 | SQLRETURN rc = SQLFetch(layerinfo->conn->hstmt); |
| 1280 | |
| 1281 | /* Any error assume out of recordset bounds */ |
| 1282 | if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) |
| 1283 | { |
| 1284 | handleSQLError(layer); |
| 1285 | return MS_DONE; |
| 1286 | } |
| 1287 | |
| 1288 | /* retreive an item */ |
| 1289 | |
| 1290 | { |
| 1291 | /* have to retrieve shape attributes */ |
| 1292 | shape->values = (char **) msSmallMalloc(sizeof(char *) * layer->numitems); |
| 1293 | shape->numvalues = layer->numitems; |
| 1294 | |
| 1295 | for(t=0; t < layer->numitems; t++) |
| 1296 | { |
| 1297 | /* figure out how big the buffer needs to be */ |
| 1298 | rc = SQLGetData(layerinfo->conn->hstmt, (SQLUSMALLINT)(t + 1), SQL_C_BINARY, dummyBuffer, 0, &needLen); |
no test coverage detected