Separate the package creation and package query stages.

Before, after each package query the package would be created however the pkgdb
holds (in the current implementation) a SHARED lock.  Since package creation
could take a long time it resulted in the SHARED lock being help for an extended
amount of time blocking any attempts to alter the database (such as a package
install or package deletion).

By separating the package query and package creation the SHARED lock is only
held for the shortest possible time allowing other operations to continue.

WARNING: this can result in some spurious errors where a package is deleted
before it is created however this results in an error in package creation (vs
the current error of either delayed package deletion or database access timeout)
NOTE: this change cannot introduce inconsistencies into the database.
Merge branch 'master' of https://github.com/pkgng/pkgng into lock-scope
Free packages using the correct reference.  Plugs a memory leak.
Fix assignments within if () statements.  This properly enumerates over pkgs.

Also display a message indicating that the package list is being loaded as
loading all the packages may have a noticeable delay.
Remove excess whitespace
Avoid memory leak in pkgdb_stats()
Document -q for pkg-stats
Fix importing deleted ports
Add pkg-stats and sort
SQL strings need to be quoted in single quotes and single quotes need to be doubled.
The fact that sqlite also accepts double quotes if it can't find a
corresponding field as strings doesn't change that. for fun (and proof), try
pkg query -e '%n=name' '%o'
on a non-empty installation ;)

Conflicts:

	pkg/query.c
Improve error message for bad/incomplete expression.
It's still possible to generate an invalid expression with a non-matching number of opening and closing brackets.
Extend the evaluation format documentation.
Caveat: I'm not a writer, nor a native speaker. But imho any documentation is better than none ;)
Emit error message for unknown operators instead of silently ignoring any unexpected characters.
Don't arbitrarily disallow semicolons in query strings.
If you're trying to guard against sql injection, this is not the way (and there would still be statements that don't need a semicolon to work). However, with the string quoting patch I'm quite confident that there can be no sql injection.
Don't copy whitespace into the sql query.
IMHO it doesn't make sense. It's just extra calls and extra stuff for sqlite to parse. Plus we're putting our own whitespace where it's needed.

Conflicts:

	pkg/query.c
move the type_t enum directly to the format_sql_condition function, which is the only place it should ever be used, and rename it to state_t.
Improve expression parsing so that only valid expressions are accepted.
I believe this will now catch all possible expression errors and generate only correct sql. Please let me know if you disagree, preferably with an example.
Don't insist on a space after an integer.
Forcing a space before the closing bracket in a call like
pkg query -e '(%s>1000 && %s<2000)' '%o %sb'
looks/feels awkward.

Conflicts:

	pkg/query.c
Merge pull request #264 from DragonSA/lock-scope

Separate the package creation and package query stages.
Merge remote-tracking branch 'upstream/master'