Problem with view.Prepare() statement
| Fri, 2005-11-25 14:30 | |
|
Hi All
i am creating create an application to read data from database everything work fine my code is given below for reading the data from database: RDbs dbSession; User::LeaveIfError(dbSession.Connect()); CleanupClosePushL(dbSession); RDbNamedDatabase database; User::LeaveIfError( database.Open( dbSession, KDataBaseName ) ); database.Open( dbSession, KDataBaseName ); CleanupClosePushL( database ); RDbView view; view.Prepare( database, TDbQuery(KSQLQuery)); User::LeaveIfError(view.EvaluateAll()); TBufC<40> EmpName; TUint32 EmpCode; view.FirstL(); while (view.AtRow()) { view.GetL(); EmpName = view.ColDes(1); CAknInformationNote* informationNote; informationNote = new ( ELeave ) CAknInformationNote; informationNote->ExecuteLD(EmpName); EmpCode = view.ColUint32(2); view.NextL(); } view.Close(); CleanupStack::Pop(2); database.Close(); dbSession.Close(); when i execute this my application give an gives a message and closed. when i debug the application after view.Prepare( database, TDbQuery(KSQLQuery)); line error is occured. Help me!! Wating for yr reply and suggestion.... Regards |
|






Forum posts: 23
By the way, why you are opening your database two times?
Forum posts: 71
_LIT(KDataBaseName,"c:\\mydatabase\\JITENDRA_DB");
_LIT(KSqlQueryCreateTable,"Create table Employee EmpCode int, EmpName char(20),EmpAddress char(100)");
_LIT(KSqlQueryInsertRecord,"insert into Employee (EmpCode,EmpName,EmpAddress),'111','Jitendra','Delhi')");
_LIT(KSQLQuery, "SELECT EmpCode,EmpName from Employee");
first line of database open is comment sorry i just forget to give it here !
i am making in helloworldbasic and the error is
Program Closed:Helloworldasic
Forum posts: 23
You can check it like this: TInt err = view.Prepare( database, TDbQuery(KSQLQuery));
After this you know little bit more about the error.
Forum posts: 140
Paul Todd
Forum posts: 71
when i am inserting recored in db it shows sucessful to me but i could not bu able to understand why this problem is occur.
what is the mean of -6 is it equal to KErrNone, but i don't think so bcoz if i give condition like
if (i=KErrNone)
{
}
it was not execute if condition.
help me !!!
Forum posts: 140
Paul Todd
Forum posts: 140
Paul Todd
Forum posts: 23
Return value
TInt KErrNone, if successful, otherwise one of the other system-wide error codes.
Specifically: KErrNotFound if The table does not exist in the database or a column name in the SQL query does not exist.KErrNotSupported if a sort-specification in the SQL query cannot be provided by an index. KErrArgument if an invalid or unrecognised SQL syntax was used. KErrGeneral if there is a column type mismatch in a predicate in the SQL query or if a date-literal in the SQL query was invalid. KErrOverflow if a number-literal in the SQL query for an integral column was too large (did not fit in a 32-bit integral representation). This can also be one of the DBMS database error codes.
So there is someting wrong in your SQL statement.
Forum posts: 71
All
firstly i say Thanks a Lot for UR kind Help.
my all sql querry wok fine in SQL Envirment.
Problem is something else and i solved it.
Thanks.
Regards,
JKS
Forum posts: 13
Congratulations that you solved your problem, but you could have at least given the description of how you did it. So many people were trying to help you and you finish with no conclusions for others:/ it is not fair.
Now I am also having a similar problem with Prepare -> gives me KErrArgument (-6) :/
iDatabase is already opened
_LIT(KSQLTemplate,"SELECT timeout, timestamp FROM baskets WHERE name = ");TBuf<200> SQLStatement;
SQLStatement=KSQLTemplate();
SQLStatement.Append(aName);
// create a view on the iDatabase
RDbView view;
User::LeaveIfError(view.Prepare(*iDatabase,TDbQuery(SQLStatement,EDbCompareNormal)));
Leaves with -6 :/
Regards
Later:
Ok, in my case I simply forgot to add apostrophes in the sql statement, so when adding the name now it looks like this:
_LIT(KApostrophe, "'");
...
SQLStatement.Append(KApostrophe());
SQLStatement.Append(aName);
SQLStatement.Append(KApostrophe());
...
Of course, now it works.
Regards