4040import org .labkey .api .data .ContainerFilter ;
4141import org .labkey .api .data .ContainerManager ;
4242import org .labkey .api .data .DbScope ;
43+ import org .labkey .api .data .FieldKeyRowMap ;
4344import org .labkey .api .data .JdbcType ;
4445import org .labkey .api .data .MutableColumnInfo ;
4546import org .labkey .api .data .PHI ;
@@ -1241,14 +1242,14 @@ public List<Map<String, Object>> insertRows(User user, Container container, List
12411242 }
12421243
12431244 @ Override
1244- protected Map <String , Object > getRow (User user , Container container , Map <String , Object > keys ) throws InvalidKeyException
1245+ protected Map <String , Object > getRow (User user , Container container , Map <String , Object > keys ) throws InvalidKeyException , SQLException
12451246 {
12461247 return getRow (user , container , keys , false );
12471248 }
12481249
12491250 /* This class overrides getRow() in order to support getRow() using "rowid" or "lsid" */
12501251 @ Override
1251- protected Map <String , Object > getRow (User user , Container container , Map <String , Object > keys , boolean allowCrossContainer ) throws InvalidKeyException
1252+ protected Map <String , Object > getRow (User user , Container container , Map <String , Object > keys , boolean allowCrossContainer ) throws InvalidKeyException , SQLException
12521253 {
12531254 aliasColumns (_columnMapping , keys );
12541255
@@ -1263,19 +1264,7 @@ protected Map<String, Object> getRow(User user, Container container, Map<String,
12631264 if (null == rowId && null == lsid && null == name )
12641265 throw new InvalidKeyException ("Value must be supplied for key field 'rowid' or 'lsid' or 'name'" , keys );
12651266
1266- Map <String ,Object > row = _select (container , rowId , lsid , name , classId , allowCrossContainer );
1267-
1268- //PostgreSQL includes a column named _row for the row index, but since this is selecting by
1269- //primary key, it will always be 1, which is not only unnecessary, but confusing, so strip it
1270- if (null != row )
1271- {
1272- if (row instanceof ArrayListMap arrayListMap )
1273- arrayListMap .getFindMap ().remove ("_row" );
1274- else
1275- row .remove ("_row" );
1276- }
1277-
1278- return row ;
1267+ return _select (container , rowId , lsid , name , classId , allowCrossContainer );
12791268 }
12801269
12811270 @ Override
@@ -1284,32 +1273,34 @@ protected Map<String, Object> _select(Container container, Object[] keys) throws
12841273 throw new IllegalStateException ();
12851274 }
12861275
1287- protected Map <String , Object > _select (Container container , Integer rowid , String lsid , String name , Integer classId , boolean allowCrossContainer ) throws ConversionException
1276+ protected Map <String , Object > _select (Container container , Integer rowId , String lsid , String name , Integer classId , boolean allowCrossContainer ) throws SQLException
12881277 {
1289- if (null == rowid && null == lsid && (null == name || null == classId ))
1278+ if (null == rowId && null == lsid && (null == name || null == classId ))
12901279 return null ;
12911280
1292- // FIXME Issue 52886: This retrieves raw db column names, which doesn't work well for comparing existing and new audit records if the name doesn't match the field key
1293- TableInfo d = getDbTable ();
1294- TableInfo t = _dataClassDataTableSupplier .get ();
1295-
1296- SQLFragment sql = new SQLFragment ()
1297- .append ("SELECT t.*, d.RowId, d.Name, d.ClassId, d.Container, d.Description, d.CreatedBy, d.Created, d.ModifiedBy, d.Modified" )
1298- .append (" FROM " ).append (d , "d" )
1299- .append (" LEFT OUTER JOIN " ).append (t , "t" )
1300- .append (" ON d.lsid = t.lsid WHERE " );
1301-
1302- if (null != rowid )
1303- sql .append ("d.rowid=?" ).add (rowid );
1281+ // Issue 52886: Use queryTable here, not raw database table, so the rows are from the user schema with names
1282+ // as expected to match row inserts and other querySchema data
1283+ SimpleFilter filter = new SimpleFilter ();
1284+ if (null != rowId )
1285+ filter .addCondition (Column .RowId .fieldKey (), rowId );
13041286 else if (null != lsid )
1305- sql . append ( "d.lsid=?" ). add ( lsid );
1287+ filter . addCondition ( Column . LSID . fieldKey (), lsid );
13061288 else
1307- sql . append ( "d.classid=? AND d.name=?" ). add ( classId ). add ( name );
1308-
1289+ filter . addCondition ( Column . ClassId . fieldKey (), classId )
1290+ . addCondition ( Column . Name . fieldKey (), name );
13091291 if (!allowCrossContainer )
1310- sql .append (" AND d.Container=?" ).add (container .getEntityId ());
1292+ filter .addCondition (Column .Folder .fieldKey (), container .getEntityId ());
1293+
1294+ TableInfo queryTable = getQueryTable ();
1295+ TableSelector selector = new TableSelector (queryTable , filter , null );
13111296
1312- return new SqlSelector (getDbTable ().getSchema (), sql ).getMap ();
1297+ try (var results = selector .getResults ()) {
1298+ if (results .next ())
1299+ {
1300+ return FieldKeyRowMap .toNameMap (results .getFieldKeyRowMap ());
1301+ }
1302+ }
1303+ return null ;
13131304 }
13141305
13151306 @ Override
0 commit comments