@@ -151,6 +151,7 @@ typedef struct ms_MSSQL2008_layer_info_t {
151
151
char * urid_name ; /* name of user-specified unique identifier or OID */
152
152
char * user_srid ; /* zero length = calculate, non-zero means using this value! */
153
153
char * index_name ; /* hopefully this isn't necessary - but if the optimizer ain't cuttin' it... */
154
+ char * sort_spec ; /* the sort by specification which should be applied to the generated select statement */
154
155
155
156
msODBCconn * conn ; /* Connection to db */
156
157
msGeometryParserInfo gpi ; /* struct for the geometry parser */
@@ -451,7 +452,7 @@ static char *strstrIgnoreCase(const char *haystack, const char *needle)
451
452
return (char * ) (match < 0 ? NULL : haystack + match );
452
453
}
453
454
454
- static int msMSSQL2008LayerParseData (layerObj * layer , char * * geom_column_name , char * * geom_column_type , char * * table_name , char * * urid_name , char * * user_srid , char * * index_name , int debug );
455
+ static int msMSSQL2008LayerParseData (layerObj * layer , char * * geom_column_name , char * * geom_column_type , char * * table_name , char * * urid_name , char * * user_srid , char * * index_name , char * * sort_spec , int debug );
455
456
456
457
/* Close connection and handles */
457
458
static void msMSSQL2008CloseConnection (void * conn_handle )
@@ -626,6 +627,7 @@ int msMSSQL2008LayerOpen(layerObj *layer)
626
627
layerinfo -> urid_name = NULL ;
627
628
layerinfo -> user_srid = NULL ;
628
629
layerinfo -> index_name = NULL ;
630
+ layerinfo -> sort_spec = NULL ;
629
631
layerinfo -> conn = NULL ;
630
632
631
633
layerinfo -> conn = (msODBCconn * ) msConnPoolRequest (layer );
@@ -688,7 +690,7 @@ int msMSSQL2008LayerOpen(layerObj *layer)
688
690
689
691
setMSSQL2008LayerInfo (layer , layerinfo );
690
692
691
- if (msMSSQL2008LayerParseData (layer , & layerinfo -> geom_column , & layerinfo -> geom_column_type , & layerinfo -> geom_table , & layerinfo -> urid_name , & layerinfo -> user_srid , & layerinfo -> index_name , layer -> debug ) != MS_SUCCESS ) {
693
+ if (msMSSQL2008LayerParseData (layer , & layerinfo -> geom_column , & layerinfo -> geom_column_type , & layerinfo -> geom_table , & layerinfo -> urid_name , & layerinfo -> user_srid , & layerinfo -> index_name , & layerinfo -> sort_spec , layer -> debug ) != MS_SUCCESS ) {
692
694
msSetError ( MS_QUERYERR , "Could not parse the layer data" , "msMSSQL2008LayerOpen()" );
693
695
return MS_FAILURE ;
694
696
}
@@ -920,6 +922,10 @@ static int prepare_database(layerObj *layer, rectObj rect, char **query_string)
920
922
}
921
923
}
922
924
925
+ if (layerinfo -> sort_spec ) {
926
+ strcat (query_string_temp , layerinfo -> sort_spec );
927
+ }
928
+
923
929
msFree (data_source );
924
930
msFree (f_table_name );
925
931
msFree (columns_wanted );
@@ -1021,6 +1027,11 @@ int msMSSQL2008LayerClose(layerObj *layer)
1021
1027
layerinfo -> index_name = NULL ;
1022
1028
}
1023
1029
1030
+ if (layerinfo -> sort_spec ) {
1031
+ msFree (layerinfo -> sort_spec );
1032
+ layerinfo -> sort_spec = NULL ;
1033
+ }
1034
+
1024
1035
if (layerinfo -> sql ) {
1025
1036
msFree (layerinfo -> sql );
1026
1037
layerinfo -> sql = NULL ;
@@ -1995,9 +2006,9 @@ int msMSSQL2008LayerRetrievePK(layerObj *layer, char **urid_name, char* table_na
1995
2006
* column name, table name and name of a column to serve as a
1996
2007
* unique record id
1997
2008
*/
1998
- static int msMSSQL2008LayerParseData (layerObj * layer , char * * geom_column_name , char * * geom_column_type , char * * table_name , char * * urid_name , char * * user_srid , char * * index_name , int debug )
2009
+ static int msMSSQL2008LayerParseData (layerObj * layer , char * * geom_column_name , char * * geom_column_type , char * * table_name , char * * urid_name , char * * user_srid , char * * index_name , char * * sort_spec , int debug )
1999
2010
{
2000
- char * pos_opt , * pos_scn , * tmp , * pos_srid , * pos_urid , * pos_geomtype , * pos_geomtype2 , * pos_indexHint , * data ;
2011
+ char * pos_opt , * pos_scn , * tmp , * pos_srid , * pos_urid , * pos_geomtype , * pos_geomtype2 , * pos_indexHint , * data , * pos_order ;
2001
2012
int slength ;
2002
2013
2003
2014
data = msStrdup (layer -> data );
@@ -2116,6 +2127,13 @@ static int msMSSQL2008LayerParseData(layerObj *layer, char **geom_column_name, c
2116
2127
}
2117
2128
}
2118
2129
2130
+ /* Find the order by */
2131
+ pos_order = strstrIgnoreCase (pos_opt , " order by " );
2132
+
2133
+ if (pos_order ) {
2134
+ * sort_spec = msStrdup (pos_order );
2135
+ }
2136
+
2119
2137
if (debug ) {
2120
2138
msDebug ("msMSSQL2008LayerParseData: unique column = %s, srid='%s', geom_column_name = %s, table_name=%s\n" , * urid_name , * user_srid , * geom_column_name , * table_name );
2121
2139
}
0 commit comments