Tuesday, April 12, 2016

sql_mode "only_full_group_by" in MySql

If you are getting one of the following errors, you have this problem;

  1. Error Code: 1055. 'test.somefield' isn't in GROUP BY
  2. SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.somefield' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
Check the current sql_mode in your mysql server with the following command to see if the only_full_group_by is enabled;

SELECT @@sql_mode;

This will give a list of sql_modes enabled in the server. Example as follows,

ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

As you can see from the above result, you have a value called "only_full_group_by". That means if you have a group by clause in your sql statement, only the fields which are listed in a group by clause can be used in the select clause or order by clause, unless you aggregate the fields. i.e, using aggregate functions such as min(), max() etc

NOTE: As of MySQL Server version 5.7.5, the only_full_group_by is enabled in the sql_mode by default.

Temporary Fix:
Temporarily you can fix this issue by disabling this check in the server by globally and/or only in the active session by issuing the following command respectively.

SET GLOBAL sql_mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";

SET SESSION sql_mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";

Permanent Fix:
- Make sure nonagregated field list in select or order by clause are in group by
- Restructure the sql statement

Thursday, December 17, 2015

ASP.NET MVC Controller Lifecycle

ASP.NET MVC Controller will be executed in the following  order:

Every controller action call go through the certain events events. Some of the methods I have listed below.

1) Initialize
Executed at the beginning of action call.

protected override void Initialize(RequestContext requestContext)
{
}

2) On Authorization
Executed at the time of authorizing the action call

protected override void OnAuthorization(AuthorizationContext filterContext)
{
}

1) On Action Executing
Executed at the time of executing the action just after authorization.

protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
}

MySql prepare historic data for reporting purpose

-- Prepare a table for days to get sequence of numbers from 1 to 32

CREATE TABLE ids (
id INT UNSIGNED AUTO_INCREMENT NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM;

INSERT INTO ids SET id = 1;           #      1      1
INSERT INTO ids SELECT NULL FROM ids; #      2      2
INSERT INTO ids SELECT NULL FROM ids; #      4      4
INSERT INTO ids SELECT NULL FROM ids; #      8      8
INSERT INTO ids SELECT NULL FROM ids; #     10     16
INSERT INTO ids SELECT NULL FROM ids; #     20     32


set @enddate = "2015-12-01";
set @days = 15;

SELECT date(qb.date) as date, COALESCE(sum(net_amount), 0) as total from invoice qa
right join
(SELECT
(SELECT @enddate FROM invoice qc LIMIT 1) + INTERVAL 1 DAY - INTERVAL a.id DAY AS date
FROM test.ids a
    ) as qb
on date(qa.date) = qb.date
where qb.date > DATE_SUB(@enddate, INTERVAL @days day)
group by qb.date
order by qb.date asc;

Wednesday, October 7, 2015

Concrete, Abstract, Virtual and Sealed

Concrete class;
  1. Standard class that we write our methods
  2. Cannot contain abstract methods
  3. Can be used as base class or child class
  4. Can create object and call methods
Abstract class;
  1. It is declared with the keyword abstract
  2. Must be used only as a base class. i.e, cannot create object like concrete class
  3. Cannot create instance of class.
  4. Can contain abstract methods as well as concrete (standard) methods
Abstract method;
  1. An abstract member cannot provide any implementation. It is only a method definition.
  2. You must implement (override) using the keyword override in your child class with your own functionality when you derive the class that contains this method.
  3. An abstract member is implicitly virtual.
  4. Can only reside inside an abstract class
Virtual method; 
  1. A method which does something.
  2. You may either override with your own functionality or not. It is not a must to override.
  3. It is recommended to use the keyword override when doing so. Because, it will work without the override keyword also.
Sealed class;
  1. Is used to restrict a class from being inherited.
Sealed method;
  1. You can only make a method sealed for an overridden method.
  2. You seal a method to prevent making any changes to it in the derived classes.

Wednesday, August 26, 2015

Remove "NVRAM WARNING: ERR 0x10" from WIFI List

Many MTK device's users are facing the WiFi NVRAM WARNING err 0x10 Problem by formatting the whole flash by SP Flash Tool.

Following is an easy method I have found from Internet.

Required
1. A Rooted MTK device 
2. Root Explorer or Root Browser (download from Play Store)
3. Wifi Error Fix.rar (find the download link at the bottom)

Steps
1. Make sure you switch off the WIFI

2. On your rooted device go to the following location using a root explorer mentioned above
data/nvram/APCFG/APRDEB

3. Delete the following files from the above location
WIFI
WIFI_CUSTOM

4. Now extract the files from the WiFi fix.rar and copy / move them to the above location (data/nvram/APCFG/APRDEB)

5. Reboot the device and switch on the WIFI. That's it, it's gone.

I tested this on Lenovo a3000

Update: Broken link for download updated. Many people have requested permission. Sorry for the inconvenience.

Download

Tuesday, August 25, 2015

Restore lost IMEI on Android Phone

1. Use imei.exe via cmd. Download link found at the end of this post.
Code:
imei imei_sim1 imei_sim2
a) make sure you replace the imei_sim1 and imei_sim2 to your imei
b) skip imei_sim2 if your phone is not dual sim

A file with the name "MP0B_001_NEW" created in the working folder

2. Rename it to "MP0B_001" and copy it to /data/nvram/md/NVRAM/NVD_IMEI folder of your Android phone
3. Then chown and chmod as shown below.
a) via adb
Code:
adb.exe shell "su -c 'chmod 660 /data/nvram/md/NVRAM/NVD_IMEI/MP0B_001'"
adb.exe shell "su -c 'chown nvram.nvram /data/nvram/md/NVRAM/NVD_IMEI/MP0B_001'"
OR
b) via terminal
Code:
su
chmod 660 /data/nvram/md/NVRAM/NVD_IMEI/MP0B_001
chown nvram.nvram /data/nvram/md/NVRAM/NVD_IMEI/MP0B_001
4. Restart the phone and check your IMEI via *#06#.
Enjoy!!!

Download

Wednesday, August 12, 2015

HTTP Error 500.19 - Internal Server Error

Have you ever get an error as follows;

HTTP Error 500.19 - Internal Server Error 
The requested page cannot be accessed because the related configuration data for the page is invalid. 
Error Code: 0x8007000d
Config Source:
-1:
0:


Solution:
Install URL Rewrite 2.0 via Web Platform installer