Exclusively for you!! Trial version of Google Apps, Apply Coupon-CNHPGX6T6QRWGV!!
Few lines about Static code analysis
Dec18

Few lines about Static code analysis

Welcome to CodeSpread! Static code analysis We divide the term into two parts: Static+code analysis. Static in programming can be referred to as non-running/non-dynamic and code analysis is a process where the code is analyzed for any vulnerability, also it had been always used for possible improvements. So, we can say that, it is a process of detecting errors and defects in software’s source code in a static state where the entire code base is analyzed and code flaws are exposed. Advantages: This process covers whole code base and find vulnerabilities in the code at the exact location. This process can locate anti-patterns. This process can identify performance issues and also suggest improvements. Limitations: Automated tools may not support all programming languages or compilers. Automated tools produce false positives and false negatives. Manual review or Personal review is always considered to be more beneficial and reliable than a tool. We have many Static code analysis tools available like StyleCop, FxCop etc. and using them can always take off the burden from reviewer’s shoulders...

Read More
SQL: Usage of char, varchar and varchar(MAX)
Nov24

SQL: Usage of char, varchar and varchar(MAX)

These are character data types in SQL. We will take an example and describe each type. Later we determine the cases where one of them can be applied. Create Table testable( Name char(20), Email varchar(250), Address varchar(Max)) CHAR We usually call it char or character. In the above example, Name is declared with char(20) as type. Here, 20 is the storage size and it does not depend on the actual length of name entered, whether is below 20 or above 20. It is always fixed length and can have value from from 1 through 8,000. The default length is 1 and can be mentioned as in below example. DECLARE @testvariable AS char VARCHAR We usually call it varchar or varying character. In the above example, Email is declared with varchar(250) as type. Here, 250 is the maximum storage size. The storage size is flexible and dependent on the actual length of data entered so finally storage size is computed as actual length + 2 bytes. It is always variable length and can have value from 1 through 8,000. Plus point is that the data entered can be 0 characters in length. VARCHAR(MAX) The only difference is the max storage limit which in this case is 2^31-1 bytes. Suggestions: When we are considerably sure about the length of the data in column, we should use char. The main concern is consistency about the column entries. Varchar is exact reverse condition of char. If there is a lack of consistency in column entries or length of the column data vary considerably, use varchar. Varchar(max) is a superlative form and used when the size might exceed 8,000 bytes. Conclusion: In the real world, we are more concerned about the storage space and above points, though miniscule, can really help...

Read More
SQL fry: PIVOT and UNPIVOT
Apr16

SQL fry: PIVOT and UNPIVOT

What is PIVOT? In our day-to-day SQL server coding, PIVOT and UNPIVOT are not very familiar words but still holds good if we understand them correctly and know when to use it.Web Definition of PIVOT says “The central point, pin, or shaft on which a mechanism turns or oscillates.” We just have to concentrate on two points of the above definition- a central point and a mechanism. These two points are required to define PIVOT in SQL server. In SQL server, we have a Table like Transactions which records Customer,UnitsBought and AmountPaid. This table with sample data looks like When we are going to pivot this table, we require a ‘central point’ which for example we take as SUM(UnitsBought) and ‘a mechnaism’ which is the static values of Amount paid [10,100,150,500]. Now we just have to turn this mechanism on a central point. Lets see the query to do that and how the result looks like SELECT * FROM transactions PIVOT (SUM(UnitsBought) For AmountPaid IN ([500],[100],[150],[10])) AS EachAmountPaid And the result of PIVOT operation will be When we say static values of Amount paid [10,100,150,500], then we mean that the amount paid should not vary for each and every row ,as for that condition we will have to write a dynamic pivot query. We stick with this simple example to grasp the concept. Also, we will keep the post short and cover UNPIVOT in subsequent...

Read More
SQL:Target a SubQuery
Feb05

SQL:Target a SubQuery

People ask me a lot about subquery so I thought let’s answer with a article touching a bit of everything about subquery. Before discussing SubQuery, there are few things which we should know like: What is a Query? I will go with its English Definition first. As a verb, “Put a question or questions to”. Technical definition w.r.t. SQL “These are the commands issued to a database for retrieval of required information.” If we see closely,both the definitions complement each other. For example: select all data the in employees table. select * from employees Lets put a condition like- select all employees with salary>5000 select * from employee where salary>5000 What is a SubQuery? SubQuery can be treated as a ‘query on query’. A subquery is the inner query which provides a targeted result to the outer main query . We can try few examples to learn it Example: select employee name with its manager name select emp.name,(select mgr.name from employee AS mgr where emp.mgrid=mgr.empid) from employee AS emp We mostly see subqueries in where clause like – select employees having average salary select * from employee where salary=(select AVG(salary) from employee) What is Correlated SubQuery? A correlated sub-query  is a sub-query that uses values from the outer query in its WHERE clause.Let’s try with an example select employees having salary greater than average salary of employees of department ‘IT’ select * from employee where salary=(select AVG(salary) from employee where department=’IT’) The main difference is that the subquery will be executed for each row before the result can be used by outer query. Why do we require SubQuery or advantages of SubQuery? SubQuery holds the results like a temporary table which can be used by outer query. SubQuery are easier to understand SubQuery breaks down a complex query into small and simple queries. SubQuery are easy to use as a replacement of joins.There is no major difference in performance. SubQuery Rules A subquery is subject to the following restrictions: Up to 32 levels of nesting is possible, although the limit varies based on available memory and the complexity of other expressions in the query If a table appears only in a subquery and not in the outer query, then columns from that table cannot be included in the output The select list of a subquery introduced with a comparison operator can include only one expression or column name (except that EXISTS and IN operate on SELECT * or a list, respectively). If the WHERE clause of an outer query includes a column name, it must be join-compatible with the column in the subquery select list. The ntext, text, and...

Read More
C# – Box(ing) and Un-box(ing)
Dec31

C# – Box(ing) and Un-box(ing)

I have heard this concept from many people and their different versions so I always wanted to share some insight on it which can work as a one stop solution. What is boxing and un-boxing? The Conversion of a value type into reference type is boxing and the reverse process is un-boxing. What is Value Type? Value Types in C# are the primitive data types such as Boolean, char,numeric, enum and structures. Note: The value types are stored in stack if they are declared inside a method and are stored in heap if they are declared outside method and inside a reference type. What is Reference Type? Reference types are class, delegates, objects ,string and interface. A reference type is always stored in heap. Converting Value types into reference types: Let’s take a simple example. int num = 5;              // num is value type object obj = num;  //obj is reference type Let us go through the underlying steps to understand what really happens during boxing. Statement 1: int num = 5; The numeric constant value 5 is pushed onto stack. The value is then popped into the local variable num. Statement 2: object obj = num ; (Box) As the value type will be represented as object, the memory is allocated on heap. The amount of memory allocated will be equal to the size of the value type plus the memory sufficient to hold object and its internal structures. The Value type (num’s) value (5) is then copied to the newly allocated heap memory. The address of the object is stored on the stack which points to newly allocated heap memory.   Converting reference types to value types: From the above example it is clear that we don’t need to do any explicit conversion when converting value type to a reference type. However, to un-box casting is necessary. This is because, the object is being converted to a type and the run-time can validate the cast. int num = 5; object obj = num; int anotherNumber = (int)obj; // Un-boxing Now, let us understand what happens during un-boxing. Statement 3: Un-boxing First, The runtime validates the object, pointed by the address on the stack. If the value cannot be converted to the type specified in the instruction then, InvalidCastException is thrown. If the object is valid, then CLR proceeds further. The value of the instance (in this case 5) into the value type (int) variable (anotherNumber). .NET features automatic type handling. Why do I need to be careful about boxing and un-boxing? It is true that nothing special needs to be done to take advantage of boxing....

Read More