Analytics


Google

Thursday, December 25, 2008

Shell Scripting on Unix

Ideally to learn how to do scripting, we need to have a unix environment to try out the scripts and this can be easily done by setting up Linux or Open Solaris on your computer. However, what happens if you don't have a spare computer to do that?

You could use a live CD. Problem with that is you need to reconfigure it each time which is troublesome. Alternatively, you can setup Cygwin. There are two version - Cygwin which is purely command prompt and Cygwin/X which provides a X Windows environment.

Given that you can then use the various tutorials on Internet to learn scripts like bash:

Linux Config org
Bash Programming How To
Advanced Bash Tutorial

Alternatively, you can use perl, php or even java to automate your unix scripts.

Monday, December 22, 2008

Free Charting Libraries

When writing program, we have an option to either write everything ourselves or to use/leverage on utilities/libraries that are already written. This is especially true when it comes to charting.

When using asp classic, you can use the mschart control that comes with MS Office. However, that requires that you install MS Office on your webserver. Also, I found the library quite difficult to work with.

The following are some popular opensource/freeware libraries you can use:

For Java, you can use jfreechart.
For .Net, you can use zedgraph. I saw a good article on this on this web page, which is in fact how I found this library.

Alternatively, you can use paid software, our previous software was chartfx and then we started working on Netchart.

Netchart is good in that it can be used for different platforms because it uses webservices and provides libraries for java, asp etc. Only thing it is requires a server to serve the webservices.

Some additional libraries that I found are:

Open Flash Chart
Fusion Chart Free A good sample code on how to use Fusion Chart Free using .net is found here.
Some additional java script charting components are found here.

Friday, December 19, 2008

Can't find table in stored function, procedure or package in Oracle

This is a strange problem:

We have rights to select a table and can select in normal sql statement. However, when we write a stored procedure or function (with or without a package), we encounter an error that says table not found.

The one solution we found was to grant that account select any table rights. Once granted, we can compile and use the stored procedure/package. However, the problem with doing that is the account can also select any table in any schema in that instance.

I found the following solution thanks to a support from the community forum:

Note:388774.1


Applies to:
Oracle Server - Enterprise Edition - Version: 9.2.0.1 to 10.2.0.3
This problem can occur on any platform.
Symptoms
When SYSTEM user grants select on a table to another user with SQL*Plus , it works fine: SYSTEM user has the GRANT ANY OBJECT PRIVILEGE system privilege .

SQL> CONNECT system/xxx
Connected.
SQL> grant SELECT, INSERT, UPDATE, DELETE on SCOTT.TEST TO X;
Grant succeeded.
1. Under 10g, when this statement is in a stored procedure, it returns "ORA-1031 - insufficient privilege".
2. Under 9i, it returns "ORA-00942: table or view does not exist "

SQL> CREATE OR REPLACE PROCEDURE system.def_grant_test
IS
cursor_handle INTEGER;
BEGIN
cursor_handle := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cursor_handle, 'GRANT SELECT, INSERT, UPDATE, DELETE on SCOTT.TEST TO X', dbms_sql.native );
DBMS_SQL.CLOSE_CURSOR(cursor_handle);
END;
/


Procedure created.
SQL 9i> exec system.def_grant_test
BEGIN system.def_grant_test; END;
*
ERROR at line 1:
ORA-00942: table or view does not exist
ORA-06512: at "SYS.DBMS_SYS_SQL", line 826
ORA-06512: at "SYS.DBMS_SQL", line 39
ORA-06512: at "SYSTEM.DEF_GRANT_TEST", line 6
ORA-06512: at line 1
SQL 10g> exec system.def_grant_test
BEGIN system.def_grant_test; END;

*
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "SYS.DBMS_SYS_SQL", line 906
ORA-06512: at "SYS.DBMS_SQL", line 39
ORA-06512: at "SYSTEM.DEF_GRANT_TEST", line 6
ORA-06512: at line 1
Cause
Generally an invokers's called procedure executes using the caller's privileges and all unqualified objects are resolved in the schema of the caller.
The privileges of the invoker are checked during runtime only for
DML statements ('insert', 'update','delete', 'update')
dynamic sql statements ('execute immediate' and 'open for using')
cursor statements ('open' and 'open for update')
DDL statements ('lock table')
parsed SQL statements using dbms_sql.parse
Solution
To implement the solution, please execute the following steps:

1. Create the procedure defined as an invoker's right procedure , with AUTHID CURRENT_USER clause:

SQL> CREATE OR REPLACE PROCEDURE system.inv_grant_test authid current_user
IS
cursor_handle INTEGER;
BEGIN
cursor_handle := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cursor_handle, 'GRANT SELECT, INSERT, UPDATE, DELETE on SCOTT.TEST TO X', dbms_sql.native );
DBMS_SQL.CLOSE_CURSOR(cursor_handle);
END;
/


Procedure created.
SQL> exec system.inv_grant_test
PL/SQL procedure successfully completed.
SQL> select * from dba_tab_privs where table_name='TEST' and grantee='X';

GRANTEE OWNER TABLE_NAME GRANTOR PRIVILEGE GRA HIE

-------- -------- ---------- -------- ---------- --- ---
X SCOTT TEST SCOTT INSERT NO NO
X SCOTT TEST SCOTT DELETE NO NO
X SCOTT TEST SCOTT SELECT NO NO
X SCOTT TEST SCOTT UPDATE NO NO

Wednesday, December 17, 2008

Java Enterprise Edition (JEE) servers

Two of the most renown JEE servers are JBoss (now under RedHat) and GlassFish (from Sun).

However, if your company is primarily using Weblogic at the corp level and you want to have a development environment, you can download it here, it comes with a free developer license (which allows up to 5 ip addresses) to perform your test and development.

Maybe it is due to my lack of knowledge of the server. I was unable to successfully create my own project using the easy start. The project was created using the wizard but failed to start. Also, I noted that the weblogic server (10.3 still uses Java 1.4 instead of Java 1.5 or Java 1.6) as used by the JBoss and Glassfish. Also, there was no easy way to start the server by itself.

I tried JBoss, starting and stopping is very simple. I have yet to try out Glassfish.

JBoss 4.2.x is JEE 5 able but not certified. JBoss 5.0 is JEE 5 certified. Glassfish and Weblogic also support JEE 5. All three servers are supported by NetBeans.

Tuesday, December 16, 2008

m.www.yahoo.com

I recently received a complaint from a colleague that she is not able to get to the yahoo website:

http://www.yahoo.com

instead she was redirected to the following website:

http://m.www.yahoo.com

The first reaction from our helpdesk was that there could be a possible spyware on her computer. Mostly because others who type the following address were redirected to the following page:

http://www.yahoo.com/?nm=1

A quick search in Google quickly revealed that she was directed to a new interface which yahoo is testing. The frustrating part is the users are picked at random and are not given a choice to revert back.

The fix is to clear the cookie and the cache in her browser. Also her feedback was that she did not really like the new interface, she preferred the old one because:
  1. To her it was prettier with the pictures that changes according to season. Like right now there is the Christmas greeting.
  2. Everything is with one click.
I read comments from other sites and a lot of them did not like it either, even though Yahoo was trying to emulate Google's cleaner interface. I guess that is a lesson to be learned. One your user base is used to an interface, you should not just change it; otherwise you risk angering your loyal customers!!!

Sunday, December 14, 2008

Compiling .Net programs with Nant

Nant is the .Net Version of Ant. It is capable of doing a lot of things as indicaed in the task reference here. However, for the purpose of this article, I am going to focus how to use it to either compile an .net assembly either to .exe or .dll.

In my previous article, I provided an example how we can write a program without using Visual Studio. Assuming you have written your program, you could use the command line vbc (for Visual Basic compiler) and csc (C# compiler) to compile. However, it is tedious if the program references a lot of libraries or there are multiple source file.

To compile using Nant, first step is to download NANT. The home page is found here. Download and unzip the zip file. Assuming you downloaded Nant 8.5, you can unzip everything to c:\nant-0.85. When unzipping, just say use the folder in the zip file then unzip it to c:\. It will automatically create a folder tree c:\nant-0.85\...

Next, create a build file:

Here is an example for compiling .exe:

<?xml version="1.0"?>
<project name="FileLimAlert" default="build" basedir=".">
<property name="debug" value="true" unless="${property::exists('debug')}" />
<property name="verbose" value="true" />
<target name="clean" description="remove all generated files">
<delete file="FileLimAlert.exe" failonerror="false" />
<delete file="FileLimAlert.pdb" failonerror="false" />
</target>
<target name="build" description="compiles the source code">
<vbc target="exe" output="FileLimAlert.exe" debug="${debug}">
<sources>
<include name="FileLimAlert.vb" />
</sources>
<references>
<include name="System.dll" />
<include name="System.Web.dll" />
<include name="System.Web.Services.dll" />
<include name="System.XML.dll" />
</references>
</vbc>
</target>
</project>


Here is a sample to compile code behind (into .dll) - assuming this is called newLdaplogin.build.xml:

<?xml version="1.0"?>
<project name="newLDAPLogin" default="build" basedir=".">
<property name="debug" value="true" unless="${property::exists('debug')}" />
<property name="verbose" value="true" />
<target name="clean" description="remove all generated files">
<delete file="bin\newLDAPLogin.dll" failonerror="false" />
<delete file="bin\newLDAPLogin.pdb" failonerror="false" />
</target>
<target name="build" description="compiles the source code">
<vbc target="library" output="bin\newLDAPLogin.dll" debug="${debug}">
<sources>
<include name="newLDAPLogin.aspx.vb" />
</sources>
<references>
<include name="System.dll" />
<include name="System.Web.dll" />
<include name="System.Data.dll" />
</references>
</vbc>
</target>
</project>


Note
  1. The target build will instruct nant what to do. In the above example to use VBC to compile either.
  2. In the first example above, the vbc target is to exe and the second one is to library.
  3. The references section within the target are for the libraries your program is referencing.
  4. The sources section within the target are for all the source code.
  5. As shown above, each section can include multiple includes, so you could have multiple source code compiling into either an exe or a dll.
  6. Clean basically instruct nant what are the files to delete.
To compile, just type (if you are building for Framework 1.1):

c:\nant-0.85\bin\nant -buildfile:newLdaplogin.build.xml -t:net-1.1

The output will look something like this:

NAnt 0.85 (Build 0.85.2478.0; release; 10/14/2006)
Copyright (C) 2001-2006 Gerry Shaw
http://nant.sourceforge.net

Buildfile: file:///C:/project/vbUtils/clsldap.build.xml
Target framework: Microsoft .NET Framework 1.1
Target(s) specified: build


build:

[vbc] Compiling 1 files to 'C:\project\vbUtils\bin\
newLDAPLogin'.

BUILD SUCCEEDED

Total time: 3.7 seconds.


If you want to build for framework 2.0 then change -t:net-1.1 to -t:net-2.0.

The build will detect is a recompilation is necessary and will not compile if the assembly is already up to date. Each version of nant will have a list of framework that is supported.

The latest version 0.86-Beta 1 supports the following framework:

FrameworkTargetRuntime
.NET Framework 1.0**
.NET Framework 1.1**
.NET Framework 2.0**
.NET Framework 3.5**
.NET Compact Framework 1.0*
.NET Compact Framework 2.0*
Mono 1.0 Profile**
Mono 2.0 Profile**
Mono 3.5 Profile**
Moonlight 2.0*
Shared Source CLI 1.0*
Silverlight 2.0*

You can check the version supported by looking into the nant.exe.config file.

Friday, December 5, 2008

Removing standby or logout from Windows XP shutdown menu

Obtained the following from here - Have not verified:


HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ACPI\Parameters
Click in the right pane and create a new REG_DWORD value.
Give it the name Attributes
Set the value to 00000070

After reboot, Standby is unavailable.

********************************

to remove logoff :-

Start the Registry Editor (go to Start, Run and type Regedt32). Find the key

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer]
create a new dword called NoLogOff and give it a value of 1

the above can be done on the hklu part of the registry if it is just for a particular user.

Monday, December 1, 2008

Oracle Hints

Every so often, when you have an application which is working fine and suddenly the applications slows down for no apparent reason. I have seen this on many occasions and found that majority of the time is somehow Oracle decided the fastest way to perform my sql query is to do a full table scan on some huge tables because the database has many extends.

In those situations, I use hints to "advice" Oracle to use the index for example:

select /*+ index(e iempmaster) */ empno, title, extension from empmaster e where empno = 'XXX123';

Note the the hints starts with /*+, it needs a space immediately after that prior to the hint. Index is not the only options there are many other hints such as hash etc. You can find reference to the rest in the following sites:

http://www.psoug.org/reference/hints.html
http://www.dba-oracle.com/t_sql_hints_tuning.htm

To test if your hint is working or not, perform an explain plan without the hint and run the explain plan with the hint. You should see the difference. You can perform explain plan from the sqlplus (dos prompt) or use SQL Developer, there is a button for execute Explain plan. However, to do that you need to have a table called plan_table with the following structure:

Column Name Data type
STATEMENT_ID VARCHAR2(30 BYTE)
TIMESTAMP DATE
REMARKS VARCHAR2(80 BYTE)
OPERATION VARCHAR2(30 BYTE)
OPTIONS VARCHAR2(30 BYTE)
OBJECT_NODE VARCHAR2(128 BYTE)
OBJECT_OWNER VARCHAR2(30 BYTE)
OBJECT_NAME VARCHAR2(30 BYTE)
OBJECT_INSTANCE NUMBER
OBJECT_TYPE VARCHAR2(30 BYTE)
OPTIMIZER VARCHAR2(255 BYTE)
SEARCH_COLUMNS NUMBER
ID NUMBER
PARENT_ID NUMBER
POSITION NUMBER
COST NUMBER
CARDINALITY NUMBER
BYTES NUMBER
OTHER_TAG VARCHAR2(255 BYTE)
PARTITION_START VARCHAR2(255 BYTE)
PARTITION_STOP VARCHAR2(255 BYTE)
PARTITION_ID NUMBER
OTHER LONG
DISTRIBUTION VARCHAR2(30 BYTE)