Saturday, July 21, 2007
  Lightning Calendar Plug-In for Thunderbird AMD64

Mozilla Sunbird is a calendar project that's being designed as a sister program to Thunderbird and Firefox. It's now at the 0.5 version, and there is a plug-in that integrates Sunbird with Thunderbird, called Lightning. It allows you to not only have a calendar, but send and receive meeting requests as well.

I'm running Thunderbird 2 under Ubuntu Feisty Fawn (7.04) on the AMD64 architecture, and could not find a pre-compiled version of this that worked. So, I decided to give it a shot. It was pretty easy, and the result is a plug-in that works with the AMD64 version of Thunderbird! Since I had trouble finding it, I thought I would share it.

Since I have just started using it, I haven't wrung it out, or tested all the options. Use at your own risk, etc.

You can download the plug-in here (UPDATE: See this post.) Happy storming! ;)

Categorized under
Tagged , , , , ,

Monday, July 9, 2007
  Transferring Data Between Oracle and SQL Server

There are lots of “how to” articles on sharing data between Oracle and SQL Server. Most of these involve installing Oracle's code base on the SQL Server machine, then using that instance to link tables within Oracle. This technique does not require that, thanks to a product from Oracle called Oracle Instant Client.

To set up the Oracle piece, download the packages for “Basic” and “ODBC Supplement”, and follow the instructions for installation, on the machine with SQL Server. (This is not an “install” per se - it's basically an unzip.) Next, you'll need to provide a TNSNAMES.ORA file - this can be any valid file, including a simple shell with an “ifile=” statement pointing to a common TNSNAMES.ORA file. Finally, set the environment variable TNS_ADMIN to point to the directory where this TNSNAMES.ORA file resides.

Now, you can easily create a DTS script through SQL Server to push or pull data however you'd like. Oracle Instant Client will appear in the drop-down list of providers, and you'll be able to specify your connection the way you normally do (i.e., “DB01.WORLD”).

Happy migrating!

Categorized under ,
Tagged , , , ,

Friday, June 15, 2007
  Transferring CLOBs Across Linked Oracle Databases

Linking databases in Oracle make it easy to share data, and can be useful for replication. However, there is a limitation in Oracle that prevents Character Large Objects (CLOBs) from coming across these links. The following technique uses stored procedures and a temporary table to pull CLOBs across a database link.

First, you'll need the temporary table, which will hold a sequence number, the primary key for the table where you'll want to reconstruct the CLOB, and some text. This table can reside in the source or destination database, but must be linked from the other one. For our purposes, it looks like this…

create table clob_xfer_area
(
  cxa_pk      number(12),
  cxa_number  number(12),
  cxa_text    varchar2(4000 byte)
);
alter table clob_xfer_area add
(
  constraint pk_cxa_id
    primary key (cxa_pk, cxa_number)
);

Second, you'll need the procedure in the source database that breaks the CLOB apart and populates the temporary table.

set serveroutput on size 1000000
set lines 1000
set pages 0
set tab off
set feedback on
create or replace
procedure break_clobs_apart
is
  v_line_number   number(3);
  v_text_piece    varchar2(4000);
  v_total_length  number(12);
  cursor clob_cur is
    select twc_pk, twc_clob_field
    from   table_with_clob;
begin /* { */
  for clob_rec in clob_cur loop /* { */
    v_total_length := 1;
    v_line_number  := 0;
    while (v_total_length <=
           DBMS_LOB.GETLENGTH(clob_rec.twc_clob_field)) loop /* { */
      v_line_number := v_line_number + 1;
      v_text_piece := DBMS_LOB.SUBSTR(clob_rec.twc_clob_field,
        3999, v_total_length);
      v_total_length := v_total_length + 3999;
      insert into clob_xfer_area (
        cxa_pk,
        cxa_number,
        cxa_text
      )
        values (
          clob_rec.twc_pk, -- cxa_pk
          v_line_number,   -- cxa_number
          v_text_piece     -- cxa_text
        );
    end loop; /* } of while */
  end loop; /* } of clob_cur */
end; /* } of procedure break_clobs_apart */

Third, you'll need a procedure in the destination database that puts the CLOB back together, and deletes the data from the temporary table.

set serveroutput on size 1000000
set lines 1000
set pages 0
set feedback on
set tab off
create or replace
procedure put_clobs_together
is
  v_new_clob   clob;
  cursor pk_cur is
    select distinct cxa_pk
    from   clob_xfer_area;
  cursor piece_cur(p_cxa_pk number) is
    select cxa_text
    from   clob_xfer_area
    where  cxa_pk = p_cxa_pk
    order by cxa_number;
begin /* { */
  for pk_rec in pk_cur loop /* { */
    DBMS_LOB.CREATETEMPORARY(v_new_clob, TRUE);
    DBMS_LOB.OPEN(v_new_clob, DBMS_LOB.LOB_READWRITE);
    for piece_rec in piece_cur(pk_rec.cxa_pk) loop /* { */
      DBMS_LOB.WRITEAPPEND(v_new_clob, LENGTH(piece_rec.cxa_text),
        piece_rec.cxa_text);
    end loop;  /* } of piece_cur */
    DBMS_LOB.CLOSE(v_new_clob);
    update dest_table_with_clob
      set  migrated_clob = v_new_clob
      where dtwc_pk = pk_rec.cxa_pk;
  end loop; /* } of pk_cur */
  delete from clob_xfer_area;
end; /* } of procedure put_clobs_together */

Finally, you'll need a procedure that controls the whole thing. We'll assume that this procedure is loaded in the destination database, and the source database is linked with the name “source”.

set lines 1000
set pages 0
set feedback on
set tab off
create or replace
procedure xfer_clobs
is
begin /* { */
  break_clobs_apart@source;
  put_clobs_together;
end; /* } */

(This does not include a commit - the changes will not be persistent unless they are committed.)

Of course, these processes could (and, to be useful, likely would) be integrated into other procedures and scripts. But, this framework will successfully transfer CLOBs across linked databases in Oracle.

Categorized under ,
Tagged , , , ,

Wednesday, June 13, 2007
  Posting Source Code in WordPress, Take 2

In my searching, I have found another WordPress source code plugin, called wp-syntax. This one uses GeSHi, the Generic Syntax Highlighter. It features many languages, and is extensible to even more. (If I ever post a COBOL snippet, I'll probably add COBOL support to it, and contribute it to the codebase.)

To use it, you simply put a pre tag, followed by lang=[language]. It will also do line numbering. Of course, with a single “language” parameter, the embedded language will not be highlighted as well. In this case, the previous plug-in works better; although the syntax highlighting has to be done manually, it can handle multiple languages.

(NOTE: The samples have been removed, as this blog is not running under WordPress. However, since the source code from another post was moved here, it is presented below using myWebLog's code highlighting.)

<?php
/**
 * This creates a list of category links that can be used with a category dropdown
 */
$aCategories = get_all_category_ids();
$iMaxCat = 0;
foreach($aCategories as $iThisCat) {
    if ($iMaxCat < $iThisCat) {
        $iMaxCat = $iThisCat;
    }
}
$iMaxCat++;
?>
<div style="text-align:center;">
<form name="categoryform" action="" style="text-align:center;">
    <script type="text/javascript">
        var aLink = new Array(<?php echo($iMaxCat); ?>);
<?php
foreach($aCategories as $iThisCat) {
    echo("aLink[$iThisCat] = \"" . get_category_link($iThisCat) . "\";\n");
} ?>
        function goCat() {
            window.location =
                aLink[document.getElementById('cat')[document.getElementById('cat').selectedIndex].text;
        }
    </script>
    <?php wp_dropdown_categories('class=sidebardropdown&orderby=name&show_count=1&hierarchical=1'); ?>
    <br /><br />
    <button class="sidebarbutton" type="button" style="margin-top:5px;" onclick="goCat();">View Category</button>
    </form>
</div>

This is another option, and is probably what I'll use for single-language posts, or posts where the embedded language may not be crucial.

Categorized under
Tagged , , , ,

Wednesday, May 30, 2007
  Posting Source Code in WordPress

Traditionally, posting source code in a WordPress blog, especially if it were HTML or PHP, was problematic. There are a few reasons for this…

  • WordPress is very good about ensuring that it outputs valid XHTML, so it strips mis-matched and invalid tags. This is usually desirable, but it wreaks havoc with HTML and XML code posts.
  • Since WordPress is coded in PHP, blocks of PHP will attempt to execute.
  • White space is collapsed, which can kill any readability that the user has set out; the “visual editor” (TinyMCE) does its best to create efficient HTML. This can actually break spacing-oriented languages such as Python.

So how do you do it? It's actually pretty easy, using the Code Markup WordPress plugin. You can download the plugin from that link, and upload it to ./wp-content/plugins. The instructions on the website are critical - the “visual” editor will not allow the code to come through unscathed. However, the visual editor only corrupts the code if you actually save it; what I have done is write the post using the visual editor, then disable it and put the code in. It's the best of both worlds! (Make sure that, once you have the code in, you don't edit the post using the visual editor - unless you have a good backup…)

The post below this one (about category lists in WordPress) was done using this plugin. (This isn't running in WordPress any more.) In addition, you can use the span tag to do the color-coding. I created a few CSS classes (“key” for keywords, “func” for functions, “attr” for attributes, “embed” for embedded language), and used them to accomplish the color coding. It seems that it would be pretty easy to write another plugin that used a list of keywords to do this syntax highlighting; maybe that's a challenge for another day.

A big “atta boy” to Bennet McElwee for a fantastic plugin!

Categorized under
Tagged , , ,

Thursday, May 24, 2007
  Category Drop-Down in WordPress

WordPress provides a template tag, wp_dropdown_categories, that inserts a drop-down list (the HTML select element) of categories, where the value of each item is the ID from the database. This works fine if you are not using rewrite rules (AKA “pretty links”) - you can construct a URL using the value (?cat=[number]). However, if you use any sort of rewrite rules, this does not work. I recently converted my personal site, which uses the Pool theme, to utilize a JavaScript array to assist with displaying category pages.

Here's the code…

Edit: Code has been moved to this post.

This works for both “pretty” and standard links, as it uses the template tag get_category_link to specify the link.

Categorized under ,
Tagged , ,