Skip to content

Commit a186362

Browse files
sharkAndsharknyurik
authored andcommitted
wip
1 parent 10d2882 commit a186362

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

martin/src/pg/query_tables.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ fn escape_with_alias(mapping: &HashMap<String, String>, field: &str) -> String {
9898
}
9999
}
100100

101+
#[allow(clippy::too_many_lines)]
101102
/// Generate a query to fetch tiles from a table.
102103
/// The function is async because it may need to query the database for the table bounds (could be very slow).
103104
pub async fn table_to_query(
@@ -117,16 +118,30 @@ pub async fn table_to_query(
117118
BoundsCalcType::Skip => {}
118119
BoundsCalcType::Calc => {
119120
debug!("Computing {} table bounds for {id}", info.format_id());
120-
info.bounds =
121-
calc_bounds(&pool, &schema, &table, &geometry_column, srid, false).await?;
121+
info.bounds = calc_bounds(
122+
&pool,
123+
&info.schema,
124+
&info.table,
125+
&info.geometry_column,
126+
srid,
127+
false,
128+
)
129+
.await?;
122130
}
123131
BoundsCalcType::Quick => {
124132
debug!(
125133
"Computing {} table bounds with {}s timeout for {id}",
126134
info.format_id(),
127135
DEFAULT_BOUNDS_TIMEOUT.as_secs()
128136
);
129-
let bounds = calc_bounds(&pool, &schema, &table, &geometry_column, srid, true);
137+
let bounds = calc_bounds(
138+
&pool,
139+
&info.schema,
140+
&info.table,
141+
&info.geometry_column,
142+
srid,
143+
true,
144+
);
130145
pin_mut!(bounds);
131146
if let Ok(bounds) = timeout(DEFAULT_BOUNDS_TIMEOUT, &mut bounds).await {
132147
info.bounds = bounds?;
@@ -221,8 +236,14 @@ async fn calc_bounds(
221236
is_quick: bool,
222237
) -> PgResult<Option<Bounds>> {
223238
let sql = if is_quick {
224-
format!("SELECT ST_EstimatedExtent('{schema}', '{table}', '{geometry_column}') as bounds")
239+
let schema = escape_literal(schema);
240+
let table = escape_literal(table);
241+
let geometry_column = escape_literal(geometry_column);
242+
format!("SELECT ST_EstimatedExtent({schema}, {table}, {geometry_column}) as bounds")
225243
} else {
244+
let schema = escape_identifier(schema);
245+
let table = escape_identifier(table);
246+
let geometry_column = escape_identifier(geometry_column);
226247
format!(
227248
r#"
228249
WITH real_bounds AS (SELECT ST_SetSRID(ST_Extent({geometry_column}), {srid}) AS rb FROM {schema}.{table})

0 commit comments

Comments
 (0)