code

Thursday, May 26, 2005

Cenqua Clover Code Coverage for Java

Cenqua Clover Code Coverage for Java

Wednesday, May 11, 2005

Some examples of using Unix find command.

This seems to work better than the grep -H -r * technique.

Some examples of using Unix find command.: "find . -exec grep 'www.athabasca' '{}' \; -print"

Sunday, May 08, 2005

Tip #26 - Getting rid of ^M - mixing dos and unix : vim online

Tip #26 - Getting rid of ^M - mixing dos and unix : vim online: "If you work in a mixed environment you will often open files that have ^M's in them. An example would be this:

------------------------------------------------------------------
import java.util.Hashtable; ^M
import java.util.Properties; ^Mimport java.io.IOException;
import org.xml.sax.AttributeList; ^M
import org.xml.sax.HandlerBase; ^Mimport org.xml.sax.SAXException;

/**^M
* XMLHandler: This class parses the elements contained^M
* within a XML message and builds a Hashtable^M

[snip]
------------------------------------------------------------------

Notice that some programs are not consistent in the way they insert the line breaks so you end up with some lines that have both a carrage return and a ^M and some lines that have a ^M and no carrage return (and so blend into one). There are two steps to clean this up.

1. replace all extraneous ^M:

:%s/^M$//g

BE SURE YOU MAKE the ^M USING 'CTRL-V CTRL-M' NOT BY TYPING 'CARROT M'! This expression will replace all the ^M's that have carriage returns after them with nothing. (The dollar ties the search to the end of a line)

2. replace all ^M's that need to have carriage returns:

:%s/^M/ /g

Once again: BE SURE YOU MAKE the ^M USING 'CTRL-V CTRL-M' NOT BY TYPING 'CARROT M'! This expression will replace all the ^M's that didn't have carriage returns after them with a carriage return.

Voila! Clean file. Map this to something if you do it frequently.

:help ffs - for more info on file formats

thanks to jonathan merz, douglas potts, and benji fisher
<> "

Wednesday, May 04, 2005

Case Insensitive Queries

Some databases have an "ignore case" flag that can be set for the entire database. Oracle does not, and thus case-insensitive queries have long caused problems, not with coding them, but with their performance (since indexes are typically not used to determine the result).

Its relatively straightforward to create a case-insensitive query:

SQL> select *
2 from EMP
3 where upper(ENAME) = upper(:b1)

but of course (by default) the "UPPER(ENAME)" cannot take advantage of an index that may have been defined on the ENAME column.

Enter 8i, where the concept of a function-based index is now possible. Before you rush off and try to create them, take note of the following:

* You must have the system privelege query rewrite to create function based indexes on tables in your own schema.
* You must have the system privelege global query rewrite to create function based indexes on tables in other schemas
* For the optimizer to use function based indexes, the following session or system variables must be set:
QUERY_REWRITE_ENABLED=TRUE
QUERY_REWRITE_INTEGRITY=TRUSTED
* You must be using the Cost Based Optimiser (which means analyzing your tables/indexes)

and then its just a case of creating the index in the conventional way:

create index UPPER_ENAME_IX on ENAME ( UPPER(ENAME) ) ;

Note that this index will NOT be used for case-SENSITIVE queries. You could always have two indexes, one on ENAME and one on UPPER(ENAME), but it would probably be more efficient to just have the function-based one and code:

SQL> select *
2 from EMP
3 where upper(ENAME) = upper(:b1)
4 and ENAME = :b1

for the times where you do not want case-insenstivity.


Thanks to (http://www.jlcomp.demon.co.uk/faq/case_insensitive_query.html)