Monday, November 30, 2009

notes from learning mysql stored procedures

what is a stored procedure? - it is a set of sql statements that are stored within the database.

Stored procedures advantages

Stored procedure increases performance of application. Once created, stored procedure is compiled and stored in the database catalog. It runs faster than uncompiled SQL commands which are sent from application.


Stored procedure reduced the traffic between application and database server because instead of sending multiple uncompiled long SQL commands statement, application only has to send the stored procedure name and get the result back.


Stored procedure is reusable and transparent to any application which wants to use it. Stored procedure exposes the database interface to all applications so developer doesn’t have to program the functions which are already supported instored procedure in all programs.


Stored procedure is secured. Database administrator can grant the right to application which to access which stored procedures in database catalog without granting any permission on the underlying database table.

Beside those advantages, stored procedure still has its own disadvantages which are bellow

Stored procedures disadvantages

Stored procedure make the database server high load in both memory for and processors. Instead of being focused on the storing and retrieving data, you could be asking thedatabase server to perform a number of logical operations or a complex of business logic which is not the role of it.

Stored procedure only contains declarative SQL so it is very difficult to write a procedure with complexity of business like other languages in application layer such as Java, C#, C++…

You cannot debug stored procedure in almost RDMBSs and in MySQL also. There are some workarounds on this problem but it still not good enough to do so.

Writing and maintain stored procedure usually required specialized skill set that not all developers possess. This introduced the problem in both application development and maintain phrase.

DELIMITER // - changes the delimiter to //
CREATE PROCEDURE GetAllProducts() -
GetAllProducts() is the name of the stored procedure.
BEGIN - tells the start of the procedure's workings
SELECT * FROM products; - the actual procedure
END //
- changes the delimiter to // and tells the end of the procedure
DELIMITER ; - changes back the delimiter to a semicolon
this is how a stored procedure is called - CALL STORED_PROCEDURE_NAME()

a variable is instantiated in a stored procedure this way: declare variable_name data type(size) default value. eg declare totalProducts int default 0

multiple variables with the same data type can be declared together. eg. declare x, y int default 0

there are two ways to assign values to variables:

1 - using the set keyword - set totalProducts = 39;
2 - using select... into - select count(*) into totalProducts from products

variables have scopes which determine their life span.

variables with an @ are session variables and have a life span until the end of the session.

variables have modes: in, out, inout

to be continued

blackbery security

i had the unfortunate event of not remembering my password for my bb a minute after i had set it. I tried it a couple of times and was told that it was wrong. i googled it and i found out that all i had to do was to enter it the maximum amount of times and it would erase all my data from the phone and then i would be able to use it again.

do you see a problem with that? i do. if my phone gets stolen or lost, all someone will have to do is to enter the incorrect password 10times or the maximum amount of times and then they would be able to use the phone. i thought the phone would be locked but alas, thats not the case. so if this information gets into the hands of some people, it would be detrimental to alot of others in the bb world :)

Friday, November 27, 2009

Zend Studio opens with no menu

when this happens, the instructions to fix it are here: http://www.zend.com/support/knowledgebase.php?kbid=241&view_only=1 but you can follow them below:

Symptoms



When running Zend Studio:
1. The ZS's main window comes up totally empty.
2. Sometimes the window has some of the frames painted, but the rest of the window is empty.
3. In the empty ZS window the mouse cursor is changing while moving around the window (as if there are objects: like buttons and other objects).
4. There were erratic mouse/window movements reported.


Summary



Zend Studio starts up with various windowing GUI problems in some linux distros, while using the XGL-Compiz/Beryl product.


Cause



1. Incompatibility between the XGL environment, the JRE, and the Zend Studio Client.
2. The decoration in the 3D environment clashes with the Java Runtime and distorts the operation and visualization of the Zend Studio client's window.


Workaround



There are two ways to execute Zend Studio, by running the ZDE script, and by running the runStudio_unix.sh script, both are in the bin directory of zend studio
(usually /usr/local/Zend/ZendStudio-/bin)

The following workarounds may be used, but there is no guarantee how well or how long it might work for you in your environment.


modification of ZDE script for xgl:


1. Open your ZDE script with your favorite editor
2. add the next line of code at line 1693.
options="$options -Dawt.toolkit=sun.awt.motif.MToolkit"

for example:
1693:
1694: debugOut ""
1695: unset POSIXLY_CORRECT
1696: if [ $DO_NOT_FORK ]

becomes:
1693: options="$options -Dawt.toolkit=sun.awt.motif.MToolkit"
1694: debugOut ""
1695: unset POSIXLY_CORRECT
1696: if [ $DO_NOT_FORK ]

3. Save the file.


modification of runStudio_unix.sh script for xgl:


1. open the the file in your favorite editor.
2. modify the java execution line,
the line starts with: ../jre/bin/java -Xms16m -Xmx256m -cp...
change it to: ../jre/bin/java -Dawt.toolkit=sun.awt.motif.MToolkit -Xms16m -Xmx256m -cp...
^^^^^^^^^^^^^^^^^^^^^^^^^^
as you can see, the only difference is an extra parameter to the java program.
3. Save the file.

Another solution



the AWT_TOOLKIT environment variable can be set in order for Java to choose a working AWT Toolkit.

export AWT_TOOLKIT="MToolkit"

In most Linux Distributions it's enough to append this line to /etc/profile.

Older Girls Party



wow. arent these "young" girls having fun, sticking things in holes, running, etc. i wonder what the other activities were? hmm. :)

Wednesday, November 25, 2009

gimp save for web plugin

i had need for the save for web plugin that photoshop has and didnt find one in ubuntu gimp since i dont use WINDOWS. i found the plugin here: http://my.opera.com/area42/blog/gimp-save-for-web-plugin-0-28-4.

for ubuntu users, download the Ubuntu deb archive of 0.28.4 file.

Monday, November 23, 2009

Clear textarea default value

this is the code used to clear the default value of a textarea.

onfocus="if(this.value==this.defaultValue){this.value='';}" onblur="if(this.value==''){this.value=this.defaultValue;}"

Thursday, November 19, 2009

Wednesday, November 18, 2009

p4a alphabet sorter with text search

i wrote this module with p4a and decided to share. its an alphabet sorter.

function textSearchWithcreateAlphabeticalSorter(){

$alphabet_array = array();

$alphabet_array[] = 'A';
$alphabet_array[] = 'B';
$alphabet_array[] = 'C';
$alphabet_array[] = 'D';
$alphabet_array[] = 'E';
$alphabet_array[] = 'F';
$alphabet_array[] = 'G';
$alphabet_array[] = 'H';
$alphabet_array[] = 'I';
$alphabet_array[] = 'J';
$alphabet_array[] = 'K';
$alphabet_array[] = 'L';
$alphabet_array[] = 'M';
$alphabet_array[] = 'N';
$alphabet_array[] = 'O';
$alphabet_array[] = 'P';
$alphabet_array[] = 'Q';
$alphabet_array[] = 'R';
$alphabet_array[] = 'S';
$alphabet_array[] = 'T';
$alphabet_array[] = 'U';
$alphabet_array[] = 'V';
$alphabet_array[] = 'W';
$alphabet_array[] = 'X';
$alphabet_array[] = 'Y';
$alphabet_array[] = 'Z';

$frmeAlphabet = & $this->build('p4a_frame', 'frmeAlphabet');

$name = & $this->build('p4a_field', 'txtName');
$name->setLabel('Horse Name');
$name->addAction('onReturnPress');
$this->intercept($name, "onReturnPress", "searchHorses");

foreach ($alphabet_array as $letter){
//echo $letter;
//echo 'btn'.$letter;exit;
$btn = & $this->build('p4a_button', 'btn'.$letter);
$btn->setLabel($letter);
$btn->setValue($letter);
$btn->setBgcolor('white');
$btn->setStyleProperty('border', '0');
$frmeAlphabet->anchorLeft($btn);
//$btn->addAction('onClick');
$this->intercept($btn, 'onClick', 'sortBySelectedButtonValue');
}

$frmeMain = & $this->build('p4a_frame', 'frmeMain');
$frmeMain->anchor($name);
$frmeMain->anchor($frmeAlphabet);
return $frmeMain;
}

function searchHorses(){

$horse_name = & $this->txtName->getNewValue();

$where = " 0=0 and horse_name like '%$horse_name%'";
$this->horseSrc->setWhere($where);
}

function sortBySelectedButtonValue($letter){
//echo $letter->getValue();
$selectedLetter = $letter->getValue();
//echo $this->getActiveObject();exit;

//$query = "select * from horses where 0=0 and horse_name like '$selectedLetter%'";
$where = "0=0 and horse_name like '$selectedLetter%'";
//$this->horseSrc->setQuery($query);
$this->horseSrc->setWhere($where);
//$this->horseSrc->setWhere($query);

}

Toyota trucks with gadgets and all!!!!!!!!!!!

check out these trucks: http://editorial.autos.msn.com/photopopup.aspx?cp-documentid=1106307&mediaid=357e5d66103d44ca9c2e473aac110e61&rf=http://editorial.autos.msn.com/photogallery.aspx?cp-documentid=1106307#mediaid=357e5d66103d44ca9c2e473aac110e61

Monday, November 16, 2009

Job Interview Questions and Answers

Below is the link to some job interview questions and answers.

See them here

Google's interview brain teasers

Our story on Google's hiring practices on Friday generated quite a bit of reader feedback, including an email from a Seattle interview coach with a list of 140 common interview questions at the Mountain View Internet giant.

Why Google Employees Quit

In 2008 Google HR set up a private Google Group to ask former employees why they left the company. We’ve been forwarded what appears to be authentic posts to the thread by a number of ex-Googlers, which we reprint below minus identifying information other than their first names.

Read more here

Wednesday, November 11, 2009

remove hiberfile on windows partition from ubuntu

as i speak i am using my ubuntu live cd. i am about to install ubuntu 9.10 but i encountered a problem. i had hibernated my windows partition and now i cant perform certain tasks on it. i figure out the problem, i need to remove the hiberfile from the partition to gain access to the partition. i used the code below to perform the function.

sudo mount -t ntfs-3g /dev/sda1 /media/sda1/ -o remove_hiberfile

if it works you should see something like this:

The disk contains an unclean file system (0, 0).
The file system wasn't safely closed on Windows. Fixing.

Friday, November 6, 2009

44: php: not found

i got this error while trying to create the tree structure for a zend application and i got the following error: 44: php: not found. to resolve this, you need to install php5-cli. this can be installed by the following command from the terminal: sudo apt-get install php5-cli.