Thursday, December 22, 2005

Oracle date/time functions

Oracle has an array of date functions that could be confusing because they may seems to give the same output at first sight, i will try to explain here the relation between this functions and the time zone.


First a little bit about time zones, the world is divided into 24 time zones starting at 0 from Greenwish (GMT Greenwish Mean Time , the actual or new time system is called UTC Coordinated Universal Time ) , im on Cali , Colombia so my time zone is UTC -5:00, that means that when it is 12:00 UTC then it is 7:00 here. The picture below shows all the time zones in the world:



current_timestamp VS systimestamp VS localtimestamp


When you issue this three functions apparently they give you the same date ,hour and time zone (except for localtimestamp who doesnt give time zone):


SQL>select current_timestamp,systimestamp, localtimestamp from dual;



CURRENT_TIMESTAMP
---------------------------------------------------------------------------
SYSTIMESTAMP
---------------------------------------------------------------------------
LOCALTIMESTAMP
---------------------------------------------------------------------------
29/12/05 15:17:30,214000 -05:00
29/12/05 15:17:30,214000 -05:00
29/12/05 15:17:30,214000


But after changing the session time zone you can notice (below) that systimestamp remains on -5:00 time zone while the other ones show you the date / time in -4:00 time zone. That is because the current_timestamp and localtimestamp works with the session time zone while systimestamp with the database time zone:

SQL> alter session set time_zone= '-4:00';

SQL>select current_timestamp,systimestamp, localtimestamp from dual;



CURRENT_TIMESTAMP
---------------------------------------------------------------------------
SYSTIMESTAMP
---------------------------------------------------------------------------
LOCALTIMESTAMP
---------------------------------------------------------------------------
29/12/05 16:19:36,666000 -04:00
29/12/05 15:19:36,666000 -05:00
29/12/05 16:19:36,666000


sysdate VS current_date

Finally there is no difference in the output of this other two functions if you dont get the time (the NLS_DATE_FORMAT is set to'DD-MON-YYYY' ) :


SQL> column sysdate format a15

SQL> column current_date like sysdate;

SQL> select sysdate, current_date from dual;

SYSDATE CURRENT_DATE
--------------- ---------------
29/12/05 29/12/05


But current_date works with the session time zone so if we can see the time it will show the date /time in the session time zone:

select to_char(sysdate,'DD-MM-YYYY HH24:MI:SS' ) sdate,
to_char(current_date,'DD-MM-YYYY HH24:MI:SS' ) curr_date
from dual;

SDATE CURR_DATE
--------------- ---------------
29/12/2005 15:19:55 29/12/05 16:19:55

Wednesday, December 21, 2005

My favorite firefox extensions


You cant stop using firefox once you try it, and extensions takes part of it, here are a list of my favorite firefox extensions, (i picked the ones that i most use from the whole installed):

- Smoothwheel : if you have a scroll mouse wheel it improves the default page movement.

- Stambleupon : useful if you want random links from something that you are insterested in, the links are ranked by users votes .

- All in one gestures : gathers tools for navigating using your mouse, for example if you want to open a new tab, just drag your mouse up and a new tab is open, drag your mouse left and make a history back, and so on.

- Web developer : as it says , when you're developing web app this package provides tools for debug, so you can show forms hidden elements values and allowing to change them, populate forms fields for testing, chage css of a page on the fly (in the client side), view source with a clik, etc , etc.

- Tamper data: Allows you to see and change http headers .

Monday, December 12, 2005

ORACLE Table locking

I was looking for information about table locking in Oracle and i found a very useful link, called "Oracle Locking Survival Guide" it provides some clarifying examples on every mode and level of blocking.

Tuesday, December 06, 2005

Printing an invoice from web

I found my self in the need of printing an invoice into a printed form from a web based application written in PHP + Apache + PostgresSQL, the objetive was that the data should fit precisely in the printed invoice fields boxes.

After some research i couldn't find any relevant information about printing invoices from web using php, so i started my own solution. If you print html directly from the web browser its harder to fit that displayed data in the printed paper and using different browers should affect the position of displayed and printed data, so printing html directly from browser was not an option. I thought about create a pdf to not deal with different browsers options and have some kind of compatibility, there where three choices : convert html to pdf (http://www.rustyparts.com/pdf.php), create postscript an convert it to pdf (http://pslib.codigolivre.org.br) or create the pdf directly (http://www.pdflib.com/).

For the first one it was not possible to get the html fit a precisely position and with the convertion from html to pdf you get just some kind of approach without maintain the positions of elements. For the second one you can set x,y coordinates for the data you want to display and if you have a postscript printer it can send directly to it, so i choose this one. The last one could be a choice too but it could be useful if you can send the postscript directly to the printer.

For creating postscript i used Pslib which is a library written in php an then converted it to pdf using ps2pdf which comes with some Linux distros.

If anybody knows another solution, please let me know. :P

Thursday, December 01, 2005

BSOD Blue Screen of Death: UNMOUNTABLE_BOOT_VOLUME

Yesterday in the morning i was going to burn a cd with some podcasts that i hear on my car in my way to work, when the pc was booting i face it: the scary BSOD with the message "UNMOUNTABLE_BOOT_VOLUME".




Why me?, i started to think about what i have done to this occur, i checked my IDE cables, boot again and again (safe mode, last known... bla, bla) hoping to fix it alone but nothing works, so before kicking the pc or format it , i tried booting with a win XP cd and in the recovery console (pressing "R", then choosing "c:/windows", and finally entering the administrator password) i typed this:


1. chksdsk /r [enter] --> it takes a long time
2. chksdsk /p [enter]
3. fixboot c: [enter] -->if c: is where windows is installed
4. exit ->to reboot again

And it works, i got xp back again :P.