On 2017-6-20 03:58 , Umesh Singla wrote:
Hi Bradley,
I'm having a bit difficulty in implementing the body of snapshot
procedure. Basically what I need to do now is (as I have written in my
notes, so you can tell me if I'm on right track in my thoughts as well):
"get the list of installed ports, their-installed-variants and
if-requested,
then add one port at a time to the 2nd table, its variants to the 3rd
table,
after all this, add an entry in the snapshot table for the entire snapshot,
that's it."
Taking a step back for a moment, why is an SQL database the best way to
store this data? What sorts of queries are you going to want to run on
it? Would a text (Tcl array) representation similar to the PortIndex be
a better fit?
If there's a good reason for doing it in SQL, great. If not, maybe
you're making life more difficult than it needs to be. :)
I can get this info from `port -v installed` and `port -v installed
requested` command, that is, calling /action_installed/ [1] which in
turn, calls /registry::installed/ [2] for each port from
/snapshot_main/. Is this best way to go?
Using registry::installed will work, but it's not the most efficient
since it provides the same interface as the old flat-file registry (See
below).
Further, can you point me to some port action where it deals with
retrieving and populating tables as a hint? The /action_target/ used for
most of the port commands like /install/, /clean/, /fetch/ doesn't
really hint on how to deal with it.
These don't deal with SQL directly, they use the registry API.
I hunted down till I reached /macports::registry.format/ -->
/receipt_{flat/sqlite}.tcl /files//which have a bunch of functions using
/registry::entry/ which I think is the most "basic" operation and then,
also /receipt_sqlite:://create_entry_l/function.
The way to get the list of installed ports is with 'registry::entry
imaged'. Have a look at how reclaim.tcl does it for example.
The create_entry_l procedure is there to help in converting the old
flat-file format to sqlite. It's probably not very relevant for you.
The registry::entry proc is indeed where much of the magic happens at
the Tcl level. It's implemented in src/registry2.0/entry.c and calls
down into the code in the src/cregistry directory to do the actual
sqlite calls.
Do I need to write for inserting into tables? If yes, write direct SQL
queries or Tcl procedures ( a better way, I think)?
If you do end up adding new tables to the db, you will need to add
support for them to the entire stack from cregistry up.
- Josh