Uploaded image for project: 'MariaDB Connector/C'
  1. MariaDB Connector/C
  2. CONC-699

UPDATE WHERE int mysql_stmt_affected_rows = 0

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 3.3.8
    • None
    • Prepared Statements
    • None
    • Windows 10 Pro

    Description

      The following code fails to find the relevant row with WHERE id = ? condition.
      Server version: 10.11.8-MariaDB mariadb.org binary distribution

              MYSQL mysql;
       
              mysql_init(&mysql);
              mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP, "voicelog");
              if (!mysql_real_connect(&mysql,"localhost","voicelog","voicelog","voicelog",0,NULL,0))
              {
                  WriteToLog("Invalid database connection");
                  sleep(5);
                  continue;
              }
       
                      // return results to user
                      std::string results = output_str(ctx, pcmf32s);
       
                      MYSQL_STMT* gUpdateStmt = mysql_stmt_init(&mysql);
                      if (gUpdateStmt == NULL) {
                          WriteToLog("Init stmt failed");
                          continue;
                      }
       
                      std::cout << "Initialized statement\n";
       
                      char statement[] = "UPDATE voicelog SET transcription = ? WHERE id = ?";
                      int result = mysql_stmt_prepare(gUpdateStmt, statement, strlen(statement));  
                      if (result != 0) {
                          WriteToLog("prepare stmt failed");
                          continue;
                      }
       
                      std::cout << "Prepared statement\n";
       
                      /* Get the parameter count from the statement */
                      int param_count = mysql_stmt_param_count(gUpdateStmt);
                      std::cout << "Total parameters in UPDATE: " << param_count << "\n";
       
                      MYSQL_BIND bind[2];
       
                      memset(bind, 0, sizeof(bind));
       
                      bind[0].buffer_type = MYSQL_TYPE_STRING;
                      bind[0].buffer = (char *) results.c_str();
                      bind[0].is_null = 0;
                      unsigned long resultLength = results.length();
                      bind[0].length = &resultLength;
                      bind[0].buffer_length = resultLength + 1;
                      bind[1].buffer_type = MYSQL_TYPE_LONG;
                      const int id = atoi(row[1]);
                      bind[1].buffer = (char *) &id;
                      bind[1].is_null = 0;
                      bind[1].length = 0;
       
                      result = mysql_stmt_bind_param(gUpdateStmt, bind);
                      if (result != 0) {
                          WriteToLog("bind stmt bind failed");
                          continue;
                      }
                      
                      std::cout << "Bound '" << results << "', " << id << "\n";
       
                      result = mysql_stmt_execute(gUpdateStmt); 
                      if (result != 0) {
                          WriteToLog("execute stmt update failed");
                          std::cerr << mysql_stmt_error(gUpdateStmt) << "\n";
                          continue;
                      }
       
                      int affected_rows = mysql_stmt_affected_rows(gUpdateStmt);
                      std::cout << "Executed " << affected_rows << "\n";
      

      Attachments

        Activity

          People

            georg Georg Richter
            mattilinnanvuori Matti Linnanvuori
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.