Skip to main content

Posts

Showing posts from 2011

Mysql: Multiple loop cursor in procedure

DELIMITER $$ DROP PROCEDURE IF EXISTS `updatequestion` $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `updatequestion`()  BLOCK1: begin      declare v_col1 int;      declare no_more_rows1 boolean default FALSE;      declare cursor1 cursor for          select col1          from   MyTable;      declare continue handler for not found          set no_more_rows1 := TRUE;      open cursor1;      LOOP1: loop          fetch cursor1          into  v_col1;          if no_more_rows1 then              close cursor1;         ...

Mysql Procedure syntax

DROP PROCEDURE `dg`// CREATE DEFINER=`root`@`localhost` PROCEDURE `dg`(g int(32)) begin declare p_a int(25); declare no_more_rows boolean default FALSE; declare cursor1 cursor for select id from chk; declare continue handler for not found set no_more_rows := TRUE; open cursor1; Loop1 : loop fetch cursor1 into p_a; if no_more_rows then close cursor1; leave Loop1; end if; select p_a; end loop Loop1; end

Mysql : Rollup command ..last row of the result will show the total of sum and count function

Rollup command ..last row of the result will show the total of sum and count function SELECT month,sum(star),sum(rating),count(*) FROM `rolluptest` group by month with rollup +-------+-----------+-------------+----------+ | month | sum(star) | sum(rating) | count(*) | +-------+-----------+-------------+----------+ | Feb   |        19 |           4 |        3 | | Jan   |         9 |           4 |        2 | | Mar   |         1 |           3 |        1 | | NULL  |        29 |          11 |        6 | +-------+-----------+-------------+----------+

Joomla : Add joomla modules in our Custom Component

function display()  {   global $mainframe;   $model =& $this->getModel("vadmin");   $a = new CTemplate();   $a->setfile("home");     $article->text = $a->fetch();   $params =& $mainframe->getParams();   $dispatcher =& JDispatcher::getInstance();   JPluginHelper::importPlugin('content');   $results = $dispatcher->trigger('onPrepareContent', array (& $article, & $params));   echo $article->text ;     }

PHP : Regular Expression

Adding Comments preg_match("/^ (1[-\s.])? # optional '1-', '1.' or '1' ( \( )? # optional opening parenthesis \d{3} # the area code (?(2) \) ) # if there was opening parenthesis, close it [-\s.]? # followed by '-' or '.' or space \d{3} # first 3 digits [-\s.]? # followed by '-' or '.' or space \d{4} # last 4 digits $/x",$number); Let’s put it within a code segment. $numbers = array( "123 555 6789", "1-(123)-555-6789", The trick is to use the ‘x’ modifier at the end of the regular expression . It causes the whitespaces in the pattern to be ignored, unless they are escaped (\s). This makes it easy to add comments. Comments start with ‘#’ and end at a newline. Greedy vs. Ungreedy Before I start explaining this concept, I would like to show an example first. Let’s say we are looking to find anchor tags in an html text: $html = 'Hello World! '; if (preg_...

simple recursive function to copy entire directories

<?php function recurse_copy ( $src , $dst ) {     $dir = opendir ( $src );     @ mkdir ( $dst );     while( false !== ( $file = readdir ( $dir )) ) {         if (( $file != '.' ) && ( $file != '..' )) {             if ( is_dir ( $src . '/' . $file ) ) {                 recurse_copy ( $src . '/' . $file , $dst . '/' . $file );             }             else {                 copy ( $src . '/' . $file , $dst . '/' . $file );             }         }     }     closedir ( $dir ); } ?>

CREATE JAR FILE

1) Create file HelloWorld.java 2) Compile HelloWorld.java (eg : javac Helloworld.java) to HelloWorld.class 3) create a file named manifest.txt 4) Add content "Main-Class: HelloWorld" to manifest.txt file 5) Now run this command on command Prompt ( E:\java\exe>jar -cfm test.jar manifest.txt HelloWorld.class) 6) and then command java -jar test.jar or double click test.jar file

preg_replace_callback inside a class

<?php class MyClass {   function preg_callback_url ( $matches )   {     //var_dump($matches);     $url = $matches [ 1 ]. $matches [ 2 ];     $text = '' ;     $pos = strpos ( $url , ' ' );     if ( $pos !== FALSE ) {       $text = trim ( substr ( $url , $pos + 1 ));       $url = substr ( $url , 0 , $pos );     }     return '<a href="' . $url . '" rel="nofollow">' .(( $text != '' ) ? $text : $url ). '</a>' ;   }   function ParseText ( $text )   {     return preg_replace_callback ( '/\[(http|https|ftp)(.*?)\]/iS' ,array( & $this , 'preg_callback_url' ), $text );   } } ?>