Click here to Skip to main content
15,904,877 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Added a new file to a Project. (Program won't compile afterwards.) Pin
Norman Bates19-Aug-03 1:03
Norman Bates19-Aug-03 1:03 
GeneralRe: Added a new file to a Project. (Program won't compile afterwards.) Pin
WREY19-Aug-03 8:35
WREY19-Aug-03 8:35 
GeneralRe: Added a new file to a Project. (Program won't compile afterwards.) Pin
David Crow19-Aug-03 9:04
David Crow19-Aug-03 9:04 
GeneralRe: Added a new file to a Project. (Program won't compile afterwards.) Pin
David Crow19-Aug-03 3:06
David Crow19-Aug-03 3:06 
GeneralRe: Added a new file to a Project. (Program won't compile afterwards.) Pin
WREY19-Aug-03 8:54
WREY19-Aug-03 8:54 
GeneralRe: Added a new file to a Project. (Program won't compile afterwards.) Pin
David Crow19-Aug-03 9:08
David Crow19-Aug-03 9:08 
GeneralRe: Added a new file to a Project. (Program won't compile afterwards.) Pin
WREY19-Aug-03 9:54
WREY19-Aug-03 9:54 
GeneralProblems Please help (and sorry for the size) Pin
Vassilis Papoulidis18-Aug-03 12:20
Vassilis Papoulidis18-Aug-03 12:20 
Hi everyone. I am implementing a project for my dissertation which will manipulate a database (Oracle 9). I have to use (Visual) C++ (industrial project, requirement) for which I am totally new (I have spent many hour for MSDN).I will also use CORBA or DCOM. I have post some of the problems mentioned here in separate threads but the problems persist and the deadline is near (I have two weeks yet). The problems are:
I implement a class which will act as a server. All clients will connect to this class. This class is responsible for manipulating the database. Although most operations work properly (Select, Update and Delete) I cannot add a new records. I use an MFC CRecordset derived class.
EmployeeRecordset for connecting and retrieving data from the database. A sample of this class is:

class EmployeesRecordset : public CRecordset
{
public:
CString m_EPONYMO1;
------------------------------------------------------------------------------------------------------------

Of course there are many fields.

I use a class Employee which will carry data from server to clients. This class has as many variables as the EmployeesRecordset but the data types are those of C++ (in case I use CORBA).

An example of Employee:

class Employee
{

private:
char* m_EPONYMO1;
public
char* getm_EPONYMO1(){return(m_EPONYMO1);}
void setm_EPONYMO1(char* surname1){m_EPONYMO1 = surname1;}


So far I don't use copy constructor and I don't have anything at constructor, destructor
------------------------------------------------------------------------------------------------------------

The ADDNEW method:

bool Service::AddNew(Employee e){

long id;

EmployeesRecordset records(db);

//Begin transaction
db->BeginTrans();

cout << "before opening" << endl;
//open the recordset only for adding records mode

if (db->CanUpdate()){
try{
//"SELECT * FROM [TEIDB].[T_YPALLHLON];"
if ((records.Open(CRecordset::dynaset, NULL,CRecordset::appendOnly))!=0){

cout << "recordset opened" << endl;

//if recordset is updateable add new record
if (records.CanAppend()){

//find the last YP_ID
records.MoveLast();

cout << (LPCSTR)records.m_HMER_PROSL.Format( "%A, %B %d, %Y" ) << endl;
cout << records.m_YP_ID<< endl;
cout << "LAST RECORDCOUNT" << " " << (LPCTSTR)records.m_EPONYMO1<< endl;
id = records.m_YP_ID + 1;

cout << id << endl;

records.AddNew();

records.SetFieldNull( NULL );

// cout << "set new values" << endl;

//copy new values
// CopyToRecordset(records,e);


records.m_ADDR1 = e.getm_ADDR1();
records.m_ADDR2 = e.getm_ADDR2();

records.SetFieldDirty(&records.m_ADDR1, TRUE);
records.SetFieldDirty(&records.m_ADDR2, TRUE);


// cout << "values set" << endl;

// cout << id<< endl;


if (records.Update()){

// cout << "Added" <<endl;
end="" transaction
="" records.close();
="" db-="">CommitTrans();

return (true);
}//end if

}//end if
}//end if
}//end of try
catch (CDBException cdbe){
cout << "exception raised" << endl;
records.Close();
db->Rollback();

return (false);

}//end of catch

catch (CMemoryException cme){
cout << "exception raised" << endl;
records.Close();
db->Rollback();

return (false);

}//end of catch


}//end if
else cout << "data cannot update" << endl;
cout << "end of addnew" << endl;
records.Close();
db->Rollback();

return(false);

}//end of AddNew

------------------------------------------------------------------------------------------------------------

the SELECT method of the Service(server) class is :

this method searches the database for the given employees.

vector<employee> Service::Select(char* surname){

Employee temp_e;
vector<employee> e;
EmployeesRecordset records(db);
CString str;
CString temp = (CString)surname;


cout << "Inside select" << endl;
/* //set filter
records.m_strFilter = "EPONYMO1 = ?";


//bind parameter
records.m_EPONYMO1Param = surname;

cout << LPCTSTR(surname) << endl;
*/
int i =0;
if (!temp.IsEmpty())
str = "SELECT * FROM [TEIDB].[T_YPALLHLON] WHERE EPONYMO1 = '" + (CString)surname + "';";
else str = "SELECT * FROM [TEIDB].[T_YPALLHLON];";

cout << (LPCTSTR)str << endl;
//open the recordset
try{
if (records.Open(CRecordset::dynaset,str,CRecordset::readOnly)!=0){

// test if recordset is empty
if( records.IsBOF( ) ) {
cout << "recordset empty" << endl;
records.Close();
temp_e.setstatus(false);
e.push_back(temp_e);
return (e);
}//end if


//if recorset is not empty copy data to Employees
while ( !records.IsEOF( ) ){

//copy data to employee
// CopyToEmployee(records, temp_e);

cout << (LPCTSTR)records.m_ADDR1 << endl;
temp_e.setm_ADDR1(records.m_ADDR1.GetBuffer(records.m_ADDR1.GetLength()));

temp_e.setm_ADDR2(records.m_ADDR2.GetBuffer(records.m_ADDR2.GetLength()));
temp_e.setm_YP_ID(records.m_YP_ID);
temp_e.setm_EPONYMO1(records.m_EPONYMO1.GetBuffer(records.m_EPONYMO1.GetLength()));
temp_e.setm_ONOMA(records.m_ONOMA.GetBuffer(records.m_ONOMA.GetLength()));

cout << temp_e.getm_ADDR1() << endl;


records.m_ADDR1.ReleaseBuffer(-1);
records.m_EPONYMO1.ReleaseBuffer(-1);
records.m_ONOMA.ReleaseBuffer(-1);

//copy object to vector
e.push_back(temp_e);
cout << e[i].getm_ADDR1() << endl;
i++;
records.MoveNext();
}//end of while

}//end if
}//end of try
catch (CDBException cdbe){

return (e);
records.Close();

}//end of catch

catch (CMemoryException cme){
cout << "exception raised" << endl;
records.Close();
return (false);

}//end of catch

cout << "Exit select" <<endl;
records.close();
=""
="" return(e);

}="" end="" of="" select

select="" and="" addnew="" belong="" to="" the="" object="" service.="" in="" its="" constructor="" service="" accepts="" as="" an="" argument="" a="" cdatabase="" reference,="" which="" uses="" for="" initializing="" crecordset="" derived="" classes.


------------------------------------------------------------------------------------------------------------

this="" is="" how="" i="" call="" these="" methods:="" give="" example="" select="" because="" when="" although="" can="" print="" most="" data="" types="" cannot="" (cout)="" contents="" strings.="" returns="" vector="" employees.

cdatabase="" data;
="" try{
="" if="" (!data.isopen())="" connection="data.OpenEx(_T("DSN=TEIDB;UID=DBADMIN;PWD=DBADMIN"),0);
" cout="" <<="" "connection="" established"="" endl;
="" }="" try
="" catch(="" cdbexception="" cdbe)="" {
="" failed";

="" catch

="" (connection){
="" "service"="" endl;="" service
="" serv(&data),serv1(&data);

="" "constructing="" employee"="" endl;

="" employee="" e;
="" cstring="" el="ELA" ;
="" k="KATI" e.setm_addr1(el.getbuffer(el.getlength()));
="" e.setm_eponymo1(k.getbuffer(k.getlength()));
="" el.releasebuffer(-1);
="" k.releasebuffer(-1);

="" e.getm_addr1()<<="" e.getm_eponymo1()="" "calling="" select"="" vector<employee=""> emp = serv.Select("KATI");

cout << "size of vector " << emp.size() << endl;

// Print contents of the Vector.
cout << "contents of vector" << endl;


for (int size = 0; size < emp.size(); size++)
{

cout << emp[size].getm_EPONYMO1() << " " << emp[size].getm_YP_ID() << endl;

}//end for

e.setm_ADDR2("ELA");
e.setm_EPONYMO1("KATI");
e.setm_ADDR1("FANTASTIKH");
cout << "calling addnew" << endl;

bool add = serv.AddNew(e);
if (add) cout << "added" << endl;
else cout << "not added" << endl;

data.Close();



In the AddNew method I always het a runtime error when calling records.Update();

So the problems are:

1) AddNew doesn’t work. I have made a lot of changes to the OpenEx method but nothing works.

2) I cannot print the string(char*) returned from the vector.
While inside the function Select all strings are printed normally!!!!!!!!!!!!!!!!!!!

3) How can I convert a COleDateTime to CTime. I use the following code (with a number of different formats) but it doesn’t work
COleDateTime oleDt;
cout << "oledt" << endl;

CString str = "8:30:00 Jan. 25, 1996";
oleDt.ParseDateTime(str.Left(15));
cout << "parse date" << endl;
cout << oleDt.Format("%H %M %S") << endl;

SYSTEMTIME st;
cout << "systemtime" << endl;

oleDt.GetAsSystemTime(st);
cout << "getassystemtime" << endl;

CTime myTime(st);
cout << "CTime" << endl;

cout << (LPCTSTR)myTime.Format( "%A, %B %d, %Y" ) << endl;


4) Which values should I use to change the mode of a recordset to pessimisti or optimistic? I use the SetLockingMode(); functions with arguments either (optimistic, pessimistic) or (0,1) but nothing works.

5) Since I have to use a distributed technology which one is more flexible and easier to use (CORBA or DCOM)? I have used before CORBA but with Java. I also have some thoughts about the compatibility between CORBA orbs (I have downloaded omniOrb fro AT&T) and Visual Studio (MFC Classes)?

I apologise for the length of the ‘essay’ but I am trying three days to solve the above problems and I cannot find any solution
GeneralRe: Problems Please help (and sorry for the size) Pin
Roger Stewart18-Aug-03 17:10
professionalRoger Stewart18-Aug-03 17:10 
GeneralRe: Problems Please help (and sorry for the size) Pin
David Crow19-Aug-03 3:17
David Crow19-Aug-03 3:17 
GeneralRe: Problems Please help (and sorry for the size) Pin
Vassilis Papoulidis19-Aug-03 12:04
Vassilis Papoulidis19-Aug-03 12:04 
GeneralRe: Problems Please help (and sorry for the size) Pin
Vassilis Papoulidis19-Aug-03 12:18
Vassilis Papoulidis19-Aug-03 12:18 
GeneralCRect constructor-beginner question Pin
7stud18-Aug-03 10:43
7stud18-Aug-03 10:43 
GeneralRe: CRect constructor-beginner question Pin
David Crow18-Aug-03 10:47
David Crow18-Aug-03 10:47 
GeneralRe: CRect constructor-beginner question Pin
Neville Franks18-Aug-03 10:48
Neville Franks18-Aug-03 10:48 
GeneralRe: CRect constructor-beginner question Pin
7stud18-Aug-03 11:22
7stud18-Aug-03 11:22 
GeneralRe: CRect constructor-beginner question Pin
Neville Franks18-Aug-03 11:30
Neville Franks18-Aug-03 11:30 
GeneralRe: CRect constructor-beginner question Pin
Michael Dunn18-Aug-03 11:51
sitebuilderMichael Dunn18-Aug-03 11:51 
GeneralRe: CRect constructor-beginner question Pin
7stud19-Aug-03 18:01
7stud19-Aug-03 18:01 
GeneralStay On Top - Advice Needed Pin
Norman Bates18-Aug-03 10:26
Norman Bates18-Aug-03 10:26 
GeneralRe: Stay On Top - Advice Needed Pin
valikac18-Aug-03 11:54
valikac18-Aug-03 11:54 
GeneralRe: Stay On Top - Advice Needed Pin
Hosam Aly Mahmoud18-Aug-03 12:04
Hosam Aly Mahmoud18-Aug-03 12:04 
GeneralRe: Stay On Top - Advice Needed Pin
Hosam Aly Mahmoud18-Aug-03 12:27
Hosam Aly Mahmoud18-Aug-03 12:27 
GeneralRe: Stay On Top - Advice Needed Pin
Norman Bates19-Aug-03 0:53
Norman Bates19-Aug-03 0:53 
GeneralRe: Stay On Top - Advice Needed Pin
Hosam Aly Mahmoud19-Aug-03 5:03
Hosam Aly Mahmoud19-Aug-03 5:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.