Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

Thursday, 21 August 2014

How to use and get output arguments in stored procedure using OUT parameter mode?

It is sometimes required to get the result of a stored procedure in a variable which can be used later or to output the result.

To do so, we can use the "OUT" parameter mode while defining stored procedures.

In the below section, we will be writing a stored procedure to get the square root of a number returned in an output variable provided by us.



Stored Procedure Definition:

Store the below stored procedure in a file named my_sqrt.sql and save it.

DELIMITER $$

DROP PROCEDURE IF EXISTS my_sqrt$$

CREATE PROCEDURE my_sqrt(inp_number INT, OUT op_number FLOAT)
BEGIN
    SET op_number=SQRT(inp_number);
END$$

DELIMITER ;

Execute Stored Procedure:

Open your mysql client in terminal and run the above procedure using the below command:

mysql> SOURCE my_sqrt.sql;
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Then call the stored procedure to get square root of 100 in an output variable called @sqrt:

Get square root of 100:

mysql> CALL my_sqrt(100, @sqrt);
Query OK, 0 rows affected (0.00 sec)

Now the output of the sqrt operation is stored in @sqrt variable which can be used by us as we desire.

mysql> SELECT @sqrt;
+--------+
| @sqrt  |
+--------+
|   10   |
+--------+
1 row in set (0.00 sec)

That's all it takes :)

Tuesday, 24 June 2014

Review Board - The Perfect Review System For You

If you have a big team, and manually asking or attending to peer code reviews in your team is a hassle, then "Review Board" is there for you.

Site

"Review Board makes code review easy
Saving time, money, and sanity"


"Yes, Review Board is absolutely free for commercial use."

Faqs

It's a python utility and easy to install in ubuntu and any linux system through easy_install
http://www.reviewboard.org/docs/manual/dev/admin/installation/linux/

You can setup it in your local and play around with your team in a local setup :)

Here's a demo

Some features:
1. Admin panel to manage reviews, users, groups and other customization
2. Review groups to whom review request can be sent.
3. User authorization preventing outside access.
4. Sending review requests to different members and group users easily.
5. Easy issue and tracking of comments on diffs by reviewers and reviewees.
6. Every diff review, comment sent through mail to required users and admin making it trackable and easy to follow.
7. And many others features.

Excerpts from site:
- Easily track your team's review requests
- Not your typical diff viewer
- Upload and review all kinds of files
- Comment on anything
- Keep track of everything that needs fixing
- All your history, in one place
- Birds-eye view of the server
- Helpful command-line tools
- Extensible

Get rocking :)

Wednesday, 11 June 2014

How to execute mysql query from a file in your mysql client terminal?

Being a terminal fan myself, I usually find myself running queries in the mysql client instead of a UI interface as it is much faster. You get to see the results instantaneously.

One thing which is pretty tedious is editing a big query again after once running it as the whole multi-line formatted query now appears on a single line, thus reducing its readability.

But no problems, you can edit your query from a file and run the file from your mysql client terminal as many times as you want with as many edits.

To do so, follow the below steps:

1. Open your terminal and cd into the folder you want to store our sample mysql file. Then save your query in a sample file called my_query.sql

$ cd /path/to/folder
$ vim my_query.sql

Save a sample query like:

SELECT * FROM employees
WHERE type LIKE 'hard_working'
OR type LIKE 'cool'
OR type LIKE 'crazy';

2. Then open mysql client from terminal and execute the query file using SOURCE command.

$ mysql -u username -p

> SOURCE my_query.sql;
We get the results here.

3. Edit your source file as many times and execute the SOURCE command again from the terminal. Be sure you are able to help SOURCE command in locating the source file location. Since we have opened the mysql client in the same folder which contains the source file, so there was no need for any path. If path varies, please do provide it.

> SOURCE /path/to/my_query_file.sql

How to install Phalcon PHP framework in Ubuntu linux?

Well, we have all heard about the fastest php framework out there. But how do we install it in a Ubuntu Linux machine.

Default process for any linux setup.

Steps:

1. First, we need  a few packages previously installed. To install them, issue the distro specific command in your linux terminal.

For Ubuntu:

sudo apt-get install php5-dev php5-mysql gcc libpcre3-dev

For Fedora:

sudo yum install php-devel php-mysqlnd gcc libtool

For RHEL:

sudo yum install php-devel php-mysql gcc libtool

For Suse:

yast2 -i php5-pear php5-devel php5-mysql gcc

Basically, here we are installing the dev tools we require to compile and setup the Phalcon extension.

2. Get the Phalcon build using git

git clone --depth=1 git://github.com/phalcon/cphalcon.git

3. CD into the folder and issue the install command.

cd cphalcon/build
sudo ./install

4. Now, lets add the extension to our php.ini file. At the end of the file, add the below line

extension=phalcon.so

5. Restart your apache server.

sudo service apache restart

6. Check your phpinfo and you will find the Phalcon extension installed. We are good to go now.

Note: You can also install Phalcon as a debian repo which has been offered by FortRabbit at http://debrepo.frbit.com/