Firefox Bookmarks SQLite structure - sqlite

I am trying to write a Firefox 3 add-on which will enable me to easily re-tag bookmarks. For example I have some bookmarks tagged "development" and some tagged "Development" and I would like a way to easily update all the "delelopment" tags to "Development". Unfortunately I can not find an add-on to do this so I thought I would create my own.
Having not developed an add-on before I've managed to grasp the basics and discovered that FireFox stores all bookmarks in an SQLite database called Places.sqlite. Within that database there is a table called moz_bookmarks which contains all the bookmarks, tags and folders within the bookmarks directory. The structure of the bookmark folders and their child bookmarks is represented using a foreign key id which points to the parent folder's id in the same table which again recursses upwards to that parent folder's Id until it hits the bookmarks root.
However, where I become stuck is how the tags you apply in firefox are related to the bookmarks. Each tag has a type = 2 and parent ID = 4. However I can see no correlation between this and an actual bookmarks that use the tag. If I add a bookmark in firefox to no particular folder but give it 2 or 3 tags then it's parent folder ID is 5 which corresponds to "unfiled" but I can see no further correlation to the tags associated with it.
I have found this Wiki page on the structure but it does not really help.
It's driving me nuts :( Please help...

You probably already found out yourself, but tags are applied as follows:
The central place for all URLS in the database is moz_places. The table moz_bookmarks refers to it by the foreign key column fk.
If you tag a bookmark, there are multiple entries in moz_bookmarks, all having the same reference fk: The first is the bookmark itself (having the title in the title column) For each tag, there's an additional entriy in moz_bookmarks having the same foreign key fk and refering to the tag in the parent coumn (which points to the moz_bookmarks row for the tag).
If you have a bookmark 'http://stackoverflow.com' titled 'Stackoverflow' with tags 'programming' and 'info', you will get:
moz_places
----------
id url (some more)
3636 http://stackoverflow.com
moz_bookmarks
-------------
id type fk parent title (other columns omitted...)
332 1 3636 5 Stackoverflow (parent=5 -> unfiled folder)
333 2 (NULL) 4 programming (programming tag, parent=4 -> tags folder)
334 1 3636 333 (NULL) (link to 'programming' tag)
335 2 (NULL) 4 info (info tag, parent=4 see above)
336 1 3636 335 (NULL) (link to 'info' tag)
Hope this helps...

As MartinStettner suggested tag structures are based on the foreign key for the tag id so you first have to determine the moz_bookmark.id for the target tag.
This Mozilla PDF explains the relationship in sqllite ...
Tags result in two new entries in
moz_bookmarks. The first one is the tag,
with parent=4 (tags), and fk=NULL. The
second entry follows the first one and has
the previous tag as its parent, and fk points
to the proper entry in moz_places.
Using that as a guide ... Once you know the id for the tag you can join moz_places.id ON moz_bookmarks.fk ...
SELECT moz_places.id, moz_places.url, moz_places.title, moz_bookmarks.parent
FROM moz_places
LEFT OUTER JOIN moz_bookmarks
ON moz_places.id = moz_bookmarks.fk
WHERE moz_bookmarks.parent = N
Export ...

I can't quite help you with the how-to, however, perhaps the extension 'SQLite Manager' will help you at least for the part where you're trying to figure out what to do. The plugin is a general manager, but it contains the default databases used by Firefox as standard option as well.
Using that extension it should be relatively straightforward to rename the keywords you like. If you're just looking for a way to fix it, this could work, if you still prefer to write your own tool, perhaps this one can at least help with the queries ;).

I can't help much either -- found your question looking for the same kind of answers...
What I have managed to find is the relevant Mozilla documentation. The bookmark system is called Places, and the the database tables are described at https://developer.mozilla.org/en-US/docs/The_Places_database.

Because I had to dig deeper to find this information, here is the request to fetch url, title and creation date of all your bookmarks:
SELECT h.url, b.title, b.dateAdded
FROM moz_places h
JOIN moz_bookmarks b
ON h.id = b.fk;
I hope it'd help people looking for this answer.

Related

Get Requsition ID based on PO

In FSCM I am looking to modify the Search view on Add/Update PO page (Main Menu--> Purchasing--> Purchase Orders--> Add/Update POs) to display the Requisition ID associated with the PO in the search results page. The only table I have found that has both PO_ID and REQ_ID is PS_PO_LINE_DISTRIB however unless I use a SELECT DISTINCT clause I will get multiple PO_ID rows when there are more than 1 line on a PO.
Within Purchase Order Inquiry you can see the related Requisition ID's related to a PO by clicking on Document Status link inside the Purchase Order inquiry details page.
I started looking at the PeopleCode within the the Purchase Order Inquiry to see how they are linking the PO to a Requisition and it appears to use work tables with related PeopleCode function libraries, but I wasn't able to figure our how they get linked. I am hoping someone else may know the answer to this. Thank you.
I'm on an old version of PeopleSoft (SCM 8.80, Tools 8.51), so your mileage may vary. I'm assuming you're familiar with App Designer. If not, comment below and I'll add some details about what I'm clicking on.
Find the name of the Add/Update PO component.
Open the PURCHASE_ORDER component in App Designer. Now let's find the name of the search record. Note that there is a different record for the Add Search Record, so if you want to change that too, do all of this for that record as well.
Open the PO_SRCH record, and add the REQ_ID field to it. Make sure you mark the field as a key. You should consider saving your modified PO_SRCH under a new name in case you want to be able to revert to vanilla PeopleSoft. If you do, change the Search Record in the component to your new record name.
We can see that PO_SRCH is a view. So let's modify the view to pull in REQ_ID from PO_LINE_DISTRIB. As you mentioned above, there doesn't appear to be another table with both PO_ID and REQ_ID, so you'll have to do a SELECT DISTINCT.
We should do a LEFT OUTER JOIN instead of a standard join because if you do a standard join and you enter a purchase order with no lines and save it, then you'll never be able to retrieve that purchase order in this window. Since REQ_ID is a key field, we can't have a null, so we have to do the CASE.
One odd thing that I ran into here was building the view now gave me an error about selecting fewer columns in the SQL than I had in my record definition. I solved it by modifying the view for SQL Server. I've never had to do that before and I don't know why I had to do it for this specific record. But anyway, I entered the same SQL under the record's "Microsoft SQL Server" definition.
In the properties of PO_SRCH, we can see that it has a related language record. If you're only using one language, you can probably get away without changing this, but I'll do it for completeness. Open PO_SRCHLN. Now add REQ_ID to it (mark it as a key field like you did above), and save it as PO_SRCHLN2 (I'm saving it under a new name so I don't break anything else that may be using PO_SRCHLN).
Edit the SQL the same was as you did above. Note: I didn't have to also change the Microsoft SQL Server definition like I did above. I have no idea why.
Now build PO_SRCHLN2.
Go back to PO_SRCH and change its related language record to PO_SRCHLN2.
Now build PO_SRCH.
Hopefully you didn't get any errors and your search page has the requisition ID in it now. My system doesn't use requisitions so they're all blank in the example below, but the new field is there.

How to grab items with specific value in DynamoDB?

I'm setting up a table of people in DynamoDB, and I'd like to tag those people.
For demonstrations purposes lets say those tags are just strings... "tall", "short", "likes baseball" and so on...
How can I set up the data so I can quickly query all the people with a specific tag, like all the "tall" people?
Can I avoid scanning the table? Can I avoid creating multiple tables? Is this actually a much better use case for relational data structures? What if I come up with new tags on the fly? Relational doesn't work in that case.
Update:
People Tags Mappings
====== ==== ========
John firefighter John > firefighter
Sally young John > young
Joe owner Sally > owner
Anne staff Anne > owner
Chris zebra-lover Chris > zebra-lover
Ben 42 Ben > zebra-lover
In general to avoid scanning when you want to query an attribute which is not the primary key, you can use global secondary keys. For your case that probably doesn't work well, as you might want to be able to tag people with multiple tags at once.
Therefore I'd instead go for a separate table which just contains mappings of tags to people. In that table one item should be the mapping of one tag to one person. If a person has multiple tags, just add multiple items in there.
That way you'd query the tag-table for a given tag to get the primary key of all the people you're searching and would do another query against the people-table afterwards to get their details.
That works for new tags as well, as they'd mean just additional items in the tag-table.

Issue with Finder in Drupal 7

So, I am using Drupal 7 and I'm having an issue with the Finder module.
I have a view set up with a list of a specific content type. In my Finder I have 2 select lists set up to filter the view, both with a blank option appended to the beginning, and also a text box.
When I view the page and select a value from either of the select lists the page works fine. The problem pops up when I leave both select lists blank and the text field empty. Instead of returning all results, which is the behavior I want, it return no results.
In the Finder module for my select lists I have 1 of the "Choices" set to Used Values and I have the field set to the correct content type I want to filter on. The 2nd Select List is set to "Available Options." Both Select Lists have the "Empty Choice" setting set to "empty."
If there is any other information I can provide, let me know.
This has been a very difficult bug to Google and I am hoping someone can point me in the right direction.
Answered.....Sort of.
The problem turns out to be version of WebForm module that is being used. We were using version 7.x-4.3, which is the latest, but rolled back to version 7.x-4.1 and the issue resolved itself.
It seems odd to me that a product that is used by hundreds of thousands of people would let a bug this annoying slip by.

Drupal view to list nodes and comments

I want to create a view that shows the latest posts in a forum and also any latest comments. The comments and the posts would all show in the same view. Is it possible for me to do this?
Thanks in advance,
Ben
In essence: no. Views requires you to choose one main resource in the first step: you there (amongst others) choose to go with either nodes, or comments.
However, with some (ugly) configuration, you can load the comments that go with nodes. Each result would look like, Node - Comment, e.g.:
Can I have cheesburgers - First!
Can I have cheesburgers - No, I was first!!!111oneone
Can I have cheesburgers - LAME.
and so on. With some styling, you can then get it to show comments and nodes in separate rows.
However, this is ugly and hackish. My advise: write a simple module that either exposes a block, or a menu+page, and do two simple (and light) queries on the database: SELECT nid, title, ... FROM {nodes} LIMIT 10 and SELECT nid, name AS title, ... FROM {comments} LIMIT 10 then mix these two up. Or, with some (more complex) SQL magic, you could even join the two tables and create fancy results that e.g. order by created date of either nodes or comments.
With Drupal 7 you can add a relationship Last comment and then add that field to the view.
One idea I've seen is to use Views Custom Field to "attach" a wholly separate view with PHP code. See comment #4 for the code (in a request for this feature in Views. for a code example).

Drupal 6 & Views 2 - DISTINCT field

I'm using the Feeds module to import lots of Feed Item nodes. Due to a malformed feed file, I'm getting lots of duplicates. I'm using a View to display these nodes, and need to be able to add a DISTINCT filter on the "Node: Post Date" field, so I only get 1 result for each post-date.
I will also look into tackling the problem at the source so to speak (I don't want to have all those duplicates in the first place), but this is an interesting issue in itself - I can't find a way to add a DISTINCT filter on a field other than the Node ID (which has it's own option in the View's Basic Settings box).
I found a great article on a good way to alter the SQL queries that are generated from views before they get executed: http://echodittolabs.org/blog/2010/06/group-views. I used this to basically suffix a GROUP BY clause to the end of the query (in a really nice, clean and versatile way).
As an aside, I also found a way to tackle the issue of importing lots of duplicate feed items, the details of which are here: http://drupal.org/node/661314#comment-3667228. It adopts quite an extreme approach (deleting all items before each update), but this is the only solution for some nasty malformed feeds.
I was holding out for some undiscovered feature of Views that let you do this, but I don't think there is one - maybe in the next version ;)
There are two option to solve this:\
apply this patch
OR
hook_views_query_alter => just paste
$query->distinct = 1;
$query->no_distinct = 'views_groupby';
I guess you have two options: either put some logic in the view template file to skip the duplicate items or implement hook_views_query_alter() to change the query used by the view, adding the DISTINCT clause.
We found this issue in drupal 6.x view - had 7 of 150 items duplicated one or twice. No idea why. Issue only appeared for anonymous users. Luckily, views 6.x.2.16 provides a 'distinct' setting under the basic settings, I set it to Yes and got rid of the duplicates.

Resources