Friday, February 29, 2008

Effective Interview for MBA Programs

Since I volunteer to interview MBA applicants for my alma mater, I have interviewed more than 30 persons so far. In these interviews, I have observed several key elements for an effective interview. If an applicant shows these key elements in the interview, it would be easy for me to write a favorable critique form for the applicant. The point is if an applicant can convince me, then it's easy for me to convince the admission committee. Belows are the key points I am looking for in an interview.
  1. Differentiate yourself - Why are you different from other MBA applicants?
  2. Be specific - When talk about yourself, please give examples to support your statements.
  3. Think of Win-Win - Why do you think the admission should give you, in stead of other applicants, the admission?

Wednesday, February 27, 2008

ORA-01460 in SOCI

I mentioned before about the SOCI project. Recently, I was planning to adopt the library(version 2.2.0) into my project. However, while using the library to connect to Oracle 9i, I encountered a weird exception. The trouble I had was if I use soci::use(std::string) for more than one time in a sql query, then I get ORA-01460 error. For example, I used the following code to reproduce the error.
std::string prodid1("2330"), prodid2("2885");
SOCI::Row r;
SOCI::Statement st = (sql.prepare <<
"select * from product where prodid in (:prodid1, :prodid2)",
SOCI::use(prodid1), SOCI::use(prodid2),
SOCI::into(r));
It seemed related to the binding process in the function soci::StandardUseType::bind. After tweaking the source code for a while, I found by modifying the fuction definition as follows, the error was gone.
void OracleStandardUseTypeBackEnd::prepareForBind(
void *&data, sb4 &size, ub2 &oracleType)
{
...
case eXStdString:
oracleType = SQLT_STR;
// 4000 is Oracle max VARCHAR2 size; 32768 is max LONG size
//size = 32769;
size =sizeof(static_cast<std::string *>(data)->c_str());
...
}

Monday, February 25, 2008

Networking in Virtual PC 2007

It seems pretty straightforward to use Virtual PC 2007. The only problem people might encounter while making a guest Window XP is to setup its network environment. By following the suggestions in this post, I select "Shared Networking(NAT)" and configure to use DHCP in the guest OS. Then everything works and the virtual gateway in the guest OS is always 192.168.131.254.

On the other hand, if I want to connect to the guest OS from the host, I need to select a network adapter for the guest OS and assign an IP address for the adapter in the guest OS. Also, be sure to turn off the firewall in the guest OS. Then the outside machine can access server applications in the guest OS.

Finally, the "Undo Disks" option in the setting is useful, too. If enabled, I can rollback the changes I make to the guest OS since it starts.

Update: Here is a post compiled a list of many useful information about Virtual PC.

Tuesday, February 19, 2008

WinUnit: A Unit Testing Tool for Native C++ Applications

In this MSDN article, the author introduced WinUnit, a unit testing tool for Native C++ applications on Windows platform.

To use this tool, users need to call a set of macros the author provided to write test programs, compile test programs into Dlls and run test programs against WinUnit, a DOS program. Because there is no reflection capability built in C++ language, the author took advantage of DLL exports to invoke test functions in WinUnit program.

Several references were mentioned in the article.

Sunday, February 10, 2008

SOCI (Cont'd)

This article explained how SOCI can be extended to support user-defined types. The author applied traits technique of generic programming in c++, and showed that by making use of template specialization via TypeConversion<T>, SOCI provided a noninvasive mechanism for extending SOCI.

Since std:tm is supported natively by SOCI, to work with boost::gregorian::date, a user only needs to provide the following template specialization and the compiler will make the right conversion for us.
#include <iostream>
#include <soci.h>
#include <boost/date_time/gregorian/gregorian.hpp>

using boost::gregorian::months_of_year;
using boost::gregorian::date;

namespace SOCI
{
template<> struct TypeConversion<date>
{
typedef std::tm base_type;
static date from(std::tm& t)
{
date d( t.tm_year + 1900,
static_cast<months_of_year>(t.tm_mon + 1),
t.tm_mday );
return d;
}

static std::tm to(date& d)
{
std::tm t;
t.tm_isdst = -1;
t.tm_year = d.year() - 1900;
t.tm_mon = d.month() - 1;
t.tm_mday = d.day();
t.tm_hour = 0;
t.tm_min = 0;
t.tm_sec = 0;
std::mktime(&t);
return t;
}
};
};
#endif

Friday, February 8, 2008

SOCI: Simple Oracle Call Interface

This article introduced a simple C++ database library, SOCI. According to the author, users only need to know two classes, Session and Statement, to complete most of interactions between client programs and database servers.

The following sample, excerpted from the article, demonstrated the simplicity of the library.
  • Session and Statement classes hide OCI calls from the users.
  • Free function use() binds variables to placeholders in the SQL statements.
  • Free function into() populates the variables with the values returned by select statements.
  • Shift operator in the Session enables storing a query and starts creating a temporary object that handles the rest of the expression.
  • Comma operator stores parameter information returned by use and into functions into the temporary object for later use.
  • The temporary object executes the sql statements in its destructor.
#include "soci.h"
#include <iostream>

using namespace std;
using namespace SOCI;

int main()
{
try
{
Session sql("DBNAME", "user", "password");
// example 1. - basic query with one variable used
int count;
sql << "select count(*) from some_table", into(count);
// example 2. - basic query with parameter
int id = 7;
string name;
sql << "select name from person where id = " << id, into(name);
// example 3. - the same, but with input variable
sql << "select name from person where id = :id", into(name), use(id);
// example 4. - statement with no output
id = 8;
name = "John";
sql << "insert into person(id, name) values(:id, :name)", use(id), use(name);
// example 5. - statement used multiple (three) times
Statement st1 = (sql.prepare <<
"insert into country(id, name) values(:id, :name)",
use(id), use(name));
id = 1; name = "France"; st1.execute(1);
id = 2; name = "Germany"; st1.execute(1);
id = 3; name = "Poland"; st1.execute(1);
// example 6. - statement used for fetching many rows
Statement st2 = (sql.prepare << "select name from country", into(name));
st2.execute();
while (st2.fetch())
{
cout << name << '\n';
}
}
catch (exception const &e)
{
cerr << "Error: " << e.what() << '\n';
}
}

Esper: Event Stream Processing and Correlation

I mentioned about Esper before(here). Esper allows users to submit continuous queries to its engine and sends out alerts whenever conditions match user-defined queries. In this article, the authors showed code snippets to demonstrate Esper's usage.
  1. Configure the engine using API or an XML file.
  2. Register continuous queries.
  3. Attach listeners to the queries.
For the engine to tap into event streams, according to the document, it is accomplished by sending events to the engine via the runtime interface.

Esper seems easy to use and, I think, it looks promising to gain popularity.