Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved]qt sql insert statement system not working
Forum Updated to NodeBB v4.3 + New Features

[solved]qt sql insert statement system not working

Scheduled Pinned Locked Moved General and Desktop
22 Posts 5 Posters 13.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    broadpeak
    wrote on last edited by
    #12

    Try this codesnippet:

    @

    void YourClass::init()
    {
    //...
    initDB("../../../db/mydb.db3"); // of course your db path goes here
    //...
    }

    void YourClass::initDB(QString dbPath)
    {
    vc2DB = QSqlDatabase::addDatabase("QSQLITE");
    vc2DB.setDatabaseName(dbPath);
    vc2DB.open();
    QSqlQuery query;
    query.exec("PRAGMA foreign_keys = ON;");
    bool b = query.exec("select id from role where code = 'SU'");
    if (!b) {
    std::cerr << "Failed to open database: " << dbPath.toAscii().data() << std::endl;
    exit(-1);
    }
    }
    @

    1 Reply Last reply
    0
    • D Offline
      D Offline
      developer
      wrote on last edited by
      #13

      there is not db path set @broadpeak

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gayu
        wrote on last edited by
        #14

        So u've to set the path for db

        1 Reply Last reply
        0
        • D Offline
          D Offline
          developer
          wrote on last edited by
          #15

          why the table has been created fine.
          also where to seta good path for ana pplication

          1 Reply Last reply
          0
          • B Offline
            B Offline
            broadpeak
            wrote on last edited by
            #16

            [quote author="developer" date="1353499828"]there is not db path set @broadpeak[/quote]

            What? I don't understand this.

            But! If the open() function can't open your database, it will open with the given name an another database in QSQLITE! See your databaseS.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              developer
              wrote on last edited by
              #17

              it can open the database @broadpeek

              1 Reply Last reply
              0
              • G Offline
                G Offline
                gayu
                wrote on last edited by
                #18

                even though the file does not exist, the SQLite will try to create it.

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  broadpeak
                  wrote on last edited by
                  #19

                  [quote author="developer" date="1353500452"]it can open the database @broadpeek[/quote]

                  Anyway, can you run (from your code) a simple SELECT on your database? Have you got a resultset?
                  Have you grant at all for your tables?

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    developer
                    wrote on last edited by
                    #20

                    ohhhhhhhhhh acutally its working with setting url a different databse opens and with just typing passwordmanager as databse name it works actaully the problem is with the table view thanks all problem solved i tried select staement and i got the result

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      developer
                      wrote on last edited by
                      #21

                      it also works after selecting select() thanks all

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        broadpeak
                        wrote on last edited by
                        #22

                        Ok, set your thread to [solved] :)

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved