Archive for November, 2006

title of liberty

Thursday, November 9th, 2006

Reading my scriptures this morning, I came upon Alma 46 (in the Book of Mormon). This is the chapter where Moroni raises the title of liberty, and though I’ve read this many times before, for some reason it really stirred me up this morning. I thought it was pretty cool, and wanted to share a select part of it, but it’s so good, I’m just gonna copy most of it, since it’s such a great story.

A quick background explanation is probably in order, too. This takes place in the Americas, 73 B.C., to a people then called the Nephites and Lamanites. The Lamanites (native Americans, now … all the Nephites were destroyed, which is a major topic in the Book of Mormon) had just lost a major war to the Nephites, but now there is dissension from within by a man named Amalackiah who wants to be king.

1. And it came to pass that as many as would not hearken to the words of Helaman and his brethren were gathered together against their brethren.

2. And now behold, they were exceedingly wroth, insomuch that they were determined to slay them.

3. Now the leader of those who were wroth against their brethren was a large and a strong man; and his name was Amalickiah.

4. And Amalickiah was desirous to be a king; and those people who were wroth were also desirous that he should be their king; and they were the greater part of them the lower judges of the land, and they were seeking for power.

5. And they had been led by the flatteries of Amalickiah, that if they would support him and establish him to be their king that he would make them rulers over the people.

6. Thus they were led away by Amalickiah to dissensions, notwithstanding the preaching of Helaman and his brethren, yea, notwithstanding their exceedingly great care over the church, for they were high priests over the church.

7. And there were many in the church who believed in the flattering words of Amalickiah, therefore they dissented even from the church; and thus were the affairs of the people of Nephi exceedingly precarious and dangerous, notwithstanding their great victory which they had had over the Lamanites, and their great rejoicings which they had had because of their deliverance by the hand of the Lord.

8. Thus we see how quick the children of men do forget the Lord their God, yea, how quick to do iniquity, and to be led away by the evil one.

9. Yea, and we also see the great wickedness one very wicked man can cause to take place among the children of men.

10. Yea, we see that Amalickiah, because he was a man of cunning device and a man of many flattering words, that he led away the hearts of many people to do wickedly; yea, and to seek to destroy the church of God, and to destroy the foundation of liberty which God had granted unto them, or which blessing God had sent upon the face of the land for the righteous’ sake.

(more…)

postgresql functions

Wednesday, November 8th, 2006

One thing I love about (advanced) databases is that you can write functions. They speed up the query time quite a bit, and you can do fun stuff like IF … ELSE … THEN statements.

In working on getting portage into postgres, part of the problem I’m trying to solve is find out where QA issues are so they can be fixed. Unfortunately, in the early stages of my little script, it always assumes that the everything is working correctly across the board, so I’ll write my queries assuming the foreign keys won’t break. In reality, that doesn’t happen, and I end up killing a transaction with hundreds of thousands of statements because there’s 25 queries that break.

So, I had to write a postgres function to do the checking for me. This is going to be absolutely boring to those db gurus out there, but this is still slightly new to me, so I’m really enjoying it.

DECLARE
use_id integer;
BEGIN
SELECT id FROM use WHERE name = $2 AND
(package IS NULL OR package = $3) LIMIT 1 INTO use_id;
IF use_id IS NOT NULL THEN
INSERT INTO ebuild_use (ebuild, use) VALUES ($1, use_id);
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
END;

A really simple function, I know. All it does is run a SELECT statement to see if my foreign key is going to break *before* running the INSERT statement. That way, I can continue on my happy way with my transaction, and at the same time, if I want to turn on ‘qa mode’ when inserting the data, I can check for a false return on the recordset, and know which ebuilds need attention.

Pretty cool stuff, I think. Also, for the record, pgaccess is a *great* little GUI tool to quickly and easily edit your functions.

portage in postgresql

Wednesday, November 8th, 2006

Well, I’m bored, so I figured I’d spill the beans on a project I’ve been keeping under wraps for a while.

I’ve been working on getting everything about the portage tree into postgresql so you can run all kinds of queries. What kinds of queries? How many ebuilds use eclass ‘eutils’ and USE flag ‘alsa’ and are in ‘video’ herd and amd64 is masked but x86 isn’t. That kind. Funky ones. :)

I must say, I really love postgresql even though I haven’t been using it regularly for a long time, I’m quickly getting back into it. The simplicity, the standards, the power, the tools … postgres has it all. Ahh, fanboyism.

Anyway, getting the details of the ebuilds was made incredibly easy thanks to marienz and ferringb and their work on pkgcore (and a custom python script). After that, it was just a matter of parsing the information and setting up the schemas. My importer is written in PHP and the class to import / read the data is still in its slightly butt-ugly stage. It can use some cleaning up, for sure. The database layout is going to be where the real optimizations are though. I’m going to work on setting up some good views so it will be easy to query. Right now, here’s the list of tables I have setup: arch, category, ebuild, ebuild_arch, ebuild_eclass, ebuild_homepage, ebuild_license, ebuild_use, eclass, eclass_use, herd, license, package and use. All of them can already be populated by the scripts except for eclass_use and herd. I haven’t setup the dependency ones yet, though that’ll be pretty simple too.

So there’s my big announcement. Woots. I’m working on creating the SQL to import everything right now (which takes a long time), and once that’s done, I’ll throw up a db dump somewhere. There’s still lots to be done, like finishing the import scripts and setting up some webpages to browse the tree, but it shouldn’t be too hard. I’m definately over the worst of it.