@@ -44,7 +44,6 @@ ows_layer_storage * ows_layer_storage_init()
4444 storage -> pkey = NULL ;
4545 storage -> pkey_sequence = NULL ;
4646 storage -> pkey_default = NULL ;
47- storage -> pkey_column_number = -1 ;
4847 storage -> attributes = array_init ();
4948 storage -> not_null_columns = NULL ;
5049
@@ -103,8 +102,6 @@ void ows_layer_storage_flush(ows_layer_storage * storage, FILE * output)
103102 fprintf (output , "\n" );
104103 }
105104
106- fprintf (output , "pkey_column_number: %i\n" , storage -> pkey_column_number );
107-
108105 if (storage -> pkey_sequence ) {
109106 fprintf (output , "pkey_sequence: " );
110107 buffer_flush (storage -> pkey_sequence , output );
@@ -225,28 +222,6 @@ static void ows_storage_fill_pkey(ows * o, ows_layer * l)
225222 buffer_empty (sql );
226223 PQclear (res );
227224
228- /* Retrieve the Pkey column number */
229- buffer_add_str (sql , "SELECT a.attnum FROM pg_class c, pg_attribute a, pg_type t, pg_namespace n" );
230- buffer_add_str (sql , " WHERE a.attrelid = c.oid AND a.atttypid = t.oid AND n.nspname='" );
231- buffer_copy (sql , l -> storage -> schema );
232- buffer_add_str (sql , "' AND c.relname='" );
233- buffer_copy (sql , l -> storage -> table );
234- buffer_add_str (sql , "' AND a.attname='" );
235- buffer_copy (sql , l -> storage -> pkey );
236- buffer_add_str (sql , "'" );
237- res = ows_psql_exec (o , sql -> buf );
238- if (PQresultStatus (res ) != PGRES_TUPLES_OK ) {
239- PQclear (res );
240- buffer_free (sql );
241- ows_error (o , OWS_ERROR_REQUEST_SQL_FAILED , "Unable to find pkey column number." , "pkey_column number" );
242- return ;
243- }
244-
245- /* -1 because column number start at 1 */
246- l -> storage -> pkey_column_number = atoi (PQgetvalue (res , 0 , 0 )) - 1 ;
247- buffer_empty (sql );
248- PQclear (res );
249-
250225 /* Now try to find a sequence related to this Pkey */
251226 buffer_add_str (sql , "SELECT pg_get_serial_sequence('" );
252227 buffer_copy (sql , l -> storage -> schema );
@@ -258,10 +233,16 @@ static void ows_storage_fill_pkey(ows * o, ows_layer * l)
258233
259234 res = ows_psql_exec (o , sql -> buf );
260235 if (PQresultStatus (res ) != PGRES_TUPLES_OK ) {
236+ char message [256 ];
237+ snprintf (message , sizeof (message ),
238+ "Unable to use pg_get_serial_sequence(%s, %s, %s)." ,
239+ l -> storage -> schema -> buf ,
240+ l -> storage -> table -> buf ,
241+ l -> storage -> pkey -> buf );
261242 PQclear (res );
262243 buffer_free (sql );
263244 ows_error (o , OWS_ERROR_REQUEST_SQL_FAILED ,
264- "Unable to use pg_get_serial_sequence." , "pkey_sequence retrieve" );
245+ message , "pkey_sequence retrieve" );
265246 return ;
266247 }
267248
0 commit comments