Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Portuguese
  4. Problema com select em tabela de informaçoes do mysql
Forum Updated to NodeBB v4.3 + New Features

Problema com select em tabela de informaçoes do mysql

Scheduled Pinned Locked Moved Portuguese
4 Posts 2 Posters 2.1k 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.
  • R Offline
    R Offline
    Rodrigocg
    wrote on last edited by
    #1

    Estou tentando executar o seguinte codigo:

    @QSqlQuery *query = new QSqlQuery(*base);

        QString sqlvars = "set @schema='%schema%';"
                "set @table='%table%';";
    
        QString sqltables = "select TABLE_NAME, TABLE_TYPE from information_schema.TABLES where TABLE_SCHEMA = @schema;";
    
        sqlvars.replace("%schema%","sakila");
       
        bool ok = query->exec(sqlvars+sqltables);
    
        if(ok)
            while (query->next())
                qDebug()<< query->value("TABLE_NAME").toString();@
    

    mas ele não me retorna resultados e nao sei se posso fazer isso:
    @ QString sqlvars = "set @schema='%schema%';"
    "set @table='%table%';";@

    alguem?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      TioRoy
      wrote on last edited by
      #2

      Por que usar uma string e fazer replace se você pode fazer bind de variáveis?

      @
      QSqlQuery query;
      query.prepare("select TABLE_NAME, TABLE_TYPE from information_schema.TABLES where TABLE_SCHEMA = :schema");
      query.bindValue(":schema", "sakila");

      bool ok = query->exec();

      if(ok)
      while (query->next())
      qDebug()<< query->value("TABLE_NAME").toString();
      @

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rodrigocg
        wrote on last edited by
        #3

        ..., rs! então né... nem me toquei aqui...
        Viajei legal agora...

        Mas, supondo que eu quisesse executar dois comando ao mesmo tempo como o do código que mostrei que era usando o comando set pra definir uma variável, como que eu faria isso?

        1 Reply Last reply
        0
        • T Offline
          T Offline
          TioRoy
          wrote on last edited by
          #4

          Foi mal pela demora.....

          O "driver do mysql do qt":https://qt.gitorious.org/qt/qt/source/b510e64cc5405c0664200bf471b5ccbbe3b4d081:src/sql/drivers/mysql/qsql_mysql.cpp#L900 usa a função "mysql_stmt_prepare()":http://dev.mysql.com/doc/refman/5.0/en/mysql-stmt-prepare.html que na sua documentação diz:

          "The string must consist of a single SQL statement. You should not add a terminating semicolon (“;”) or \g to the statement."

          Tradução livre minha:

          "A string consiste de um simples SQL. Você não deve adicionar o terminador ";" ou \g."

          Por isso que não funciona.

          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