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. Create Table From Resources File
Forum Updated to NodeBB v4.3 + New Features

Create Table From Resources File

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 5.2k 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.
  • D Offline
    D Offline
    dcbasso
    wrote on 10 Jul 2012, 16:45 last edited by
    #1

    Hi everyone, I'm trying to run a SQL SCRIPT to Create all my tables. The script is a CreateTable.sql file, and I added this file to Resources.qrc.

    So, I read this file as a QString and try to exec, but the Sqlite Database gives me a error and don't create any table.

    CreateTable.sql:
    @
    CREATE TABLE comandos (
    id INTEGER NOT NULL,
    codigo INTEGER NOT NULL,
    descricao TEXT NOT NULL,
    PRIMARY KEY (id)
    );

    CREATE TABLE codigoResposta (
    id INTEGER NOT NULL,
    codigo INTEGER NOT NULL,
    descricao TEXT NOT NULL,
    PRIMARY KEY(id)
    );

    CREATE TABLE velocidadeCAN (
    id INTEGER NOT NULL,
    configuracao INTEGER NOT NULL,
    taxaTransmissao TEXT NOT NULL,
    padrao INTEGER,
    PRIMARY KEY (id)
    );

    CREATE TABLE parametroConfiguracao (
    id INTEGER NOT NULL,
    parametro INTEGER NOT NULL,
    atalho TEXT NOT NULL,
    descricaoGeral TEXT NOT NULL,
    descricao TEXT,
    valor_int INTEGER,
    valor_num NUMERIC,
    destino TEXT NOT NULL,
    padrao INTEGER,
    PRIMARY KEY (id)
    );

    CREATE TABLE notificacoes (
    id INTEGER NOT NULL,
    codigo INTEGER NOT NULL,
    descricao TEXT NOT NULL,
    PRIMARY KEY (id)
    );
    @

    The code:

    @
    ...
    QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
    database.setDatabaseName( QDir::homePath() + QDir::separator() + "inoveDB.db3");
    if (database.open()) {
    QSqlQuery query(database);
    if (query.exec( readCreateTable()))
    {
    ...

    static QString readCreateTable()
    {
    QFile file(":/database/CreateTable.sql");
    if(!file.open(QIODevice::ReadOnly))
    {
    qDebug() << "error opening file: " << file.error();
    return "";
    }
    QTextStream instream(&file);
    QString createTable = instream.readAll();
    qDebug() << "---> " << createTable;
    file.close();
    return createTable;
    }
    @

    @

    There is something wrong with my code?
    I test the SQL Script on SQLite Manager (Firefox Plugin) and works!

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dcbasso
      wrote on 10 Jul 2012, 16:51 last edited by
      #2

      Sorry guys, I found the error using this:

      @
      qDebug() << "Erro ao criar tabelas. " << query.lastError();
      @

      The error:
      *QSqlError(21, "Unable to execute multiple statements at a time", "not an error")
      *

      Why this limitation? I'm using the ";" between the create's! It's not possible to do that?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on 10 Jul 2012, 18:20 last edited by
        #3

        No, that is not possible. You can only send one command at a time. Separating with a semi-colon is not possible.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dcbasso
          wrote on 10 Jul 2012, 18:28 last edited by
          #4

          I see!
          I already resolved using "my separator" and making the split on QString.
          Thanks anyway.

          • I Just have on problem know, the resource files is making cache at the build. I change the file but in test the file still in old version.
          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on 10 Jul 2012, 18:31 last edited by
            #5

            Run qmake.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on 26 Jul 2012, 22:52 last edited by
              #6

              unfortunately, running qmake is not always sufficient. Just delete the qrc_*.cpp files, they will be regenerated then.

              http://www.catb.org/~esr/faqs/smart-questions.html

              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