App crash on access new Database - c++

My application crashes on reading / writing data from the database. I have one database on c: and I copy-pasted and rename with different name. The following process is what I have used for copy...Please guide me if you have any suggestion or solution.
RFs fs;
fs.Connect();
CFileMan* fileMan=CFileMan::NewL(fs);
CleanupStack::PushL(fileMan);
TInt err=fileMan->Copy(anOld,aNew);
CleanupStack::PopAndDestroy(fileMan);
fs.Close();
if(err==KErrNone)
return ETrue;
else
return EFalse;
It crashes on following line when I am trying to insert or get any data from the database.
User::LeaveIfError( iDatabase.Execute( strSQL ) );
db creation:
TBool Open = OpenL();
if (!Open)
{
User::LeaveIfError(iDbSession.Connect());
CleanupClosePushL(iDbSession);
CleanupClosePushL(iDatabase);
User::LeaveIfError(iDatabase.Replace(iDbSession, iDBPath ));
// create table
_LIT(KSQLtest,"CREATE TABLE testtable(id INTEGER,test1 VARCHAR(50),test2 VARCHAR(50))"); User::LeaveIfError(iDatabase.Execute(KSQLtest));
iDatabase.Compact();
iDatabase.Close();
iDbSession.Close();
CleanupStack::PopAndDestroy();
CleanupStack::PopAndDestroy();
Open database:
User::LeaveIfError( iDbSession.Connect() );
CleanupClosePushL( iDbSession );
if ( KErrNone != iDatabase.Open(iDbSession, iDBPath))
{
iDbSession.Close();
CleanupStack::PopAndDestroy();
return EFalse;
}
else
{
CleanupClosePushL( iDatabase );
iIsDatabaseOpened = ETrue;
return ETrue;
}

User:: LeaveIfError() throws an exception when iDatabase.Execute() returns an error code.
You can find the most common Symbian error codes at NewLC
If the crash happens before RDbDatabase::Execute() is actually run, we'll need to see more code to figure out why iDatabase is in a bad state.

You need to explain what "crashes" means - an exception/leave? a panic? If so, what leave code, or what panic category and number?
If it "crashes" here
User::LeaveIfError( iDatabase.Execute( strSQL ) );
you might want to check the return value, i.e.
TInt error = iDatabase.Execute( strSQL );
//Now log/display the error
User::LeaveIfError(error);
A few other points of note:
If you use CleanupClosePushL() on an object, you don't need to call both Close() and CleanupStack::PopAndDestroy(). The latter will call Close() for you.
Your OpenL() function uses a mix of leaving and return code which is considered bad style generally. In addition, functions which leave something on the cleanup stack are generally named xxxxLC(), the trailing 'C' denoting a cleanup item.

Related

ADO Recordset->EndOfFile giving me _com_error when Empty Recordset

I'm using ADO, and getting a very weird com error.
So I'm simply running a stored proc using ADO CommandPtr, and storing it in a Recordset.
Here is what I'm doing:
_ConnectionPtr Connptr;
//Instantiate ConnectionPtr...
_CommapndPtr CommPtr;
CommPtr.CreateInstance(__uuidof(Command));
CommPtr->CommandType = adCmdText;
CommPtr->ActiveConnection = ConnPtr;
CommPtr->CommandText = "Execute MyDb..MyStoredProc";
_RecordsetPtr RecPtr;
RecPtr.CreateInstance(__uuidof(Recordset));
RecPtr->CursorLocation = adUseClient;
RecPtr->CacheSize = 150;
RecPtr = CommPtr->Execute(NULL, NULL, adOptionUnspecified); //RecPtr = Empty Recordset
while (!RecPtr->EndOfFile) { //ERROR HAPPENS HERE!!!
//Do something
RecPtr->MoveNext();
}
So my stored procedure is supposed to returns an empty recordset (0 rows).
But then , when I check if the recordset has reached the end (which should simply return true if it is empty). I get a com error.
When I caught the com error and printed it out, I got this.
Code = -2147217849
Meaning = IDispatch error #3153
Source = NULL
Which doesn't tell me much.
I don't understand why RecPtr->EndofFile is throwing a com error, since it should simply return true/false.
I highly doubt that the error is caused because I'm doing something wrong when initializing Connection and Command objects. (If so, then I would have gotten the error when Executing the command.)
Any ideas on what might be causing this exception?

How Can I Call PL/pgSQL Function From C++ Code

I am trying to call a function which is declared in PostgreSQL with PL/pgSQL. For that I write the code below. My function is working but after that I am taking a "PGRES_FATAL_ERROR". Also when I changed "select removestopwords()" with an sql query like "DELETE * FROM TABLE1" it's working successfully.
I am considering, that error can cause some big problem in future even if now working. How can I call a PL/pgSQL function without taking error?
void removeStopWordsDB(PGconn* conn) {
PGresult *res = PQexec(conn, "select removestopwords()");
if (PQresultStatus(res) != PGRES_COMMAND_OK) {
printf("removestopwords failed");
cout<<PQresultStatus(res);
PQclear(res);
exit_nicely(conn);
}
printf("removestopwords - OK\n");
PQclear(res);
}
If you get PGRES_FATAL_ERROR from PQresultStatus you should use PQresultErrorField to get all the error data from the result set to provide a useful error message. This will allow you to determine what the actual error is here (quite likely an error being sent over from the server).
Consider creating a class to hold PostgreSQL error details that can be constructed from q PQresult pointer, e.g.:
PgError(const PGresult *rs)
{
severity = GetErrorField(rs, PG_DIAG_SEVERITY);
sqlstate = GetErrorField(rs, PG_DIAG_SQLSTATE);
primary = GetErrorField(rs, PG_DIAG_MESSAGE_PRIMARY);
// ...
}
static std::string GetErrorField(const PGresult *rs, int fieldCode)
{
const char *message = PQresultErrorField(rs, fieldCode);
if (message == NULL) return "";
return std::string(message);
}
Then you can, for example, encapsulate dumping out the error to a stream in this object to provide details just like psql and friends do (although strictly speaking, you'd need the input SQL as well for all of that)
PostgreSQL API doesn't support some flag like "ignore all errors". If you would to ignore result, then just don't check result in host environment. But it is bad strategy.

Using UpdateResource with StringTables in C++

I need to edit the resources of a file in C++ using UpdateResource(), however I am unsure on how to go about getting the data for the 5th parameter (lpData).
I have no idea about how to create the data that needs to be provided for the function and the structure of the data, Can anybody provide guidance on how to go about getting/creating the data?
Simply you can use:
wchar_t wszMyText[] = L"Some text";
HANDLE hUpdate = BeginUpdateResourceW( L"/path/to/file", FALSE );
// test return value.
BOOL res = UpdateResourceW( hUpdate, RT_STRING, L"MyResource", wszMyText,
sizeof(wszMyText) - sizeof(wchar_t);
// check return value
EndUpdateResource( hUpdate, FALSE );

Odd ColdFusion Behavior--Abort Not Honored

Using ColdFusion 9.01, occasionally, we have observed an issue where an error may be occurring within a CFC function and when we attempt to add writeDump(foo); and abort; calls to debug the error ColdFusion does not honor those calls.
Example:
private void function index(Event)
{
var rc = Event.getCollection();
var prc = Event.getCollection(private=true);
/** NOT HONORED! **/
writeDump(var=rc);
abort;
prc.JSON = {};
prc.JSON.show = variables.APIProxy.call(
handler = 'shows'
,action = 'read'
,event = arguments.Event
/** THE ERROR IS OCCURING HERE **/
,params = { language=lcase(rc.language.getLanguage_Medium()), show=rc.show_name }
);
prc.JSON.showEpisodes = variables.APIProxy.call(
handler = 'episodes'
,action = 'index'
,event = arguments.Event
,params = { language=lcase(rc.language.getLanguage_Medium()), show=rc.show_name, detail=true }
);
prc.JSON.products = variables.APIProxy.call(
handler = 'products'
,action = 'index'
,event = arguments.Event
,params = { language=lcase(rc.language.getLanguage_Medium()), detail=true }
);
Event.addAssets(
'model/product.js
,model/show.js
,collection/product_mobile.js
,collection/show_mobile.js
,view/product_mobile.js
,view/productList.js
,view/show_mobile.js
,view/showList.js
,model/episode.js
,view/episode_mobile.js
,view/episodeList.js
,collection/episode_mobile.js
,collection/product_mobile.js
,mobile/episodeObject.css
,mobile/show.js
,mobile/show.css
,mobile/category.css
');
Event.setLayout('layout.mobile');
Event.setView("show/index_mobile");
return;
}
I believe we have successfully eliminated caching. I am curious if anyone else has encountered this.
Thank you.
Aaron
I'm guessing that the error is a parse error, not a true runtime error, so it gets thrown before the function actually executes. It's not actually skipping over your abort, it just fails to parse (or execute) the entire thing.
I'm not sure why you're getting a parse error there, but I do know the CF code that handles struct literals is somewhat flaky.
The issue was with the struct literals declared within the argument calls to a function.
i'm going to go out on a limb here and say that your issue might have something to do with this bug:
http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#bugId=86960
is there anything in your app that executes in the onRequestEnd() method?
it would be helpful to tell us what exactly is happening and/or the output you're getting when the issue happens.

mysql++ query fails

I'm a new user of mysql++ looking for some pointers (pun intended).
The problem: my update statement fails.
The connection is open. The previous statement that uses the connection works.
I'm sure the record I'm trying to update exists. I can see it with the mysql query tools.
I'm sure CustomerId is correct.
// declaration of the customer id
uint32_t CustomerId;
Why does this fail to update?
mysqlpp::Connection conn( true );
try
{
if ( conn.connect( db_rw.Name, db_rw.Host, db_rw.User, db_rw.Password ) )
{
// *snip* insert code here works fine.
// this query fails
mysqlpp::Query query = conn.query( "UPDATE customer SET AccountName=%2q, Active=%3, Password=%1 WHERE CustomerId=%0" );
query.parse();
mysqlpp::SQLQueryParms parms;
parms.push_back( mysqlpp::sql_int( CustomerId ) );
parms.push_back( mysqlpp::sql_blob( data, sizeof(data) ) ); //<- 16 byte binary blob
parms.push_back( mysqlpp::sql_varchar( widget.AccountName->text().toAscii().data() ) ); // string
parms.push_back( mysqlpp::sql_bool( widget.ActiveCheckBox->checkState() == Qt::Checked ? 1 : 0 ) ); //
mysqlpp::SimpleResult res = query.execute( parms );
}
}
If I turn off exceptions for the connection it fails silently (the result.info() method returns nothing).
if I turn exceptions on it seg faults when trying to convert to a string:
std::string Query::str(SQLQueryParms& p)
{
if (!parse_elems_.empty()) {
proc(p);
}
return sbuffer_.str();
}
Warren beat me to the answer on the mailing list, but for posterity:
BLOB data (Password) needs to be quoted and escaped.
Using an SSQLS instead of templated queries handles this automatically.
http://tangentsoft.net/mysql++/doc/html/userman/tutorial.html#id2776204
There were several issues.
The library doesn't escape binary data correctly.
If the user associated with the connection does not have update permission then the library will crash instead of throwing an exception.