~ubuntu-branches/ubuntu/maverick/mysql-dfsg-5.1/maverick

« back to all changes in this revision

Viewing changes to sql/sp.cc

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-05-18 22:22:44 UTC
  • mfrom: (1.1.5 upstream) (0.1.17 sid)
  • Revision ID: james.westby@ubuntu.com-20100518222244-xqu0aw6arb8x7uqs
Tags: 5.1.43-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/control:
    + Don't provide a libmysqlclient15-dev package as long as there
      are packages still build-depending on libmysqlclient15-dev and
      mysql-dfsg-5.0 is in the archive.
    + Lower mailx from a Recommends to a Suggests to avoid pulling in a
      full MTA on all installs of mysql-server (LP: #259477)
    + Make mysql-server-5.1 depend on mysql-server-core-5.1. (LP: #509667)
  - debian/rules:
  - debian/additions/debian-start.inc.sh: support ANSI mode (LP: #310211)
  - Add AppArmor profile:
    + debian/apparmor-profile: apparmor profile
    + debian/rules, debian/mysql-server-5.1.files: install apparmor profile.
    + debian/mysql-server-5.1.dirs: add etc/apparmor.d/fore-complain
    + debian/mysql-server-5.1.postrm: remove symlink in force-complain/ on purge.
    + debian/mysql-server-5.1.README.Debian: add apparmor documentation.
    + debian/additions/my.cnf: Add warning about apparmor. (LP: #201799)
    + debian/mysql-server-5.1.postinst: reload apparmor profiles
  - debian/additions/my.cfn: remove language options. Error message files are
    located in a different direction in Mysql 5.0. Setting the language option
    to use /usr/share/mysql/english breaks 5.0. Both 5.0 and 5.1 use a
    default value that works. (LP: #316974)
  - mysql-server-core-5.1 package for files needed by Akonadi:
    + debian/control: create mysql-server-core-5.1 package
    + debian/mysql-server-core-5.1.files, debian/mysql-server-5.1.files:
      move core mysqld files to mysql-server-core-5.1 package.
  - debian/libmysqlclient16.symbols.amd64: remove amd64 symbols as it has
    not been correctly generated in Debian.
  - Add Apport hook (LP: #354188):
    + debian/mysql-server-5.1.py: apport package hook
    + debian/mysql-server-5.1.files, debian/rules: install apport package hook
  - debian/addtions/my.cnf:
    + drop old_password option.
    + fix commentened logging options to use general_log and general_log_file.
  - Don't upgrade if there is an ndb management node configured (LP: #413792)
  - Set thread stack size to 192K rather than 128K. 128K is only useful on
    systems with < 64M RAM and causes stack overrides with some SQL commands.
    See http://dev.mysql.com/doc/refman/5.1/en/server-system-varriables.html
    for more details. (LP: #426919)
  - Convert to upstart:
    + Add mysql-server-5.1.mysql.upstart
    + Dropped debian/mysql-server-5.1.mysql.init,
      debian/additions/mysqld_safe_syslog.cnf
    + debian/additions/my.cnf:
      * Removed pid declaration
      * Set up error logging to /var/log/mysql since we're not piping anything
        around logger anymore.
    + Remove references to mysqld_safe in these files:
      * debian/rules, mysql-server-5.1.logcheck.ignore.paranoid
        mysql-server-5.1.logcheck.ignore.workstation,
        mysql-server-5.1.logcheck.ignore.server
    + debian/mysql-server-5.1.postinst:
      * Replace calls to /etc/init.d with regular upstart calls
      * Remove reference to mysqld_safe
    + Dropped debian/patches/38_scripts_mysqld_safe.sh_signals.dpatch
    + Load apparmor when loading upstart.
   - debian/mysql-server-5.1.mysql-server.logrotate: Check to see if mysql is running before
     running logrotate. (LP: #513135)
   - Make the testsuite installable. (LP: #530752)
   - debian/control: Use database for the package section (LP: #498939).
   - debian/mysql-server-5.1.templates: fix MySQL Cluster package name to
   - Move mysql_install_db and required .sql files from the server package to the 
     server-core package.
   - Dropped:
     + debian/patches/90_mysql_safer_strmov: Merged upstream.
     + debian/patches/52_CVE-2009-4030.dpatch: Merged usptream.
     + debian/patches/53_CVE-2009-4484.dpatch: Merged upstream.
     + debian/patches/54_CVE-2008-7247.dpatch: Merged upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
  MYSQL_PROC_FIELD_COUNT
71
71
};
72
72
 
 
73
static const
 
74
TABLE_FIELD_TYPE proc_table_fields[MYSQL_PROC_FIELD_COUNT] =
 
75
{
 
76
  {
 
77
    { C_STRING_WITH_LEN("db") },
 
78
    { C_STRING_WITH_LEN("char(64)") },
 
79
    { C_STRING_WITH_LEN("utf8") }
 
80
  },
 
81
  {
 
82
    { C_STRING_WITH_LEN("name") },
 
83
    { C_STRING_WITH_LEN("char(64)") },
 
84
    { C_STRING_WITH_LEN("utf8") }
 
85
  },
 
86
  {
 
87
    { C_STRING_WITH_LEN("type") },
 
88
    { C_STRING_WITH_LEN("enum('FUNCTION','PROCEDURE')") },
 
89
    { NULL, 0 }
 
90
  },
 
91
  {
 
92
    { C_STRING_WITH_LEN("specific_name") },
 
93
    { C_STRING_WITH_LEN("char(64)") },
 
94
    { C_STRING_WITH_LEN("utf8") }
 
95
  },
 
96
  {
 
97
    { C_STRING_WITH_LEN("language") },
 
98
    { C_STRING_WITH_LEN("enum('SQL')") },
 
99
    { NULL, 0 }
 
100
  },
 
101
  {
 
102
    { C_STRING_WITH_LEN("sql_data_access") },
 
103
    { C_STRING_WITH_LEN("enum('CONTAINS_SQL','NO_SQL','READS_SQL_DATA','MODIFIES_SQL_DATA')") },
 
104
    { NULL, 0 }
 
105
  },
 
106
  {
 
107
    { C_STRING_WITH_LEN("is_deterministic") },
 
108
    { C_STRING_WITH_LEN("enum('YES','NO')") },
 
109
    { NULL, 0 }
 
110
  },
 
111
  {
 
112
    { C_STRING_WITH_LEN("security_type") },
 
113
    { C_STRING_WITH_LEN("enum('INVOKER','DEFINER')") },
 
114
    { NULL, 0 }
 
115
  },
 
116
  {
 
117
    { C_STRING_WITH_LEN("param_list") },
 
118
    { C_STRING_WITH_LEN("blob") },
 
119
    { NULL, 0 }
 
120
  },
 
121
 
 
122
  {
 
123
    { C_STRING_WITH_LEN("returns") },
 
124
    { C_STRING_WITH_LEN("longblob") },
 
125
    { NULL, 0 }
 
126
  },
 
127
  {
 
128
    { C_STRING_WITH_LEN("body") },
 
129
    { C_STRING_WITH_LEN("longblob") },
 
130
    { NULL, 0 }
 
131
  },
 
132
  {
 
133
    { C_STRING_WITH_LEN("definer") },
 
134
    { C_STRING_WITH_LEN("char(77)") },
 
135
    { C_STRING_WITH_LEN("utf8") }
 
136
  },
 
137
  {
 
138
    { C_STRING_WITH_LEN("created") },
 
139
    { C_STRING_WITH_LEN("timestamp") },
 
140
    { NULL, 0 }
 
141
  },
 
142
  {
 
143
    { C_STRING_WITH_LEN("modified") },
 
144
    { C_STRING_WITH_LEN("timestamp") },
 
145
    { NULL, 0 }
 
146
  },
 
147
  {
 
148
    { C_STRING_WITH_LEN("sql_mode") },
 
149
    { C_STRING_WITH_LEN("set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES',"
 
150
    "'IGNORE_SPACE','NOT_USED','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION',"
 
151
    "'NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB',"
 
152
    "'NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40',"
 
153
    "'ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES',"
 
154
    "'STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES',"
 
155
    "'ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER',"
 
156
    "'HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH')") },
 
157
    { NULL, 0 }
 
158
  },
 
159
  {
 
160
    { C_STRING_WITH_LEN("comment") },
 
161
    { C_STRING_WITH_LEN("char(64)") },
 
162
    { C_STRING_WITH_LEN("utf8") }
 
163
  },
 
164
  {
 
165
    { C_STRING_WITH_LEN("character_set_client") },
 
166
    { C_STRING_WITH_LEN("char(32)") },
 
167
    { C_STRING_WITH_LEN("utf8") }
 
168
  },
 
169
  {
 
170
    { C_STRING_WITH_LEN("collation_connection") },
 
171
    { C_STRING_WITH_LEN("char(32)") },
 
172
    { C_STRING_WITH_LEN("utf8") }
 
173
  },
 
174
  {
 
175
    { C_STRING_WITH_LEN("db_collation") },
 
176
    { C_STRING_WITH_LEN("char(32)") },
 
177
    { C_STRING_WITH_LEN("utf8") }
 
178
  },
 
179
  {
 
180
    { C_STRING_WITH_LEN("body_utf8") },
 
181
    { C_STRING_WITH_LEN("longblob") },
 
182
    { NULL, 0 }
 
183
  }
 
184
};
 
185
 
 
186
static const TABLE_FIELD_DEF
 
187
  proc_table_def= {MYSQL_PROC_FIELD_COUNT, proc_table_fields};
 
188
 
73
189
/*************************************************************************/
74
190
 
75
191
/**
247
363
 
248
364
/*************************************************************************/
249
365
 
 
366
class Proc_table_intact : public Table_check_intact
 
367
{
 
368
private:
 
369
  bool m_print_once;
 
370
 
 
371
public:
 
372
  Proc_table_intact() : m_print_once(TRUE) {}
 
373
 
 
374
protected:
 
375
  void report_error(uint code, const char *fmt, ...);
 
376
};
 
377
 
 
378
 
 
379
/**
 
380
  Report failure to validate the mysql.proc table definition.
 
381
  Print a message to the error log only once.
 
382
*/
 
383
 
 
384
void Proc_table_intact::report_error(uint code, const char *fmt, ...)
 
385
{
 
386
  va_list args;
 
387
  char buf[512];
 
388
 
 
389
  va_start(args, fmt);
 
390
  my_vsnprintf(buf, sizeof(buf), fmt, args);
 
391
  va_end(args);
 
392
 
 
393
  if (code)
 
394
    my_message(code, buf, MYF(0));
 
395
  else
 
396
    my_error(ER_CANNOT_LOAD_FROM_TABLE, MYF(0), "proc");
 
397
 
 
398
  if (m_print_once)
 
399
  {
 
400
    m_print_once= FALSE;
 
401
    sql_print_error("%s", buf);
 
402
  }
 
403
};
 
404
 
 
405
 
 
406
/** Single instance used to control printing to the error log. */
 
407
static Proc_table_intact proc_table_intact;
 
408
 
 
409
 
250
410
/**
251
411
  Open the mysql.proc table for read.
252
412
 
266
426
  DBUG_ENTER("open_proc_table_for_read");
267
427
 
268
428
  TABLE_LIST table;
269
 
  bzero((char*) &table, sizeof(table));
270
 
  table.db= (char*) "mysql";
271
 
  table.table_name= table.alias= (char*)"proc";
272
 
  table.lock_type= TL_READ;
273
 
 
274
 
  if (!open_system_tables_for_read(thd, &table, backup))
 
429
  table.init_one_table("mysql", "proc", TL_READ);
 
430
 
 
431
  if (open_system_tables_for_read(thd, &table, backup))
 
432
    DBUG_RETURN(NULL);
 
433
 
 
434
  if (!proc_table_intact.check(table.table, &proc_table_def))
275
435
    DBUG_RETURN(table.table);
276
 
  else
277
 
    DBUG_RETURN(0);
 
436
 
 
437
  close_system_tables(thd, backup);
 
438
 
 
439
  DBUG_RETURN(NULL);
278
440
}
279
441
 
280
442
 
296
458
{
297
459
  DBUG_ENTER("open_proc_table_for_update");
298
460
 
299
 
  TABLE_LIST table;
300
 
  bzero((char*) &table, sizeof(table));
301
 
  table.db= (char*) "mysql";
302
 
  table.table_name= table.alias= (char*)"proc";
303
 
  table.lock_type= TL_WRITE;
304
 
 
305
 
  DBUG_RETURN(open_system_table_for_update(thd, &table));
 
461
  TABLE *table;
 
462
  TABLE_LIST table_list;
 
463
  table_list.init_one_table("mysql", "proc", TL_WRITE);
 
464
 
 
465
  if (!(table= open_system_table_for_update(thd, &table_list)))
 
466
    DBUG_RETURN(NULL);
 
467
 
 
468
  if (!proc_table_intact.check(table, &proc_table_def))
 
469
    DBUG_RETURN(table);
 
470
 
 
471
  close_thread_tables(thd);
 
472
 
 
473
  DBUG_RETURN(NULL);
306
474
}
307
475
 
308
476
 
732
900
  DBUG_PRINT("enter", ("type: %d  name: %.*s",type, (int) sp->m_name.length,
733
901
                       sp->m_name.str));
734
902
  String retstr(64);
 
903
  retstr.set_charset(system_charset_info);
735
904
 
736
905
  DBUG_ASSERT(type == TYPE_ENUM_PROCEDURE ||
737
906
              type == TYPE_ENUM_FUNCTION);
1235
1404
      64 -- size of "returns" column of mysql.proc.
1236
1405
    */
1237
1406
    String retstr(64);
 
1407
    retstr.set_charset(sp->get_creation_ctx()->get_client_cs());
1238
1408
 
1239
1409
    DBUG_PRINT("info", ("found: 0x%lx", (ulong)sp));
1240
1410
    if (sp->m_first_free_instance)
1506
1676
    rn->key.length= key->length;
1507
1677
    rn->key.str= (char *)rn + sizeof(Sroutine_hash_entry);
1508
1678
    memcpy(rn->key.str, key->str, key->length + 1);
1509
 
    my_hash_insert(&lex->sroutines, (uchar *)rn);
 
1679
    if (my_hash_insert(&lex->sroutines, (uchar *)rn))
 
1680
      return FALSE;
1510
1681
    lex->sroutines_list.link_in_list((uchar *)rn, (uchar **)&rn->next);
1511
1682
    rn->belong_to_view= belong_to_view;
1512
1683
    return TRUE;
1584
1755
    dependant on time of life of elements from source hash. It also
1585
1756
    won't touch lists linking elements in source and destination
1586
1757
    hashes.
 
1758
 
 
1759
  @returns
 
1760
    @return TRUE Failure
 
1761
    @return FALSE Success
1587
1762
*/
1588
1763
 
1589
 
void sp_update_sp_used_routines(HASH *dst, HASH *src)
 
1764
bool sp_update_sp_used_routines(HASH *dst, HASH *src)
1590
1765
{
1591
1766
  for (uint i=0 ; i < src->records ; i++)
1592
1767
  {
1593
1768
    Sroutine_hash_entry *rt= (Sroutine_hash_entry *)hash_element(src, i);
1594
1769
    if (!hash_search(dst, (uchar *)rt->key.str, rt->key.length))
1595
 
      my_hash_insert(dst, (uchar *)rt);
 
1770
    {
 
1771
      if (my_hash_insert(dst, (uchar *)rt))
 
1772
        return TRUE;
 
1773
    }
1596
1774
  }
 
1775
  return FALSE;
1597
1776
}
1598
1777
 
1599
1778