Advertuse

Search This Blog

Your Ad Here

Friday, 3 June 2011

CTE - SQL Server Vs ORACLE



Common table expression(CTE) can be used both in SQL Server and Oracle. However there is a significant difference between them if you use cte to insert data to a table. In SQL server, you need to create a cte first and then insert data to a table. But in ORACLE cte definition should be preceded by insert statement. 

SQL Server
create table test(i int) GO ;with cte (i) as
(  select 1 union all  select 2 ) 
insert into test(i) select i from cte select i from test  
 
ORACLE
create table test(i number) 
 insert into test with cte  as (  select 1 from dual union all  
 select 2 from dual )
select * from cte select * from testing1 

compile by Divyang Panchasara Sr. Programmer Analyst Hitech OutSourcing

Legacy Url Routing when application move from webform to MVC

// The legacy route class that exposes a RedirectActionNamepublic class LegacyRoute : Route{
    public LegacyRoute(string url, string redirectRuleName):base(url, new LegacyRouteHandler())
    {
        RedirectRuleName = redirectRuleName;
    }

    public string RedirectRuleName { get; set; }

    public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
    {
        return null;
    }
}

 
/ The legacy route handler, used for getting the HttpHandler for the requestpublic class LegacyRouteHandler : IRouteHandler{
    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        return new LegacyHandler();
    }
}

// The legacy HttpHandler that handles the requestpublic class LegacyHandler : IHttpHandler{
    public void ProcessRequest(HttpContext context)
    {
        var requestContext = context.Request.RequestContext;
        string redirectActionName = ((LegacyRoute)requestContext.RouteData.Route).RedirectRuleName;

        var queryString = requestContext.HttpContext.Request.QueryString;
        foreach (var key in queryString.AllKeys)
        {
            requestContext.RouteData.Values.Add(key, queryString[key]);
        }

        VirtualPathData data = RouteTable.Routes.GetVirtualPath(requestContext, redirectActionName, requestContext.RouteData.Values);

        context.Response.Status = "301 Moved Permanently";
        context.Response.AppendHeader("Location", data.VirtualPath);
    }

    public bool IsReusable
    {
        get { return false; }
    }
} 
 
 
 And use rout mapping in global.as
 
routes.MapRoute(
    "Newroutname", // Route name
    "querystringParameter", // URL with parameters
    new { controller = "mycontroller", action = "actionname", id = UrlParameter.Optional } // Parameter defaults);
// redirect /oldurl to the Newroutname route.routes.Add("", new LegacyRoute("oldurl", "Newroutname")); 

 more details  are at   stefanolson Blog




compile by Divyang Panchasara Sr. Programmer Analyst Hitech OutSourcing

Thursday, 2 June 2011

Migrating From MySQL to SQL Server running PHP on IIS


In the following code, we connect to the MySQL server with mysql_connect() and then select the database with mysql_select_db() that we will work against.
MySQL PHP
MySQL Actor Table Viewer
$db_host = 'localhost';
$db_user = 'root';
$db_pwd = 'pass@word1';
$database = 'sakila';
$table = 'actor';
 
if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");
 
if (!mysql_select_db($database))
    die("Can't select database");
SQL Server PHP
With SQL Server PHP, the database context is established in one call to sqlsrv_connect() that returns a connection handle for running a queries.
SQL Server Actor Table Viewer
$db_host = '.\SQLEXPRESS';
$db_user = 'sa';   //recommend using a lower privileged user
$db_pwd = 'pass@word1';
$database = 'sakila';
$table = 'actor';
 
$connectionInfo = array("UID" => $db_user, "PWD" => $db_pwd, "Database"=>$database); 
$conn = sqlsrv_connect( $db_host, $connectionInfo);
if( !$conn )
{
     echo "Connection could not be established.\n";
     die( print_r( sqlsrv_errors(), true));
}
You can refer to Connection Options for the list of supported keys for the connection array used for the variable $connectionInfo.



In the next block of code, you’ll see the differences in running a query against MySQL and SQL Server.
MySQL PHP
This example uses the mysql_query() function to execute the query and return the result as a statement handle for further processing.
// sending query
$result = mysql_query("SELECT * FROM {$table} LIMIT 0, 15");
if (!$result) {
    die("Query to show fields from table failed");
}
In this example, the query uses the LIMIT clause to display the first 15 records.
SQL Server PHP
The sqlsrv_query() function is used to run a query using the connection context provided by the $conn connection handle. In this example, the SQL statement was changed to use the TOP clause and to show the fields for the SELECT statement rather than use * for all columns.
// sending query
$tsql = "SELECT TOP 15 actor_id, first_name,last_name,CONVERT(varchar(50),last_update,121) AS lupdate FROM {$table}";
$result = sqlsrv_query( $conn, $tsql);
if (!$result) {
 die("Query to show fields from table failed");
}
I



The following block of code is used for both MySQL and SQL Server PHP to setup the HTML table.
echo "";
echo "
";
echo "
';
echo "Table :   ";
echo  $table;
echo "
"
;
echo "";
echo "
";
 
// printing table headers with desired column names
echo "
";
echo "
";
echo "
";
echo "
";
echo "
";
 
 

Using PHP to Fetch Data from MySQL and SQL Server

In this next section of code, I’ll show one of the many ways to fetch data from MySQL and the corresponding way in with SQL Server using PHP.MySQL PHPThe following code block shows how to loop through the results for the query using the mysql_fetch_assoc() function to return an array of strings keyed with the column name.// printing table rowswhile($row = mysql_fetch_assoc($result)){    echo "";    echo "";    echo "";    echo "";    echo "";    echo " \n";}echo "
';
echo "actor_id";
echo "
';
echo "first_name";
echo "
';
echo "last_name";
echo "
';
echo "last_update";
echo "
';    echo $row['actor_id'];     echo "';    echo $row['first_name'];     echo "';    echo $row['last_name'];     echo "';    echo $row['last_update'];      echo "
"
; SQL Server PHP With SQL Server PHP, you’ll use the sqlsrv_fetch_array() function to perform the same action as mysql_fetch_assoc() as shown in the next code block. // printing table rowswhile($row = sqlsrv_fetch_array($result)){    echo "";    echo "';    echo $row['actor_id'];     echo "";    echo "';    echo $row['first_name'];     echo "";    echo "';    echo $row['last_name'];     echo "";    echo "';    echo $row['lupdate'];      echo "";    echo "\n";}echo "";In this example, the last_update datetime column was converted to a varchar in the query string aliased AS lupdate executed earlier.
 
After running a query in your PHP application, it’s a good practice to close your resources. MySQL PHP In this final code block, mysql_free_result() is used to free resources for the PHP application.
// Close statement and connection
mysql_free_result($result);
?>
SQL Server PHP With SQL Server PHP, there are two functions used to free resources: sqlsrv_free_stmt() works similar to mysql_free_result(); sqlsrv_close() closes the connection to the server.
// Close statement and connection
sqlsrv_free_stmt( $result);
sqlsrv_close( $conn);
?>
compile by Divyang Panchasara Sr. Programmer Analyst Hitech OutSourcing

SQL Azure Data Sync


SQL Azure Data Sync provides a cloud based synchronization service built on top of the Microsoft Sync Framework.  It provides bi-directional data synchronization and capabilities to easily share data across SQL Azure instances and multiple data centers. 
Typical usage scenarios for Data Sync
  • On-Premises to Cloud
  • Cloud to Cloud
  • Cloud to Enterprise
  • Bi-directional or  sync-to-hub or sync-from-hub synchronization

Conclusion

The SQL Azure Data Sync is a rapidly maturing synchronization framework meant to provide synchronization in cloud and hybrid cloud solutions utilizing SQL Azure.  In a typical usage scenario, one SQL Azure instance is the "hub" database, which provides bi-directional messaging to member databases in the synchronization scheme. 

Enterprise Architecture is the art of understanding the white space between stakeholders


The more time I spend as an Enterprise Architect, the more I realize just how important this role is.  Yet, the stories that we tell fail to bring across that value.  Our metaphors (framework, capability, roadmap) are woefully inadequate to communicate the actual problems that are solved when an Enterprise Architect is “in the house.”
The metaphor I’m starting to lean toward is this: Enterprise Architecture is the art of understanding the white space between stakeholders.
Of course, this is not a new metaphor.  BPM folks have been using the concept of “white space” for a while.   BPM professionals usually use the term “white space” to refer to the gap between process steps.  That gap is important to the Enterprise Architect as well, but the EA does not stop with the gap between business processes.  An EA is also interested in the gap between business entities (information), the gap between business functions (business), and the gap between integrated systems (integration).
What do I mean by “the white space between stakeholders?”  It is a combination of many things:
  • White space is the gap in alignment between what one person expects will happen and what another person decides to do. 
  • White space is the gap between the way that information is understood and the way that it is actually collected. 
  • White space is the gap between the business function that is responsible for achieving results and the business function that performs both necessary and unnecessary activities in support of those results. 
  • White space is the gap between the performance characteristics of a system that exists and the changing needs of the people who use it.

Enterprise architecture is not the art of bridging any one of these gaps.  Solving for only one variable is a sure route to suboptimization.  Enterprise Architecture seeks to rebalance the tradeoffs between the various variables, creating a new mix of performance characteristics that is better suited for the evolving needs of the business.  The “old” tradeoffs are not wrong.  The business has simply evolved to need a better mix than exists today.
This is not to say that EA is somehow “better” than the related arts of BPM or System Integration or Information architecture.  EA identifies what variables need to change, and the direction to change them.  The related arts are necessary to get us there.  Enterprise Architects are not the people to actually improve the processes or reconfigure the information or reintegrate the systems.  They are the ones who force us to look at our goals and using analysis methods, pick the variables to change: this goal can be reached through a combination of better processes and improved systems, while that goal can be reached through restructuring the information that we will collect and changing the boundaries of various business functions. 
Enterprise Architecture lives in the white space, pulling and pushing and reconfiguring.  We are the “rack-and-pinion” system in your car.  We don’t decide what direction the car should go, but if you want to change course, it is a lot easier to use an accurate and responsive steering mechanism than to hoist a sail and move the boom.  
this was compile by NickMalik

Features of CMS

To design one CMS one  need to put following  features in system

  1. Add/Edit/Remove pages (aka. nodes) - the structure of the site
  2. Add/Edit/Remove menus, links - the navigation of the site
  3. Add edit media (photos, video, etc.) - the content of the site
  4. Various kinds of interactivity features -- comment/contact forms, etc
  5. User  management (role and rights)

compile by Divyang Panchasara Sr. Programmer Analyst Hitech OutSourcing

Wednesday, 1 June 2011

Quirks mode v/s strict mode

as web technology advancing and also need to maintain revers compatibility of older web standard with new advance web standard , all web browser are supporting two modes.
1) Quirk mode
2) Strict mode

Quirks Mode

Strict Mode

It is older browser rule to render web page in modern browser

It is new advance rule to render web pages in modern browser

if !DOCTYPE is not specified in web page then modern browser will render page as it is render by older browser.

To render your web page with strict mode in modern browser one needs to specify !DOCTYPE in webpage

This mode enable older html document work in todays browser also

This mode will not render older html document properly

In this mode IE6 browser may not follow CSS box model to calculate height and width

In this mode IE6 browser will follow CSS box model to calculate height and width

When modern browser fail to identify proper !DOCTYPE "Switch" then it will start rendering in this mode
following are some case of quirk mode

· When no !DOCTYPE describe on top of page

· When !DOCTYPE not valid or any spelling mistake will turn on quirk mode

· If you put any comment before !DOCTYPE will also turn on quirk mode in IE browser

"http://www.w3.org/TR/html4/strict.dtd">

Write 
"http://www.w3.org/TR/html4/strict.dtd">

On top of the document. Hence document will be render with strict mode in modern browser


One prominent difference between quirks and standards modes is the handling of the CSS Internet Explorer box model bug. Before version 6, Internet Explorer used an algorithm for determining the width of an element's box which conflicted with the algorithm detailed in the CSS specification, and due to Internet Explorer's popularity many pages were created which relied upon this incorrect algorithm. As of version 6, Internet Explorer uses the CSS specification's algorithm when rendering in standards mode and uses the previous, non-standard algorithm when rendering in quirks mode.

Another notable difference is the vertical alignment of certain types of inline content; many older browsers aligned images to the bottom border of their containing box, although the CSS specification requires that they be aligned to the baseline of the text within the box. In standards mode, Gecko-based browsers will align to the baseline, and in quirks mode they will align to the bottom.[3]

Additionally, many older browsers did not implement inheritance of font styles within tables; as a result, font styles had to be specified once for the document as a whole, and again for the table, even though the CSS specification requires that font styling be inherited into the table. If the font sizes are specified using relative units, a standards-compliant browser would inherit the base font size, then apply the relative font size within the table: for example, a page which declared a base font size of 80% and a table font size of 80% (to ensure a size of 80% in browsers which do not properly inherit font sizes) would, in a standards-compliant browser, display tables with a font size of 64% (80% of 80%). As a result, browsers typically do not inherit font sizes into tables in quirks mode

ક્યાં છે નવા લેખકો

ક્યાં છે નવા લેખકો? પ્રશ્ન ઊભો છે. પ્રશ્નનો જવાબ નથી. લેખકોસર્જકો નિસ્તેજ મોંયે ને ખાલી હાથે ખડા છે. લેખકો પોતાની કંગાલ કૃત્તિઓનાં અવલોકનો ન લેવાય તેની રાવ કરવામાં સમય ગુમાવે છે. અવલોકન નથી લેવાતાં એટલે પોતાની સામે કોઇ વ્યવસ્થિત કાવતરંુ થઇ રઉંાું હોય તેવી તેઓ બૂમો પાડે છે. પોતાની કૃતિને નબળી કહેનારો અવલોકનકાર કાં તો ‘વાડાનું ઢોર છે, કાં લેખકોનો તેજદ્વેષી છે, કંઇ નહીં તો તુંડમિજાજી ને ઘાતકી છે! આટલું, બસ, લેખકોનું આશ્વાસન. તેમને નથી ભાસતો એક ફક્ત પોતાનો દોષ. તેમને પોતાની કલમ પરિપક્વ થઇ ગઇ જણાય છે. તેમની ખૂબીઓ કોઇના ખ્યાલમાં વસતી નથી. આવો ખિજવાટ તેમની અભ્યાસવૃત્તિને આવરી બેસે છે. છૂપી અદાવતના અસુરો એમના મગજમાં ઊભા થાય છે. પોતાની કોઇ પણ રચનાને એ પાંચદસ સામાન્ય વાચકો પાસે વંચાવી અભિપ્રાય મેળવવાની રાહ જોતો નથી. એક કૃતિનું બે કે ત્રણ વાર પૂનર્લેખન કરવાનું એ જરૂરી ગણતો નથી. જગતસાહિત્યના ઉત્કૃષ્ટ ગ્રંથોને, કે એ ગ્રંથના થોડા થોડા ખંડોને, કેવળ હથોટી બેસાડવા માટે, ફક્ત ‘એક્સરસાઇઝ’ લેખે. એ ગુજરાતીમાં ઉતારી પછી ફાડી નાખવા તૈયાર નથી. પોતાનું લખેલું તદ્દન રદ્દી ને માલ વિનાનું છે, એવું એને મોંયે ચડીને કહેવામાં આવે છે. છતાં એ કોઇ પણ હિસાબે એક વાર, બસ, પુસ્તકરૂપ ધરે એવી કંગાલ ખ્વાએશને સંતોષવા માટે એ પ્રકાશકોને વિનવે છે. ખુશામદ કરે છે. લાચારી કરે છે. ને એમ કરી એક વાર કાગળ પર બીબાં પડાવીને પછી એ પોતાને લેખકોના મંડળમાંની એક મહત્ત્વની માન્ય થઇ ચૂકેલી વ્યક્તિ લેખે ખપાવે છે.

- ઝવેરચંદ મેઘાણી

site