Handling database

try
{
CString sConnection;

sConnection.Format(”DRIVER={PostgreSQL ANSI};SERVER=%s;port=%s;DATABASE=%s;UID=%s;PWD=%s;”, gstGlobalValues.pgsqlIP, gstGlobalValues.pgsqlPort, gstGlobalValues.pgsqlUserName, gstGlobalValues.pgsqlUserName, gstGlobalValues.pgsqlPassword );
m_db.OpenEx(sConnection);
}
catch(CDBException *e)
{
MessageBox(”Unable to connect with PostgreSQL.\n\nThe error message from PostgreSQL is \n\n”+e->m_strError,”Error message from PostgreSQL”, MB_ICONINFORMATION);
e->Delete();
EndDialog(IDCANCEL);
return TRUE;
}

{
CRecordset rs(&m_db);
CString sQuery;

sQuery.Format(”select min(tran_date), max(tran_date) from %s;”, frTRANSACTION_TBL);

try
{
rs.Open(AFX_DB_USE_DEFAULT_TYPE, sQuery);

if(rs.GetRecordCount() <= 0)
{
MessageBox(”\nNo test transaction found in database.\t\n”, “Testing not yet done”, MB_ICONEXCLAMATION);
EndDialog(IDCANCEL);
return TRUE;
}

i = 0;
rs.GetFieldValue(i, sQuery);
m_stSysTime1.wYear = atoi(sQuery.Mid(0,4));
m_stSysTime1.wMonth = atoi(sQuery.Mid(5,2));
m_stSysTime1.wDay = atoi(sQuery.Mid(8,2));

i++;
rs.GetFieldValue(i, sQuery);
m_stSysTime2.wYear = atoi(sQuery.Mid(0,4));
m_stSysTime2.wMonth = atoi(sQuery.Mid(5,2));
m_stSysTime2.wDay = atoi(sQuery.Mid(8,2));

rs.Close();
}
catch(CDBException *e)
{
MessageBox(”Unable to fetch test transaction records from PostgreSQL.\n\nThe error message from PostgreSQL is \n\n”+e->m_strError,”Error message from PostgreSQL”, MB_ICONINFORMATION);
e->Delete();
EndDialog(IDCANCEL);
return TRUE;
}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: