Tuesday, August 7, 2012

How to do ODBC Connection with C++ code

ODBC DSN Step with C++
 
 ODBC (Open Database Connectivity)

• A standard interface for connecting from C++ to relational databases
• It allows individual providers to implement and extend the standard with their own ODBC drivers

Here are procedures or rather steps used in the industry in C++ coding for connecting to a database

Steps of the ODBC

• Include Header Files
• Open a Connection to a Database
• Choose an ODBC Driver
• Query the Database
• Creating an ODBC Statement Object
• Executing a Query and Returning an ODBCResultSet Object
• Extracting Data from an ODBCResultSet
• Closing the ODBCResultSet and ODBCStatement
• Importance of closing the connection

Ok, this are actual steps how I connect to a database…definitely I used Oracle database, but I don’t want to further say what version it is.

1. Include the Header Files
# include statements at the beginning of your programs:
#include <sql.h>
#include<sqltypes.h>
#include<sqlext.h>

2. Open a Connection to a Database 

Set the environment handle:
SQLAllocHandle(SQL_HANDLE_ENV,
SQL_NULL_HANDLE, &hdlEnv);

Set ODBC Driver version:
SQLSetEnvAttr(hdlEnv,SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC30);

Set the connection handle:
SQLAllocHandle(SQL_HANDLE_DBC,
hdlEnv, &hdlConn);

Connect to the database:
SQLConnect(hdlConn, (SQLCHAR*)dsnName,SQL_NTS,(SQL CHAR*) userID,SQL_NTS, (SQLCHAR*)passwd, SQL_NTS);

3. Choose Driver
•DSN – Data Source Name
•Open the GUI ODBC Administrator (ODBCConfig)
•Choose the appropriate ODBC driver
•Provide a meaningful name to the DSN
•Specify the server and the host string (host string is required if the server is running on a different machine)

4. Query the Database
Querying the database involves the following steps:

–Creating a Statement
SQLAllocHandle(SQL_HANDLE_STMT
, hdlDbc, &hdlStmt);
It allocates the memory for the statement handle. The database handle obtained during connection phase is passed as the second argument.

– Executing a Query
SQLExecDirect(hdlStmt, stmt, SQL_NTS);
It executes the query, which is passed in as SQLCHAR* in the second argument.

5. Extract the Data out of the Executed Query

SQLGetData(hStmt,colNum,type,retVal,buffLength,&cbData);
It extracts data from table as void* data and places it in retVal

colNum refers to the column number provided in the SELECT statement in SQLExecDirect()

Type is one of the standard ODBC data types
example: DT_STRING à for a string data type
DT_DOUBLE à for a double data type

buffLength is the estimated size of the expected data

cbData is the actual size of the data

6. Traverse Through the Results
SQLFetch(hStmt);
Fetches the next record

hStmt is the statement handle obtained using SQLAllocHandle
If a record is available, It returns SQL_SUCCEEDED

7. Close the Statement and the Connection
SQLFreeHandle(SQL_HANDLE_STMT,hdlStmt);
It closes and de-allocates the memory reserved for the statement handle

SQLFreeHandle(SQL_HANDLE_DBC, hdlConn);
It disconnects and de-allocates the memory reserved for the connection handle

SQLFreeHandle(SQL_HANDLE_ENV, hdlEnv);
It de-allocates the memory occupied by the environment handle

Wednesday, April 4, 2012

Why Dynamic Programming Languages Are Slow..??


In a statically typed language, the compiler knows the data-type of a variable and how to represent that.

In a dynamically-typed language, it has to keep flag describing the actual type of the value of the variable, and the program has to perform a data-dependent branch on that value each time it manipulates a variable.  It also has to look up all methods and operators on it.

The knock-on effect of this on branching and data locality is lethal to general purpose run time performance.

That’s why the dynamic language JIT benchmarks emphasise near-C speed on small inner loops but steer clear of large data-structures and data manipulation problems.

These slides by IBM researchers describe (page 3) the performance problems of dynamism:


  • Every variable can be dynamically-typed: Need type checks
  • Every statement can potentially throw exceptions due to type mismatch and so on: Need exception checks
  • Every field and symbol can be added, deleted, and changed at runtime: Need access checks 
  • The type of every object and its class hierarchy can be changed at runtime: Need class hierarchy checks
  • Properties mean assignments may in fact be setters: Need checks for existing values before assignment
  • Properties mean references may in fact be getters: Need checks on values when referencing


    To these I would add a couple of killers:

  • Properties mean assignments may in fact be setters: Need checks for existing values before assignment
  • Properties mean references may in fact be getters: Need checks on values when referencing

With modern dynamic language compilers there are buckets of neat tricks they can do to specialize the hot paths you use.  I’m glad that’s gathering speed as we rediscover or reapply old tricks and learn new ones and they all compose together.

But fundamentally, when its done that, these traces have to inter-operate with as yet not known code-paths.  So all escaped data has to keep its type within reach.  Its at this level where you are nearly at the speed of a classic statically compiled language that I am looking at the difference and pronouncing dynamic languages fundamentally slow:

I really want dynamically-typed languages like Python to be fast.  I’ve tried using Python for classic server programming - the domain of ‘systems languages’ - and really been bitten by lack-luster performance.  I’m contemplating a rewrite of one server in Java right now, sadly. 

Therefore, I spend time thinking about how to actually statically compile Python.  After all, that’d be my dream programming language!  But whenever I think through how to mix dynamic and dynamically-typed code with a statically compiled Python, I run into data representation slow-down problems:

In a dynamic language, typically all elements in an array (or other data structure) can be different types.  Therefore, these could have different representation values.  Therefore, these values must all be stored individually on the heap rather than in-line inside the array.  This means you are performing a data-dependent branch to non-adjacent memory, which puts pressure on cache-lines.

There are some clever tricks using special bits in a variable to pack some primitives like integers into a type that is otherwise a pointer, but that costs registers to track during manipulation so adds overhead.

There are some clever approaches like JITing of hot paths, but if you start putting your values in-line and not-type-taggged rather than as tagged types individually on the heap inter operability with non-JITed code becomes hard and you get a whole can of worms if some other code goes and changes the type of one value in the middle of the array…

I've been thinking a lot about what is and isn’t static in Python.  With SSTA and escape analysis you can determine that a surprising amount of a normal program is static.  Paul Biggar gives me confidence that my guess that 90% of my Python is static is about right.

What about that 10%?  Usually I can get all that static too, or imagine it being specialized for a restricted range of parameter types.  All except the standard pattern in Python web-servers to dispatch to web handlers based on HTTP method (calling the ‘get’ method if you receive a GET request).  That’d need the programmer to rephrase in terms of a switch statement (as in a long chain of elifs).

Robert Harper gave a great explanation of how a dynamic language is implemented in terms of a static language with a single type.  There is one quote I wish he’d expand upon:

Now I am fully aware that “the compiler can optimize this away”, at least in some cases

I believe the “some cases” he allows to are where you have non-escaping things.  You have to be able to determine the type of something that escapes when interacting with later-executing code.

Some dynamic calls are nonpolluting - a compiler can see from inspection that whilst some variable (or method) is dynamic, the dynamic code would not virally infer dynamic status on other variables.  Because the varying type of a variable or the presence/absence of a method/member is restricted to identifiable types (or null), specialism is possible.

But all too often the compiler can’t see that from code inspection.  And as soon as you lose track of where the execution may go, you stop knowing how that code might depend upon or change the value of other static variables.  So all bets are off, all variables have to be truly dynamic again.

I have struggled to find a way to deal with the monkey patching, set, setattr and such efficiently in mythical Python compiler.  Tagging types kills performance.

Fast data structures are very much about memory access patterns and cache locality and minimizing branches and tagging works against each of these.

Thank you for reading.

Thursday, February 16, 2012

Cloud Computing Concerns

Perhaps the biggest concerns about cloud computing are security and privacy. The idea of handing over important data to another company worries some people. Corporate executives might hesitate to take advantage of a cloud computing system because they can't keep their company's information underlock and key.
The counterargument to this position is that the companies offering cloud computing services live and die by their reputations. It benefits these companies to have reliable security measures in place. Otherwise, the service would lose all its clients. It's in their interest to employ the most advanced techniques to protect their clients' data.
Privacy is another matter. If a client can log in from any location to access data and applications, it's possible the client's privacy could be compromised. Cloud computing companies will need to find ways to protect client privacy. One way is to use authentication techniques such as user names and passwords. Another is to employ an authorization format -- each user can access only the data and applications relevant to his or her job.
Some questions regarding cloud computing are more philosophical. Does the user or company subscribing to the cloud computing service own the data? Does the cloud computing system, which provides the actual storage space, own it? Is it possible for a cloud computing company to deny a client access to that client's data? Several companies, law firms and universities are debating these and other questions about the nature of cloud computing.
How will cloud computing affect other industries? There's a growing concern in the IT industry about how cloud computing could impact the business of computer maintenance and repair. If companies switch to using streamlined computer systems, they'll have fewer IT needs. Some industry experts believe that the need for IT jobs will migrate to the back end of the cloud computing system.
Another area of research in the computer science community is autonomic computing. An autonomic computing system is self-managing, which means the system monitors itself and takes measures to prevent or repair problems. Currently, autonomic computing is mostly theoretical. But, if autonomic computing becomes a reality, it could eliminate the need for many IT maintenance jobs

Application of Cloud Computing

The applications of cloud computing are practically limitless. With the right middleware, a cloud computing system could execute all the programs a normal computer could run. Potentially, everything from generic word processing software to customized computer programs designed for a specific company could work on a cloud computing system.
Why would anyone want to rely on another computer system to run programs and store data? Here are just a few reasons:
  • Clients would be able to access their applications and data from anywhere at any time. They could access the cloud computing system using any computer linked to the Internet. Data wouldn't be confined to a hard drive on one user's computer or even a corporation's internal network.
  • It could bring hardware costs down. Cloud computing systems would reduce the need for advanced hardware on the client side. You wouldn't need to buy the fastest computer with the most memory, because the cloud system would take care of those needs for you. Instead, you could buy an inexpensive computer terminal. The terminal could include a monitor, input devices like a keyboard and mouse and just enough processing power to run the middleware necessary to connect to the cloud system. You wouldn't need a large hard drive because you'd store all your information on a remote computer.
  • Corporations that rely on computers have to make sure they have the right software in place to achieve goals. Cloud computing systems give these organizations company-wide access to computer applications. The companies don't have to buy a set of software or software licenses for every employee. Instead, the company could pay a metered fee to a cloud computing company.
  • Servers and digital storage devices take up space. Some companies rent physical space to store servers and databases because they don't have it available on site. Cloud computing gives these companies the option of storing data on someone else's hardware, removing the need for physical space on the front end.
  • Corporations might save money on IT support. Streamlined hardware would, in theory, have fewer problems than a network of heterogeneous machines and operating systems.
  • If the cloud computing system's back end is a grid computing system, then the client could take advantage of the entire network's processing power. Often, scientists and researchers work with calculations so complex that it would take years for individual computers to complete them. On a grid computing system, the client could send the calculation to the cloud for processing. The cloud system would tap into the processing power of all available computers on the back end, significantly speeding up the calculation.



Architecture of Cloud Computing

When talking about a cloud computing system, it's helpful to divide it into two sections: the front endand the back end. They connect to each other through a network, usually the Internet. The front end is the side the computer user, or client, sees. The back end is the "cloud" section of the system.

The front end includes the client's computer (or computer network) and the application required to access the cloud computing system. Not all cloud computing systems have the same user interface. Services like Web-based e-mail programs leverage existing Web browsers like Internet Explorer or Firefox. Other systems have unique applications that provide network access to clients.

On the back end of the system are the various computers, servers and data storage systems that create the "cloud" of computing services. In theory, a cloud computing system could include practically any computer program you can imagine, from data processing to video games. Usually, each application will have its own dedicated server.

A central server administers the system, monitoring traffic and client demands to ensure everything runs smoothly. It follows a set of rules called protocols and uses a special kind of software called middleware. Middleware allows networked computers to communicate with each other. Most of the time, servers don't run at full capacity. That means there's unused processing power going to waste. It's possible to fool a physical server into thinking it's actually multiple servers, each running with its own independent operating system. The technique is called server virtualization. By maximizing the output of individual servers, server virtualization reduces the need for more physical machines.

If a cloud computing company has a lot of clients, there's likely to be a high demand for a lot of storage space. Some companies require hundreds of digital storage devices. Cloud computing systems need at least twice the number of storage devices it requires to keep all its clients' information stored. That's because these devices, like all computers, occasionally break down. A cloud computing system must make a copy of all its clients' information and store it on other devices. The copies enable the central server to access backup machines to retrieve data that otherwise would be unreachable. Making copies of data as a backup is called redundancy.

Introduction to How Cloud Computing Works

Let's say you're an executive at a large corporation. Y may be an alternative for executives like you. Instead of installing a suite of software for each computer, you'd only have to load one application. That application would allow workers to log into a Web-based service which hosts all the programs the user would need for his or her job. Remote machines owned by another company would run everything from e-mail to word processing to complex data analysis programs. It's called cloud computing, and it could change the entire computer industry.
In a cloud computing system, there's a significant workload shift. Local computers no longer have to do all the heavy lifting when it comes to running applications. The network of computers that make up the cloud handles them instead. Hardware and software demands on the user's side decrease. The only thing the user's computer needs to be able to run is the cloud computing system's interface software, which can be as simple as a Web browser, and the cloud's network takes care of the rest.
There's a good chance you've already used some form of cloud computing. If you have an e-mail account with a Web-based e-mail service like Hotmail, Yahoo! Mail or Gmail, then you've had some experience with cloud computing. Instead of running an e-mail program on your computer, you log in to a Web e-mail account remotely. The software and storage for your account doesn't exist on your computer -- it's on the service's computer cloud.
What makes up a cloud computing system? Find out in the next sectionour particular responsibilities include making sure that all of your employees have the right hardware and software they need to do their jobs. Buying computers for everyone isn't enough -- you also have to purchase software or software licenses to give employees the tools they require. Whenever you have a new hire, you have to buy more software or make sure your current software license allows another user. It's so stressful that you find it difficult to go to sleep on your huge pile of money every night.

Thursday, February 9, 2012

How to Hide Application Icon in Windows 7 Taskbar

Microsoft Windows 7 comes with a taskbar that has never before been witnessed in its predecessors. The Windows 7 taskbar features a dock-type appearance and utility tools like launching a program or running an application. Undoubtedly, the Windows 7 taskbar helps the user to an extent more than what meets the eye.
Here, we unveil a new utilization feature of the Windows 7 taskbar. Often, some programs and shortcuts to various applications are pinned to the taskbar for easy accessibility. However, sometimes for reasons concerning privacy and confidentiality, the user may want to hide these icons so that other users logging into his computer do not have access to his private applications or programs. We’ll now plow on the process to achieve this useful tweak.

To start with, the icon that needs to be hidden should remain invisible at the taskbar with only the creator knowing its perfect location and the authority to view and access it. We, here, take Mozilla Firefox as an example to the program that requires to be hidden. On completing the following procedure, your taskbar will contain Mozilla Firefox as a launch up program while keeping it invisible to anyone who logs on to your computer.

Making a program icon invisible
To make a program icon invisible, you need to use software called “Resource Hacker”. Download this freeware to start the process. The downloaded file is a “.zip” file. No installation is required to use this software.
On extraction, locate the file “ResHacker.exe” in the extracted folder. Right click on this file and select to “Run as Administrator”. Confirm on request to open Resource Hacker.
1. After the software opens, go to “File” menu (or simply press Alt+F). Select “Open” and navigate to the location where the Mozilla Firefox execution file is present. (It should be in the folder “Mozilla Firefox” in the “Programs” folder of the directory where Mozilla is installed). Select the file “firefox.exe” file and click “Open”.
2. The Resource Hacker wizard opens up. Select “Icon” and then click on the “Action” tab on the menu-bar. Select “Replace Icon“.
3. The “Replace Icon in” window appears. Select “1″ in the right pane of the window under the tag “Select icon to replace” and then click to “Open file with new Icon…“.
4. Navigate to “C:\Windows\System32\” and click on “shell32.dll” to open it.
5. On clicking “Open” a list of icons appear under the tag “Select new icon“. Select the icon number 52. Then click to “Replace”.
You will be notified that the icon has been replaced.
To proceed, you have to replace a second set of icons. Select “Open” under “File” menu. On asking whether to save your work, select “NO“, as the task is not completed yet. Follow the steps 1 to 5 once again with the exception that in step 3, this time, Select “32512″ in the right pane of the window under the tag “Select icon to replace”. Follow the remaining steps as you have done previously.
Save the file you have just created by pressing Ctrl+S to the installed program folder of Mozilla Firefox (in the folder “Mozilla Firefox” in the “Programs” folder of the directory where Mozilla is installed).
Exit Resource Hacker.
The new file created “firefox.exe” can be visualized when you open the folder where Mozilla is installed. This file does not have an icon, or more technically, the icon of this file is invisible. The original Firefox execution file still remains within the folder with it being renamed to “firefox_original.exe”. Now, right click on the file “firefox.exe” and select “Pin to taskbar”.
To the right of the pinned programs on the taskbar, appears a section which, on hovering your mouse pointer over it, displays “firefox.exe – Shortcut”. You have just created a secret invisible icon in your Windows 7 taskbar. Drag this section to the extreme left of the taskbar to the right of the “Start” button.
Your taskbar remains just as it was before you created this invisible icon. None, but you know the exact location of this icon. Your privacy gets boosted up with an increased accessibility option.

Tuesday, February 7, 2012

Windows 8 To Feature A Lot More MinWin Technology


First off, what is MinWin? Basically it’s the very basis of Windows, you need to think of it as the core of Windows. MinWin contains pretty much everything that Windows needs to boot and run independently, such as the Windows NT Kernel, memory manager, networking and drivers etc…


So what’s the big deal about this MinWin technology? Well we first started seeing MinWin playing a prominent part in Windows 7, but now it appears that it’s going to be playing an even bigger role in Windows 8. Windows 8 appears to have in excess of 6,000 references to MinWin, which is 60 times more than the 100 references or so that can be found in Windows 7.


MinWin is Microsoft’s effort to create the smallest possible standalone, bootable, core of Windows. MinWin has no dependencies outside of itself or at least it didn’t in Windows 7 so I’d expect Windows 8 to be the same. Microsoft are probably going to continue relocating APIs inside the Windows 8 core, so as to have MinWin completely operated from the rest of the operating system.


Microsoft have probably also managed to lower the size of MinWin in Windows 8. While it isn’t a particularly large file in Windows 7 – 40 MB , it could be down to 30 MB or so in Windows 8.


So this all sounds very technical and complicated, but what does it mean for the end user of Windows 8?


To be honest not that much, but I’d expect it to help Windows 8 run on more hardware limited resources such as tablets and such. But probably the main role this will play is in client virtualization, particularly with Hyper-V.

Sunday, February 5, 2012

How To disable Coping/Writing To USB Drives in Windows XP


USB drives are extremely handy tools, but in some instances it might not be a good idea to allow users to write onto these devices from their PCs. This is especially true when working with highly confidential data or intellectual property at work. Users of Windows XP with service pack 2 installed can disable writing to USB devices.

To perform you have to pass from following steps :
  • Open the Registry Editor click by clicking on START button on task bar and then click on Run and type "regedit" and click on OK to start regedit utility.
  • Follow the following sequence HKEY_LOCAL_MACHINE\System\CurrentControlSet\ Control.
  • From there right click and create a new key and name it “StorageDevicePolicies”.
  • In the window on the right then create a new DWORD value and label it WriteProtect, give it a value of “1″ and users can no longer write to USB drives.
  • To re-enable this option change the value to 0 and users are again allowed to write.
  • The modifications you made will be in effect after you reboot your PC.

Enable Windows 7's Hidden "God Mode"

Windows 7 has many features but some of that will be hidden. Today I am going to introduced one of them in front of you.
It's Name is "GOD MODE". This functionality is contains most of the OS task such as Default Program, Autoplay, Desktop Gadget, Admin Tools etc. are included in one folder.
It provides users with a centralized Control Panel for all of Windows' settings, from changing your desktop background to setting up a VPN or partitioning your hard drive. In all, there are nearly 50 categories and most have several entries.

Just Create a New Folder and rename it by following...
God Mode.{ED7BA470-8E54-465E-825C-99712043E01C}
"God Mode" is the name of folder which is desirable.
Automatically Folder Logo will becomes like following image.