Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions nusamai-gpkg/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,7 @@ impl<'c> GpkgTransaction<'c> {
let executor = self.tx.acquire().await.unwrap();

if attributes.is_empty() {
let query_string = format!(
"INSERT INTO \"{table_name}\" (id, geometry) VALUES (?, ?)"
);
let query_string = format!("INSERT INTO \"{table_name}\" (id, geometry) VALUES (?, ?)");
sqlx::query(&query_string)
.bind(id)
.bind(bytes)
Expand Down
19 changes: 19 additions & 0 deletions nusamai-gpkg/src/sql/srs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ AXIS ["Ellipsoidal height (h)",up,LENGTHUNIT["metre",1,ID["EPSG",9001]]],
ID ["EPSG",4979]]'
);

-- JGD2011 + JGD2011 (vertical) height
-- cf. https://epsg.org/crs_6697/JGD2011-JGD2011-vertical-height.html
INSERT INTO
gpkg_spatial_ref_sys (
srs_name,
srs_id,
organization,
organization_coordsys_id,
definition
)
VALUES
(
'JGD2011 + JGD2011 (vertical) height',
6697,
'EPSG',
6697,
'COMPOUNDCRS["JGD2011 + JGD2011 (vertical) height",GEOGCRS["JGD2011",DATUM["Japanese Geodetic Datum 2011",ELLIPSOID["GRS 1980",6378137,298.257222101,LENGTHUNIT["metre",1,ID["EPSG",9001]],ID["EPSG",7019]],ID["EPSG",1128]],CS[ellipsoidal,2,ID["EPSG",6422]],AXIS["Geodetic latitude (Lat)",north],AXIS["Geodetic longitude (Lon)",east],ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9102]],ID["EPSG",6668]],VERTCRS["JGD2011 (vertical) height",VDATUM["Japanese Geodetic Datum 2011 (vertical)",ID["EPSG",1131]],CS[vertical,1,ID["EPSG",6499]],AXIS["Gravity-related height (H)",up],LENGTHUNIT["metre",1,ID["EPSG",9001]],ID["EPSG",6695]],ID["EPSG",6697]]'
);
Comment on lines +64 to +74
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: sqlx::query() executes only the first statement from srs.sql, preventing subsequent INSERTs, including new CRS entries, from being applied.
Severity: CRITICAL | Confidence: 1.00

🔍 Detailed Analysis

The srs.sql file contains multiple INSERT statements, but sqlx::query() is used to execute it. sqlx::query() is designed to execute only a single SQL statement. As a result, only the first INSERT statement will be executed, and subsequent statements, including the new JGD2011 entry (SRID 6697) and other existing CRS definitions, will not be inserted into the gpkg_spatial_ref_sys table. The database initialization will appear to succeed without error, but the new CRS will be unavailable for use.

💡 Suggested Fix

Use sqlx::raw_sql() for the multi-statement script, or split srs.sql into individual statements and execute them within a transaction, or use separate execute() calls for each statement.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: nusamai-gpkg/src/sql/srs.sql#L57-L74

Potential issue: The `srs.sql` file contains multiple `INSERT` statements, but
`sqlx::query()` is used to execute it. `sqlx::query()` is designed to execute only a
single SQL statement. As a result, only the first `INSERT` statement will be executed,
and subsequent statements, including the new JGD2011 entry (SRID 6697) and other
existing CRS definitions, will not be inserted into the `gpkg_spatial_ref_sys` table.
The database initialization will appear to succeed without error, but the new CRS will
be unavailable for use.

Did we get this right? 👍 / 👎 to inform future reviews.


-- Web Mercator (WGS 84 / Pseudo-Mercator)
-- cf. https://epsg.org/crs_3857/Web_Mercator.html
INSERT INTO
Expand Down
Loading