Skip to content

Commit 3d2502b

Browse files
committed
mapmssql2008.c: fix warnings when building for Linux
1 parent d1d600c commit 3d2502b

File tree

1 file changed

+22
-47
lines changed

1 file changed

+22
-47
lines changed

mapmssql2008.c

+22-47
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
* Created.
3333
*
3434
*/
35+
#ifndef _WIN32
36+
#define _GNU_SOURCE
37+
#endif
3538

3639
#define _CRT_SECURE_NO_WARNINGS 1
3740

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

4447
#ifdef USE_MSSQL2008
4548

49+
#ifdef _WIN32
4650
#include <windows.h>
51+
#endif
4752
#include <sql.h>
4853
#include <sqlext.h>
4954
#include <sqltypes.h>
@@ -478,7 +483,7 @@ int ParseSqlGeometry(msMSSQL2008LayerInfo* layerinfo, shapeObj *shape)
478483
ReadPoint(gpi, &shape->line[0].point[0], 0);
479484
ReadPoint(gpi, &shape->line[0].point[1], 1);
480485
} else {
481-
int iShape, iFigure, iSegment;
486+
int iShape, iFigure, iSegment = 0;
482487
// complex geometries
483488
gpi->nNumPoints = ReadInt32(6);
484489

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

661-
/* remove white space */
662-
/* dont send in empty strings or strings with just " " in them! */
663-
static char* removeWhite(char *str)
664-
{
665-
size_t initial;
666-
char *orig, *loc;
667-
668-
initial = strspn(str, " ");
669-
if(initial) {
670-
memmove(str, str + initial, strlen(str) - initial + 1);
671-
}
672-
/* now final */
673-
if(strlen(str) == 0) {
674-
return str;
675-
}
676-
if(str[strlen(str) - 1] == ' ') {
677-
/* have to remove from end */
678-
orig = str;
679-
loc = &str[strlen(str) - 1];
680-
while((*loc = ' ') && (loc >orig)) {
681-
*loc = 0;
682-
loc--;
683-
}
684-
}
685-
return str;
686-
}
687-
688666
/* TODO Take a look at glibc's strcasestr */
689667
static char *strstrIgnoreCase(const char *haystack, const char *needle)
690668
{
@@ -785,7 +763,7 @@ static msODBCconn * mssql2008Connect(char * connString)
785763
}
786764
else
787765
{
788-
rc = SQLDriverConnect(conn->hdbc, NULL, connString, SQL_NTS, outConnString, 1024, &outConnStringLen, SQL_DRIVER_NOPROMPT);
766+
rc = SQLDriverConnect(conn->hdbc, NULL, (SQLCHAR*)connString, SQL_NTS, outConnString, 1024, &outConnStringLen, SQL_DRIVER_NOPROMPT);
789767
}
790768

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

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

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

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

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

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

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

1962+
#if 0
19911963
/* ******************************************************* */
19921964
/* wkb assumed to be same endian as this machine. */
19931965
/* 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)
20792051

20802052
return MS_SUCCESS;
20812053
}
2054+
#endif
20822055

20832056
///* if there is any polygon in wkb, return force_polygon */
20842057
///* if there is any line in wkb, return force_line */
@@ -2187,7 +2160,6 @@ static void find_bounds(shapeObj *shape)
21872160
int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *record)
21882161
{
21892162
msMSSQL2008LayerInfo *layerinfo;
2190-
int result;
21912163
SQLLEN needLen = 0;
21922164
SQLLEN retLen = 0;
21932165
char dummyBuffer[1];
@@ -2309,6 +2281,9 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *recor
23092281
case MS_LAYER_POLYGON:
23102282
shape->type = MS_SHAPE_POLYGON;
23112283
break;
2284+
2285+
default:
2286+
break;
23122287
}
23132288
}
23142289
} else {
@@ -2335,20 +2310,20 @@ int msMSSQL2008LayerGetShapeRandom(layerObj *layer, shapeObj *shape, long *recor
23352310

23362311
switch(layer->type) {
23372312
case MS_LAYER_POINT:
2338-
result = force_to_points(wkbBuffer, shape);
2313+
/*result =*/ force_to_points(wkbBuffer, shape);
23392314
break;
23402315

23412316
case MS_LAYER_LINE:
2342-
result = force_to_lines(wkbBuffer, shape);
2317+
/*result =*/ force_to_lines(wkbBuffer, shape);
23432318
break;
23442319

23452320
case MS_LAYER_POLYGON:
2346-
result = force_to_polygons(wkbBuffer, shape);
2321+
/*result =*/ force_to_polygons(wkbBuffer, shape);
23472322
break;
23482323

23492324
case MS_LAYER_QUERY:
23502325
case MS_LAYER_CHART:
2351-
result = dont_force(wkbBuffer, shape);
2326+
/*result =*/ dont_force(wkbBuffer, shape);
23522327
break;
23532328

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

24432418
if(layer->debug) {
2444-
msDebug("msMSSQL2008LayerGetShape called for shapeindex = %i\n", shapeindex);
2419+
msDebug("msMSSQL2008LayerGetShape called for shapeindex = %ld\n", shapeindex);
24452420
}
24462421

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

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

25002475
query_str = msStrdup(buffer);
25012476

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

27232698
for(t = 0; t < cols; t++) {
27242699
char colBuff[256];
2725-
SQLSMALLINT itemType;
2700+
SQLSMALLINT itemType = 0;
27262701

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

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

0 commit comments

Comments
 (0)