Programming
if exists syntax in sybase
by Samet Kilictas on Apr.20, 2010, under General, SQL, Tips
Below shows the if exists usage with examples in sybase
If exists (select record)
begin
sql statement 1
sql statement 2
end
else
begin
sql statement 3
sql statement 4
end
Example
Scripts that include constructs like the following may produce errors if the table described in the script does not include the specified column:
if exists (select 1 from syscolumns
where id = object_id("some_table")
and name = "some_column")
begin
alter table some_table drop some_column
end
In this example, some_column must exist in some_table for the batch to succeed.
If some_column exists in some_table, the first time you run the batch, alter table drops the column. On subsequent executions, the batch does not compile.
Adaptive Server raises these errors while preprocessing this batch, which are similar to those that are raised when a normal select tries to access a nonexistent column. These errors are raised when you modify a table’s schema using clauses that require a data copy. If you add a null column, and use the above construct, Adaptive Server does not raise these errors.
To avoid such errors when you modify a table’s schema, include alter table in an execute immediate command:
if exists (select 1 from syscolumns
where id = object_id("some_table")
and name = "some_column")
begin
exec ("alter table some_table drop
some_column")
end
Because the execute immediate statement is run only if the if exists() function succeeds, Adaptive Server does not raise any errors when it compiles this script.
You must also use the execute immediate construct for other uses of alter table, for example, to change the locking scheme, and for any other cases when the command does not require data copy.
A common error with GROUP BY Clause
by Samet Kilictas on Apr.16, 2010, under SQL, Tips
A common error with groups is to try to get information which cannot properly be put in a group. For example,
SELECT sales_rep, emp_lname, count( * ) FROM sales_order KEY JOIN employee GROUP BY sales_rep
gives the error
column ‘emp_lname’ cannot be used unless it is in a GROUP BY.
SQL does not realize that each of the rows for an employee with a given ID have the same value of emp_lname. An error is reported since SQL does not know which of the names to display.
However, the following is valid:
SELECT sales_rep, max( emp_lname ), count( * ) FROM sales_order KEY JOIN employee GROUP BY sales_rep
The max function chooses the maximum (last alphabetically) surname from the detail rows for each group. The surname is the same on every detail row within a group so the max is just a trick to bypass a limitation of SQL.
Cannot load mysqli extension. Please check your PHP configuration
by Samet Kilictas on Aug.25, 2009, under PHP, Programming, Tips
Probably you are trying to access your phpmyadmin. You will get this error if you have more then one “php.ini” file in your system. It is kinda conflicting. For instance i have wampserver2.0 and IIS7 together in my current system. I have activated IIS7 FastCgı method to use php on it. So it has one php.ini file at path of “c:\wamp\….” and another one in “c:\Program Files\Php” . You can get a temporary solution if you rename your php.ini file which is in your “program files” path.
That is it.
Gedit Modifications for PHP
by Samet Kilictas on May.17, 2009, under General, Linux, PHP, Programming
Since i am coding with codeigniter framework on gedit, i was looking for snippets for codeigniter on gedit
download gedit snippet for codeigniter
By the way if you want to make your gedit more useful for programming surely you may add some third party plugins as many as you want or simply just active default plugins. Idea is that firstly download a plugin then extract its content to ‘~/.gnome2/gedit/plugins/’ directory. Once you have installed the plugin you want, you need to enable it via Edit>Preferences and then the Plugins Tab. Such as;
- Snippets
- Class Browser
- Bracket Completation
- Character Map
- Embedded Terminal
etc..
You can basicly find out third-party plugins by clicking on this link
What is MVC Architecture? (Model – View – Controller)
by Samet Kilictas on Apr.19, 2009, under General, Programming
MVC Architecture has implemented by Trygve Reenskaug at 1979 for the first time. It was implemented on Smalltalk at Xerox labs. Then benefits and advantages of this architecture has been accepted by most of the coders and software engineers.
It was an information about MVC’s history above. Now lets talk about what really MVC is. What do you understand from MVC. The word M stands for Model, V stands for View and C stands for Controller. I am going to mention about each item.
The figure above may help you while thinking what structure it might have. Let’s start with Model.
Model:
It handles data processing and database works part. Model processes events sent by controller. After processing these events then it sends processed data to controller (thus, controller may reprocess it) or directly to view side.
View:
View prepares an interface to show to the user. Controller or model tells view what to show to the user. Also view handles requests from user and informs controller.

Thanks for dropping by! Feel free to join the discussion by leaving comments, and stay updated by subscribing to the 