~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: Stewart Smith
  • Date: 2008-12-16 23:22:36 UTC
  • mto: This revision was merged to the branch mainline in revision 711.
  • Revision ID: stewart@flamingspork.com-20081216232236-7zdqtm1dp2xwqr6a
remove global read_only (this should be the job of an auth plugin, not the kernel).

also remove now redundant tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
145
145
  return false;
146
146
}
147
147
 
148
 
 
149
 
static bool some_non_temp_table_to_be_updated(Session *session, TableList *tables)
150
 
{
151
 
  for (TableList *table= tables; table; table= table->next_global)
152
 
  {
153
 
    assert(table->db && table->table_name);
154
 
    if (table->updating &&
155
 
        !find_temporary_table(session, table->db, table->table_name))
156
 
      return 1;
157
 
  }
158
 
  return 0;
159
 
}
160
 
 
161
 
 
162
148
/**
163
149
  Mark all commands that somehow changes a table.
164
150
 
432
418
}
433
419
 
434
420
/**
435
 
  Determine if an attempt to update a non-temporary table while the
436
 
  read-only option was enabled has been made.
437
 
 
438
 
  This is a helper function to mysql_execute_command.
439
 
 
440
 
  @note SQLCOM_MULTI_UPDATE is an exception and dealt with elsewhere.
441
 
 
442
 
  @see mysql_execute_command
443
 
 
444
 
  @returns Status code
445
 
    @retval true The statement should be denied.
446
 
    @retval false The statement isn't updating any relevant tables.
447
 
*/
448
 
 
449
 
static bool deny_updates_if_read_only_option(Session *session,
450
 
                                                TableList *all_tables)
451
 
{
452
 
  if (!opt_readonly)
453
 
    return(false);
454
 
 
455
 
  LEX *lex= session->lex;
456
 
 
457
 
  if (!(sql_command_flags[lex->sql_command].test(CF_BIT_CHANGES_DATA)))
458
 
    return(false);
459
 
 
460
 
  /* Multi update is an exception and is dealt with later. */
461
 
  if (lex->sql_command == SQLCOM_UPDATE_MULTI)
462
 
    return(false);
463
 
 
464
 
  const bool create_temp_tables=
465
 
    (lex->sql_command == SQLCOM_CREATE_TABLE) &&
466
 
    (lex->create_info.options & HA_LEX_CREATE_TMP_TABLE);
467
 
 
468
 
  const bool drop_temp_tables=
469
 
    (lex->sql_command == SQLCOM_DROP_TABLE) &&
470
 
    lex->drop_temporary;
471
 
 
472
 
  const bool update_real_tables=
473
 
    some_non_temp_table_to_be_updated(session, all_tables) &&
474
 
    !(create_temp_tables || drop_temp_tables);
475
 
 
476
 
 
477
 
  const bool create_or_drop_databases=
478
 
    (lex->sql_command == SQLCOM_CREATE_DB) ||
479
 
    (lex->sql_command == SQLCOM_DROP_DB);
480
 
 
481
 
  if (update_real_tables || create_or_drop_databases)
482
 
  {
483
 
      /*
484
 
        An attempt was made to modify one or more non-temporary tables.
485
 
      */
486
 
      return(true);
487
 
  }
488
 
 
489
 
 
490
 
  /* Assuming that only temporary tables are modified. */
491
 
  return(false);
492
 
}
493
 
 
494
 
/**
495
421
  Perform one connection-level (COM_XXXX) command.
496
422
 
497
423
  @param command         type of command to perform
1141
1067
      return(0);
1142
1068
    }
1143
1069
  }
1144
 
  else
1145
 
  {
1146
 
    /*
1147
 
      When option readonly is set deny operations which change non-temporary
1148
 
      tables. Except for the replication thread and the 'super' users.
1149
 
    */
1150
 
    if (deny_updates_if_read_only_option(session, all_tables))
1151
 
    {
1152
 
      my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only");
1153
 
      return(-1);
1154
 
    }
1155
 
  } /* endif unlikely slave */
 
1070
 
1156
1071
  status_var_increment(session->status_var.com_stat[lex->sql_command]);
1157
1072
 
1158
1073
  assert(session->transaction.stmt.modified_non_trans_table == false);
1693
1608
    {
1694
1609
      if (res)
1695
1610
        break;
1696
 
      if (opt_readonly &&
1697
 
          some_non_temp_table_to_be_updated(session, all_tables))
1698
 
      {
1699
 
        my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only");
1700
 
        break;
1701
 
      }
 
1611
 
1702
1612
    }  /* unlikely */
1703
1613
 
1704
1614
    res= mysql_multi_update(session, all_tables,