Skip to content
Permalink
Browse files
mapmssql2008.c: fix warnings when building for Linux
  • Loading branch information
rouault committed Feb 23, 2020
1 parent d1d600c commit 3d2502b7e9a759ee2cf1e722a2b6ec19f742e662
Showing 1 changed file with 22 additions and 47 deletions.
@@ -32,6 +32,9 @@
* Created.
*
*/
#ifndef _WIN32
#define _GNU_SOURCE
#endif

#define _CRT_SECURE_NO_WARNINGS 1

@@ -43,7 +46,9 @@

#ifdef USE_MSSQL2008

#ifdef _WIN32
#include <windows.h>
#endif
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>
@@ -478,7 +483,7 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape)
ReadPoint(gpi, &shape->line[0].point[0], 0);
ReadPoint(gpi, &shape->line[0].point[1], 1);
} else {
int iShape, iFigure, iSegment;
int iShape, iFigure, iSegment = 0;
// complex geometries
gpi->nNumPoints = ReadInt32(6);

@@ -658,33 +663,6 @@ void handleSQLError(layerObj *layer)
}
}

/* remove white space */
/* dont send in empty strings or strings with just " " in them! */
static char* removeWhite(char *str)
{
size_t initial;
char *orig, *loc;

initial = strspn(str, " ");
if(initial) {
memmove(str, str + initial, strlen(str) - initial + 1);
}
/* now final */
if(strlen(str) == 0) {
return str;
}
if(str[strlen(str) - 1] == ' ') {
/* have to remove from end */
orig = str;
loc = &str[strlen(str) - 1];
while((*loc = ' ') && (loc >orig)) {
*loc = 0;
loc--;
}
}
return str;
}

/* TODO Take a look at glibc's strcasestr */
static char *strstrIgnoreCase(const char *haystack, const char *needle)
{
@@ -785,7 +763,7 @@ static msODBCconn * mssql2008Connect(char * connString)
}
else
{
rc = SQLDriverConnect(conn->hdbc, NULL, connString, SQL_NTS, outConnString, 1024, &outConnStringLen, SQL_DRIVER_NOPROMPT);
rc = SQLDriverConnect(conn->hdbc, NULL, (SQLCHAR*)connString, SQL_NTS, outConnString, 1024, &outConnStringLen, SQL_DRIVER_NOPROMPT);
}

if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
@@ -837,7 +815,6 @@ static int columnName(msODBCconn *conn, int index, char *buffer, int bufferLengt
SQLULEN columnSize;
SQLSMALLINT decimalDigits;
SQLSMALLINT nullable;
msMSSQL2008LayerInfo *layerinfo = getMSSQL2008LayerInfo(layer);

rc = SQLDescribeCol(
conn->hstmt,
@@ -1612,7 +1589,7 @@ static int prepare_database(layerObj *layer, rectObj rect, char **query_string)
layerinfo->itemtypes = msSmallMalloc(sizeof(SQLSMALLINT) * (layer->numitems + 1));
for (t = 0; t < layer->numitems; t++) {
char colBuff[256];
SQLSMALLINT itemType;
SQLSMALLINT itemType = 0;

columnName(layerinfo->conn, t + 1, colBuff, sizeof(colBuff), layer, pass_field_def, &itemType);
layerinfo->itemtypes[t] = itemType;
@@ -1769,7 +1746,6 @@ static int force_to_points(char *wkb, shapeObj *shape)
/* we're going to make a 'line' for each entity (point, line or ring) in the geom collection */

int offset = 0;
int pt_offset;
int ngeoms;
int t, u, v;
int type, nrings, npoints;
@@ -1812,7 +1788,6 @@ static int force_to_points(char *wkb, shapeObj *shape)

memcpy(&nrings, &wkb[offset+5],4); /* num rings */
/* add a line for each polygon ring */
pt_offset = 0;
offset += 9; /* now points at 1st linear ring */
for(u = 0; u < nrings; u++) {
/* for each ring, make a line */
@@ -1844,7 +1819,6 @@ static int force_to_points(char *wkb, shapeObj *shape)
static int force_to_lines(char *wkb, shapeObj *shape)
{
int offset = 0;
int pt_offset;
int ngeoms;
int t, u, v;
int type, nrings, npoints;
@@ -1878,7 +1852,6 @@ static int force_to_lines(char *wkb, shapeObj *shape)

memcpy(&nrings, &wkb[offset + 5], 4); /* num rings */
/* add a line for each polygon ring */
pt_offset = 0;
offset += 9; /* now points at 1st linear ring */
for(u = 0; u < nrings; u++) {
/* for each ring, make a line */
@@ -1907,7 +1880,6 @@ static int force_to_lines(char *wkb, shapeObj *shape)
static int force_to_polygons(char *wkb, shapeObj *shape)
{
int offset = 0;
int pt_offset;
int ngeoms;
int t, u, v;
int type, nrings, npoints;
@@ -1926,7 +1898,6 @@ static int force_to_polygons(char *wkb, shapeObj *shape)

memcpy(&nrings, &wkb[offset + 5], 4); /* num rings */
/* add a line for each polygon ring */
pt_offset = 0;
offset += 9; /* now points at 1st linear ring */
for(u=0; u < nrings; u++) {
/* for each ring, make a line */
@@ -1988,6 +1959,7 @@ static int dont_force(char *wkb, shapeObj *shape)
return MS_FAILURE; /* unknown type */
}

#if 0
/* ******************************************************* */
/* wkb assumed to be same endian as this machine. */
/* Should be in little endian (default if created by Microsoft platforms) */
@@ -2079,6 +2051,7 @@ static int force_to_shapeType(char *wkb, shapeObj *shape, int msShapeType)

return MS_SUCCESS;
}
#endif

///* if there is any polygon in wkb, return force_polygon */
///* if there is any line in wkb, return force_line */
@@ -2187,7 +2160,6 @@ static void find_bounds(shapeObj *shape)
int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *record)
{
msMSSQL2008LayerInfo *layerinfo;
int result;
SQLLEN needLen = 0;
SQLLEN retLen = 0;
char dummyBuffer[1];
@@ -2309,6 +2281,9 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *recor
case MS_LAYER_POLYGON:
shape->type = MS_SHAPE_POLYGON;
break;

default:
break;
}
}
} else {
@@ -2335,20 +2310,20 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *recor

switch(layer->type) {
case MS_LAYER_POINT:
result = force_to_points(wkbBuffer, shape);
/*result =*/ force_to_points(wkbBuffer, shape);
break;

case MS_LAYER_LINE:
result = force_to_lines(wkbBuffer, shape);
/*result =*/ force_to_lines(wkbBuffer, shape);
break;

case MS_LAYER_POLYGON:
result = force_to_polygons(wkbBuffer, shape);
/*result =*/ force_to_polygons(wkbBuffer, shape);
break;

case MS_LAYER_QUERY:
case MS_LAYER_CHART:
result = dont_force(wkbBuffer, shape);
/*result =*/ dont_force(wkbBuffer, shape);
break;

case MS_LAYER_RASTER:
@@ -2394,7 +2369,7 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *recor
if(shape->type != MS_SHAPE_NULL) {
return MS_SUCCESS;
} else {
msDebug("msMSSQL2008LayerGetShapeRandom bad shape: %d\n", *record);
msDebug("msMSSQL2008LayerGetShapeRandom bad shape: %ld\n", *record);
}
/* if (layer->type == MS_LAYER_POINT) {return MS_DONE;} */
}
@@ -2441,7 +2416,7 @@ int msMSSQL2008LayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record
long resultindex = record->resultindex;

if(layer->debug) {
msDebug("msMSSQL2008LayerGetShape called for shapeindex = %i\n", shapeindex);
msDebug("msMSSQL2008LayerGetShape called for shapeindex = %ld\n", shapeindex);
}

layerinfo = getMSSQL2008LayerInfo(layer);
@@ -2495,7 +2470,7 @@ int msMSSQL2008LayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record
}

/* index_name is ignored here since the hint should be for the spatial index, not the PK index */
snprintf(buffer, sizeof(buffer), "select %s from %s where %s = %d", columns_wanted, layerinfo->geom_table, layerinfo->urid_name, shapeindex);
snprintf(buffer, sizeof(buffer), "select %s from %s where %s = %ld", columns_wanted, layerinfo->geom_table, layerinfo->urid_name, shapeindex);

query_str = msStrdup(buffer);

@@ -2722,7 +2697,7 @@ int msMSSQL2008LayerGetItems(layerObj *layer)

for(t = 0; t < cols; t++) {
char colBuff[256];
SQLSMALLINT itemType;
SQLSMALLINT itemType = 0;

columnName(layerinfo->conn, t + 1, colBuff, sizeof(colBuff), layer, pass_field_def, &itemType);

@@ -2786,7 +2761,7 @@ int msMSSQL2008LayerRetrievePK(layerObj *layer, char **urid_name, char* table_na
tmp2 = (char *)msSmallMalloc(sizeof(char)*(strlen(tmp1) + strlen(sql) + 1));
strcpy(tmp2, tmp1);
strcat(tmp2, sql);
msSetError(MS_QUERYERR, tmp2, "msMSSQL2008LayerRetrievePK()");
msSetError(MS_QUERYERR, "%s", "msMSSQL2008LayerRetrievePK()", tmp2);
msFree(tmp2);
return(MS_FAILURE);
}

0 comments on commit 3d2502b

Please sign in to comment.