×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Super Contributor
    Join Date
    Mar 2004
    Location
    Bangalore,India
    Posts
    2,146

    application crash and database related issue

    i am creating a database using the following code...:-

    TBufC<60> CMyDatabase::MakeDatabase()
    {
    //create the file session
    RFs fsSession;
    User::LeaveIfError(fsSession.Connect());
    CleanupClosePushL(fsSession);

    //create the database

    _LIT(KDbFileName,"C:\\trial");
    TInt value;
    User::LeaveIfError(value=database.create(fsSession,KDbDatabase));
    if(value!=KErrNone)
    {
    User::LeaveIfError(database.Open(fsSession,KDbFileName));
    _LIT(KSQLQuery, "SELECT name,dept_code,FROM employees ORDER BY emp_num");
    RDbView view;
    view.Prepare(database, TDbQuery(KSQLQuery));
    view.EvaluateAll();
    TBufC<KDbNameLen> name;
    TUint32 dept_code;
    view.FirstL();
    while (view.AtRow())
    {
    view.GetL();
    name = view.ColDes(1);
    dept_code = view.ColUint32(2);
    view.NextL();
    return(name);
    }


    }
    else
    {
    CleanupClosePushL(database);
    // Create tables etc.

    _LIT(KSQLCreateTable, "CREATE TABLE employees (name CHAR (60) NOT NULL, address CHAR (250) NOT NULL, emp_num COUNTER,dept_code UNSIGNED INTEGER NOT NULL)");

    // Execute the SQL statement

    User::LeaveIfError(database.Execute(KSQLCreateTable));

    //insert data

    _LIT(KSQLInsert, "INSERT INTO employees (name, address, dept_num ) VALUES ('J Bloggs', '1 High Street,Newtown', 101)");
    TInt ret = database.Execute(KSQLInsert);
    CleanupStack::PopAndDestroy();//database
    return(NULL);
    }

    but when i execute this application the first time..the database is created but the application crashes ...when i run it the next time and again it just keeps crashing without any compiler/linker or run time error.
    can anyone tell me what i am missing out?
    ciao

  2. #2
    Registered User
    Join Date
    May 2004
    Posts
    39
    please read the document from nokia forum documents about database, cos there are many wrong things in your code

    for example, if the database is a member object why are u pushing it to CleanupStack, and are u sure you wanna return without closing the view

    please read this documentation well

    thank you, and never mind you would get good enough with it

  3. #3
    Super Contributor
    Join Date
    Mar 2004
    Location
    Bangalore,India
    Posts
    2,146
    thanks for the reply..but even now when i have made the changes to the code it still wont run..can u tell me why?btw this is the code that i took from the SDK so i was assuming it should run and not crash..any leads?
    ciao

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •