Alternative to ArcGIS Desktop for software development?
OGR can convert GML and/or shapefile to PostGIS, SpatiaLite and a number of other datastores, and has a well developed API. Both postgis and spatialite can support the kind of query you want, though I personally have not done so (actually depending on the details of your queries, you may be able to do all of it in OGR).
Based on your description, you will need the OGR library (to convert from GML/shape to your database) and a spatially enabled database (I would recommend PostGIS).
If you are happy with a raw database to query with SQL, that's all you need. There are plenty of postgres utility libraries, and one for your programming language of choice.
Free GIS Alternatives:
http://www.qgis.org/
http://udig.refractions.net/
http://www.openjump.org/
http://grass.itc.it/
Web GIS
http://mapserver.org/
http://geoserver.org/display/GEOS/Welcome
*Some require plugins or additional steps to incorporate your GIS requirements
Mapperz uses all of the above with Postgres (with Postgis) as the Spatial Database.