Problem with view.Prepare() statement

Login to reply to this topic.
Fri, 2005-11-25 14:30
Joined: 2005-11-18
Forum posts: 71
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

Fri, 2005-11-25 18:43
Joined: 2005-07-13
Forum posts: 23
Re: Problem with view.Prepare() statement
I think there is someting wrong in your SQL query statement (KSQLQuery). Could you post it here?

By the way, why you are opening your database two times?
Sat, 2005-11-26 05:43
Joined: 2005-11-18
Forum posts: 71
Re: Problem with view.Prepare() statement
these are the string that i used for database..   

_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

Sat, 2005-11-26 10:06
Joined: 2005-07-13
Forum posts: 23
Re: Problem with view.Prepare() statement
What is the return value of view.Prepare( database, TDbQuery(KSQLQuery)) ?

You can check it like this: TInt err = view.Prepare( database, TDbQuery(KSQLQuery));

After this you know little bit more about the error.
Sat, 2005-11-26 11:20
Joined: 2004-09-14
Forum posts: 140
Re: Problem with view.Prepare() statement
The problem is proably that the table does not exist, check the return code from database.Open( dbSession, KDataBaseName );

Paul Todd

Mon, 2005-11-28 07:09
Joined: 2005-11-18
Forum posts: 71
Re: Problem with view.Prepare() statement
it return -6 to me.
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 !!!
Mon, 2005-11-28 09:54
Joined: 2004-09-14
Forum posts: 140
Re: Problem with view.Prepare() statement
-6 == KErrArgument,

Paul Todd

Mon, 2005-11-28 09:56
Joined: 2004-09-14
Forum posts: 140
Re: Problem with view.Prepare() statement
If you read the documentation for Execute, which I assume you are using judging from the SQL statements, you will see the return code was for the SQL that inserts a row into your database returned that 0 rows were inserted.

Paul Todd

Mon, 2005-11-28 18:33
Joined: 2005-07-13
Forum posts: 23
Re: Problem with view.Prepare() statement
Copy-paste from the help:

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.
Thu, 2005-12-01 05:40
Joined: 2005-11-18
Forum posts: 71
Re: Problem with view.Prepare() statement
hi !
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
Wed, 2008-07-09 09:22
Joined: 2008-05-26
Forum posts: 13
Re: Problem with view.Prepare() statement

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

  • Login to reply to this topic.