Hello,
"Unsaved" is a state in the EA client, and it applies only to diagrams, not packages. What it means is that changes have been made to the layout of a diagram which have not yet been written to the database. Saving the diagram writes the changes.
So a SQL query isn't going to help, because that returns only what's in the database. There is no way in the documented API to get at the internal client state.
All non-layout properties, such as element names, attributes, tagged values, etc etc, are written to the database immediately upon clicking OK in the dialog. Therefore, a package can not itself be in an unsaved state, but one or more of its diagrams might.
It's slightly different if you're using the API to modify things. Then your changes remain unwritten until you call the
.Update() method on the appropriate
Package,
Element,
Attribute, etc, object. But it would make no sense for you to omit that and then go calling
Project.ExportPackageXMI(), and I'm not sure EA would even pick up on that situation: it is a fault state that you can only force the client into by not following the prescribed procedure.
The simplest way to deal with this situation is to call
Repository.SaveAllDiagrams() before doing the export. It's probably a good idea to inform the user that this side effect will occur.
Which is essentially what Geert is saying.

HTH,
/Uffe