Stumped on C++ compile error.

rw123's Avatar, Join Date: Apr 2011
Newbie Member
Hi.
Am new to c++ and getting error "Cannot use DBSql to initialize DBSql."
My code compiles fine on older Sun versions (CC 5.3 and 5.8).
I marked the lines below that are having this problem.
Apologies for the icons. I noticed them being inserted
while previewing my post but didn't see a way to prevent this.
Anyways, looking for expert help on the compile error.
Thanks so much.
-RW

Unix version: SunOS ut51278 5.10 Generic_141444-09 sun4u sparc SUNW,SPARC-Enterprise
Compiler version: CC: Sun C++ 5.11 SunOS_sparc 2010/08/13
============= BEGIN database.h ====================
Code:
#include <dbserver.h> 
#include <dbstoredproc.h> 
#include "dbsql.h" 
class Database : public DBServer 
{ 
public : 
DBSql SQL( const char* sqlCmd ); 
DBSql SQL( const std::string& sqlCmd ); 
DBSql Table( const char* tableName ); 
DBSql Table( const std::string& tableName ); 
DBStoredProc storedProc( const char* spName ); 
DBStoredProc storedProc( const std::string& tableName ); 
}; 
============= END database.h ======================= 
============= BEGIN dbsql.h ========================= 
#include <string> 
#include "dbaccess.h" 
#include "dbtable.h" 
class DBSql : public DBAccess 
{ 
public: 
DBSql(DBServer *pServer,const char *sql) ; 
DBSql(DBServer *pServer,const std::string& sql); 
DBSql(DBSql& dbSql); 
DBSql& operator=(DBSql& dbSql); 
virtual DBTable getResultSet(); 
protected: 
DBSql(); 
void init(DBServer *pServer,const std::string& sql); 
}; 
============== END dbsql.h ========================= 
============== BEGIN database.cpp ==================== 
#include <database.h> 
#include "dbsql.h" 
using namespace std; 
DBSql Database::Table( const char* tableName ) 
{ 
return Table( string( tableName ) ); <=== This line getting error... "Error: Cannot use DBSql to initialize DBSql." 
} 
DBSql Database::Table( const string& tableName ) 
{ 
string sqlCmd = "select * from " + tableName; 
return SQL( sqlCmd.c_str() ); <=== This line getting error... "Error: Cannot use DBSql to initialize DBSql." 
} 
DBSql Database::SQL( const char* sqlCmd ) 
{ 
return DBSql(this,sqlCmd); <=== This line getting error... "Error: Cannot use DBSql to initialize DBSql." 
} 
DBSql Database::SQL( const string& sqlCmd ) 
{ 
return SQL( sqlCmd.c_str() ); <=== This line getting error... "Error: Cannot use DBSql to initialize DBSql." 
} 
DBStoredProc Database::storedProc( const char* spName ) 
{ 
return DBStoredProc( this, spName ); 
} 
DBStoredProc Database::storedProc( const std::string& spName ) 
{ 
return DBStoredProc( this, spName ); 
} 
============ END database.cpp ========================== 
============ BEGIN dbsql.cpp =========================== 
#include "dbsql.h" 
#include "dbcommon.h" 
using namespace std; 
using namespace ORACLE; 
DBSql::DBSql(DBServer *pServer,const char* sql) 
{ 
init(pServer,string(sql)); 
} 
DBSql::DBSql(DBServer *pServer,const string& sql) 
{ 
init(pServer,sql); 
} 
DBSql::DBSql(DBSql& dbSql) 
: DBAccess(dbSql) 
{ 
} 
DBSql& DBSql::operator=(DBSql& dbSql) 
{ 
DBAccess::assign(dbSql); 
return *this; 
} 
DBSql::DBSql() 
{ 
} 
void DBSql::init(DBServer *pServer,const string& sql) 
{ 
execSQL(pServer,sql.c_str()); 
} 
DBTable DBSql::getResultSet() 
{ 
DBTable result; 
if(DBAccess::getResultSet(false)) 
{ 
//In order to prevent DBAccess from closing the previous result set, pass false to 
//getResultSet 
result = DBTable(m_pStmt,m_pResultSet,true); // Pass true to DBTable to allow it 
m_pStmt = NULL; // to control the statement. 
} 
m_pResultSet = NULL; 
return result; 
}
=========== END dbsql.cpp ==============================

Last edited by shabbir; 23Apr2011 at 22:55.. Reason: Code blocks
rw123's Avatar, Join Date: Apr 2011
Newbie Member
Am reposting exact same code as above except with code tags for better readability.
Just in case.
Thanks.
Code:
 
========================= BEGIN database.h ============================================ 
#include <dbserver.h> 
#include <dbstoredproc.h> 
#include "dbsql.h" 
class Database : public DBServer 
{ 
public : 
DBSql SQL( const char* sqlCmd ); 
DBSql SQL( const std::string& sqlCmd ); 
DBSql Table( const char* tableName ); 
DBSql Table( const std::string& tableName ); 
DBStoredProc storedProc( const char* spName ); 
DBStoredProc storedProc( const std::string& tableName ); 
}; 
========================= END database.h =============================================== 
========================= BEGIN dbsql.h ================================================ 
#include <string> 
#include "dbaccess.h" 
#include "dbtable.h" 
class DBSql : public DBAccess 
{ 
public: 
DBSql(DBServer *pServer,const char *sql) ; 
DBSql(DBServer *pServer,const std::string& sql); 
DBSql(DBSql& dbSql); 
DBSql& operator=(DBSql& dbSql); 
virtual DBTable getResultSet(); 
protected: 
DBSql(); 
void init(DBServer *pServer,const std::string& sql); 
}; 
========================= END dbsql.h ================================================== 
========================= BEGIN database.cpp =========================================== 
#include <database.h> 
#include "dbsql.h" 
using namespace std; 
DBSql Database::Table( const char* tableName ) 
{ 
return Table( string( tableName ) ); <=== This line getting error... "Error: Cannot use DBSql to initialize DBSql." 
} 
DBSql Database::Table( const string& tableName ) 
{ 
string sqlCmd = "select * from " + tableName; 
return SQL( sqlCmd.c_str() ); <=== This line getting error... "Error: Cannot use DBSql to initialize DBSql." 
} 
DBSql Database::SQL( const char* sqlCmd ) 
{ 
return DBSql(this,sqlCmd); <=== This line getting error... "Error: Cannot use DBSql to initialize DBSql." 
} 
DBSql Database::SQL( const string& sqlCmd ) 
{ 
return SQL( sqlCmd.c_str() ); <=== This line getting error... "Error: Cannot use DBSql to initialize DBSql." 
} 
DBStoredProc Database::storedProc( const char* spName ) 
{ 
return DBStoredProc( this, spName ); 
} 
DBStoredProc Database::storedProc( const std::string& spName ) 
{ 
return DBStoredProc( this, spName ); 
} 
========================= END database.cpp ============================================= 
========================= BEGIN dbsql.cpp ================================================ 
#include "dbsql.h" 
#include "dbcommon.h" 
using namespace std; 
using namespace ORACLE; 
DBSql::DBSql(DBServer *pServer,const char* sql) 
{ 
init(pServer,string(sql)); 
} 
DBSql::DBSql(DBServer *pServer,const string& sql) 
{ 
init(pServer,sql); 
} 
DBSql::DBSql(DBSql& dbSql) 
: DBAccess(dbSql) 
{ 
} 
DBSql& DBSql::operator=(DBSql& dbSql) 
{ 
DBAccess::assign(dbSql); 
return *this; 
} 
DBSql::DBSql() 
{ 
} 
void DBSql::init(DBServer *pServer,const string& sql) 
{ 
execSQL(pServer,sql.c_str()); 
} 
DBTable DBSql::getResultSet() 
{ 
DBTable result; 
if(DBAccess::getResultSet(false)) 
{ 
//In order to prevent DBAccess from closing the previous result set, pass false to 
//getResultSet 
result = DBTable(m_pStmt,m_pResultSet,true); // Pass true to DBTable to allow it 
m_pStmt = NULL; // to control the statement. 
} 
m_pResultSet = NULL; 
return result; 
} 
========================= END dbsql.cpp ====================================================