Bug #6047 permission problem when executing mysql_stmt_execute with derived tables
Submitted: 12 Oct 2004 17:12 Modified: 22 Oct 2004 23:30
Reporter: Georg Richter Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1 OS:Linux (Linux)
Assigned to: Michael Widenius CPU Architecture:Any

[12 Oct 2004 17:12] Georg Richter
Description:
When using "UPDATE `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 
1) AS P2 ON P1.N = P2.N SET P1.M = 2" from derived.test with prepared statements 
mysql_stmt_execute fails with permission problem: 
 
Error in mysql_stmt_execute: Access denied for user ''@'localhost' to database '' 
 
The same statement works fine when using mysql_query. 

How to repeat:
#include <stdio.h> 
#include <mysql.h> 
 
int main () { 
  MYSQL       *mysql = mysql_init(NULL); 
  MYSQL_STMT     *stmt; 
  MYSQL_BIND    bind[1]; 
  char      query[500]; 
 
  int             b; 
 
  if (!mysql_real_connect(mysql, "localhost", "", "", "test", 0, NULL, 0)) { 
      printf("Can't connect! Error: %s\n", mysql_error(mysql)); 
      return 1; 
  } 
 
  mysql_query(mysql, "DROP TABLE IF EXISTS t1"); 
  mysql_query(mysql, "CREATE TABLE t1 (N int, M tinyint)"); 
  mysql_query(mysql, "INSERT INTO a1 VALUES (1,0),(1,0),(2,0),(2,0),(3,0)"); 
 
  stmt = mysql_stmt_init(mysql); 
    
  strcpy(query, "UPDATE t1 AS P1 INNER JOIN (SELECT N FROM t1 GROUP BY N HAVING Count(M) > 
1)" \ 
                "AS P2 ON P1.N = P2.N SET P1.M = 2"); 
 
  if (mysql_stmt_prepare(stmt, query, strlen(query))) { 
    printf("Error in mysql_stmt_prepare: %s\n", mysql_error(mysql)); 
    return 1; 
  } 
 
  if (mysql_stmt_execute(stmt)) { 
    printf("Error in mysql_stmt_execute: %s\n", mysql_stmt_error(stmt)); 
    return 1; 
  } 
 
  mysql_stmt_close(stmt); 
  mysql_close(mysql); 
}
[22 Oct 2004 23:30] Michael Widenius
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.mysql.com/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to 'Open'.

Thank you for your interest in MySQL.

Additional info:

I tried to repeat this in the current 4.1 tree but was not able to do that.
I did however create a test case for this in ps.test